Skip to content

Commit

Permalink
fix: (type-import-style) Support import aliases when fixing (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
danwang authored and gajus committed Feb 22, 2018
1 parent 3c67223 commit d7ccd0d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/rules/typeImportStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ const create = (context) => {
context.report({
fix (fixer) {
const imports = node.specifiers.map((specifier) => {
return 'type ' + specifier.local.name;
if (specifier.type === 'ImportDefaultSpecifier') {
return 'type default as ' + specifier.local.name;
} else if (specifier.imported.name === specifier.local.name) {
return 'type ' + specifier.local.name;
} else {
return 'type ' + specifier.imported.name + ' as ' + specifier.local.name;
}
});
const source = node.source.value;

Expand Down
12 changes: 12 additions & 0 deletions tests/rules/assertions/typeImportStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ export default {
options: ['identifier'],
output: 'import {type A, type B} from \'a\';'
},
{
code: 'import type {A, B as C} from \'a\';',
errors: [{message: 'Unexpected "import type"'}],
options: ['identifier'],
output: 'import {type A, type B as C} from \'a\';'
},
{
code: 'import type A from \'a\';',
errors: [{message: 'Unexpected "import type"'}],
options: ['identifier'],
output: 'import {type default as A} from \'a\';'
},
{
code: 'import {type A, type B} from \'a\';',
errors: [
Expand Down

0 comments on commit d7ccd0d

Please sign in to comment.