Skip to content

Commit

Permalink
[Fix] namespace: do not report on shadowed import names
Browse files Browse the repository at this point in the history
Fixes #518.
  • Loading branch information
ljharb committed Jun 23, 2020
1 parent a963e8d commit b944e94
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`order`]/[`newline-after-import`]: ignore TypeScript's "export import object" ([#1830], thanks [@be5invis])
- [`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])

### Changed
- [`no-extraneous-dependencies`]: add tests for importing types ([#1824], thanks [@taye])
Expand Down Expand Up @@ -887,6 +888,7 @@ for info on changes for earlier releases.
[#555]: https://github.com/benmosher/eslint-plugin-import/pull/555
[#538]: https://github.com/benmosher/eslint-plugin-import/pull/538
[#527]: https://github.com/benmosher/eslint-plugin-import/pull/527
[#518]: https://github.com/benmosher/eslint-plugin-import/pull/518
[#509]: https://github.com/benmosher/eslint-plugin-import/pull/509
[#508]: https://github.com/benmosher/eslint-plugin-import/pull/508
[#503]: https://github.com/benmosher/eslint-plugin-import/pull/503
Expand Down
1 change: 1 addition & 0 deletions src/rules/namespace.js
Expand Up @@ -106,6 +106,7 @@ module.exports = {
MemberExpression(dereference) {
if (dereference.object.type !== 'Identifier') return
if (!namespaces.has(dereference.object.name)) return
if (declaredScope(context, dereference.object.name) !== 'module') return

if (dereference.parent.type === 'AssignmentExpression' && dereference.parent.left === dereference) {
context.report(
Expand Down
1 change: 1 addition & 0 deletions tests/files/color.js
@@ -0,0 +1 @@
export const example = 'example';
8 changes: 8 additions & 0 deletions tests/src/rules/namespace.js
Expand Up @@ -164,6 +164,14 @@ const valid = [
]),

...SYNTAX_CASES,

test({
code: `
import * as color from './color';
export const getBackgroundFromColor = (color) => color.bg;
export const getExampleColor = () => color.example
`,
}),
]

const invalid = [
Expand Down

0 comments on commit b944e94

Please sign in to comment.