-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
Unable to use ESLint flat config for linting JavaScript #3570
Comments
I tried getting around this by removing the # .mega-linter.yml
# ...other configs
JAVASCRIPT_ES_CONFIG_FILE: ./eslint.config.mjs
JAVASCRIPT_ES_COMMAND_REMOVE_ARGUMENTS: ["--eslintrc"] When I run the linter with this configuration, I get this error:
|
I found that replacing
It seems javascript.megalinter-descriptor defines the ignore option to be
|
Is the flat config supported before version 9 of eslint? I see the last release of Megalinter had eslint 8.57.0. |
Yes, the eslint website has a migration guide which mentions the flat config is the default in eslint 9, but is also available in eslint 8. |
In that migration guide, I read that using an ignore file isn't supported anymore. That would explain why --ignore-path doesn't work. They say to https://eslint.org/docs/latest/use/configure/migration-guide#ignoring-files The old way of ignoring (what Megalinter is still set up for), has docs here: https://eslint.org/docs/latest/use/configure/ignore-deprecated You can try to extrapolate what config is created by the linter's descriptor here (or use debug logging if possible to see what would be called):
And finally, at the end of all this, I'd like to know your experience on if it would be possible to support both current config and flat config in Megalinter, or we need to force all users to use v9 and migrate their configs+project configs and those who can't would need to use an older Megalinter. Since the eslintignore doesn't exist anymore, is there a way we could have a working base preset/config for users that don't have a config yet? |
It depends on what we can do in EslintLinter.py ESlint v8 and v9 still support both formats, the default just changed between the two versions. We can set an environment variable to override it (ESLINT_USE_FLAT_CONFIG=false). Figuring out which format a user wants could be done in a few ways:
(A flat config file has the name "eslint.config.[mc]?js") Is there currently a default .eslintignore? Does the user's .eslintignore override it, or extend it? |
I knew the topic about eslint 9 would come at some point, I've not completely understood how required is the use of eslint.config.js as in beta the test cases still work :/ |
Frankly, I knew nothing about the flat config until just a few days ago. It seems like support for eslintrc will be dropped when v10 releases, so megalinter may eventually need to support two versions of eslint. 😕 Maybe the FlatCompat utility can help? |
So, I have some good news. Under the right circumstances, this configuration does currently work: JAVASCRIPT_ES_CONFIG_FILE: ./eslint.config.mjs # or .js, .cjs
JAVASCRIPT_ES_COMMAND_REMOVE_ARGUMENTS: ["--no-eslintrc"] # Not valid option for eslint with flat config Here are the requirements:
This solution, although hacky, should work for supporting flat config in ESlint 8. |
@ethanchristensen01 thanks for the analysis :) What is your suggestion so we can by default use eslint.config.js by default according to eslint 9 and still avoid a crash for MegaLinter users who have eslint 8 config ? ( we can play with python to detect files at the root of the repo and use different arguments / env vars depending what we find ^^ ) |
It's weird that you had to use the env var ESLINT_USE_FLAT_CONFIG and also have your eslint.config.js at the root of the repo. The docs specifically say that it is "or". https://eslint.org/docs/latest/use/configure/migration-guide#start-using-flat-config-files That might be something on our end, where if there isn't any valid config files (we need to add more files names), we add a default file that makes it so the repo has both files in the root of the repo. |
@echoix You might be right. Adding .eslintrc and .eslintignore might be causing that. I noticed these errors at the bottom of my lint logs.
(last line added for context) This might suggest there's a file cache of some kind, and it just happens to be working for me because it thinks I still have a .eslintignore in my project. That might prevent the default .eslintignore from getting copied in. (totally just a guess, haven't tested this theory yet) @nvuillam Good question! For now, I'm assuming we're going to add a configuration variable like I made a flowchart that should hopefully cover all cases! flowchart TD;
start(((Start)))
q0["Has the current ESLint version abandoned eslintrc support?"]
y0[["Use flat config"]]
q1["Is the 'JAVASCRIPT_ES_USE_FLAT_CONFIG' configuration variable set?"]
y1q1["Is that variable true?"]
y1y1[["Use flat config"]]
y1n1[["Use eslintrc config"]]
q2["Is the environment variable 'ESLINT_USE_FLAT_CONFIG' set?"]
q3["Is the configuration variable 'JAVASCRIPT_ES_CONFIG_FILE' set?"]
y3q1["Is it eslint.config.{js, cjs, mjs}?"]
y3y1[["Use flat config"]]
y3n1q1["Are we using ESLint 9+?"]
y3n1y1[["Use flat config"]]
y3n1n1[["Use eslintrc config"]]
q4["Is eslint.config.{js, cjs, mjs} in the project root?"]
y4[["Use flat config"]]
q5["Is .eslintrc* in the project root?"]
y5[["Use eslintrc config"]]
start --> q0
q0 -->|Yes| y0
q0 -.->|No| q1
q1 -->|Yes| y1q1
q1 -.->|No| q2
y1q1 -->|Yes| y1y1
y1q1 -.->|No| y1n1
q2 -->|Yes| y1q1
q2 -.->|No| q3
q3 -->|Yes| y3q1
q3 -.->|No| q4
y3q1 -->|Yes| y3y1
y3q1 -.->|No| y3n1q1
y3n1q1 -->|Yes| y3n1y1
y3n1q1 -.->|No| y3n1n1
q4 -->|Yes| y4
q4 -.->|No| q5
q5 -->|Yes| y5
q5 -.->|No| y3n1q1
|
@ethanchristensen01 amazing ! |
This issue has been automatically marked as stale because it has not had recent activity. If you think this issue should stay open, please remove the |
I saw a discussion pass by on this in the super-linter repo. |
I just encountered this problem 😅 |
@ethanchristensen01 gave us the specs... :D If a good samaritan wanna take it, i'd be glad to check the PR, otherwise i'll try to find a way before the next major release ^^ |
This issue has been automatically marked as stale because it has not had recent activity. If you think this issue should stay open, please remove the |
An issue that was triaged as a bug shouldn't get marked as stale and then closed. |
@theetrain indeed :) |
This issue has been automatically marked as stale because it has not had recent activity. If you think this issue should stay open, please remove the |
Just encountered this as well. Following the @ethanchristensen01 workaround, this is what I've done in the JAVASCRIPT_ES_CONFIG_FILE: eslint.config.mjs
JAVASCRIPT_ES_COMMAND_REMOVE_ARGUMENTS: ["--no-eslintrc"] # Not valid option for eslint with flat config
PRE_COMMANDS:
# temporary workaround for supporting flat config in eslint
# from https://github.com/oxsecurity/megalinter/issues/3570#issuecomment-2138193684
# first ensure .eslintignore is not present
- command: rm -f .eslintignore
cwd: workspace
# then add ESLINT_FLAT_CONFIG=true to ENV
- command: export ESLINT_FLAT_CONFIG="true"
# Will collect the values of output variables and update MegaLinter own ENV context
# See https://github.com/oxsecurity/megalinter?tab=readme-ov-file#pre-commands
output_variables: ["ESLINT_FLAT_CONFIG"] |
@serpro69 Removing the .eslintignore file by force might be an unexpected side effect.
Thanks for figuring out how to configure this in the megalinter file! |
Yeah, that was just a dirty hackaround. After reading a little bit about the flat config, I can see that our repo wasn't properly configured for using it in the first place, and we had both Thanks to you too for providing a working solution for this issue! 🤜 🤛 |
This issue has been automatically marked as stale because it has not had recent activity. If you think this issue should stay open, please remove the |
Maybe consider removing the stale GitHub action and opt for manual triaging and roadmapping instead. Or set megalinter/.github/workflows/stale.yml Line 37 in 2e057ee
Reference: https://github.com/actions/stale?tab=readme-ov-file#days-before-close |
We have a label for ignoring it permanently on a PR or issue, but it does its job of pinging people back when there is lost interest |
All it needs is someone to take the action to apply @ethanchristensen01 's analysis and solution :) It will probably end being me... but it's probably a full day of work and it's hard to find it ^^ |
This issue has been automatically marked as stale because it has not had recent activity. If you think this issue should stay open, please remove the |
Describe the bug
I tried pointing MegaLinter to my
eslint.config.js
, but it yielded the error:To Reproduce
.mega-linter.yml
Expected behavior
Flat ESLint config file is picked up, and runs without error.
The text was updated successfully, but these errors were encountered: