Skip to content

Commit

Permalink
Option2 - no-extraneous-dependencies includes only paths that can be …
Browse files Browse the repository at this point in the history
…resolved, but ignores import/ignore setting

Only resolved paths can be checked whether they actually live in "node_modules" directory
import/ignore does not make sense here, as it's mostly used to ignore imports unknown to this plugin, like .css files.
But still, you may import a css file from a dependency, and this rule should check that.
  • Loading branch information
panrafal committed Oct 12, 2017
1 parent 710f600 commit 4d49f24
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
6 changes: 2 additions & 4 deletions docs/rules/no-extraneous-dependencies.md
Expand Up @@ -3,6 +3,8 @@
Forbid the import of external modules that are not declared in the `package.json`'s `dependencies`, `devDependencies`, `optionalDependencies` or `peerDependencies`.
The closest parent `package.json` will be used. If no `package.json` is found, the rule will not lint anything. This behaviour can be changed with the rule option `packageDir`.

Modules have to be installed for this rule to work.

### Options

This rule supports the following options:
Expand Down Expand Up @@ -33,10 +35,6 @@ Also there is one more option called `packageDir`, this option is to specify the
"import/no-extraneous-dependencies": ["error", {"packageDir": './some-dir/'}]
```

A module path that is [ignored] or couldn't be resolved will not be reported when imported.

[ignored]: ../README.md#importignore

## Rule Details

Given the following `package.json`:
Expand Down
4 changes: 1 addition & 3 deletions src/rules/no-extraneous-dependencies.js
Expand Up @@ -2,7 +2,6 @@ import path from 'path'
import fs from 'fs'
import readPkgUp from 'read-pkg-up'
import minimatch from 'minimatch'
import isIgnored from 'eslint-module-utils/ignore'
import resolve from 'eslint-module-utils/resolve'
import importType from '../core/importType'
import isStaticRequire from '../core/staticRequire'
Expand Down Expand Up @@ -60,8 +59,7 @@ function reportIfMissing(context, deps, depsOptions, node, name) {
return
}
const resolved = resolve(name, context)

if (!resolved || isIgnored(resolved, context)) {
if (!resolved) {
return
}
const splitName = name.split('/')
Expand Down
8 changes: 0 additions & 8 deletions tests/src/rules/no-extraneous-dependencies.js
Expand Up @@ -69,14 +69,6 @@ ruleTester.run('no-extraneous-dependencies', rule, {
code: 'import "doctrine"',
options: [{packageDir: path.join(__dirname, '../../../')}],
}),
test({
code: 'import bar from "not-a-dependency"',
settings: { 'import/ignore': ['/node_modules/'] },
}),
test({
code: 'import bar from "chai"',
settings: { 'import/ignore': ['/node_modules/'] },
}),
],
invalid: [
test({
Expand Down

0 comments on commit 4d49f24

Please sign in to comment.