12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- "use strict"
- const getAllowModules = require("./get-allow-modules")
- const getPackageJson = require("./get-package-json")
- module.exports = function checkForExtraneous(context, filePath, targets) {
- const packageInfo = getPackageJson(filePath)
- if (!packageInfo) {
- return
- }
- const allowed = new Set(getAllowModules(context))
- const dependencies = new Set(
- [].concat(
- Object.keys(packageInfo.dependencies || {}),
- Object.keys(packageInfo.devDependencies || {}),
- Object.keys(packageInfo.peerDependencies || {}),
- Object.keys(packageInfo.optionalDependencies || {})
- )
- )
- for (const target of targets) {
- const extraneous =
- target.moduleName != null &&
- target.filePath != null &&
- !dependencies.has(target.moduleName) &&
- !allowed.has(target.moduleName)
- if (extraneous) {
- context.report({
- node: target.node,
- loc: target.node.loc,
- message: '"{{moduleName}}" is extraneous.',
- data: target,
- })
- }
- }
- }
|