Skip to content

Commit

Permalink
perf: avoid unnecessary fs.statSync calls
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marvinhagemeister committed Jan 10, 2023
1 parent 46de0e8 commit 3eae619
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,26 @@ function getMappedPath(
]),
)
.flat(2)
.filter(mappedPath => isFile(mappedPath) || isModule(mappedPath))
.filter(mappedPath => {
if (mappedPath === undefined) {
return false
}

try {
const stat = fs.statSync(mappedPath, { throwIfNoEntry: false })
if (stat === undefined) return false
if (stat.isFile()) return true

// Maybe this is a module dir?
if (stat.isDirectory()) {
return isModule(mappedPath)
}
} catch {
return false
}

return false
})
}

if (retry && paths.length === 0) {
Expand Down

0 comments on commit 3eae619

Please sign in to comment.