Skip to content

Commit

Permalink
fix(linter/no-unused-vars): panic in fixer when removing destructures (
Browse files Browse the repository at this point in the history
…#4923)

Closes #4839
  • Loading branch information
DonIsaac authored Aug 15, 2024
1 parent c21d735 commit 4081293
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl<'s, 'a> Symbol<'s, 'a> {
Symbol<'s, 'a>: PartialEq<T>,
{
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down Expand Up @@ -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;",
Expand Down
16 changes: 16 additions & 0 deletions crates/oxc_linter/src/snapshots/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -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]
1const 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]
1const l="",{e}=r
· ┬
· ╰── 'e' is declared here
╰────
help: Consider removing this declaration.

0 comments on commit 4081293

Please sign in to comment.