From 951615228d90c3188dc551147f422dc3165dbadd Mon Sep 17 00:00:00 2001 From: Kevin Mui Date: Tue, 3 Mar 2020 22:58:03 -0600 Subject: [PATCH] [Fix] `no-duplicates`: Handle TS import type Fixes #1667. --- CHANGELOG.md | 3 +++ package.json | 4 ++-- tests/src/rules/no-duplicates.js | 31 ++++++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5525a6f14..ea4eebef6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]) @@ -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 @@ -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 diff --git a/package.json b/package.json index 33209b314..acbf3dbbf 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { diff --git a/tests/src/rules/no-duplicates.js b/tests/src/rules/no-duplicates.js index 917d0e400..0137221b0 100644 --- a/tests/src/rules/no-duplicates.js +++ b/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' @@ -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: [], + }) + }) +}) +