Closed fisker closed 1 year ago
The cache key needs to take into account the gitignore file mtime
, otherwise, it will cause incorrect stale results if the gitginore file changes.
Hmm, this caching seem to assume it's being used in a short-running process.
For xo
, it should created an isGitIgnored
on each xo.lintFiles()
call, and only read .gitignore
once. So let's add a createIsGitIgnored
function?
One second, it seems xo
already filter the ignored file https://github.com/xojs/xo/blob/b15cbfed6e7db7100158fc9d614b69621449604e/index.js#LL31C34-L31C34, maybe just remove this line https://github.com/xojs/xo/blob/b15cbfed6e7db7100158fc9d614b69621449604e/index.js#L93? This line also use ignore: ignorePatterns
, but isGitIgnoredSync
doesn't accept it at all https://github.com/sindresorhus/globby/blob/cb892abe709a6359e80e1895b8a6d4a0890155f4/ignore.js#L59.
Finally understand the problem.
xo
isn't use isGitIgnoredSync
correctly.
+ const isIgnore = isGitIgnoredSync({cwd});
const reports = await Promise.all(
Object.values(groups)
.map(async filesWithOptions => {
for (const options of filesWithOptions) {
/* ... */
- isGitIgnoredSync({cwd})(filePath)
+ isIgnore(filePath)
/* ... */
}
}));
We have to admire this isGitIgnoredSync
is a bad design.
I was running
xo
ineslint-plugin-unicorn
project, and found it's very slow. So I add some debug infoAnd found
isGitIgnoredSync
is very slow. It keeps glob and read.gitignore
file again and again.After this
Problem is how should we process this? Add an option? Add a new
createIsGitIgnored
function? Or just cache the result?