-
-
Notifications
You must be signed in to change notification settings - Fork 43
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: FlatCompat.config
doesn't work with overrides
#125
Bug: FlatCompat.config
doesn't work with overrides
#125
Comments
I'm sorry, the reproduction case isn't very clear to me. What is it you're trying to show? For what it's worth, we already know that configs with eslintrc/tests/lib/flat-compat.js Line 391 in 6cfa046
If you'd like to add a test that shows what is failing, we can definitely take a look. Regarding |
Using const legacyConfig = compat.config({
rules: {
'no-undef': 'error',
},
overrides: [{
files: ['node.js'],
env: {
node: true
},
}]
}) generates something like: [
{ rules: { no-undef: "error" }, // ✅ correct
{ languageOptions: { globals: { … }} }, // ⚠️ applied globally as there are no files
{ files() { … } }, // ⚠️ doesn't contain the globals
] But my understanding of the flat config is that, as Instead I'd imagine [
{ rules: { no-undef: "error" }, // ✅ correct
{ languageOptions: { globals: { … }}, files() { … } }, // 👍 has both the files and the languageOptions
] I can try to modify the test to showcase what I mean. |
That's what I figured. I only mentioned this because this could make working with const legacyConfig = compat.config({
overrides: [{
files: ['node.js'],
env: {
node: true,
es2020: true
},
}]
}) This may need to generate: [
// The field `files()` is duplicated in both entries
{ languageOptions: { globals: { globals for node }}, files() { … } },
{ languageOptions: { globals: { globals for es2020 }}, files() { … } },
] |
I created the test here: https://github.com/eslint/eslintrc/compare/main...Ayc0:eslintrc:Ayc0/potential-bug-investigation?expand=1 If you want, I can open the PR |
Thanks, I'll take a look. As an FYI: the eslintrc-style configs are first translated into an intermediate form (the form that ESLint uses internally) and then into flat config format. The intermediate form doesn't exactly match either eslintrc or flat config formats, which is why there's not always a 1-to-1 matching in either direction. |
I've confirmed that there is a bug here: when environments are in an overrides object, the globals are added as a universal config rather than using the same I'm working on this. |
Step to reproduce
eslint
:8.46.0
@eslint/eslintrc
:2.1.1
You can open & run: https://runkit.com/ayc0/64cac9cf2e21ef0008bee16d
This runkit gets lost / deleted / edited, here is the raw code
Explanation of the bug
If we have this config:
With the legacy config, using
process.cwd()
shouldn't be allowed in a file likeno-node.js
, but allowed innode.js
And if we use
FlatCompat
to port it to the new structure, we should have the same result.But when we do:
We can see that the
files
and envs' config aren't merged together, instead we have 1 row for theenv
, and another one empty one for the overrides:And surely, when we run eslint with this config, no errors are reported (see the
""
x2):The text was updated successfully, but these errors were encountered: