Skip to content

Commit

Permalink
Revert "feat(import-target): Add resolution error reason"
Browse files Browse the repository at this point in the history
This reverts commit ed7b25c.
  • Loading branch information
scagood committed Apr 8, 2024
1 parent ed7b25c commit 6bae8e5
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 61 deletions.
3 changes: 1 addition & 2 deletions lib/util/check-existence.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, *>} */ (target),
})
}
Expand Down Expand Up @@ -86,5 +86,4 @@ exports.checkExistence = function checkExistence(context, targets) {

exports.messages = {
notFound: '"{{name}}" is not found.',
notFoundBecause: '"{{name}}" is not found.\n{{resolveError}}',
}
25 changes: 3 additions & 22 deletions lib/util/import-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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
}
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

27 changes: 1 addition & 26 deletions tests/lib/rules/no-missing-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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
? [
Expand Down

0 comments on commit 6bae8e5

Please sign in to comment.