Skip to content

Commit 3eae619

Browse files
perf: avoid unnecessary fs.statSync calls
Only resolve a module dir when we now that the mapped path is a directory. This improves linting time by about 18% in some projects with lots of files.
1 parent 46de0e8 commit 3eae619

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Diff for: src/index.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,26 @@ function getMappedPath(
287287
]),
288288
)
289289
.flat(2)
290-
.filter(mappedPath => isFile(mappedPath) || isModule(mappedPath))
290+
.filter(mappedPath => {
291+
if (mappedPath === undefined) {
292+
return false
293+
}
294+
295+
try {
296+
const stat = fs.statSync(mappedPath, { throwIfNoEntry: false })
297+
if (stat === undefined) return false
298+
if (stat.isFile()) return true
299+
300+
// Maybe this is a module dir?
301+
if (stat.isDirectory()) {
302+
return isModule(mappedPath)
303+
}
304+
} catch {
305+
return false
306+
}
307+
308+
return false
309+
})
291310
}
292311

293312
if (retry && paths.length === 0) {

0 commit comments

Comments
 (0)