Skip to content

Commit

Permalink
add test + fixes #370
Browse files Browse the repository at this point in the history
  • Loading branch information
benmosher committed Jun 21, 2016
1 parent 9fb7274 commit 1e05a0f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/rules/no-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/files/issue-370-commonjs-namespace/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// bar.js
export { default as foo } from './foo'
2 changes: 2 additions & 0 deletions tests/files/issue-370-commonjs-namespace/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// foo.js
module.exports = { foo: 'foo' }
5 changes: 4 additions & 1 deletion tests/src/rules/no-deprecated.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from '../utils'
import { test, SYNTAX_CASES } from '../utils'

import { RuleTester } from 'eslint'

Expand Down Expand Up @@ -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: [

Expand Down
5 changes: 5 additions & 0 deletions tests/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'] },
}),
]

0 comments on commit 1e05a0f

Please sign in to comment.