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 issue with ignoreLocallyUsed #300

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions features/ignore-locally-used.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,26 @@ Scenario: ignoreLocallyUsed works with more complex file extensions
"""
When running ts-unused-exports "tsconfig.json" --ignoreLocallyUsed
Then the CLI result at status is 0

Scenario: ignoreLocallyUsed works with template literals
Given file "local.test.ts" is
"""
export const a = 1;
const b = `text ${a} some more text`;
"""
When running ts-unused-exports "tsconfig.json" --ignoreLocallyUsed
Then the CLI result at status is 0

Scenario: ignoreLocallyUsed works with objects
Given file "local.test.ts" is
"""
export const a = 1;
export const b = 2;
const c = {
a
};
c['b'] = b;
"""
When running ts-unused-exports "tsconfig.json" --ignoreLocallyUsed
Then the CLI result at status is 0

7 changes: 1 addition & 6 deletions src/parser/nodeProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,7 @@ export const processNode = (
addImportsFromNamespace(node, imports, addImport);
}

if (
extraOptions?.ignoreLocallyUsed &&
kind === ts.SyntaxKind.Identifier &&
node.parent.kind !== ts.SyntaxKind.VariableDeclaration &&
node.parent.kind !== ts.SyntaxKind.FunctionDeclaration
) {
if (extraOptions?.ignoreLocallyUsed && kind === ts.SyntaxKind.Identifier) {
addImport({
from: removeTsFileExtension(node.getSourceFile().fileName),
what: [node.getText()],
Expand Down