diff --git a/crates/oxc_linter/src/context.rs b/crates/oxc_linter/src/context.rs index 8db8b2436ace2..9bc9b00fcb5c3 100644 --- a/crates/oxc_linter/src/context.rs +++ b/crates/oxc_linter/src/context.rs @@ -7,6 +7,8 @@ use oxc_semantic::{AstNodes, JSDocFinder, ScopeTree, Semantic, SymbolTable}; use oxc_span::{GetSpan, SourceType, Span}; use oxc_syntax::module_record::ModuleRecord; +#[cfg(debug_assertions)] +use crate::rule::RuleFixMeta; use crate::{ config::OxlintRules, disable_directives::{DisableDirectives, DisableDirectivesBuilder}, @@ -41,6 +43,8 @@ pub struct LintContext<'a> { // states current_plugin_prefix: &'static str, current_rule_name: &'static str, + #[cfg(debug_assertions)] + current_rule_fix_capabilities: RuleFixMeta, /// Current rule severity. Allows for user severity overrides, e.g. /// ```json @@ -79,6 +83,8 @@ impl<'a> LintContext<'a> { eslint_config: Arc::new(OxlintConfig::default()), current_plugin_prefix: "eslint", current_rule_name: "", + #[cfg(debug_assertions)] + current_rule_fix_capabilities: RuleFixMeta::None, severity: Severity::Warning, frameworks: FrameworkFlags::empty(), } @@ -105,6 +111,12 @@ impl<'a> LintContext<'a> { self } + #[cfg(debug_assertions)] + pub fn with_rule_fix_capabilities(mut self, capabilities: RuleFixMeta) -> Self { + self.current_rule_fix_capabilities = capabilities; + self + } + pub fn with_severity(mut self, severity: AllowWarnDeny) -> Self { self.severity = Severity::from(severity); self @@ -296,24 +308,18 @@ impl<'a> LintContext<'a> { C: Into>, F: FnOnce(RuleFixer<'_, 'a>) -> C, { - // if let Some(accepted_fix_kind) = self.fix { - // let fixer = RuleFixer::new(fix_kind, self); - // let rule_fix: RuleFix<'a> = fix(fixer).into(); - // let diagnostic = match (rule_fix.message(), &diagnostic.help) { - // (Some(message), None) => diagnostic.with_help(message.to_owned()), - // _ => diagnostic, - // }; - // if rule_fix.kind() <= accepted_fix_kind { - // let fix = rule_fix.into_fix(self.source_text()); - // self.add_diagnostic(Message::new(diagnostic, Some(fix))); - // } else { - // self.diagnostic(diagnostic); - // } - // } else { - // self.diagnostic(diagnostic); - // } let fixer = RuleFixer::new(fix_kind, self); let rule_fix: RuleFix<'a> = fix(fixer).into(); + #[cfg(debug_assertions)] + { + assert!( + self.current_rule_fix_capabilities.supports_fix(fix_kind), + "Rule `{}` does not support safe fixes. Did you forget to update fix capabilities in declare_oxc_lint?.\n\tSupported fix kinds: {:?}\n\tAttempted fix kind: {:?}", + self.current_rule_name, + FixKind::from(self.current_rule_fix_capabilities), + rule_fix.kind() + ); + } let diagnostic = match (rule_fix.message(), &diagnostic.help) { (Some(message), None) => diagnostic.with_help(message.to_owned()), _ => diagnostic, diff --git a/crates/oxc_linter/src/lib.rs b/crates/oxc_linter/src/lib.rs index d52ab6b55cba4..db0a174f886d0 100644 --- a/crates/oxc_linter/src/lib.rs +++ b/crates/oxc_linter/src/lib.rs @@ -120,18 +120,7 @@ impl Linter { .rules .iter() .filter(|rule| rule.should_run(&ctx)) - .map(|rule| { - let rule_name = rule.name(); - let plugin_name = self.map_jest(rule.plugin_name(), rule_name); - - ( - rule, - ctx.clone() - .with_plugin_name(plugin_name) - .with_rule_name(rule_name) - .with_severity(rule.severity), - ) - }) + .map(|rule| (rule, self.ctx_for_rule(&ctx, rule))) .collect::>(); for (rule, ctx) in &rules { @@ -186,6 +175,18 @@ impl Linter { ctx } + fn ctx_for_rule<'a>(&self, ctx: &LintContext<'a>, rule: &RuleWithSeverity) -> LintContext<'a> { + let rule_name = rule.name(); + let plugin_name = self.map_jest(rule.plugin_name(), rule_name); + + #[cfg(debug_assertions)] + let ctx = ctx.clone().with_rule_fix_capabilities(rule.rule.fix()); + #[cfg(not(debug_assertions))] + let ctx = ctx.clone(); + + ctx.with_plugin_name(plugin_name).with_rule_name(rule_name).with_severity(rule.severity) + } + fn map_jest(&self, plugin_name: &'static str, rule_name: &str) -> &'static str { if self.options.vitest_plugin && plugin_name == "jest" diff --git a/crates/oxc_linter/src/rules/eslint/eqeqeq.rs b/crates/oxc_linter/src/rules/eslint/eqeqeq.rs index 0d18f279bbaef..2f58ede818c69 100644 --- a/crates/oxc_linter/src/rules/eslint/eqeqeq.rs +++ b/crates/oxc_linter/src/rules/eslint/eqeqeq.rs @@ -35,7 +35,8 @@ declare_oxc_lint!( /// a == b /// ``` Eqeqeq, - pedantic + pedantic, + conditional_fix ); impl Rule for Eqeqeq { diff --git a/crates/oxc_linter/src/rules/eslint/no_debugger.rs b/crates/oxc_linter/src/rules/eslint/no_debugger.rs index 7a2fa7146b27c..af14da3d0fe3c 100644 --- a/crates/oxc_linter/src/rules/eslint/no_debugger.rs +++ b/crates/oxc_linter/src/rules/eslint/no_debugger.rs @@ -27,7 +27,8 @@ declare_oxc_lint!( /// debugger; /// ``` NoDebugger, - correctness + correctness, + fix ); impl Rule for NoDebugger { diff --git a/crates/oxc_linter/src/rules/eslint/no_div_regex.rs b/crates/oxc_linter/src/rules/eslint/no_div_regex.rs index c71e1aabd1c32..1b748962e4306 100644 --- a/crates/oxc_linter/src/rules/eslint/no_div_regex.rs +++ b/crates/oxc_linter/src/rules/eslint/no_div_regex.rs @@ -30,6 +30,7 @@ declare_oxc_lint!( /// ``` NoDivRegex, restriction, + fix ); impl Rule for NoDivRegex { diff --git a/crates/oxc_linter/src/rules/eslint/no_unsafe_negation.rs b/crates/oxc_linter/src/rules/eslint/no_unsafe_negation.rs index 7b49b4657b4c9..71ea2319c58b3 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unsafe_negation.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unsafe_negation.rs @@ -39,7 +39,8 @@ declare_oxc_lint!( /// } /// ``` NoUnsafeNegation, - correctness + correctness, + fix ); impl Rule for NoUnsafeNegation { diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_labels.rs b/crates/oxc_linter/src/rules/eslint/no_unused_labels.rs index b7d6a73d9e1c2..496b5bc3cd303 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_labels.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_labels.rs @@ -35,7 +35,8 @@ declare_oxc_lint!( /// } /// ``` NoUnusedLabels, - correctness + correctness, + fix ); impl Rule for NoUnusedLabels { diff --git a/crates/oxc_linter/src/rules/eslint/no_useless_constructor.rs b/crates/oxc_linter/src/rules/eslint/no_useless_constructor.rs index f5aee8b854f0a..31f091792b2e4 100644 --- a/crates/oxc_linter/src/rules/eslint/no_useless_constructor.rs +++ b/crates/oxc_linter/src/rules/eslint/no_useless_constructor.rs @@ -78,6 +78,7 @@ declare_oxc_lint!( ///``` NoUselessConstructor, suspicious, + fix ); impl Rule for NoUselessConstructor { diff --git a/crates/oxc_linter/src/rules/eslint/no_useless_escape.rs b/crates/oxc_linter/src/rules/eslint/no_useless_escape.rs index a72931cbdd757..ffda849250af2 100644 --- a/crates/oxc_linter/src/rules/eslint/no_useless_escape.rs +++ b/crates/oxc_linter/src/rules/eslint/no_useless_escape.rs @@ -26,7 +26,8 @@ declare_oxc_lint!( /// ```javascript /// ``` NoUselessEscape, - correctness + correctness, + fix ); impl Rule for NoUselessEscape { diff --git a/crates/oxc_linter/src/rules/eslint/sort_imports.rs b/crates/oxc_linter/src/rules/eslint/sort_imports.rs index 5597f9094e664..e6f83c8c6c082 100644 --- a/crates/oxc_linter/src/rules/eslint/sort_imports.rs +++ b/crates/oxc_linter/src/rules/eslint/sort_imports.rs @@ -73,7 +73,8 @@ declare_oxc_lint!( /// import e from 'bar.js'; /// ``` SortImports, - style + style, + conditional_fix ); impl Rule for SortImports { diff --git a/crates/oxc_linter/src/rules/eslint/unicode_bom.rs b/crates/oxc_linter/src/rules/eslint/unicode_bom.rs index 2fa335d890654..d0d7596f361bf 100644 --- a/crates/oxc_linter/src/rules/eslint/unicode_bom.rs +++ b/crates/oxc_linter/src/rules/eslint/unicode_bom.rs @@ -40,6 +40,7 @@ declare_oxc_lint!( /// ``` UnicodeBom, restriction, + fix ); impl Rule for UnicodeBom { diff --git a/crates/oxc_linter/src/rules/eslint/use_isnan.rs b/crates/oxc_linter/src/rules/eslint/use_isnan.rs index 7ea3c5d1d12c7..52c4cd4d5b524 100644 --- a/crates/oxc_linter/src/rules/eslint/use_isnan.rs +++ b/crates/oxc_linter/src/rules/eslint/use_isnan.rs @@ -75,6 +75,7 @@ declare_oxc_lint!( /// ``` UseIsnan, correctness, + conditional_fix ); impl Rule for UseIsnan { diff --git a/crates/oxc_linter/src/rules/eslint/valid_typeof.rs b/crates/oxc_linter/src/rules/eslint/valid_typeof.rs index a323997380e66..4ac9d1fb35435 100644 --- a/crates/oxc_linter/src/rules/eslint/valid_typeof.rs +++ b/crates/oxc_linter/src/rules/eslint/valid_typeof.rs @@ -50,6 +50,7 @@ declare_oxc_lint!( /// ``` ValidTypeof, correctness, + conditional_fix ); impl Rule for ValidTypeof { diff --git a/crates/oxc_linter/src/rules/jest/consistent_test_it.rs b/crates/oxc_linter/src/rules/jest/consistent_test_it.rs index 25a13ec8580b0..926dabd77c469 100644 --- a/crates/oxc_linter/src/rules/jest/consistent_test_it.rs +++ b/crates/oxc_linter/src/rules/jest/consistent_test_it.rs @@ -164,6 +164,7 @@ declare_oxc_lint!( /// } ConsistentTestIt, style, + fix ); impl Rule for ConsistentTestIt { diff --git a/crates/oxc_linter/src/rules/jest/no_alias_methods.rs b/crates/oxc_linter/src/rules/jest/no_alias_methods.rs index a50a3b5954b1b..98ebe36f59bca 100644 --- a/crates/oxc_linter/src/rules/jest/no_alias_methods.rs +++ b/crates/oxc_linter/src/rules/jest/no_alias_methods.rs @@ -54,7 +54,8 @@ declare_oxc_lint!( /// } /// ``` NoAliasMethods, - style + style, + fix ); impl Rule for NoAliasMethods { diff --git a/crates/oxc_linter/src/rules/jest/no_deprecated_functions.rs b/crates/oxc_linter/src/rules/jest/no_deprecated_functions.rs index df238dd87bce7..2ad429d3ef276 100644 --- a/crates/oxc_linter/src/rules/jest/no_deprecated_functions.rs +++ b/crates/oxc_linter/src/rules/jest/no_deprecated_functions.rs @@ -75,6 +75,7 @@ declare_oxc_lint!( /// ``` NoDeprecatedFunctions, style, + fix ); const DEPRECATED_FUNCTIONS_MAP: Map<&'static str, (usize, &'static str)> = phf_map! { diff --git a/crates/oxc_linter/src/rules/jest/no_focused_tests.rs b/crates/oxc_linter/src/rules/jest/no_focused_tests.rs index e7a1b852154d9..ab25383aae116 100644 --- a/crates/oxc_linter/src/rules/jest/no_focused_tests.rs +++ b/crates/oxc_linter/src/rules/jest/no_focused_tests.rs @@ -61,7 +61,8 @@ declare_oxc_lint!( /// } /// ``` NoFocusedTests, - correctness + correctness, + fix ); impl Rule for NoFocusedTests { diff --git a/crates/oxc_linter/src/rules/jest/no_jasmine_globals.rs b/crates/oxc_linter/src/rules/jest/no_jasmine_globals.rs index 6f8f22423385a..7a49ee5e5c735 100644 --- a/crates/oxc_linter/src/rules/jest/no_jasmine_globals.rs +++ b/crates/oxc_linter/src/rules/jest/no_jasmine_globals.rs @@ -34,7 +34,8 @@ declare_oxc_lint!( /// }); /// ``` NoJasmineGlobals, - style + style, + conditional_fix ); const NON_JASMINE_PROPERTY_NAMES: [&str; 4] = ["spyOn", "spyOnProperty", "fail", "pending"]; diff --git a/crates/oxc_linter/src/rules/jest/no_test_prefixes.rs b/crates/oxc_linter/src/rules/jest/no_test_prefixes.rs index 433b9e2a93891..dcf49906ae113 100644 --- a/crates/oxc_linter/src/rules/jest/no_test_prefixes.rs +++ b/crates/oxc_linter/src/rules/jest/no_test_prefixes.rs @@ -53,7 +53,8 @@ declare_oxc_lint!( /// } /// ``` NoTestPrefixes, - style + style, + fix ); impl Rule for NoTestPrefixes { diff --git a/crates/oxc_linter/src/rules/jest/no_untyped_mock_factory.rs b/crates/oxc_linter/src/rules/jest/no_untyped_mock_factory.rs index bf7e98a73ce1a..d2943551cb84e 100644 --- a/crates/oxc_linter/src/rules/jest/no_untyped_mock_factory.rs +++ b/crates/oxc_linter/src/rules/jest/no_untyped_mock_factory.rs @@ -88,6 +88,7 @@ declare_oxc_lint!( /// NoUntypedMockFactory, style, + conditional_fix ); impl Rule for NoUntypedMockFactory { diff --git a/crates/oxc_linter/src/rules/jest/prefer_comparison_matcher.rs b/crates/oxc_linter/src/rules/jest/prefer_comparison_matcher.rs index 3d0a5b74b1c13..2d7b6fa90d753 100644 --- a/crates/oxc_linter/src/rules/jest/prefer_comparison_matcher.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_comparison_matcher.rs @@ -56,6 +56,7 @@ declare_oxc_lint!( /// PreferComparisonMatcher, style, + fix ); impl Rule for PreferComparisonMatcher { diff --git a/crates/oxc_linter/src/rules/jest/prefer_expect_resolves.rs b/crates/oxc_linter/src/rules/jest/prefer_expect_resolves.rs index ac3582842dd83..585b705812018 100644 --- a/crates/oxc_linter/src/rules/jest/prefer_expect_resolves.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_expect_resolves.rs @@ -72,6 +72,7 @@ declare_oxc_lint!( /// ``` PreferExpectResolves, style, + fix ); impl Rule for PreferExpectResolves { diff --git a/crates/oxc_linter/src/rules/jest/prefer_jest_mocked.rs b/crates/oxc_linter/src/rules/jest/prefer_jest_mocked.rs index 3822be1036ed2..2c69be0de12b2 100644 --- a/crates/oxc_linter/src/rules/jest/prefer_jest_mocked.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_jest_mocked.rs @@ -51,6 +51,7 @@ declare_oxc_lint!( /// ``` PreferJestMocked, style, + fix ); impl Rule for PreferJestMocked { diff --git a/crates/oxc_linter/src/rules/jest/prefer_lowercase_title.rs b/crates/oxc_linter/src/rules/jest/prefer_lowercase_title.rs index 756b722f394a4..bf18595235b67 100644 --- a/crates/oxc_linter/src/rules/jest/prefer_lowercase_title.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_lowercase_title.rs @@ -129,6 +129,7 @@ declare_oxc_lint!( /// PreferLowercaseTitle, style, + fix ); impl Rule for PreferLowercaseTitle { diff --git a/crates/oxc_linter/src/rules/jest/prefer_mock_promise_shorthand.rs b/crates/oxc_linter/src/rules/jest/prefer_mock_promise_shorthand.rs index 4f62a552e1dba..94036fbca6e37 100644 --- a/crates/oxc_linter/src/rules/jest/prefer_mock_promise_shorthand.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_mock_promise_shorthand.rs @@ -52,6 +52,7 @@ declare_oxc_lint!( /// PreferMockPromiseShorthand, style, + conditional_fix ); impl Rule for PreferMockPromiseShorthand { diff --git a/crates/oxc_linter/src/rules/jest/prefer_spy_on.rs b/crates/oxc_linter/src/rules/jest/prefer_spy_on.rs index c1a81a759c359..cd5d1859a1994 100644 --- a/crates/oxc_linter/src/rules/jest/prefer_spy_on.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_spy_on.rs @@ -53,6 +53,7 @@ declare_oxc_lint!( /// ``` PreferSpyOn, style, + fix ); impl Rule for PreferSpyOn { diff --git a/crates/oxc_linter/src/rules/jest/prefer_strict_equal.rs b/crates/oxc_linter/src/rules/jest/prefer_strict_equal.rs index 44e087c944432..0aef34e3d858a 100644 --- a/crates/oxc_linter/src/rules/jest/prefer_strict_equal.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_strict_equal.rs @@ -35,6 +35,7 @@ declare_oxc_lint!( /// PreferStrictEqual, style, + fix ); impl Rule for PreferStrictEqual { diff --git a/crates/oxc_linter/src/rules/jest/prefer_to_be.rs b/crates/oxc_linter/src/rules/jest/prefer_to_be.rs index c21c3b7438d60..6ab21b0c223f3 100644 --- a/crates/oxc_linter/src/rules/jest/prefer_to_be.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_to_be.rs @@ -66,6 +66,7 @@ declare_oxc_lint!( /// ``` PreferToBe, style, + fix ); #[derive(Clone, Debug, PartialEq)] diff --git a/crates/oxc_linter/src/rules/jest/prefer_to_have_length.rs b/crates/oxc_linter/src/rules/jest/prefer_to_have_length.rs index 62989af72c081..c8400f9457d36 100644 --- a/crates/oxc_linter/src/rules/jest/prefer_to_have_length.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_to_have_length.rs @@ -51,6 +51,7 @@ declare_oxc_lint!( /// PreferToHaveLength, style, + fix ); impl Rule for PreferToHaveLength { diff --git a/crates/oxc_linter/src/rules/jest/prefer_todo.rs b/crates/oxc_linter/src/rules/jest/prefer_todo.rs index 7b8b18369e350..6534d5b7559bc 100644 --- a/crates/oxc_linter/src/rules/jest/prefer_todo.rs +++ b/crates/oxc_linter/src/rules/jest/prefer_todo.rs @@ -47,6 +47,7 @@ declare_oxc_lint!( /// ``` PreferTodo, style, + fix ); impl Rule for PreferTodo { diff --git a/crates/oxc_linter/src/rules/jsx_a11y/aria_props.rs b/crates/oxc_linter/src/rules/jsx_a11y/aria_props.rs index 17da41c4ddd68..f11b525d75550 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/aria_props.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/aria_props.rs @@ -41,7 +41,8 @@ declare_oxc_lint!( /// /// ``` AriaProps, - correctness + correctness, + conditional_fix ); impl Rule for AriaProps { diff --git a/crates/oxc_linter/src/rules/jsx_a11y/no_autofocus.rs b/crates/oxc_linter/src/rules/jsx_a11y/no_autofocus.rs index 8d12077e77e67..4a8303f840213 100644 --- a/crates/oxc_linter/src/rules/jsx_a11y/no_autofocus.rs +++ b/crates/oxc_linter/src/rules/jsx_a11y/no_autofocus.rs @@ -58,7 +58,8 @@ declare_oxc_lint!( /// ``` /// NoAutofocus, - correctness + correctness, + fix ); impl NoAutofocus { diff --git a/crates/oxc_linter/src/rules/oxc/no_const_enum.rs b/crates/oxc_linter/src/rules/oxc/no_const_enum.rs index 63754946a1ffa..3cee8b2df9d41 100644 --- a/crates/oxc_linter/src/rules/oxc/no_const_enum.rs +++ b/crates/oxc_linter/src/rules/oxc/no_const_enum.rs @@ -36,6 +36,7 @@ declare_oxc_lint!( /// ``` NoConstEnum, restriction, + fix ); impl Rule for NoConstEnum { diff --git a/crates/oxc_linter/src/rules/promise/no_new_statics.rs b/crates/oxc_linter/src/rules/promise/no_new_statics.rs index 81bc870501533..2154fe36a8582 100644 --- a/crates/oxc_linter/src/rules/promise/no_new_statics.rs +++ b/crates/oxc_linter/src/rules/promise/no_new_statics.rs @@ -26,7 +26,8 @@ declare_oxc_lint!( /// new Promise.resolve(value); /// ``` NoNewStatics, - correctness + correctness, + fix ); impl Rule for NoNewStatics { diff --git a/crates/oxc_linter/src/rules/typescript/array_type.rs b/crates/oxc_linter/src/rules/typescript/array_type.rs index b175de4d23b32..c05cb425e9c62 100644 --- a/crates/oxc_linter/src/rules/typescript/array_type.rs +++ b/crates/oxc_linter/src/rules/typescript/array_type.rs @@ -26,6 +26,7 @@ declare_oxc_lint!( /// ``` ArrayType, style, + fix ); fn generic(x0: &str, x1: &str, x2: &str, span3: Span) -> OxcDiagnostic { diff --git a/crates/oxc_linter/src/rules/typescript/ban_ts_comment.rs b/crates/oxc_linter/src/rules/typescript/ban_ts_comment.rs index b3a2c50452cbc..1d53581df9c2f 100644 --- a/crates/oxc_linter/src/rules/typescript/ban_ts_comment.rs +++ b/crates/oxc_linter/src/rules/typescript/ban_ts_comment.rs @@ -109,7 +109,8 @@ declare_oxc_lint!( /// } /// ``` BanTsComment, - pedantic + pedantic, + conditional_fix ); impl Rule for BanTsComment { diff --git a/crates/oxc_linter/src/rules/typescript/ban_tslint_comment.rs b/crates/oxc_linter/src/rules/typescript/ban_tslint_comment.rs index d5ac94b2f6f59..ded9a04039de8 100644 --- a/crates/oxc_linter/src/rules/typescript/ban_tslint_comment.rs +++ b/crates/oxc_linter/src/rules/typescript/ban_tslint_comment.rs @@ -27,7 +27,8 @@ declare_oxc_lint!( /// someCode(); /// ``` BanTslintComment, - style + style, + fix ); impl Rule for BanTslintComment { diff --git a/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs b/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs index 3457ec9239c52..9a99f55837056 100644 --- a/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs +++ b/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs @@ -53,7 +53,8 @@ declare_oxc_lint!( /// type Foo = Record; /// ``` ConsistentIndexedObjectStyle, - style + style, + conditional_fix ); impl Rule for ConsistentIndexedObjectStyle { diff --git a/crates/oxc_linter/src/rules/typescript/consistent_type_definitions.rs b/crates/oxc_linter/src/rules/typescript/consistent_type_definitions.rs index ddad23a22432c..53c0b8d6dbd6f 100644 --- a/crates/oxc_linter/src/rules/typescript/consistent_type_definitions.rs +++ b/crates/oxc_linter/src/rules/typescript/consistent_type_definitions.rs @@ -48,7 +48,8 @@ declare_oxc_lint!( /// } /// ``` ConsistentTypeDefinitions, - style + style, + fix ); impl Rule for ConsistentTypeDefinitions { diff --git a/crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs b/crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs index 097c4be7da957..1b0f55c57b5f6 100644 --- a/crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs +++ b/crates/oxc_linter/src/rules/typescript/consistent_type_imports.rs @@ -103,6 +103,7 @@ declare_oxc_lint!( /// ``` ConsistentTypeImports, nursery, + conditional_fix ); impl Rule for ConsistentTypeImports { diff --git a/crates/oxc_linter/src/rules/typescript/no_explicit_any.rs b/crates/oxc_linter/src/rules/typescript/no_explicit_any.rs index c9c5141b87d2c..06f220e3f93da 100644 --- a/crates/oxc_linter/src/rules/typescript/no_explicit_any.rs +++ b/crates/oxc_linter/src/rules/typescript/no_explicit_any.rs @@ -82,7 +82,8 @@ declare_oxc_lint!( /// Whether to enable auto-fixing in which the `any` type is converted to the `unknown` type. /// `false` by default. NoExplicitAny, - restriction + restriction, + conditional_fix ); impl Rule for NoExplicitAny { diff --git a/crates/oxc_linter/src/rules/typescript/no_import_type_side_effects.rs b/crates/oxc_linter/src/rules/typescript/no_import_type_side_effects.rs index 047ba524a01f7..74b9230645dd1 100644 --- a/crates/oxc_linter/src/rules/typescript/no_import_type_side_effects.rs +++ b/crates/oxc_linter/src/rules/typescript/no_import_type_side_effects.rs @@ -52,6 +52,7 @@ declare_oxc_lint!( /// ``` NoImportTypeSideEffects, restriction, + fix ); impl Rule for NoImportTypeSideEffects { diff --git a/crates/oxc_linter/src/rules/typescript/no_useless_empty_export.rs b/crates/oxc_linter/src/rules/typescript/no_useless_empty_export.rs index c26a8246e331f..b5344493cbf9f 100644 --- a/crates/oxc_linter/src/rules/typescript/no_useless_empty_export.rs +++ b/crates/oxc_linter/src/rules/typescript/no_useless_empty_export.rs @@ -33,7 +33,8 @@ declare_oxc_lint!( /// ``` /// NoUselessEmptyExport, - correctness + correctness, + fix ); impl Rule for NoUselessEmptyExport { diff --git a/crates/oxc_linter/src/rules/typescript/prefer_as_const.rs b/crates/oxc_linter/src/rules/typescript/prefer_as_const.rs index 1b7ada4315900..c4f1d0ce6c7ef 100644 --- a/crates/oxc_linter/src/rules/typescript/prefer_as_const.rs +++ b/crates/oxc_linter/src/rules/typescript/prefer_as_const.rs @@ -35,7 +35,8 @@ declare_oxc_lint!( /// let foo = { bar: 'baz' as 'baz' }; /// ``` PreferAsConst, - correctness + correctness, + conditional_fix ); impl Rule for PreferAsConst { diff --git a/crates/oxc_linter/src/rules/typescript/prefer_function_type.rs b/crates/oxc_linter/src/rules/typescript/prefer_function_type.rs index a689644b3dd06..93834a184ca0b 100644 --- a/crates/oxc_linter/src/rules/typescript/prefer_function_type.rs +++ b/crates/oxc_linter/src/rules/typescript/prefer_function_type.rs @@ -74,7 +74,8 @@ declare_oxc_lint!( /// type Intersection = ((data: string) => number) & ((id: number) => string); /// ``` PreferFunctionType, - style + style, + conditional_fix ); fn has_one_super_type(decl: &TSInterfaceDeclaration) -> bool { diff --git a/crates/oxc_linter/src/rules/typescript/prefer_namespace_keyword.rs b/crates/oxc_linter/src/rules/typescript/prefer_namespace_keyword.rs index 1cc117533b414..aaa3abff1cc9c 100644 --- a/crates/oxc_linter/src/rules/typescript/prefer_namespace_keyword.rs +++ b/crates/oxc_linter/src/rules/typescript/prefer_namespace_keyword.rs @@ -30,7 +30,8 @@ declare_oxc_lint!( /// module Example {} /// ``` PreferNamespaceKeyword, - style + style, + fix ); impl Rule for PreferNamespaceKeyword { diff --git a/crates/oxc_linter/src/rules/typescript/prefer_ts_expect_error.rs b/crates/oxc_linter/src/rules/typescript/prefer_ts_expect_error.rs index 737e3b7c6429a..b59ac0690c304 100644 --- a/crates/oxc_linter/src/rules/typescript/prefer_ts_expect_error.rs +++ b/crates/oxc_linter/src/rules/typescript/prefer_ts_expect_error.rs @@ -38,7 +38,8 @@ declare_oxc_lint!( /// const multiLine: number = 'value'; /// ``` PreferTsExpectError, - pedantic + pedantic, + fix ); impl Rule for PreferTsExpectError { diff --git a/crates/oxc_linter/src/rules/unicorn/empty_brace_spaces.rs b/crates/oxc_linter/src/rules/unicorn/empty_brace_spaces.rs index a4311665a98ea..1aaadc673a9f1 100644 --- a/crates/oxc_linter/src/rules/unicorn/empty_brace_spaces.rs +++ b/crates/oxc_linter/src/rules/unicorn/empty_brace_spaces.rs @@ -28,7 +28,8 @@ declare_oxc_lint!( /// } /// ``` EmptyBraceSpaces, - style + style, + fix ); impl Rule for EmptyBraceSpaces { diff --git a/crates/oxc_linter/src/rules/unicorn/escape_case.rs b/crates/oxc_linter/src/rules/unicorn/escape_case.rs index 546254415610d..04635d80a66e5 100644 --- a/crates/oxc_linter/src/rules/unicorn/escape_case.rs +++ b/crates/oxc_linter/src/rules/unicorn/escape_case.rs @@ -37,7 +37,8 @@ declare_oxc_lint!( /// const foo = '\cA'; /// ``` EscapeCase, - pedantic + pedantic, + fix ); fn is_hex_char(c: char) -> bool { diff --git a/crates/oxc_linter/src/rules/unicorn/explicit_length_check.rs b/crates/oxc_linter/src/rules/unicorn/explicit_length_check.rs index b24b0b0f0f70a..27cbe365ed1ab 100644 --- a/crates/oxc_linter/src/rules/unicorn/explicit_length_check.rs +++ b/crates/oxc_linter/src/rules/unicorn/explicit_length_check.rs @@ -77,7 +77,8 @@ declare_oxc_lint!( /// const isEmpty = foo.length === 0; /// ``` ExplicitLengthCheck, - pedantic + pedantic, + conditional_fix ); fn is_literal(expr: &Expression, value: f64) -> bool { matches!(expr, Expression::NumericLiteral(lit) if (lit.value - value).abs() < f64::EPSILON) diff --git a/crates/oxc_linter/src/rules/unicorn/no_console_spaces.rs b/crates/oxc_linter/src/rules/unicorn/no_console_spaces.rs index 35a437fc078d0..ae9657cbe9310 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_console_spaces.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_console_spaces.rs @@ -41,7 +41,8 @@ declare_oxc_lint!( /// /// ``` NoConsoleSpaces, - style + style, + fix ); impl Rule for NoConsoleSpaces { diff --git a/crates/oxc_linter/src/rules/unicorn/no_hex_escape.rs b/crates/oxc_linter/src/rules/unicorn/no_hex_escape.rs index e8b721cb9f90a..52780a6fbcc58 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_hex_escape.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_hex_escape.rs @@ -31,7 +31,8 @@ declare_oxc_lint!( /// const foo = `\u001B${bar}`; /// ``` NoHexEscape, - pedantic + pedantic, + fix ); // \x -> \u00 diff --git a/crates/oxc_linter/src/rules/unicorn/no_instanceof_array.rs b/crates/oxc_linter/src/rules/unicorn/no_instanceof_array.rs index 488ae40fab824..d619ff99cc540 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_instanceof_array.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_instanceof_array.rs @@ -28,7 +28,8 @@ declare_oxc_lint!( /// [1,2,3] instanceof Array; /// ``` NoInstanceofArray, - pedantic + pedantic, + fix ); impl Rule for NoInstanceofArray { diff --git a/crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs b/crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs index 0f5d2b0018ad5..616adc4b7eca6 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_nested_ternary.rs @@ -39,7 +39,8 @@ declare_oxc_lint!( /// const foo = i > 5 ? (i < 100 ? true : false) : (i < 100 ? true : false); /// ``` NoNestedTernary, - restriction + restriction, + conditional_fix ); impl Rule for NoNestedTernary { diff --git a/crates/oxc_linter/src/rules/unicorn/no_null.rs b/crates/oxc_linter/src/rules/unicorn/no_null.rs index 1ed6c23b82cef..8ca9f9afb8de9 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_null.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_null.rs @@ -55,7 +55,8 @@ declare_oxc_lint!( /// let foo /// ``` NoNull, - style + style, + fix ); fn match_null_arg(call_expr: &CallExpression, index: usize, span: Span) -> bool { diff --git a/crates/oxc_linter/src/rules/unicorn/no_single_promise_in_promise_methods.rs b/crates/oxc_linter/src/rules/unicorn/no_single_promise_in_promise_methods.rs index adf45fa9c150b..2aa873898401c 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_single_promise_in_promise_methods.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_single_promise_in_promise_methods.rs @@ -50,7 +50,8 @@ declare_oxc_lint!( /// ``` /// NoSinglePromiseInPromiseMethods, - correctness + correctness, + conditional_fix ); impl Rule for NoSinglePromiseInPromiseMethods { diff --git a/crates/oxc_linter/src/rules/unicorn/no_unnecessary_await.rs b/crates/oxc_linter/src/rules/unicorn/no_unnecessary_await.rs index 6f8845ec54ac7..8b89895c73f2e 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_unnecessary_await.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_unnecessary_await.rs @@ -26,7 +26,8 @@ declare_oxc_lint!( /// await await promise; /// ``` NoUnnecessaryAwait, - correctness + correctness, + conditional_fix ); impl Rule for NoUnnecessaryAwait { diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_fallback_in_spread.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_fallback_in_spread.rs index 2cb432a743da4..e9399c44b3c1a 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_fallback_in_spread.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_fallback_in_spread.rs @@ -35,7 +35,8 @@ declare_oxc_lint!( /// /// ``` NoUselessFallbackInSpread, - correctness + correctness, + conditional_fix ); impl Rule for NoUselessFallbackInSpread { diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_promise_resolve_reject.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_promise_resolve_reject.rs index fbbaa9b781d36..417d171e6ac4e 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_promise_resolve_reject.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_promise_resolve_reject.rs @@ -47,7 +47,8 @@ declare_oxc_lint!( /// async () => bar; /// ``` NoUselessPromiseResolveReject, - pedantic + pedantic, + fix ); impl Rule for NoUselessPromiseResolveReject { diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_spread.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_spread.rs index 5d64b8fde4850..264e4a9e184e9 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_spread.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_spread.rs @@ -127,7 +127,8 @@ declare_oxc_lint!( /// /// ``` NoUselessSpread, - correctness + correctness, + conditional_fix ); impl Rule for NoUselessSpread { diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs index b9022e5e3ec60..f9205ee0fb11e 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs @@ -47,6 +47,7 @@ declare_oxc_lint!( /// ``` NoUselessUndefined, pedantic, + fix ); // Create a static set for all function names diff --git a/crates/oxc_linter/src/rules/unicorn/no_zero_fractions.rs b/crates/oxc_linter/src/rules/unicorn/no_zero_fractions.rs index 3872921bd0f60..38ae865d503e8 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_zero_fractions.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_zero_fractions.rs @@ -43,7 +43,8 @@ declare_oxc_lint!( /// const foo = 1.1; /// ``` NoZeroFractions, - style + style, + fix ); impl Rule for NoZeroFractions { diff --git a/crates/oxc_linter/src/rules/unicorn/number_literal_case.rs b/crates/oxc_linter/src/rules/unicorn/number_literal_case.rs index 6b4c17e3a6dd4..c39e4b8807d88 100644 --- a/crates/oxc_linter/src/rules/unicorn/number_literal_case.rs +++ b/crates/oxc_linter/src/rules/unicorn/number_literal_case.rs @@ -67,7 +67,8 @@ declare_oxc_lint!( /// const foo = 2e+5; /// ``` NumberLiteralCase, - style + style, + fix ); impl Rule for NumberLiteralCase { diff --git a/crates/oxc_linter/src/rules/unicorn/numeric_separators_style.rs b/crates/oxc_linter/src/rules/unicorn/numeric_separators_style.rs index 162e2640adaa9..c13413e2c7a55 100644 --- a/crates/oxc_linter/src/rules/unicorn/numeric_separators_style.rs +++ b/crates/oxc_linter/src/rules/unicorn/numeric_separators_style.rs @@ -79,7 +79,8 @@ declare_oxc_lint!( /// ]; /// ``` NumericSeparatorsStyle, - style + style, + fix ); impl Rule for NumericSeparatorsStyle { diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_code_point.rs b/crates/oxc_linter/src/rules/unicorn/prefer_code_point.rs index 1867ebed96ccd..42e0f68b93625 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_code_point.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_code_point.rs @@ -37,7 +37,8 @@ declare_oxc_lint!( /// String.fromCodePoint(0x1f984); /// ``` PreferCodePoint, - pedantic + pedantic, + fix ); impl Rule for PreferCodePoint { diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs index afd40268ce271..e93a3898f0abd 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_append.rs @@ -33,7 +33,8 @@ declare_oxc_lint!( // /// ``` PreferDomNodeAppend, - pedantic + pedantic, + fix ); impl Rule for PreferDomNodeAppend { diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_text_content.rs b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_text_content.rs index cee899f4e7e4f..d7ea3483c98f2 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_text_content.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_text_content.rs @@ -35,7 +35,8 @@ declare_oxc_lint!( /// const text = foo.textContent; /// ``` PreferDomNodeTextContent, - style + style, + conditional_fix ); impl Rule for PreferDomNodeTextContent { diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_node_protocol.rs b/crates/oxc_linter/src/rules/unicorn/prefer_node_protocol.rs index 3afe4274755c5..772c344502e78 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_node_protocol.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_node_protocol.rs @@ -31,7 +31,8 @@ declare_oxc_lint!( /// import fs from "node:fs"; /// ``` PreferNodeProtocol, - restriction + restriction, + fix ); impl Rule for PreferNodeProtocol { diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs b/crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs index 13edb47603e43..50d23fd8ce1ed 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_prototype_methods.rs @@ -44,7 +44,8 @@ declare_oxc_lint!( /// const maxValue = Math.max.apply(Math, numbers); /// ``` PreferPrototypeMethods, - pedantic + pedantic, + fix ); impl Rule for PreferPrototypeMethods { diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_query_selector.rs b/crates/oxc_linter/src/rules/unicorn/prefer_query_selector.rs index f80fa527792d2..ca382444cc6d5 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_query_selector.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_query_selector.rs @@ -43,7 +43,8 @@ declare_oxc_lint!( /// document.querySelector('li').querySelectorAll('a'); /// ``` PreferQuerySelector, - pedantic + pedantic, + conditional_fix ); impl Rule for PreferQuerySelector { diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_spread.rs b/crates/oxc_linter/src/rules/unicorn/prefer_spread.rs index 6b3a599fe0c2d..df57a817fe164 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_spread.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_spread.rs @@ -37,7 +37,8 @@ declare_oxc_lint!( /// /// ``` PreferSpread, - style + style, + conditional_fix ); impl Rule for PreferSpread { diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_string_starts_ends_with.rs b/crates/oxc_linter/src/rules/unicorn/prefer_string_starts_ends_with.rs index 3df52d5bb8c63..5eef4e5322a9b 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_string_starts_ends_with.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_string_starts_ends_with.rs @@ -44,7 +44,8 @@ declare_oxc_lint!( /// foo.startsWith("abc"); /// ``` PreferStringStartsEndsWith, - correctness + correctness, + fix ); impl Rule for PreferStringStartsEndsWith { diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_string_trim_start_end.rs b/crates/oxc_linter/src/rules/unicorn/prefer_string_trim_start_end.rs index ded40e6d82457..116e193d8d095 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_string_trim_start_end.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_string_trim_start_end.rs @@ -34,7 +34,8 @@ declare_oxc_lint!( /// str.trimEnd(); /// ``` PreferStringTrimStartEnd, - style + style, + fix ); impl Rule for PreferStringTrimStartEnd { diff --git a/crates/oxc_linter/src/rules/unicorn/require_number_to_fixed_digits_argument.rs b/crates/oxc_linter/src/rules/unicorn/require_number_to_fixed_digits_argument.rs index 24b76637121e8..02be98b85bfb6 100644 --- a/crates/oxc_linter/src/rules/unicorn/require_number_to_fixed_digits_argument.rs +++ b/crates/oxc_linter/src/rules/unicorn/require_number_to_fixed_digits_argument.rs @@ -32,7 +32,8 @@ declare_oxc_lint!( /// number.toFixed(); /// ``` RequireNumberToFixedDigitsArgument, - pedantic + pedantic, + fix ); impl Rule for RequireNumberToFixedDigitsArgument { diff --git a/crates/oxc_linter/src/rules/unicorn/switch_case_braces.rs b/crates/oxc_linter/src/rules/unicorn/switch_case_braces.rs index 73efed6a6b8cc..d0b2e9f60c479 100644 --- a/crates/oxc_linter/src/rules/unicorn/switch_case_braces.rs +++ b/crates/oxc_linter/src/rules/unicorn/switch_case_braces.rs @@ -35,7 +35,8 @@ declare_oxc_lint!( /// } /// ``` SwitchCaseBraces, - style + style, + fix ); impl Rule for SwitchCaseBraces { diff --git a/crates/oxc_linter/src/rules/vitest/no_import_node_test.rs b/crates/oxc_linter/src/rules/vitest/no_import_node_test.rs index b7a1f55fbcf60..bd31ab5401daa 100644 --- a/crates/oxc_linter/src/rules/vitest/no_import_node_test.rs +++ b/crates/oxc_linter/src/rules/vitest/no_import_node_test.rs @@ -40,6 +40,7 @@ declare_oxc_lint!( /// ``` NoImportNodeTest, style, + fix ); impl Rule for NoImportNodeTest {