diff --git a/CHANGELOG.md b/CHANGELOG.md index ac420f24c..d3e97ae69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel - [`first`]: fix handling of `import = require` ([#1963], thanks [@MatthiasKunnen]) - [`no-cycle`]/[`extensions`]: fix isExternalModule usage ([#1696], thanks [@paztis]) - [`extensions`]/[`no-cycle`]/[`no-extraneous-dependencies`]: Correct module real path resolution ([#1696], thanks [@paztis]) +- [`no-named-default`]: ignore Flow import type and typeof ([#1983], thanks [@christianvuerings]) ### Changed - [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. [`memo-parser`]: ./memo-parser/README.md +[#1983]: https://github.com/benmosher/eslint-plugin-import/pull/1983 [#1974]: https://github.com/benmosher/eslint-plugin-import/pull/1974 [#1958]: https://github.com/benmosher/eslint-plugin-import/pull/1958 [#1948]: https://github.com/benmosher/eslint-plugin-import/pull/1948 @@ -1334,4 +1336,5 @@ for info on changes for earlier releases. [@guillaumewuip]: https://github.com/guillaumewuip [@tapayne88]: https://github.com/tapayne88 [@panrafal]: https://github.com/panrafal -[@ttmarek]: https://github.com/ttmarek \ No newline at end of file +[@ttmarek]: https://github.com/ttmarek +[@christianvuerings]: https://github.com/christianvuerings diff --git a/docs/rules/no-named-default.md b/docs/rules/no-named-default.md index 86fb41d61..bb8b13bca 100644 --- a/docs/rules/no-named-default.md +++ b/docs/rules/no-named-default.md @@ -4,6 +4,10 @@ Reports use of a default export as a locally named import. Rationale: the syntax exists to import default exports expressively, let's use it. +Note that type imports, as used by [Flow], are always ignored. + +[Flow]: https://flow.org/ + ## Rule Details Given: diff --git a/src/rules/no-named-default.js b/src/rules/no-named-default.js index db046f0ae..d1c15d62e 100644 --- a/src/rules/no-named-default.js +++ b/src/rules/no-named-default.js @@ -13,6 +13,10 @@ module.exports = { return { 'ImportDeclaration': function (node) { node.specifiers.forEach(function (im) { + if (im.importKind === 'type' || im.importKind === 'typeof') { + return; + } + if (im.type === 'ImportSpecifier' && im.imported.name === 'default') { context.report({ node: im.local, diff --git a/tests/src/rules/no-named-default.js b/tests/src/rules/no-named-default.js index ee8e0959e..56470f2ba 100644 --- a/tests/src/rules/no-named-default.js +++ b/tests/src/rules/no-named-default.js @@ -9,6 +9,16 @@ ruleTester.run('no-named-default', rule, { test({ code: 'import bar from "./bar";' }), test({ code: 'import bar, { foo } from "./bar";' }), + // Should ignore imported flow types + test({ + code: 'import { type default as Foo } from "./bar";', + parser: require.resolve('babel-eslint'), + }), + test({ + code: 'import { typeof default as Foo } from "./bar";', + parser: require.resolve('babel-eslint'), + }), + ...SYNTAX_CASES, ],