Skip to content

Commit

Permalink
Add failing test for no-extraneous-dependencies
Browse files Browse the repository at this point in the history
While writing imports in VSCode recently, I started to get errors throwm
from eslint that appear to originate from eslint-plugin-import.

Here's the strack trace from the output panel:

```
[Error - 3:52:43 PM] TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:124:11)
    at isAbsolute (path.js:1029:5)
    at isAbsolute (/path/to/repo/node_modules/eslint-plugin-import/src/core/importType.js:17:10)
    at typeTest (/path/to/repo/node_modules/eslint-plugin-import/src/core/importType.js:92:7)
    at resolveImportType (/path/to/repo/node_modules/eslint-plugin-import/src/core/importType.js:105:10)
    at reportIfMissing (/path/to/repo/node_modules/eslint-plugin-import/src/rules/no-extraneous-dependencies.js:170:7)
    at commonjs (/path/to/repo/node_modules/eslint-plugin-import/src/rules/no-extraneous-dependencies.js:267:7)
    at checkSourceValue (/path/to/repo/node_modules/eslint-module-utils/moduleVisitor.js:29:5)
    at checkSource (/path/to/repo/node_modules/eslint-module-utils/moduleVisitor.js:34:5)
    at /path/to/repo/node_modules/eslint/lib/linter/safe-emitter.js:45:58
```

I am able to trigger this consistently when writing an import, before I
start the open quote, like this:

```
import foo from
```

I found #1931
which pointed at a problem in the resolvers causing this problem. We do
use some custom resolvers with this plugin, so I tried disabling that
but the problem persisted.

Thankfully, I was able to reproduce this error in the test suite.

It would be good if this plugin handled this scenario gracefully instead
of throwing an error.
  • Loading branch information
lencioni committed Nov 17, 2021
1 parent 7c239fe commit 2f91c2e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/src/rules/no-extraneous-dependencies.js
Expand Up @@ -164,7 +164,13 @@ ruleTester.run('no-extraneous-dependencies', rule, {
`,
settings: { 'import/resolver': 'webpack' },
}),

// Incomplete line, e.g. like while typing in your editor
test({
code: 'import foo from ',
}),
],

invalid: [
test({
code: 'import "not-a-dependency"',
Expand Down

0 comments on commit 2f91c2e

Please sign in to comment.