diff --git a/crates/oxc_linter/src/generated/rule_runner_impls.rs b/crates/oxc_linter/src/generated/rule_runner_impls.rs index 32bd52da7d7e2..97c2629f10a4e 100644 --- a/crates/oxc_linter/src/generated/rule_runner_impls.rs +++ b/crates/oxc_linter/src/generated/rule_runner_impls.rs @@ -548,8 +548,9 @@ impl RuleRunner for crate::rules::eslint::no_object_constructor::NoObjectConstru } impl RuleRunner for crate::rules::eslint::no_param_reassign::NoParamReassign { - const NODE_TYPES: Option<&AstTypesBitset> = None; - const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::RunOnSymbol; + const NODE_TYPES: Option<&AstTypesBitset> = + Some(&AstTypesBitset::from_types(&[AstType::FormalParameter])); + const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run; } impl RuleRunner for crate::rules::eslint::no_plusplus::NoPlusplus { diff --git a/crates/oxc_linter/src/rules/eslint/no_param_reassign.rs b/crates/oxc_linter/src/rules/eslint/no_param_reassign.rs index 522b858af1771..fc8a5c89d5dba 100644 --- a/crates/oxc_linter/src/rules/eslint/no_param_reassign.rs +++ b/crates/oxc_linter/src/rules/eslint/no_param_reassign.rs @@ -6,14 +6,14 @@ use oxc_ast::{ ast::{ AssignmentExpression, AssignmentTargetPropertyIdentifier, AssignmentTargetPropertyProperty, CallExpression, ChainExpression, ComputedMemberExpression, ForInStatement, ForOfStatement, - FormalParameter, ObjectProperty, ParenthesizedExpression, StaticMemberExpression, - TSAsExpression, TSNonNullExpression, TSSatisfiesExpression, TSTypeAssertion, - UnaryExpression, UpdateExpression, + ObjectProperty, ParenthesizedExpression, StaticMemberExpression, TSAsExpression, + TSNonNullExpression, TSSatisfiesExpression, TSTypeAssertion, UnaryExpression, + UpdateExpression, }, }; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; -use oxc_semantic::{NodeId, Reference, SymbolId}; +use oxc_semantic::{AstNode, NodeId, Reference}; use oxc_span::{GetSpan, Span}; use oxc_syntax::operator::UnaryOperator; use serde_json::Value; @@ -112,55 +112,46 @@ impl Rule for NoParamReassign { rule } - fn run_on_symbol(&self, symbol_id: SymbolId, ctx: &LintContext<'_>) { - if !is_parameter_symbol(symbol_id, ctx) { + fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) { + let AstKind::FormalParameter(param) = node.kind() else { return; - } + }; let symbol_table = ctx.scoping(); - let declaration_id = symbol_table.symbol_declaration(symbol_id); - let name = symbol_table.symbol_name(symbol_id); + for ident in param.pattern.get_binding_identifiers() { + let Some(symbol_id) = ident.symbol_id.get() else { + continue; + }; - let mut seen_nodes: FxHashSet = FxHashSet::default(); + let declaration_id = symbol_table.symbol_declaration(symbol_id); + let name = symbol_table.symbol_name(symbol_id); - for reference in symbol_table.get_resolved_references(symbol_id) { - let node_id = reference.node_id(); - if !seen_nodes.insert(node_id) { - continue; - } + let mut seen_nodes: FxHashSet = FxHashSet::default(); - if ctx.nodes().ancestor_ids(node_id).any(|ancestor| ancestor == declaration_id) { - continue; - } + for reference in symbol_table.get_resolved_references(symbol_id) { + let node_id = reference.node_id(); + if !seen_nodes.insert(node_id) { + continue; + } - let span = ctx.semantic().reference_span(reference); + if ctx.nodes().ancestor_ids(node_id).any(|ancestor| ancestor == declaration_id) { + continue; + } - if reference.is_write() { - ctx.diagnostic(assignment_to_param_diagnostic(name, span)); - continue; - } + let span = ctx.semantic().reference_span(reference); - if self.0.props && !self.0.is_ignored(name) && is_modifying_property(reference, ctx) { - ctx.diagnostic(assignment_to_param_property_diagnostic(name, span)); - } - } - } -} + if reference.is_write() { + ctx.diagnostic(assignment_to_param_diagnostic(name, span)); + continue; + } -fn is_parameter_symbol(symbol_id: SymbolId, ctx: &LintContext<'_>) -> bool { - let declaration_id = ctx.scoping().symbol_declaration(symbol_id); - for ancestor_id in - std::iter::once(declaration_id).chain(ctx.nodes().ancestor_ids(declaration_id)) - { - match ctx.nodes().kind(ancestor_id) { - AstKind::FormalParameter(FormalParameter { .. }) => return true, - AstKind::Function(_) | AstKind::ArrowFunctionExpression(_) | AstKind::Program(_) => { - return false; + if self.0.props && !self.0.is_ignored(name) && is_modifying_property(reference, ctx) + { + ctx.diagnostic(assignment_to_param_property_diagnostic(name, span)); + } } - _ => {} } } - false } fn is_modifying_property(reference: &Reference, ctx: &LintContext<'_>) -> bool {