diff --git a/crates/oxc_linter/src/generated/rule_runner_impls.rs b/crates/oxc_linter/src/generated/rule_runner_impls.rs index 2b7ec46550f78..5d991622066bf 100644 --- a/crates/oxc_linter/src/generated/rule_runner_impls.rs +++ b/crates/oxc_linter/src/generated/rule_runner_impls.rs @@ -484,7 +484,8 @@ impl RuleRunner for crate::rules::eslint::no_loss_of_precision::NoLossOfPrecisio } impl RuleRunner for crate::rules::eslint::no_magic_numbers::NoMagicNumbers { - const NODE_TYPES: Option<&AstTypesBitset> = None; + const NODE_TYPES: Option<&AstTypesBitset> = + Some(&AstTypesBitset::from_types(&[AstType::BigIntLiteral, AstType::NumericLiteral])); const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run; } @@ -2307,7 +2308,8 @@ impl RuleRunner for crate::rules::react::react_in_jsx_scope::ReactInJsxScope { } impl RuleRunner for crate::rules::react::require_render_return::RequireRenderReturn { - const NODE_TYPES: Option<&AstTypesBitset> = None; + const NODE_TYPES: Option<&AstTypesBitset> = + Some(&AstTypesBitset::from_types(&[AstType::ArrowFunctionExpression, AstType::Function])); const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run; } @@ -2939,7 +2941,8 @@ impl RuleRunner for crate::rules::unicorn::empty_brace_spaces::EmptyBraceSpaces } impl RuleRunner for crate::rules::unicorn::error_message::ErrorMessage { - const NODE_TYPES: Option<&AstTypesBitset> = None; + const NODE_TYPES: Option<&AstTypesBitset> = + Some(&AstTypesBitset::from_types(&[AstType::CallExpression, AstType::NewExpression])); const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run; } @@ -3270,7 +3273,8 @@ impl RuleRunner } impl RuleRunner for crate::rules::unicorn::no_useless_spread::NoUselessSpread { - const NODE_TYPES: Option<&AstTypesBitset> = None; + const NODE_TYPES: Option<&AstTypesBitset> = + Some(&AstTypesBitset::from_types(&[AstType::ArrayExpression, AstType::ObjectExpression])); const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run; } diff --git a/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs b/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs index 403c034c8ef92..51e07d2c9562e 100644 --- a/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs +++ b/crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs @@ -289,8 +289,9 @@ impl Rule for NoMagicNumbers { } fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if !matches!(node.kind(), AstKind::NumericLiteral(_) | AstKind::BigIntLiteral(_)) { - return; + match node.kind() { + AstKind::NumericLiteral(_) | AstKind::BigIntLiteral(_) => {} + _ => return, } let nodes = ctx.nodes(); diff --git a/crates/oxc_linter/src/rules/react/require_render_return.rs b/crates/oxc_linter/src/rules/react/require_render_return.rs index ac64a679b269c..5cf813fe480d8 100644 --- a/crates/oxc_linter/src/rules/react/require_render_return.rs +++ b/crates/oxc_linter/src/rules/react/require_render_return.rs @@ -70,9 +70,11 @@ declare_oxc_lint!( impl Rule for RequireRenderReturn { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if !matches!(node.kind(), AstKind::ArrowFunctionExpression(_) | AstKind::Function(_)) { - return; + match node.kind() { + AstKind::ArrowFunctionExpression(_) | AstKind::Function(_) => {} + _ => return, } + let parent = ctx.nodes().parent_node(node.id()); if !is_render_fn(parent) { return; diff --git a/crates/oxc_linter/src/rules/typescript/explicit_function_return_type.rs b/crates/oxc_linter/src/rules/typescript/explicit_function_return_type.rs index 8d6ff189c90b6..2c1e86aa3997c 100644 --- a/crates/oxc_linter/src/rules/typescript/explicit_function_return_type.rs +++ b/crates/oxc_linter/src/rules/typescript/explicit_function_return_type.rs @@ -722,9 +722,6 @@ fn check_return_statements<'a>(statements: &'a [Statement<'a>]) -> bool { * ``` */ fn is_property_of_object_with_type(node: &AstNode, ctx: &LintContext) -> bool { - if !matches!(node.kind(), AstKind::ObjectProperty(_)) { - return false; - } if !matches!(node.kind(), AstKind::ObjectProperty(_)) { return false; } diff --git a/crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs b/crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs index 8828714454e61..c262bcdddc336 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_useless_spread/mod.rs @@ -145,8 +145,9 @@ declare_oxc_lint!( impl Rule for NoUselessSpread { fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { - if !matches!(node.kind(), AstKind::ArrayExpression(_) | AstKind::ObjectExpression(_)) { - return; + match node.kind() { + AstKind::ArrayExpression(_) | AstKind::ObjectExpression(_) => {} + _ => return, } if check_useless_spread_in_list(node, ctx) { diff --git a/tasks/linter_codegen/src/early_diverge_detector.rs b/tasks/linter_codegen/src/early_diverge_detector.rs index 1f01e4990d56c..2fe51f5eaf344 100644 --- a/tasks/linter_codegen/src/early_diverge_detector.rs +++ b/tasks/linter_codegen/src/early_diverge_detector.rs @@ -34,6 +34,17 @@ impl EarlyDivergeDetector { } return Some(detector.node_types); } + // Stand-alone `match node.kind() { ... }` that diverges + else if let Stmt::Expr(Expr::Match(match_expr), _) = stmt + && is_node_kind_call(&match_expr.expr) + { + let mut detector = Self { node_types: NodeTypeSet::new() }; + let result = detector.extract_variants_from_diverging_match_expr(match_expr); + if result == CollectionResult::Incomplete || detector.node_types.is_empty() { + return None; + } + return Some(detector.node_types); + } None } @@ -72,6 +83,26 @@ impl EarlyDivergeDetector { } CollectionResult::Incomplete } + Pat::Or(or) => { + let mut overall_result = CollectionResult::Complete; + for case in &or.cases { + let result = match case { + Pat::TupleStruct(ts) => { + if let Some(variant) = astkind_variant_from_path(&ts.path) { + self.node_types.insert(variant); + CollectionResult::Complete + } else { + CollectionResult::Incomplete + } + } + _ => CollectionResult::Incomplete, + }; + if result == CollectionResult::Incomplete { + overall_result = CollectionResult::Incomplete; + } + } + overall_result + } _ => CollectionResult::Incomplete, } }