Do not remove unlinted files from cache if `--cache` is used
See original GitHub issueFirst, here’s a little background on the problem I’m trying to solve:
I run a linting step on my entire project prior to every commit. I use --cache
to speed up linting and check only the files which have changed. So far so good.
However, between commits I also am saving code in Atom, using linter-eslint’s auto-fix on save
option. This executes ESLint without the --cache
flag, so my cache is cleared and the next time I manually lint the cache has to be rebuilt, taking much longer than I’d like.
So, I thought I could just add an option in linter-eslint to add the --cache
flag (https://github.com/AtomLinter/linter-eslint/issues/635), but I realized this still wouldn’t work, because the cache file will be completely overwritten with the cache results of just the one file that was saved/auto-fixed. Aside: to verify this is the case, lint two files, check that the .eslintcache
file contains both filenames, then lint just one of those files (still using --cache
), and you’ll see that the other file has disappeared.
So my proposal is this:
Instead of throwing away the old cache file each time, simply update the results for files that are linted in that run. This way, files which were previously linted stay cached. I have submitted https://github.com/royriojas/file-entry-cache/issues/2 upstream to add that possibility in the package we use for our caching, and if that is accepted the only change to ESLint would likely be to update the dependency.
If the upstream change is not accepted, there are still ways we could accomplish the same result (albeit less cleanly) if the team thinks this would be a worthwhile change.
Issue Analytics
- State:
- Created 7 years ago
- Comments:18 (18 by maintainers)
Sure, I don’t anticipate files to grow too much out of control, though. In this case is also pretty easy to just delete the cache file. Prune might also be able to check if files exists and then decide to remove them from the cache. That can probably be added as an option on the
file-entry-cache
module to avoid adding another flag oneslint
. Something that can be done with:at saving time, entries that were not visited can be check for existence in the file system and be removed if they are not longer found. Will give that a try as well.
Hi @IanVS, I remembered the reason I didn’t keep the files, it is because otherwise files that were deleted will stay forever in the cache. I might have to find another solution to make sure files are not kept in the cache forever if they are not longer present. Or maybe that’s not an issue and users can simply delete the files manually. It seems the benefits of keeping the files are greater than deleting them.
Will try to give it a try during the weekend.
Regards