Skip to content

Commit

Permalink
fix(unused-imported-specifier): fix unused specifier rule - wrong det…
Browse files Browse the repository at this point in the history
…ection
  • Loading branch information
Romakita committed Mar 30, 2024
1 parent 86bff13 commit 6bed750
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const ruleTester = new RuleTester({
parser: "@typescript-eslint/parser"
});

describe("missingImportSpecifiers", () => {
describe("unusedImportedSpecifier", () => {
ruleTester.run(name, rule, {
valid: [
{
Expand Down
10 changes: 5 additions & 5 deletions src/rules/unused-imported-specifier/unusedImportedSpecifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ export const rule = createRule<[], RULES>({
const program = context.sourceCode.ast;
const imports = getImportDeclarations(program);

const isUsed = program.tokens.reduce((isUsed, token, currentIndex) => {
if (token.type === "Identifier" && program.tokens[currentIndex + 1].type === "Punctuator" && program.tokens[currentIndex - 1].value === "@") {
isUsed.add(token.value);
const tokens = program.tokens.reduce((isUsed, token, currentIndex) => {
if (token.type === "Identifier") {
isUsed.set(token.value, (isUsed.get(token.value) || 0) + 1);
}

return isUsed;
}, new Set());
}, new Map());

imports
.filter((importDeclaration) => {
return importDeclaration.source.value.startsWith("@tsed/");
})
.map((importDeclaration) => {
importDeclaration.specifiers.forEach((specifier, index, specifiers) => {
if (!isUsed.has(specifier.local.name)) {
if (tokens.get(specifier.local.name) === 1) {
context.report({
node: specifier,
messageId: "unused-imported-specifier",
Expand Down

0 comments on commit 6bed750

Please sign in to comment.