Skip to content

Commit

Permalink
fix(linter/no-unused-vars): false positive in some default export cases
Browse files Browse the repository at this point in the history
Fixes a false positive in `eslint/no-unused-vars` when a function expression is
default exported within an array.

```js
export default [ function foo() {} ]
```
  • Loading branch information
DonIsaac committed Oct 9, 2024
1 parent 2fca16f commit 0d0c3df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_unused_vars/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,16 @@ impl<'s, 'a> Symbol<'s, 'a> {
AstKind::ModuleDeclaration(module) => {
return module.is_export();
}
AstKind::VariableDeclaration(_) => {
AstKind::ExportDefaultDeclaration(_) => {
return true;
}
AstKind::VariableDeclaration(_)
| AstKind::ExpressionArrayElement(_)
| AstKind::ArrayExpressionElement(_)
| AstKind::ArrayExpression(_)
| AstKind::ParenthesizedExpression(_)
| AstKind::TSAsExpression(_)
| AstKind::TSSatisfiesExpression(_) => {
continue;
}
_ => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,15 @@ fn test_exports() {
"export interface A {}",
"export type A = string",
"export enum E { }",
// default exports
"export default class Foo {}",
"export default [ class Foo {} ];",
"export default function foo() {}",
"export default { foo() {} };",
"export default { foo: function foo() {} };",
"export default { get foo() {} };",
"export default [ function foo() {} ];",
"export default (function foo() { return 1 })();",
// "export enum E { A, B }",
"const a = 1; export { a }",
"const a = 1; export default a",
Expand Down

0 comments on commit 0d0c3df

Please sign in to comment.