Skip to content

Commit

Permalink
refactor: use modueVisitor for no-extraneous-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
adamborowski committed Apr 26, 2020
1 parent 92caa35 commit ed7e57f
Showing 1 changed file with 5 additions and 24 deletions.
29 changes: 5 additions & 24 deletions src/rules/no-extraneous-dependencies.js
Expand Up @@ -4,7 +4,8 @@ import readPkgUp from 'read-pkg-up'
import minimatch from 'minimatch'
import resolve from 'eslint-module-utils/resolve'
import importType from '../core/importType'
import isStaticRequire from '../core/staticRequire'
import moduleVisitor from 'eslint-module-utils/moduleVisitor'

import docsUrl from '../docsUrl'

function hasKeys(obj = {}) {
Expand Down Expand Up @@ -200,28 +201,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 ed7e57f

Please sign in to comment.