typescript-eslint: Bug: Project service settings can be nondeterministic based on config and file glob result orders
Before You File a Bug Report Please Confirm You Have Done The Following…
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have searched for related issues and found none that matched my issue.
- I have read the FAQ and my problem is not listed.
Issue Description
I’m getting this error under eslint@9.12.0, which did not occur under eslint@9.11.1:
/wherever/vitest.config.ts
0:0 error Parsing error: /wherever/vitest.config.ts was not found by the project service.
Consider either including it in the tsconfig.json or including it in allowDefaultProject
The pertinent config is:
{
files: ['*.ts', '{src,db}/**/*.ts'],
extends: [...ts.configs.recommendedTypeChecked],
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ['vitest.config.ts'],
},
tsconfigRootDir: import.meta.dirname,
},
},
},
{
files: ['db/**/*.ts'],
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname + '/db',
},
},
},
The problem disappears if any of these are changed:
- eslint is downgraded to lower version
- the last block (with
files: ['db/**/*.ts']) is removed - the first block is changed to not overlap with the second (i.e.,
files: ['*.ts', 'src/**/*.ts'])
Reproduction Repository Link
https://github.com/LukeNotable/eslint-9.12.0-allow-default-project-bug
Repro Steps
- clone the repo
yarn installyarn eslint .
Versions
| package | version |
|---|---|
@typescript-eslint/eslint-plugin |
8.9.0 |
@typescript-eslint/parser |
8.9.0 |
@typescript-eslint/scope-manager |
8.9.0 |
@typescript-eslint/typescript-estree |
8.9.0 |
@typescript-eslint/type-utils |
8.9.0 |
@typescript-eslint/utils |
8.9.0 |
TypeScript |
5.5.4 |
ESLint |
9.12.0 |
node |
22.9.0 |
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 7
- Comments: 17 (7 by maintainers)
I would be curious if TS 5.7’s project loading changes would make this more well-behaved; might be worth a try. There have been improvements to project loading which should result in projects being more correctly/optimally loaded (and even fewer loads).
Ok, yes, I do see this reproducing sometimes now. It didn’t the first couple of times I tried. 🫠 Doing a bit of debugging with
DEBUG=*…When project resolution succeeds, some relevant log lines:
When it fails:
Going up, I see that when
createParseSettingsis first called withdb/bar.ts, we do see the error. But when it’s first called withvitest.config.tsthen we don’t see the error. So, yes, it looks like it’s nondeterministic based on which of the two config blocks happens to hit the file first.A root reason for this is that we create a single project service once per lint run: https://github.com/typescript-eslint/typescript-eslint/blob/8d35958494eb0c97cc36c3fc0844aea377542315/packages/typescript-estree/src/parseSettings/createParseSettings.ts#L110-L120
We would love to have more intelligent project service creation, but can’t because ESLint core doesn’t tell parsers such as
@typescript-eslint/parser(which is what calls to@typescript-eslint/typescript-estree) session information. We asked for this in https://github.com/eslint/rfcs/pull/102 but it was not accepted.In the meantime, I’m not sure the best way to do this. Maybe we could, in
createParseSettings:tsestreeOptions.projectServicehas changed (like a deep equality check)Maphashing project service settings to project servicescc @bradzacher @jakebailey - I suspect we’d have to do some experimentation to see how bad it is to have multiple project services floating around. My hunch is that, no, that’s really bad for memory in larger projects and shouldn’t be allowed.
It’s non-deterministic. For me it fails ~80% of the time with
yarn eslint .(4 files), or ~20% of the time withyarn eslint vitest.config.ts db/bar.ts(2 files).