diff --git a/CHANGELOG.md b/CHANGELOG.md index ac420f24c4..137f3f057f 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 ([], thanks [@christianvuerings]) ### Changed - [Generic Import Callback] Make callback for all imports once in rules ([#1237], thanks [@ljqx]) @@ -1334,4 +1335,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 86fb41d615..bb8b13bca4 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 db046f0aee..d1c15d62e0 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 ee8e0959ee..56470f2bac 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, ],