Skip to content

Commit

Permalink
feat(IgnoreImports): allow ignored imports in no-extraneous-dependency
Browse files Browse the repository at this point in the history
Fix : import-js#2400

Idk how to use globs here, so it's no glob, and support `./` for rootDir
  • Loading branch information
kopax-polyconseil authored Sep 27, 2022
1 parent 753505d commit 028972a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ function reportIfMissing(context, deps, depsOptions, node, name) {

if (
declarationStatus.isInDeps ||
depsOptions.allowIgnoreImports ||
(depsOptions.allowDevDeps && declarationStatus.isInDevDeps) ||
(depsOptions.allowPeerDeps && declarationStatus.isInPeerDeps) ||
(depsOptions.allowOptDeps && declarationStatus.isInOptDeps) ||
Expand All @@ -216,6 +217,7 @@ function reportIfMissing(context, deps, depsOptions, node, name) {

if (
declarationStatus.isInDeps ||
depsOptions.allowIgnoreImports ||
(depsOptions.allowDevDeps && declarationStatus.isInDevDeps) ||
(depsOptions.allowPeerDeps && declarationStatus.isInPeerDeps) ||
(depsOptions.allowOptDeps && declarationStatus.isInOptDeps) ||
Expand Down Expand Up @@ -250,6 +252,16 @@ function testConfig(config, filename) {
));
}

function testIgnoreImports(config, filename) {
if (!config) {
return true
}
return config.some(c => (
filename.includes(value.substr(0, 2) === './' ? value.replace('.', process.cwd()) : value)
))
}


module.exports = {
meta: {
type: 'problem',
Expand All @@ -268,6 +280,7 @@ module.exports = {
'packageDir': { 'type': ['string', 'array'] },
'includeInternal': { 'type': ['boolean'] },
'includeTypes': { 'type': ['boolean'] },
'ignoreImports': { 'type': ['array'] },
},
'additionalProperties': false,
},
Expand All @@ -280,6 +293,7 @@ module.exports = {
const deps = getDependencies(context, options.packageDir) || extractDepFields({});

const depsOptions = {
allowIgnoreImports: testIgnoreImports(options.ignoreImports, filename) !== false,
allowDevDeps: testConfig(options.devDependencies, filename) !== false,
allowOptDeps: testConfig(options.optionalDependencies, filename) !== false,
allowPeerDeps: testConfig(options.peerDependencies, filename) !== false,
Expand Down

0 comments on commit 028972a

Please sign in to comment.