Description
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
- I have read the FAQ and my problem is not listed.
Repro
If you run node index.js
on this stackblitz and follow the instructions it prints, you'll run into the error: https://stackblitz.com/edit/node-skp6gk?file=index.js
Generally, I run into this when I have one file containing an interface with a property and another file that references that property. Then following these steps gets me a "@typescript-eslint/no-unnecessary-type-assertion" error on step 3:
- Run esLint.lintFiles(["code_file_path.ts", "interface_file_path.ts"])
- Make the property on the interface optional in interface_file_path.ts and add a non-null assertion to where we reference it in code_file_path.ts
- Run the same command from step 1
If I then kill the node process that I'm running the linter from and restart it, it doesn't throw the error on step 1. Additionally, if I swap the order that the files go into the linter that seems to fix it too.
Expected Result
I expect that without any caching enabled, there shouldn't be a case where running eslint.lintFiles on a file a second time would give me an error based on the state of the files when they were passed into eslint.lintFiles the first time.
Actual Result
Even after disabling any kind of ESLint caching, following the steps in the repro case causes a linter error even though the passed in files are correctly formatted.
Additional Info
Sorry if this is on the wrong repo, I don't understand enough about the inner workings to be sure this is the right place.
I ran into this using ESLintWebpackPlugin, which uses webpack's compilation hooks to determine what files have changed during a rebuild and passes an array of their absolute paths into eslint.lintFiles. Before opening a bug with them to see if there's a way to order this list to put dependencies before files they depend on, I want to make sure that the lintFiles function having a required order for files that are passed into it is deliberate.
Versions
package | version |
---|---|
@typescript-eslint/parser |
5.16.0 |
TypeScript |
4.6.3 |
ESLint |
8.11.0 |
node |
14.19.0 |