Skip to content

Commit 6bae8e5

Browse files
committed
Revert "feat(import-target): Add resolution error reason"
This reverts commit ed7b25c.
1 parent ed7b25c commit 6bae8e5

File tree

6 files changed

+5
-61
lines changed

6 files changed

+5
-61
lines changed

lib/util/check-existence.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function markMissing(context, target) {
2222
loc: /** @type {import('eslint').AST.SourceLocation} */ (
2323
target.node.loc
2424
),
25-
messageId: target.resolveError ? "notFoundBecause" : "notFound",
25+
messageId: "notFound",
2626
data: /** @type {Record<string, *>} */ (target),
2727
})
2828
}
@@ -86,5 +86,4 @@ exports.checkExistence = function checkExistence(context, targets) {
8686

8787
exports.messages = {
8888
notFound: '"{{name}}" is not found.',
89-
notFoundBecause: '"{{name}}" is not found.\n{{resolveError}}',
9089
}

lib/util/import-target.js

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,6 @@ module.exports = class ImportTarget {
131131
*/
132132
this.moduleName = this.getModuleName()
133133

134-
/**
135-
* This is the full resolution failure reasons
136-
* @type {string | null}
137-
*/
138-
this.resolveError = null
139-
140134
/**
141135
* The full path of this import target.
142136
* If the target is a module and it does not exist then this is `null`.
@@ -292,25 +286,12 @@ module.exports = class ImportTarget {
292286

293287
const cwd = this.context.settings?.cwd ?? process.cwd()
294288
for (const directory of this.getPaths()) {
295-
const baseDir = resolve(cwd, directory)
296-
297289
try {
290+
const baseDir = resolve(cwd, directory)
298291
const resolved = requireResolve(baseDir, this.name)
299292
if (typeof resolved === "string") return resolved
300-
} catch (error) {
301-
if (error instanceof Error === false) {
302-
throw error
303-
}
304-
305-
// This is the usual error
306-
if (
307-
error.message ===
308-
`Can't resolve '${this.name}' in '${baseDir}'`
309-
) {
310-
continue
311-
}
312-
313-
this.resolveError = error.message
293+
} catch {
294+
continue
314295
}
315296
}
316297

tests/fixtures/no-missing/node_modules/misconfigured-default/build/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/fixtures/no-missing/node_modules/misconfigured-default/package.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/fixtures/no-missing/node_modules/misconfigured-default/src/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/lib/rules/no-missing-import.js

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ function fixture(name) {
3939
return path.resolve(__dirname, "../../fixtures/no-missing", name)
4040
}
4141

42-
/** @type {import('eslint').RuleTester} */
4342
const ruleTester = new RuleTester({
4443
languageOptions: {
4544
sourceType: "module",
@@ -314,17 +313,7 @@ ruleTester.run("no-missing-import", rule, {
314313
{
315314
filename: fixture("test.js"),
316315
code: "import abcdef from 'esm-module/sub.mjs';",
317-
// errors: ['"esm-module/sub.mjs" is not found.'],
318-
errors: [
319-
{
320-
messageId: "notFoundBecause",
321-
data: {
322-
name: "esm-module/sub.mjs",
323-
resolveError:
324-
"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)",
325-
},
326-
},
327-
],
316+
errors: ['"esm-module/sub.mjs" is not found.'],
328317
},
329318
{
330319
filename: fixture("test.js"),
@@ -404,20 +393,6 @@ ruleTester.run("no-missing-import", rule, {
404393
errors: ['"./A.js" is not found.'],
405394
},
406395

407-
{
408-
filename: fixture("test.js"),
409-
code: "import 'misconfigured-default';",
410-
errors: [
411-
{
412-
messageId: "notFoundBecause",
413-
data: {
414-
name: "misconfigured-default",
415-
resolveError: "Default condition should be last one",
416-
},
417-
},
418-
],
419-
},
420-
421396
// import()
422397
...(DynamicImportSupported
423398
? [

0 commit comments

Comments
 (0)