eslint-plugin-unused-imports
eslint-plugin-unused-imports copied to clipboard
Rule throws on unused enum member
I have the following TypeScript test file on which this plugin throws an error during linting:
import test from "ava";
import { enumValuesToMetadataStates } from "./Metadata";
enum TestEnum {
"Easy" = 0x00,
"This is complicated" = 0x02,
"2 lets have some numbers" = 0x08,
"8 and one more" = 0x09,
}
test("enumValuesToMetadataStates() -> should translate the whole enum by default", (t) => {
const actual = enumValuesToMetadataStates(TestEnum);
const expected = {
0: "Easy",
2: "This is complicated",
8: "2 lets have some numbers",
9: "8 and one more",
};
t.deepEqual(actual, expected);
});
test("enumValuesToMetadataStates() -> should correctly translate a subset if requested", (t) => {
const actual = enumValuesToMetadataStates(TestEnum, [0, 9]);
const expected = {
0: "Easy",
9: "8 and one more",
};
t.deepEqual(actual, expected);
});
The error is the following:
TypeError: Cannot read properties of undefined (reading 'start')
Rule: "unused-imports/no-unused-imports"
at file:///.../node_modules/.store/eslint-plugin-unused-imports-virtual-0b5783ab2f/package/dist/index.mjs:9:75
at FileContext.value [as report] (file:///.../node_modules/.store/eslint-plugin-unused-imports-virtual-0b5783ab2f/package/dist/index.mjs:72:30)
I'm not sure how to fix it, but I was able to narrow it down a bit with debugging:
- In the
"Program:exit"handler,unusedVarhas no references and no identifiers: - As a result, the
nodepassed tocontext.reportisundefined, causing the error.
Probably enum members should be ignored by this rule altogether.