Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): [no-unused-vars] check if any variable definition is exported #6873

Merged
merged 6 commits into from
Jul 17, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/eslint-plugin/src/util/collectUnusedVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,7 @@ function isMergableExported(variable: TSESLint.Scope.Variable): boolean {
* @returns True if the variable is exported, false if not.
*/
function isExported(variable: TSESLint.Scope.Variable): boolean {
const definition = variable.defs[0];

if (definition) {
return variable.defs.some(definition => {
let node = definition.node;

if (node.type === AST_NODE_TYPES.VariableDeclarator) {
Expand All @@ -438,8 +436,7 @@ function isExported(variable: TSESLint.Scope.Variable): boolean {
}

return node.parent!.type.indexOf('Export') === 0;
}
return false;
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,18 @@ export class Foo {
typescript: '4.4',
},
},
`
interface Foo {
bar: string;
}
export const Foo = 'bar';
`,
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
`
export const Foo = 'bar';
interface Foo {
bar: string;
}
`,
],

invalid: [
Expand Down Expand Up @@ -1805,5 +1817,25 @@ x = foo(x);
},
],
},
{
code: `
interface Foo {
bar: string;
}
const Foo = 'bar';
`,
errors: [
{
messageId: 'unusedVar',
line: 5,
column: 7,
data: {
varName: 'Foo',
action: 'assigned a value',
additional: '',
},
},
],
},
],
});