Skip to content

Commit 98292ed

Browse files
adamborowskiljharb
authored andcommitted
[Refactor] no-extraneous-dependencies: use moduleVisitor
1 parent 515957a commit 98292ed

File tree

2 files changed

+7
-24
lines changed

2 files changed

+7
-24
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
2323
- [`no-unused-modules`]: avoid order-dependence ([#1744], thanks [@darkartur])
2424

2525
### Changed
26+
- [Refactor] `no-extraneous-dependencies`: use moduleVisitor ([#1735], thanks [@adamborowski])
2627
- TypeScript config: Disable [`named`][] ([#1726], thanks [@astorije])
2728
- [readme] Remove duplicate no-unused-modules from docs ([#1690], thanks [@arvigeus])
2829
- [Docs] `order`: fix bad inline config ([#1788], thanks [@nickofthyme])
@@ -695,6 +696,7 @@ for info on changes for earlier releases.
695696
[#1751]: https://github.com/benmosher/eslint-plugin-import/pull/1751
696697
[#1744]: https://github.com/benmosher/eslint-plugin-import/pull/1744
697698
[#1736]: https://github.com/benmosher/eslint-plugin-import/pull/1736
699+
[#1735]: https://github.com/benmosher/eslint-plugin-import/pull/1735
698700
[#1726]: https://github.com/benmosher/eslint-plugin-import/pull/1726
699701
[#1724]: https://github.com/benmosher/eslint-plugin-import/pull/1724
700702
[#1722]: https://github.com/benmosher/eslint-plugin-import/issues/1722
@@ -1183,3 +1185,4 @@ for info on changes for earlier releases.
11831185
[@darkartur]: https://github.com/darkartur
11841186
[@MikeyBeLike]: https://github.com/MikeyBeLike
11851187
[@barbogast]: https://github.com/barbogast
1188+
[@adamborowski]: https://github.com/adamborowski

src/rules/no-extraneous-dependencies.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import fs from 'fs'
33
import readPkgUp from 'read-pkg-up'
44
import minimatch from 'minimatch'
55
import resolve from 'eslint-module-utils/resolve'
6+
import moduleVisitor from 'eslint-module-utils/moduleVisitor'
67
import importType from '../core/importType'
7-
import isStaticRequire from '../core/staticRequire'
88
import docsUrl from '../docsUrl'
99

1010
function hasKeys(obj = {}) {
@@ -200,28 +200,8 @@ module.exports = {
200200
allowBundledDeps: testConfig(options.bundledDependencies, filename) !== false,
201201
}
202202

203-
// todo: use module visitor from module-utils core
204-
return {
205-
ImportDeclaration: function (node) {
206-
if (node.source) {
207-
reportIfMissing(context, deps, depsOptions, node, node.source.value)
208-
}
209-
},
210-
ExportNamedDeclaration: function (node) {
211-
if (node.source) {
212-
reportIfMissing(context, deps, depsOptions, node, node.source.value)
213-
}
214-
},
215-
ExportAllDeclaration: function (node) {
216-
if (node.source) {
217-
reportIfMissing(context, deps, depsOptions, node, node.source.value)
218-
}
219-
},
220-
CallExpression: function handleRequires(node) {
221-
if (isStaticRequire(node)) {
222-
reportIfMissing(context, deps, depsOptions, node, node.arguments[0].value)
223-
}
224-
},
225-
}
203+
return moduleVisitor(node => {
204+
reportIfMissing(context, deps, depsOptions, node, node.value)
205+
}, {commonjs: true})
226206
},
227207
}

0 commit comments

Comments
 (0)