From a3576a386ed3af37d84345f8c3518ada5990f24b Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 17 Feb 2023 09:21:34 +0100 Subject: [PATCH] chore: fixing the eslint rule Signed-off-by: blam --- packages/eslint-plugin/lib/visitImports.js | 2 ++ .../eslint-plugin/rules/no-undeclared-imports.js | 12 +++++++----- .../eslint-plugin/src/no-undeclared-imports.test.ts | 11 +++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/eslint-plugin/lib/visitImports.js b/packages/eslint-plugin/lib/visitImports.js index 43401bf5f9..1a344c1101 100644 --- a/packages/eslint-plugin/lib/visitImports.js +++ b/packages/eslint-plugin/lib/visitImports.js @@ -34,6 +34,7 @@ const getPackages = require('./getPackages'); * @property {'value' | 'type'} kind * @property {string} path * @property {import('./getPackages').ExtendedPackage} package + * @property {string} packageName */ /** @@ -160,6 +161,7 @@ module.exports = function visitImports(context, visitor) { kind: info.kind, path: subPath, package: pkg, + packageName, }); } diff --git a/packages/eslint-plugin/rules/no-undeclared-imports.js b/packages/eslint-plugin/rules/no-undeclared-imports.js index 42624beb5c..c86792b933 100644 --- a/packages/eslint-plugin/rules/no-undeclared-imports.js +++ b/packages/eslint-plugin/rules/no-undeclared-imports.js @@ -151,11 +151,13 @@ module.exports = { } return visitImports(context, (node, imp) => { - if (imp.type !== 'external') { - return; - } - // We leave checking of type imports to the repo-tools check - if (imp.kind === 'type') { + // We leave checking of type imports to the repo-tools check, + // and we skip builtins and local imports + if ( + imp.kind === 'type' || + imp.type === 'builtin' || + imp.type === 'local' + ) { return; } diff --git a/packages/eslint-plugin/src/no-undeclared-imports.test.ts b/packages/eslint-plugin/src/no-undeclared-imports.test.ts index 1b5cbee853..78844899ba 100644 --- a/packages/eslint-plugin/src/no-undeclared-imports.test.ts +++ b/packages/eslint-plugin/src/no-undeclared-imports.test.ts @@ -236,5 +236,16 @@ ruleTester.run(RULE, rule, { ), ], }, + { + code: `import '@internal/foo'`, + filename: joinPath(FIXTURE, 'packages/bar/src/index.ts'), + errors: [ + ERR_UNDECLARED( + '@internal/foo', + 'dependencies', + joinPath('packages', 'bar'), + ), + ], + }, ], });