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-extraneous-dependencies: Exclude flow typeof imports #1534

Merged
merged 1 commit into from
Feb 1, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`no-cycle`]/[`extensions`]: fix isExternalModule usage ([#1696], thanks [@paztis])
- [`extensions`]/[`no-cycle`]/[`no-extraneous-dependencies`]: Correct module real path resolution ([#1696], thanks [@paztis])
- [`no-named-default`]: ignore Flow import type and typeof ([#1983], thanks [@christianvuerings])
- [`no-extraneous-dependencies`]: Exclude flow `typeof` imports ([#1534], thanks [@devongovett])

### Changed
- [Generic Import Callback] Make callback for all imports once in rules ([#1237], thanks [@ljqx])
Expand Down Expand Up @@ -819,6 +820,7 @@ for info on changes for earlier releases.
[#1560]: https://github.com/benmosher/eslint-plugin-import/pull/1560
[#1551]: https://github.com/benmosher/eslint-plugin-import/pull/1551
[#1542]: https://github.com/benmosher/eslint-plugin-import/pull/1542
[#1534]: https://github.com/benmosher/eslint-plugin-import/pull/1534
[#1528]: https://github.com/benmosher/eslint-plugin-import/pull/1528
[#1526]: https://github.com/benmosher/eslint-plugin-import/pull/1526
[#1521]: https://github.com/benmosher/eslint-plugin-import/pull/1521
Expand Down Expand Up @@ -1338,3 +1340,4 @@ for info on changes for earlier releases.
[@panrafal]: https://github.com/panrafal
[@ttmarek]: https://github.com/ttmarek
[@christianvuerings]: https://github.com/christianvuerings
[@devongovett]: https://github.com/devongovett
2 changes: 1 addition & 1 deletion src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function getModuleRealName(resolved) {

function reportIfMissing(context, deps, depsOptions, node, name) {
// Do not report when importing types
if (node.importKind === 'type' || (node.parent && node.parent.importKind === 'type')) {
if (node.importKind === 'type' || (node.parent && node.parent.importKind === 'type') || node.importKind === 'typeof') {
return;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ ruleTester.run('no-extraneous-dependencies', rule, {
options: [{ packageDir: packageDirWithFlowTyped }],
parser: require.resolve('babel-eslint'),
}),
test({
code: `
// @flow
import typeof TypeScriptModule from 'typescript';
`,
options: [{ packageDir: packageDirWithFlowTyped }],
parser: require.resolve('babel-eslint'),
}),
test({
code: 'import react from "react";',
options: [{ packageDir: packageDirMonoRepoWithNested }],
Expand Down