diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/fix_symbol.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/fix_symbol.rs index e80141b8be5e6..d067d65edc54d 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/fix_symbol.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/fixers/fix_symbol.rs @@ -19,7 +19,7 @@ impl<'s, 'a> Symbol<'s, 'a> { Symbol<'s, 'a>: PartialEq, { let Some(own_position) = list.iter().position(|el| self == el) else { - debug_assert!(false, "Symbol not found within its own parent declaration list"); + // Happens when the symbol is in a destructuring pattern. return fixer.noop(); }; let mut delete_range = own.span(); diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs index e38c0948a2fc7..47f8ef1a6522f 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs @@ -293,6 +293,8 @@ fn test_vars_destructure() { "const { a: { b }, ...rest } = obj; console.log(rest)", Some(json!( [{ "ignoreRestSiblings": true }] )), ), + // https://github.com/oxc-project/oxc/issues/4839 + (r#"const l="",{e}=r"#, None), ]; let fix = vec![ @@ -339,6 +341,8 @@ fn test_vars_destructure() { None, FixKind::DangerousSuggestion, ), + // TODO: destructures in VariableDeclarations with more than one declarator + (r#"const l="",{e}=r"#, r"const {e}=r", None, FixKind::All), // renaming // ( // "let a = 1; a = 2;", diff --git a/crates/oxc_linter/src/snapshots/no_unused_vars@oxc-vars-destructure.snap b/crates/oxc_linter/src/snapshots/no_unused_vars@oxc-vars-destructure.snap index 0b3bcf90c4d89..2bb7e83e4caaf 100644 --- a/crates/oxc_linter/src/snapshots/no_unused_vars@oxc-vars-destructure.snap +++ b/crates/oxc_linter/src/snapshots/no_unused_vars@oxc-vars-destructure.snap @@ -48,3 +48,19 @@ source: crates/oxc_linter/src/tester.rs · ╰── 'b' is declared here ╰──── help: Consider removing this declaration. + + ⚠ eslint(no-unused-vars): Variable 'l' is declared but never used. + ╭─[no_unused_vars.tsx:1:7] + 1 │ const l="",{e}=r + · ┬ + · ╰── 'l' is declared here + ╰──── + help: Consider removing this declaration. + + ⚠ eslint(no-unused-vars): Variable 'e' is declared but never used. + ╭─[no_unused_vars.tsx:1:13] + 1 │ const l="",{e}=r + · ┬ + · ╰── 'e' is declared here + ╰──── + help: Consider removing this declaration.