Skip to content

Commit

Permalink
[Fix] export: avoid warning on export * as non-conflicts
Browse files Browse the repository at this point in the history
Fixes #1834.
  • Loading branch information
ljharb committed Jun 23, 2020
1 parent b944e94 commit 07dc92a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/rules/export.js
Expand Up @@ -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

Expand All @@ -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}'.`
)
}
},

Expand Down
1 change: 1 addition & 0 deletions tests/files/named-export-collision/a.js
@@ -0,0 +1 @@
export const FOO = 'a-foobar';
1 change: 1 addition & 0 deletions tests/files/named-export-collision/b.js
@@ -0,0 +1 @@
export const FOO = 'b-foobar';
17 changes: 17 additions & 0 deletions tests/src/rules/export.js
Expand Up @@ -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: [
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 07dc92a

Please sign in to comment.