Skip to content

Commit aea9954

Browse files
authored
import-style: Fix false positive for type-only import (#2891)
1 parent 317e084 commit aea9954

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

rules/import-style.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const messages = {
77
};
88

99
const getActualImportDeclarationStyles = importDeclaration => {
10+
if (importDeclaration.importKind === 'type') {
11+
return [];
12+
}
13+
1014
const {specifiers} = importDeclaration;
1115

1216
if (specifiers.length === 0) {
@@ -27,6 +31,10 @@ const getActualImportDeclarationStyles = importDeclaration => {
2731
}
2832

2933
if (specifier.type === 'ImportSpecifier') {
34+
if (specifier.importKind === 'type') {
35+
continue;
36+
}
37+
3038
if (specifier.imported.type === 'Identifier' && specifier.imported.name === 'default') {
3139
styles.add('default');
3240
continue;

test/import-style.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,20 @@ test.babel({
714714
].map(test => addDefaultOptions(test)),
715715
});
716716

717+
test.typescript({
718+
valid: [
719+
{
720+
code: 'import {type ChalkInstance} from \'chalk\'',
721+
options: [],
722+
},
723+
{
724+
code: 'import type {ChalkInstance} from \'chalk\'',
725+
options: [],
726+
},
727+
],
728+
invalid: [],
729+
});
730+
717731
test.snapshot({
718732
valid: [
719733
'let a',

0 commit comments

Comments
 (0)