Skip to content

Commit d7ccd0d

Browse files
danwanggajus
authored andcommitted
fix: (type-import-style) Support import aliases when fixing (#321)
1 parent 3c67223 commit d7ccd0d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/rules/typeImportStyle.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ const create = (context) => {
2929
context.report({
3030
fix (fixer) {
3131
const imports = node.specifiers.map((specifier) => {
32-
return 'type ' + specifier.local.name;
32+
if (specifier.type === 'ImportDefaultSpecifier') {
33+
return 'type default as ' + specifier.local.name;
34+
} else if (specifier.imported.name === specifier.local.name) {
35+
return 'type ' + specifier.local.name;
36+
} else {
37+
return 'type ' + specifier.imported.name + ' as ' + specifier.local.name;
38+
}
3339
});
3440
const source = node.source.value;
3541

tests/rules/assertions/typeImportStyle.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ export default {
1111
options: ['identifier'],
1212
output: 'import {type A, type B} from \'a\';'
1313
},
14+
{
15+
code: 'import type {A, B as C} from \'a\';',
16+
errors: [{message: 'Unexpected "import type"'}],
17+
options: ['identifier'],
18+
output: 'import {type A, type B as C} from \'a\';'
19+
},
20+
{
21+
code: 'import type A from \'a\';',
22+
errors: [{message: 'Unexpected "import type"'}],
23+
options: ['identifier'],
24+
output: 'import {type default as A} from \'a\';'
25+
},
1426
{
1527
code: 'import {type A, type B} from \'a\';',
1628
errors: [

0 commit comments

Comments
 (0)