When you have a branch checked out and the code is linted with eslint and the --cache
flag, it generates a .eslintcache
file. Because the .eslintcache
is in my .gitignore
, when you switch to another branch and the code is linted again, the cache file is already there so eslint in theory reuses it but we cannot assume that the previous cached files are valid. So shouldn't we remove the .eslintcache
file when switching branches?
Asked
Active
Viewed 5,229 times
15

icc97
- 11,395
- 8
- 76
- 90

Gabriel Llamas
- 18,244
- 26
- 87
- 112
-
2I don't see why you couldn't check in the `.eslintcache` file. ESLint itself does a good job of cache invalidation, and you'll get the benefits of the cache in your CI as well. – IanVS Sep 29 '21 at 14:24
-
Eslint uses files' metadata for caching so I guess there won't be a problem as same files in different branches will have the same metadata. – Vahid Jan 07 '22 at 12:30
-
1Here's an example of why you shouldn't commit it to source control: https://stackoverflow.com/questions/65055617/deploying-create-react-app-on-openshift-eacces-permission-denied-open-home – icc97 Feb 15 '22 at 09:35
2 Answers
4
Could not find any suggestions on this matter, but adding .eslintcache to .gitignore is a more convinient way than deleting it manually every time

o-faro
- 789
- 8
- 16
-
4I think that you should add it to your `.gitignore` - but I think the question was more asking "what's invalidating the cache?" since the code will change when switching branches thus the lint cache may become outdated. – Edward Thomson Dec 15 '20 at 16:24
0
This is a bit of guess work - but I believe that you are fine to leave the .eslintcache
in your project when you switch branches.
For a single file in .eslintcache
it will have the something like the following info:
"/path/to/project/src/components/App.js": "6",
...
{
"size": 538,
"mtime": 1644596159286,
"results": "439",
"hashOfConfig": "434"
},
...
{
"filePath": "876",
"messages": "877",
"errorCount": 0,
"fatalErrorCount": 0,
"warningCount": 0,
"fixableErrorCount": 0,
"fixableWarningCount": 0
},
...
"/path/to/project/src/components/App.js",
[],
So it has a modified time in the cache - I assume if you switch branches then the modified time will change which should result in the cache detecting that the new files pulled in to your branch need re-linting.
I'm guessing also that the cache will delete any files that no longer exist, add any new files.

icc97
- 11,395
- 8
- 76
- 90