Skip to content

Commit

Permalink
[Refactor] no-extraneous-dependencies: use moduleVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
adamborowski authored and ljharb committed Apr 26, 2020
1 parent 515957a commit 98292ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`no-unused-modules`]: avoid order-dependence ([#1744], thanks [@darkartur])

### Changed
- [Refactor] `no-extraneous-dependencies`: use moduleVisitor ([#1735], thanks [@adamborowski])
- TypeScript config: Disable [`named`][] ([#1726], thanks [@astorije])
- [readme] Remove duplicate no-unused-modules from docs ([#1690], thanks [@arvigeus])
- [Docs] `order`: fix bad inline config ([#1788], thanks [@nickofthyme])
Expand Down Expand Up @@ -695,6 +696,7 @@ for info on changes for earlier releases.
[#1751]: https://github.com/benmosher/eslint-plugin-import/pull/1751
[#1744]: https://github.com/benmosher/eslint-plugin-import/pull/1744
[#1736]: https://github.com/benmosher/eslint-plugin-import/pull/1736
[#1735]: https://github.com/benmosher/eslint-plugin-import/pull/1735
[#1726]: https://github.com/benmosher/eslint-plugin-import/pull/1726
[#1724]: https://github.com/benmosher/eslint-plugin-import/pull/1724
[#1722]: https://github.com/benmosher/eslint-plugin-import/issues/1722
Expand Down Expand Up @@ -1183,3 +1185,4 @@ for info on changes for earlier releases.
[@darkartur]: https://github.com/darkartur
[@MikeyBeLike]: https://github.com/MikeyBeLike
[@barbogast]: https://github.com/barbogast
[@adamborowski]: https://github.com/adamborowski
28 changes: 4 additions & 24 deletions src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import fs from 'fs'
import readPkgUp from 'read-pkg-up'
import minimatch from 'minimatch'
import resolve from 'eslint-module-utils/resolve'
import moduleVisitor from 'eslint-module-utils/moduleVisitor'
import importType from '../core/importType'
import isStaticRequire from '../core/staticRequire'
import docsUrl from '../docsUrl'

function hasKeys(obj = {}) {
Expand Down Expand Up @@ -200,28 +200,8 @@ module.exports = {
allowBundledDeps: testConfig(options.bundledDependencies, filename) !== false,
}

// todo: use module visitor from module-utils core
return {
ImportDeclaration: function (node) {
if (node.source) {
reportIfMissing(context, deps, depsOptions, node, node.source.value)
}
},
ExportNamedDeclaration: function (node) {
if (node.source) {
reportIfMissing(context, deps, depsOptions, node, node.source.value)
}
},
ExportAllDeclaration: function (node) {
if (node.source) {
reportIfMissing(context, deps, depsOptions, node, node.source.value)
}
},
CallExpression: function handleRequires(node) {
if (isStaticRequire(node)) {
reportIfMissing(context, deps, depsOptions, node, node.arguments[0].value)
}
},
}
return moduleVisitor(node => {
reportIfMissing(context, deps, depsOptions, node, node.value)
}, {commonjs: true})
},
}

0 comments on commit 98292ed

Please sign in to comment.