Skip to content

Commit 4c92c47

Browse files
christianvueringsljharb
authored andcommitted
[Fix] no-named-default: ignore Flow import type and typeof
1 parent a45661b commit 4c92c47

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
2323
- [`first`]: fix handling of `import = require` ([#1963], thanks [@MatthiasKunnen])
2424
- [`no-cycle`]/[`extensions`]: fix isExternalModule usage ([#1696], thanks [@paztis])
2525
- [`extensions`]/[`no-cycle`]/[`no-extraneous-dependencies`]: Correct module real path resolution ([#1696], thanks [@paztis])
26+
- [`no-named-default`]: ignore Flow import type and typeof ([#1983], thanks [@christianvuerings])
2627

2728
### Changed
2829
- [Generic Import Callback] Make callback for all imports once in rules ([#1237], thanks [@ljqx])
@@ -757,6 +758,7 @@ for info on changes for earlier releases.
757758

758759
[`memo-parser`]: ./memo-parser/README.md
759760

761+
[#1983]: https://github.com/benmosher/eslint-plugin-import/pull/1983
760762
[#1974]: https://github.com/benmosher/eslint-plugin-import/pull/1974
761763
[#1958]: https://github.com/benmosher/eslint-plugin-import/pull/1958
762764
[#1948]: https://github.com/benmosher/eslint-plugin-import/pull/1948
@@ -1334,4 +1336,5 @@ for info on changes for earlier releases.
13341336
[@guillaumewuip]: https://github.com/guillaumewuip
13351337
[@tapayne88]: https://github.com/tapayne88
13361338
[@panrafal]: https://github.com/panrafal
1337-
[@ttmarek]: https://github.com/ttmarek
1339+
[@ttmarek]: https://github.com/ttmarek
1340+
[@christianvuerings]: https://github.com/christianvuerings

docs/rules/no-named-default.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Reports use of a default export as a locally named import.
44

55
Rationale: the syntax exists to import default exports expressively, let's use it.
66

7+
Note that type imports, as used by [Flow], are always ignored.
8+
9+
[Flow]: https://flow.org/
10+
711
## Rule Details
812

913
Given:

src/rules/no-named-default.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ module.exports = {
1313
return {
1414
'ImportDeclaration': function (node) {
1515
node.specifiers.forEach(function (im) {
16+
if (im.importKind === 'type' || im.importKind === 'typeof') {
17+
return;
18+
}
19+
1620
if (im.type === 'ImportSpecifier' && im.imported.name === 'default') {
1721
context.report({
1822
node: im.local,

tests/src/rules/no-named-default.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ ruleTester.run('no-named-default', rule, {
99
test({ code: 'import bar from "./bar";' }),
1010
test({ code: 'import bar, { foo } from "./bar";' }),
1111

12+
// Should ignore imported flow types
13+
test({
14+
code: 'import { type default as Foo } from "./bar";',
15+
parser: require.resolve('babel-eslint'),
16+
}),
17+
test({
18+
code: 'import { typeof default as Foo } from "./bar";',
19+
parser: require.resolve('babel-eslint'),
20+
}),
21+
1222
...SYNTAX_CASES,
1323
],
1424

0 commit comments

Comments
 (0)