-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Duplicate error message displayed when flat config contains eslintrc top-level key #17560
Comments
I'm on macOS and I couldn't reproduce this locally with VSCode. > npx eslint index.js
Oops! Something went wrong! :(
ESLint: 8.49.0
A config object is using the "globals" key, which is not supported in flat config system.
Flat config uses "languageOptions.globals" to define global variables for your files.
Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#configuring-language-options Could this be a Windows specific issue? |
That's what I'm wondering. Need someone else with Windows to confirm. |
I can reproduce this on Windows and MacOS if I pass two non-empty directories as command-line arguments (or the same argument twice):
My repro: https://stackblitz.com/edit/stackblitz-starters-tqtbuu?file=README.md Not sure why the behavior in StackBlitz is different. |
I can reproduce this on Windows. I'd guess this has something to do with how |
Perhaps we should do |
Relevant: #7569. |
|
Maybe we could change Lines 119 to 120 in 55c1685
? |
That would causes Node.js to print a stacktrace of the second error, because it's unhandled. This is what the output on MacOS looks like when > lint
> eslint src/ test/
Oops! Something went wrong! :(
ESLint: 8.47.0
A config object is using the "globals" key, which is not supported in flat config system.
Flat config uses "languageOptions.globals" to define global variables for your files.
Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#configuring-language-options
[...]/node_modules/@humanwhocodes/object-schema/src/object-schema.js:221
throw ex;
^
IncompatibleKeyError: Key "globals": This appears to be in eslintrc format rather than flat config format.
at Object.validate ([...]/node_modules/eslint/lib/config/flat-config-schema.js:488:19)
at ObjectSchema.validate ([...]/node_modules/@humanwhocodes/object-schema/src/object-schema.js:218:35)
at [...]/node_modules/@humanwhocodes/object-schema/src/object-schema.js:171:18
at Array.reduce (<anonymous>)
at ObjectSchema.merge ([...]/node_modules/@humanwhocodes/object-schema/src/object-schema.js:169:24)
at [...]/node_modules/@humanwhocodes/config-array/api.js:966:42
at Array.reduce (<anonymous>)
at FlatConfigArray.getConfig ([...]/node_modules/@humanwhocodes/config-array/api.js:965:39)
at FlatConfigArray.isFileIgnored ([...]/node_modules/@humanwhocodes/config-array/api.js:993:15)
at [...]/node_modules/eslint/lib/eslint/eslint-helpers.js:312:49 {
messageTemplate: 'eslintrc-incompat',
messageData: { key: 'globals' }
}
Node.js v20.6.1 Not sure where the last line with "Node.js v20.6.1" is coming from. |
We could update |
Execution isn't actually continuing here , it's already stopped. All that is to say that ensuring a duplicate message isn't output is probably the path of least resistance to addressing this and I don't think there are any side effects to be concerned with. |
In some cases, eslint could keep working for a long time after an error occurs. For example, add this to if (context.filename.endsWith("Makefile.js")) {
throw new Error("Crashed!");
} Then run The error appears quickly because
But then it continues linting other files, which seems wrong because the rule and its callers (e.g., linter) are possibly in a broken state, and it takes 30-40s before the command prompt appears again. |
@mdjermanovic that seems like a bug in error handling for rules that should be fixed? Do you want to open a separate issue for that? For some further context: testing locally it seems that running ESLint via I haven't been able to come up with an automated test that displays this behavior, but I did put together a PR with a possible approach: #17584 |
I thought we would fix this by exiting the process, and that would fix the problem I mentioned as well (though only when ESLint is used through CLI). I opened a separate issue now: #17621 |
* fix: Ensure crash error messages are not duplicated Fixes #17560 * Add test * Fix merge conflicts * Add tests --------- Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Environment
Node version: v18.16.0
npm version: v7.10.0
Local ESLint version: v8.49.0 (Currently used)
Global ESLint version: Not found
Operating System: win32 10.0.19045
What parser are you using?
Default (Espree)
What did you do?
Created an
eslint.config.js
file withglobals
as a top-level key.Configuration
What did you expect to happen?
I should get an error message explaining that
globals
is invalid.What actually happened?
I got two error messages explaining that
globals
is invalid.Link to Minimal Reproducible Example
https://stackblitz.com/edit/stackblitz-starters-yk4rv3
Participation
Additional comments
Interestingly, the StackBlitz repro doesn't show this behavior but I'm able to reproduce it consistently locally (on Windows in VS Code).
The text was updated successfully, but these errors were encountered: