Skip to content
Closed
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
9 changes: 7 additions & 2 deletions src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function getModuleRealName(resolved) {
return getFilePackageName(resolved);
}

function reportIfMissing(context, deps, depsOptions, node, name) {
function reportIfMissing(context, deps, depsOptions, node, name, ignore) {
// Do not report when importing types
if (node.importKind === 'type' || (node.parent && node.parent.importKind === 'type') || node.importKind === 'typeof') {
return;
Expand All @@ -144,6 +144,10 @@ function reportIfMissing(context, deps, depsOptions, node, name) {
// fallback on original name in case no package.json found
const packageName = getModuleRealName(resolved) || getModuleOriginalName(name);

if (packageName.match(ignore)) {
return;
}

const isInDeps = deps.dependencies[packageName] !== undefined;
const isInDevDeps = deps.devDependencies[packageName] !== undefined;
const isInOptDeps = deps.optionalDependencies[packageName] !== undefined;
Expand Down Expand Up @@ -200,6 +204,7 @@ module.exports = {
'peerDependencies': { 'type': ['boolean', 'array'] },
'bundledDependencies': { 'type': ['boolean', 'array'] },
'packageDir': { 'type': ['string', 'array'] },
'ignore': { 'type': 'regexp' },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a very bad idea to allow regex strings in eslint configs; that's how you get CVEs. this should be a glob string instead.

i'd also expect it to be allowed to be an array of glob strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that's a good idea!

},
'additionalProperties': false,
},
Expand All @@ -219,7 +224,7 @@ module.exports = {
};

return moduleVisitor((source, node) => {
reportIfMissing(context, deps, depsOptions, node, source.value);
reportIfMissing(context, deps, depsOptions, node, source.value, options.ignore);
}, { commonjs: true });
},
};