Skip to content

Commit f2db74a

Browse files
devongovettljharb
andcommitted
[Fix] no-extraneous-dependencies: Exclude flow typeof imports
Co-authored-by: Devon Govett <devongovett@gmail.com> Co-authored-by: Jordan Harband <ljharb@gmail.com>
1 parent 1031e1c commit f2db74a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
2424
- [`no-cycle`]/[`extensions`]: fix isExternalModule usage ([#1696], thanks [@paztis])
2525
- [`extensions`]/[`no-cycle`]/[`no-extraneous-dependencies`]: Correct module real path resolution ([#1696], thanks [@paztis])
2626
- [`no-named-default`]: ignore Flow import type and typeof ([#1983], thanks [@christianvuerings])
27+
- [`no-extraneous-dependencies`]: Exclude flow `typeof` imports ([#1534], thanks [@devongovett])
2728

2829
### Changed
2930
- [Generic Import Callback] Make callback for all imports once in rules ([#1237], thanks [@ljqx])
@@ -819,6 +820,7 @@ for info on changes for earlier releases.
819820
[#1560]: https://github.com/benmosher/eslint-plugin-import/pull/1560
820821
[#1551]: https://github.com/benmosher/eslint-plugin-import/pull/1551
821822
[#1542]: https://github.com/benmosher/eslint-plugin-import/pull/1542
823+
[#1534]: https://github.com/benmosher/eslint-plugin-import/pull/1534
822824
[#1528]: https://github.com/benmosher/eslint-plugin-import/pull/1528
823825
[#1526]: https://github.com/benmosher/eslint-plugin-import/pull/1526
824826
[#1521]: https://github.com/benmosher/eslint-plugin-import/pull/1521
@@ -1338,3 +1340,4 @@ for info on changes for earlier releases.
13381340
[@panrafal]: https://github.com/panrafal
13391341
[@ttmarek]: https://github.com/ttmarek
13401342
[@christianvuerings]: https://github.com/christianvuerings
1343+
[@devongovett]: https://github.com/devongovett

src/rules/no-extraneous-dependencies.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ function getModuleRealName(resolved) {
128128

129129
function reportIfMissing(context, deps, depsOptions, node, name) {
130130
// Do not report when importing types
131-
if (node.importKind === 'type' || (node.parent && node.parent.importKind === 'type')) {
131+
if (node.importKind === 'type' || (node.parent && node.parent.importKind === 'type') || node.importKind === 'typeof') {
132132
return;
133133
}
134134

tests/src/rules/no-extraneous-dependencies.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ ruleTester.run('no-extraneous-dependencies', rule, {
8686
options: [{ packageDir: packageDirWithFlowTyped }],
8787
parser: require.resolve('babel-eslint'),
8888
}),
89+
test({
90+
code: `
91+
// @flow
92+
import typeof TypeScriptModule from 'typescript';
93+
`,
94+
options: [{ packageDir: packageDirWithFlowTyped }],
95+
parser: require.resolve('babel-eslint'),
96+
}),
8997
test({
9098
code: 'import react from "react";',
9199
options: [{ packageDir: packageDirMonoRepoWithNested }],

0 commit comments

Comments
 (0)