diff --git a/src/rules/no-deprecated.js b/src/rules/no-deprecated.js index 034827034..882f5e48c 100644 --- a/src/rules/no-deprecated.js +++ b/src/rules/no-deprecated.js @@ -50,11 +50,11 @@ module.exports = function (context) { } // unknown thing can't be deprecated - if (!imports.has(imported)) return + const exported = imports.get(imported) + if (exported == null) return // capture import of deep namespace - const { namespace } = imports.get(imported) - if (namespace) namespaces.set(local, namespace) + if (exported.namespace) namespaces.set(local, exported.namespace) const deprecation = getDeprecation(imports.get(imported)) if (!deprecation) return diff --git a/tests/files/issue-370-commonjs-namespace/bar.js b/tests/files/issue-370-commonjs-namespace/bar.js new file mode 100644 index 000000000..3ec93603a --- /dev/null +++ b/tests/files/issue-370-commonjs-namespace/bar.js @@ -0,0 +1,2 @@ +// bar.js +export { default as foo } from './foo' \ No newline at end of file diff --git a/tests/files/issue-370-commonjs-namespace/foo.js b/tests/files/issue-370-commonjs-namespace/foo.js new file mode 100644 index 000000000..ba097965e --- /dev/null +++ b/tests/files/issue-370-commonjs-namespace/foo.js @@ -0,0 +1,2 @@ +// foo.js +module.exports = { foo: 'foo' } \ No newline at end of file diff --git a/tests/src/rules/no-deprecated.js b/tests/src/rules/no-deprecated.js index ef6912dd1..1ab242b00 100644 --- a/tests/src/rules/no-deprecated.js +++ b/tests/src/rules/no-deprecated.js @@ -1,4 +1,4 @@ -import { test } from '../utils' +import { test, SYNTAX_CASES } from '../utils' import { RuleTester } from 'eslint' @@ -37,6 +37,9 @@ ruleTester.run('no-deprecated', rule, { test({ code: "import { deepDep } from './deep-deprecated'; function x(deepDep) { console.log(deepDep.MY_TERRIBLE_ACTION) }", }), + + + ...SYNTAX_CASES, ], invalid: [ diff --git a/tests/src/utils.js b/tests/src/utils.js index db5fed076..83330f67a 100644 --- a/tests/src/utils.js +++ b/tests/src/utils.js @@ -63,4 +63,9 @@ export const SYNTAX_CASES = [ settings: { 'import/extensions': ['.js'] }, // breaking: remove for v2 }), + // issue #370: deep commonjs import + test({ + code: 'import { foo } from "./issue-370-commonjs-namespace/bar"', + settings: { 'import/ignore': ['foo'] }, + }), ]