Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions crates/oxc_linter/src/generated/rule_runner_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions crates/oxc_linter/src/rules/eslint/no_magic_numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions crates/oxc_linter/src/rules/react/require_render_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 31 additions & 0 deletions tasks/linter_codegen/src/early_diverge_detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
}
}
Expand Down
Loading