diff --git a/lib/util/check-existence.js b/lib/util/check-existence.js index a015d3a4..a7899a75 100644 --- a/lib/util/check-existence.js +++ b/lib/util/check-existence.js @@ -22,7 +22,7 @@ function markMissing(context, target) { loc: /** @type {import('eslint').AST.SourceLocation} */ ( target.node.loc ), - messageId: target.resolveError ? "notFoundBecause" : "notFound", + messageId: "notFound", data: /** @type {Record} */ (target), }) } @@ -86,5 +86,4 @@ exports.checkExistence = function checkExistence(context, targets) { exports.messages = { notFound: '"{{name}}" is not found.', - notFoundBecause: '"{{name}}" is not found.\n{{resolveError}}', } diff --git a/lib/util/import-target.js b/lib/util/import-target.js index 36c2dfd3..93f72c74 100644 --- a/lib/util/import-target.js +++ b/lib/util/import-target.js @@ -131,12 +131,6 @@ module.exports = class ImportTarget { */ this.moduleName = this.getModuleName() - /** - * This is the full resolution failure reasons - * @type {string | null} - */ - this.resolveError = null - /** * The full path of this import target. * If the target is a module and it does not exist then this is `null`. @@ -292,25 +286,12 @@ module.exports = class ImportTarget { const cwd = this.context.settings?.cwd ?? process.cwd() for (const directory of this.getPaths()) { - const baseDir = resolve(cwd, directory) - try { + const baseDir = resolve(cwd, directory) const resolved = requireResolve(baseDir, this.name) if (typeof resolved === "string") return resolved - } catch (error) { - if (error instanceof Error === false) { - throw error - } - - // This is the usual error - if ( - error.message === - `Can't resolve '${this.name}' in '${baseDir}'` - ) { - continue - } - - this.resolveError = error.message + } catch { + continue } } diff --git a/tests/fixtures/no-missing/node_modules/misconfigured-default/build/index.js b/tests/fixtures/no-missing/node_modules/misconfigured-default/build/index.js deleted file mode 100644 index 336ce12b..00000000 --- a/tests/fixtures/no-missing/node_modules/misconfigured-default/build/index.js +++ /dev/null @@ -1 +0,0 @@ -export {} diff --git a/tests/fixtures/no-missing/node_modules/misconfigured-default/package.json b/tests/fixtures/no-missing/node_modules/misconfigured-default/package.json deleted file mode 100644 index 34cec732..00000000 --- a/tests/fixtures/no-missing/node_modules/misconfigured-default/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "misconfigured-default", - "exports": { - ".": { - "default": "./build/index.js", - "types": "./src/index.ts" - } - } -} diff --git a/tests/fixtures/no-missing/node_modules/misconfigured-default/src/index.ts b/tests/fixtures/no-missing/node_modules/misconfigured-default/src/index.ts deleted file mode 100644 index 336ce12b..00000000 --- a/tests/fixtures/no-missing/node_modules/misconfigured-default/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export {} diff --git a/tests/lib/rules/no-missing-import.js b/tests/lib/rules/no-missing-import.js index 1ca7f6c6..2f6ea3f0 100644 --- a/tests/lib/rules/no-missing-import.js +++ b/tests/lib/rules/no-missing-import.js @@ -39,7 +39,6 @@ function fixture(name) { return path.resolve(__dirname, "../../fixtures/no-missing", name) } -/** @type {import('eslint').RuleTester} */ const ruleTester = new RuleTester({ languageOptions: { sourceType: "module", @@ -314,17 +313,7 @@ ruleTester.run("no-missing-import", rule, { { filename: fixture("test.js"), code: "import abcdef from 'esm-module/sub.mjs';", - // errors: ['"esm-module/sub.mjs" is not found.'], - errors: [ - { - messageId: "notFoundBecause", - data: { - name: "esm-module/sub.mjs", - resolveError: - "Package path ./sub.mjs is not exported from package /home/scagood/github/open-source/eslint-plugin-n/tests/fixtures/no-missing/node_modules/esm-module (see exports field in /home/scagood/github/open-source/eslint-plugin-n/tests/fixtures/no-missing/node_modules/esm-module/package.json)", - }, - }, - ], + errors: ['"esm-module/sub.mjs" is not found.'], }, { filename: fixture("test.js"), @@ -404,20 +393,6 @@ ruleTester.run("no-missing-import", rule, { errors: ['"./A.js" is not found.'], }, - { - filename: fixture("test.js"), - code: "import 'misconfigured-default';", - errors: [ - { - messageId: "notFoundBecause", - data: { - name: "misconfigured-default", - resolveError: "Default condition should be last one", - }, - }, - ], - }, - // import() ...(DynamicImportSupported ? [