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 2 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
8 changes: 3 additions & 5 deletions packages/eslint-plugin/src/util/collectUnusedVariables.ts
Expand Up @@ -423,9 +423,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) {
const exportedDefinition = variable.defs.find(definition => {
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
let node = definition.node;

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

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

/**
Expand Down
Expand Up @@ -1072,6 +1072,12 @@ export class Foo {
typescript: '4.4',
},
},
`
interface Foo {
bar: string;
}
export const Foo = 'bar';
`,
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
],

invalid: [
Expand Down