Skip to content

Commit df6ad2a

Browse files
GertSallaertsscagood
andauthoredNov 15, 2024··
fix(no-missing-require): handle multiple resolvePaths (#383)
Co-authored-by: Sebastian Good <2230835+scagood@users.noreply.github.com>
1 parent c4d1551 commit df6ad2a

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed
 

‎lib/util/import-target.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ module.exports = class ImportTarget {
270270
this.resolveError = error.message
271271
}
272272

273+
/**
274+
* @returns {void}
275+
*/
276+
resetResolutionError() {
277+
this.resolveError = null
278+
}
279+
273280
/**
274281
* Resolve the given id to file paths.
275282
* @returns {string | null} The resolved path.
@@ -324,7 +331,10 @@ module.exports = class ImportTarget {
324331

325332
try {
326333
const resolved = requireResolve(baseDir, this.name)
327-
if (typeof resolved === "string") return resolved
334+
if (typeof resolved === "string") {
335+
this.resetResolutionError()
336+
return resolved
337+
}
328338
} catch (error) {
329339
this.handleResolutionError(error)
330340
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ ruleTester.run("no-missing-import", rule, {
181181
code: "import a from './fixtures/no-missing/a.js';",
182182
options: [{ resolvePaths: ["tests"] }],
183183
},
184+
{
185+
filename: fixture("test.js"),
186+
code: "import a from './fixtures/no-missing/a.js';",
187+
options: [{ resolvePaths: ["scripts", "tests"] }],
188+
},
184189

185190
// typescriptExtensionMap
186191
{

‎tests/lib/rules/no-missing-require.js

+10
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ ruleTester.run("no-missing-require", rule, {
130130
code: "require('./fixtures/no-missing/a');",
131131
options: [{ resolvePaths: ["tests"] }],
132132
},
133+
{
134+
filename: fixture("test.js"),
135+
code: "require('./fixtures/no-missing/a');",
136+
options: [{ resolvePaths: ["scripts", "tests"] }],
137+
},
138+
{
139+
filename: fixture("test.js"),
140+
code: "require('./a');",
141+
options: [{ resolvePaths: ["tests"] }],
142+
},
133143

134144
// Ignores it if not callee.
135145
{

0 commit comments

Comments
 (0)
Please sign in to comment.