Skip to content

Commit b944e94

Browse files
committed
[Fix] namespace: do not report on shadowed import names
Fixes #518.
1 parent a963e8d commit b944e94

4 files changed

Lines changed: 12 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1616
- [`order`]/[`newline-after-import`]: ignore TypeScript's "export import object" ([#1830], thanks [@be5invis])
1717
- [`dynamic-import-chunkname`]/TypeScript: supports `@typescript-eslint/parser` ([#1833], thanks [@noelebrun])
1818
- [`order`]/TypeScript: ignore ordering of object imports ([#1831], thanks [@manuth])
19+
- [`namespace`]: do not report on shadowed import names ([#518], thanks [@ljharb])
1920

2021
### Changed
2122
- [`no-extraneous-dependencies`]: add tests for importing types ([#1824], thanks [@taye])
@@ -887,6 +888,7 @@ for info on changes for earlier releases.
887888
[#555]: https://github.com/benmosher/eslint-plugin-import/pull/555
888889
[#538]: https://github.com/benmosher/eslint-plugin-import/pull/538
889890
[#527]: https://github.com/benmosher/eslint-plugin-import/pull/527
891+
[#518]: https://github.com/benmosher/eslint-plugin-import/pull/518
890892
[#509]: https://github.com/benmosher/eslint-plugin-import/pull/509
891893
[#508]: https://github.com/benmosher/eslint-plugin-import/pull/508
892894
[#503]: https://github.com/benmosher/eslint-plugin-import/pull/503

src/rules/namespace.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ module.exports = {
106106
MemberExpression(dereference) {
107107
if (dereference.object.type !== 'Identifier') return
108108
if (!namespaces.has(dereference.object.name)) return
109+
if (declaredScope(context, dereference.object.name) !== 'module') return
109110

110111
if (dereference.parent.type === 'AssignmentExpression' && dereference.parent.left === dereference) {
111112
context.report(

tests/files/color.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const example = 'example';

tests/src/rules/namespace.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ const valid = [
164164
]),
165165

166166
...SYNTAX_CASES,
167+
168+
test({
169+
code: `
170+
import * as color from './color';
171+
export const getBackgroundFromColor = (color) => color.bg;
172+
export const getExampleColor = () => color.example
173+
`,
174+
}),
167175
]
168176

169177
const invalid = [

0 commit comments

Comments
 (0)