From 2f91c2e5fefa94758825f097179fabf94bf541ac Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Wed, 17 Nov 2021 15:54:44 -0600 Subject: [PATCH] Add failing test for no-extraneous-dependencies 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 https://github.com/import-js/eslint-plugin-import/issues/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. --- tests/src/rules/no-extraneous-dependencies.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/src/rules/no-extraneous-dependencies.js b/tests/src/rules/no-extraneous-dependencies.js index 131604ad95..336c802db1 100644 --- a/tests/src/rules/no-extraneous-dependencies.js +++ b/tests/src/rules/no-extraneous-dependencies.js @@ -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"',