From 07dc92a22319a7e24c46a64132370012779a7df3 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 23 Jun 2020 14:02:47 -0700 Subject: [PATCH] [Fix] `export`: avoid warning on `export * as` non-conflicts Fixes #1834. --- CHANGELOG.md | 2 ++ src/rules/export.js | 9 +++++++-- tests/files/named-export-collision/a.js | 1 + tests/files/named-export-collision/b.js | 1 + tests/src/rules/export.js | 17 +++++++++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/files/named-export-collision/a.js create mode 100644 tests/files/named-export-collision/b.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cca87815..11df4a2fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel - [`dynamic-import-chunkname`]/TypeScript: supports `@typescript-eslint/parser` ([#1833], thanks [@noelebrun]) - [`order`]/TypeScript: ignore ordering of object imports ([#1831], thanks [@manuth]) - [`namespace`]: do not report on shadowed import names ([#518], thanks [@ljharb]) +- [`export`]: avoid warning on `export * as` non-conflicts ([#1834], thanks [@ljharb]) ### Changed - [`no-extraneous-dependencies`]: add tests for importing types ([#1824], thanks [@taye]) @@ -721,6 +722,7 @@ for info on changes for earlier releases. [#1836]: https://github.com/benmosher/eslint-plugin-import/pull/1836 [#1835]: https://github.com/benmosher/eslint-plugin-import/pull/1835 +[#1834]: https://github.com/benmosher/eslint-plugin-import/issues/1834 [#1833]: https://github.com/benmosher/eslint-plugin-import/pull/1833 [#1831]: https://github.com/benmosher/eslint-plugin-import/pull/1831 [#1830]: https://github.com/benmosher/eslint-plugin-import/pull/1830 diff --git a/src/rules/export.js b/src/rules/export.js index f131374df..340972eda 100644 --- a/src/rules/export.js +++ b/src/rules/export.js @@ -118,6 +118,9 @@ module.exports = { 'ExportAllDeclaration': function (node) { if (node.source == null) return // not sure if this is ever true + // `export * as X from 'path'` does not conflict + if (node.exported && node.exported.name) return + const remoteExports = ExportMap.get(node.source.value, context) if (remoteExports == null) return @@ -135,8 +138,10 @@ module.exports = { addNamed(name, node, parent)) if (!any) { - context.report(node.source, - `No named exports found in module '${node.source.value}'.`) + context.report( + node.source, + `No named exports found in module '${node.source.value}'.` + ) } }, diff --git a/tests/files/named-export-collision/a.js b/tests/files/named-export-collision/a.js new file mode 100644 index 000000000..cb04b2cb2 --- /dev/null +++ b/tests/files/named-export-collision/a.js @@ -0,0 +1 @@ +export const FOO = 'a-foobar'; diff --git a/tests/files/named-export-collision/b.js b/tests/files/named-export-collision/b.js new file mode 100644 index 000000000..ebf954ee0 --- /dev/null +++ b/tests/files/named-export-collision/b.js @@ -0,0 +1 @@ +export const FOO = 'b-foobar'; diff --git a/tests/src/rules/export.js b/tests/src/rules/export.js index fb301495e..b31ab82dc 100644 --- a/tests/src/rules/export.js +++ b/tests/src/rules/export.js @@ -24,6 +24,15 @@ ruleTester.run('export', rule, { test({ code: 'export default foo; export * from "./bar"' }), ...SYNTAX_CASES, + + test({ + code: ` + import * as A from './named-export-collision/a'; + import * as B from './named-export-collision/b'; + + export { A, B }; + `, + }), ], invalid: [ @@ -191,6 +200,14 @@ context('TypeScript', function () { code: 'export * from "./file1.ts"', filename: testFilePath('typescript-d-ts/file-2.ts'), }, parserConfig)), + + test({ + code: ` + export * as A from './named-export-collision/a'; + export * as B from './named-export-collision/b'; + `, + parser: parser, + }), ], invalid: [ // type/value name clash