Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] no-duplicates: Handle TS import type #1676

Merged
merged 1 commit into from Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -10,6 +10,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`group-exports`]: Flow type export awareness ([#1702], thanks [@ernestostifano])
- [`order`]: Recognize pathGroup config for first group ([#1719], [#1724], thanks [@forivall], [@xpl])
- [`no-unused-modules`]: Fix re-export not counting as usage when used in combination with import ([#1722], thanks [@Ephem])
- [`no-duplicates`]: Handle TS import type ([#1676], thanks [@kmui2])

### Changed
- TypeScript config: Disable [`named`][] ([#1726], thanks [@astorije])
Expand Down Expand Up @@ -673,6 +674,7 @@ for info on changes for earlier releases.
[#1722]: https://github.com/benmosher/eslint-plugin-import/issues/1722
[#1719]: https://github.com/benmosher/eslint-plugin-import/issues/1719
[#1702]: https://github.com/benmosher/eslint-plugin-import/issues/1702
[#1676]: https://github.com/benmosher/eslint-plugin-import/pull/1676
[#1666]: https://github.com/benmosher/eslint-plugin-import/pull/1666
[#1664]: https://github.com/benmosher/eslint-plugin-import/pull/1664
[#1658]: https://github.com/benmosher/eslint-plugin-import/pull/1658
Expand Down Expand Up @@ -1141,3 +1143,4 @@ for info on changes for earlier releases.
[@xpl]: https://github.com/xpl
[@astorije]: https://github.com/astorije
[@Ephem]: https://github.com/Ephem
[@kmui2]: https://github.com/kmui2
4 changes: 2 additions & 2 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.23.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.6",
Expand Down Expand Up @@ -84,7 +84,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
31 changes: 30 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,32 @@ ruleTester.run('no-duplicates', rule, {
}),
],
})

context('TypeScript', function() {
getNonDefaultParsers()
.filter((parser) => parser !== require.resolve('typescript-eslint-parser'))
.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: [],
})
})
})