From 12f0300100b9bb90c6a952d07c133f2d5842ad57 Mon Sep 17 00:00:00 2001 From: Noureldin Shaker <43860275+Pandemic1617@users.noreply.github.com> Date: Tue, 7 Nov 2023 15:37:39 +0000 Subject: [PATCH] [Fix] `no-extraneous-dependencies`: ignore `export type { ... } from '...'` when `includeTypes` is false --- CHANGELOG.md | 5 +++++ src/rules/no-extraneous-dependencies.js | 1 + tests/src/rules/no-extraneous-dependencies.js | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc3fc1918..f902dec7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ## [Unreleased] +### Fixed +- [`no-extraneous-dependencies`]: ignore `export type { ... } from '...'` when `includeTypes` is `false` ([#2919], thanks [@Pandemic1617]) + ## [2.29.0] - 2023-10-22 ### Added @@ -1094,6 +1097,7 @@ for info on changes for earlier releases. [`memo-parser`]: ./memo-parser/README.md +[#2919]: https://github.com/import-js/eslint-plugin-import/pull/2919 [#2884]: https://github.com/import-js/eslint-plugin-import/pull/2884 [#2854]: https://github.com/import-js/eslint-plugin-import/pull/2854 [#2851]: https://github.com/import-js/eslint-plugin-import/pull/2851 @@ -1830,6 +1834,7 @@ for info on changes for earlier releases. [@ntdb]: https://github.com/ntdb [@nwalters512]: https://github.com/nwalters512 [@ombene]: https://github.com/ombene +[@Pandemic1617]: https://github.com/Pandemic1617 [@ota-meshi]: https://github.com/ota-meshi [@OutdatedVersion]: https://github.com/OutdatedVersion [@panrafal]: https://github.com/panrafal diff --git a/src/rules/no-extraneous-dependencies.js b/src/rules/no-extraneous-dependencies.js index 0408e0866..df9798790 100644 --- a/src/rules/no-extraneous-dependencies.js +++ b/src/rules/no-extraneous-dependencies.js @@ -177,6 +177,7 @@ function reportIfMissing(context, deps, depsOptions, node, name) { && ( node.importKind === 'type' || node.importKind === 'typeof' + || node.exportKind === 'type' || Array.isArray(node.specifiers) && node.specifiers.length && node.specifiers.every((specifier) => specifier.importKind === 'type' || specifier.importKind === 'typeof') ) ) { diff --git a/tests/src/rules/no-extraneous-dependencies.js b/tests/src/rules/no-extraneous-dependencies.js index 21561615c..cb0398ada 100644 --- a/tests/src/rules/no-extraneous-dependencies.js +++ b/tests/src/rules/no-extraneous-dependencies.js @@ -427,6 +427,18 @@ describe('TypeScript', () => { options: [{ packageDir: packageDirWithTypescriptDevDependencies, devDependencies: false }], ...parserConfig, }), + + test({ + code: 'import type { T } from "a"; export type { T };', + options: [{ packageDir: packageDirWithTypescriptDevDependencies, devDependencies: false }], + ...parserConfig, + }), + + test({ + code: 'export type { T } from "a";', + options: [{ packageDir: packageDirWithTypescriptDevDependencies, devDependencies: false }], + ...parserConfig, + }), ], invalid: [ test({