Skip to content

Commit

Permalink
[Fix] no-duplicates: Handle TS import type
Browse files Browse the repository at this point in the history
  • Loading branch information
kmui2 authored and ljharb committed Mar 4, 2020
1 parent efd6be1 commit 4c4d23a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -55,7 +55,7 @@
"devDependencies": {
"@eslint/import-test-order-redirect-scoped": "file:./tests/files/order-redirect-scoped",
"@test-scope/some-module": "file:./tests/files/symlinked-module",
"@typescript-eslint/parser": "1.10.3-alpha.13",
"@typescript-eslint/parser": "^2.22.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.6",
Expand All @@ -68,7 +68,7 @@
"cross-env": "^4.0.0",
"eslint": "2.x - 6.x",
"eslint-import-resolver-node": "file:./resolvers/node",
"eslint-import-resolver-typescript": "^1.0.2",
"eslint-import-resolver-typescript": "^2.0.0",
"eslint-import-resolver-webpack": "file:./resolvers/webpack",
"eslint-import-test-order-redirect": "file:./tests/files/order-redirect",
"eslint-module-utils": "file:./utils",
Expand All @@ -82,7 +82,7 @@
"rimraf": "^2.7.1",
"semver": "^6.3.0",
"sinon": "^2.4.1",
"typescript": "~3.2.2",
"typescript": "^3.8.3",
"typescript-eslint-parser": "^22.0.0"
},
"peerDependencies": {
Expand Down
29 changes: 28 additions & 1 deletion tests/src/rules/no-duplicates.js
@@ -1,5 +1,5 @@
import * as path from 'path'
import { test as testUtil } from '../utils'
import { test as testUtil, getNonDefaultParsers } from '../utils'

import { RuleTester } from 'eslint'

Expand Down Expand Up @@ -399,3 +399,30 @@ ruleTester.run('no-duplicates', rule, {
}),
],
})

context('TypeScript', function() {
getNonDefaultParsers().forEach((parser) => {
const parserConfig = {
parser: parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
}

ruleTester.run('no-duplicates', rule, {
valid: [
// #1667: ignore duplicate if is a typescript type import
test(
{
code: "import type { x } from './foo'; import y from './foo'",
parser,
},
parserConfig,
),
],
invalid: [],
})
})
})

0 comments on commit 4c4d23a

Please sign in to comment.