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): [consistent-type-imports] handle imports without specifiers #8308

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export default createRule<Options, MessageIds>({
} else {
if (
!sourceImports.valueOnlyNamedImport &&
node.specifiers.length &&
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
node.specifiers.every(
specifier =>
specifier.type === AST_NODE_TYPES.ImportSpecifier,
Expand Down
43 changes: 43 additions & 0 deletions packages/eslint-plugin/tests/rules/consistent-type-imports.test.ts
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2230,5 +2230,48 @@ let baz: D;
},
],
},
// https://github.com/typescript-eslint/typescript-eslint/issues/7209
{
code: `
import 'foo';
import type { Foo, Bar } from 'foo';
@deco
class A {
constructor(foo: Foo) {}
}
`,
output: `
import 'foo';
import { Foo} from 'foo';
import type { Bar } from 'foo';
@deco
class A {
constructor(foo: Foo) {}
}
`,
errors: [{ messageId: 'aImportInDecoMeta', line: 3, column: 1 }],
parserOptions: withMetaConfigParserOptions,
},
{
code: `
import {} from 'foo';
import type { Foo, Bar } from 'foo';
@deco
class A {
constructor(foo: Foo) {}
}
`,
output: `
import {} from 'foo';
import { Foo} from 'foo';
import type { Bar } from 'foo';
@deco
class A {
constructor(foo: Foo) {}
}
`,
errors: [{ messageId: 'aImportInDecoMeta', line: 3, column: 1 }],
parserOptions: withMetaConfigParserOptions,
},
],
});