fix(inline-type): ignore default import
This commit is contained in:
parent
0af15d4bf4
commit
07a15be095
@ -0,0 +1,27 @@
|
|||||||
|
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
|
||||||
|
import { it } from 'vitest'
|
||||||
|
import rule, { RULE_NAME } from './prefer-inline-type-import'
|
||||||
|
|
||||||
|
const valids = [
|
||||||
|
'import { type Foo } from \'foo\'',
|
||||||
|
'import type Foo from \'foo\'',
|
||||||
|
'import type * as Foo from \'foo\'',
|
||||||
|
]
|
||||||
|
const invalids = [
|
||||||
|
['import type { Foo } from \'foo\'', 'import { type Foo } from \'foo\''],
|
||||||
|
]
|
||||||
|
|
||||||
|
it('runs', () => {
|
||||||
|
const ruleTester: RuleTester = new RuleTester({
|
||||||
|
parser: require.resolve('@typescript-eslint/parser'),
|
||||||
|
})
|
||||||
|
|
||||||
|
ruleTester.run(RULE_NAME, rule, {
|
||||||
|
valid: valids,
|
||||||
|
invalid: invalids.map(i => ({
|
||||||
|
code: i[0],
|
||||||
|
output: i[1].trim(),
|
||||||
|
errors: [{ messageId: 'preferInlineTypeImport' }],
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
})
|
@ -26,6 +26,9 @@ export default createEslintRule<Options, MessageIds>({
|
|||||||
const sourceCode = context.getSourceCode()
|
const sourceCode = context.getSourceCode()
|
||||||
return {
|
return {
|
||||||
ImportDeclaration: (node) => {
|
ImportDeclaration: (node) => {
|
||||||
|
// ignore bare type imports
|
||||||
|
if (node.specifiers.length === 1 && ['ImportNamespaceSpecifier', 'ImportDefaultSpecifier'].includes(node.specifiers[0].type))
|
||||||
|
return
|
||||||
if (node.importKind === 'type') {
|
if (node.importKind === 'type') {
|
||||||
context.report({
|
context.report({
|
||||||
*fix(fixer) {
|
*fix(fixer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user