-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Following the ESLint 9 support, import/no-unused-modules
only works in flat config if an .eslintrc
file exists as well
#3079
Comments
This is not something that's come up before. There are issues with |
Hi, can confirm that this is the case. I had a test-repo ready to go, here it is: https://github.com/KristjanTammekivi/eslint-plugin-import-x-flat-config-debug npm run lint # error ESLint couldn't find a configuration file.
touch .eslintrc
npm run lint # linting works, shows unused exports |
@michaelfaith In the examples eslint find .eslintrc in the root of the repo and it satisfies the requirements and linting passes. You can check that it fails by
|
Sounds like we need a dynamic test case to cover this scenario. |
Thanks for the repo, that's helpful. It looks like it's blowing up when we're calling the og eslint-plugin-import/src/rules/no-unused-modules.js Lines 65 to 68 in 67cc798
So, my first thought is that maybe eslint put more strict controls in place to prevent using that deprecated api in flat config. However, what's really vexing, is I'm struggling to re-create it in this repo. We have a flat config example, and even after updating to the latest eslint (the same version as your repo uses), both at the root of the project and in the example project, those same lines of code work fine. And I double checked that the instance of I'll keep trying to reproduce it in this repo to either confirm or debunk that initial suspicion. |
Well damn. It just occurred to me, while this repo doesn't have an rc config in the example folder I'm running the tests in, it does have one at the root of the repo that it uses for its own linting. And as we know the way rc config climbs the directory tree to merge configs means it was satisfied by the presence of the root rc config being there. So this issue was flying under the radar. At least we know it's not some funky issue with this repo's version set up. @ljharb how would you like to approach this? It doesn't seem as though we can fallback on the deprecated |
@michaelfaith If I got the code correctly it shouldn't even try to use FileEnumerator due to this check eslint-plugin-import/src/rules/no-unused-modules.js Lines 165 to 171 in 67cc798
|
Right. It was a bit of a chicken and egg situation. They didn't want to move forward with adding those new functions to the session until we demonstrated demand. So we added that solution in so that the proposal could move forward (knowing that we'd possibly have to tweak it, if the final api landed in a slightly different form), but still fall back on the deprecated api until it was available. But it seems they've pulled back on that plan (i think). |
It'd be better for the rule to error in flat config than silently noop, but even better still to figure out how to get it working. |
@KristjanTammekivi, thanks for the example repo! I saw many discussions around the |
I think there are a couple options that we could explore, but I don't think any of them are great. We could possibly patch That factory class has a This is where it throws the config error (but only if So that could provide a path to get around it, but honestly i question the value of going that route, since it continues to rely on Until there's a first-class api added to eslint, like the original plan involved, I don't really see a great option other than throwing a (better) error. What do you think? |
I agree a temporary band-aid isn't great, but it would buy us lots of time because eslint 10 would need to come out and it always takes the ecosystem many months to catch up to eslint - so it's not a terrible idea. If we have a need for a first-class API in eslint, that we can't polyfill/implement ourselves, then that's evidence we'd want to provide to eslint maintainers. |
Sounds good. I can explore that, if nobody else beats me to it.
I think your original issue / feature request (eslint/eslint#18087) covered everything. @nzakas seems unsupportive of covering this use case after the original proposal didn't move forward, and I'm not sure that we have any new information to share? |
I think it's best to wait this time until we've built our own replacement, and then we can clearly articulate what we need from eslint, and what the complexity addition to core buys us in terms of correctness, performance, maintainability, other plugins using it, etc. |
So, just to be clear, this plugin is unusable until we have a fix for this? Or does it currently only require a dummy EDIT: Can confirm, it requires an empty |
Not the plugin, but this one rule, yes, it seems that's the case. |
I just discovered the same case with |
Maybe the need of an empty |
I set my default esport to Melee. |
Actually, the |
Have You had any time to explore it? (aka bump) I would do it myself, but I'm not very familiar with either this repo or eslint internals. |
Unfortunately not; been too busy. I'll try to make time for it in the next month or two. Happy to review anything that you want to take a stab at though. Anything that you'd need to know from this repo is pretty isolated to the one file for this rule, and i linked to some of the relevant places in the eslint repo. So the breadcrumbs are there, if you want to give it a shot. |
I finally had some time to work on this this morning: #3116 Note: This doesn't fix the fact that the |
Wouldn’t it be better to error out with a better error message when using |
Does that mean that you are actually removing support for ignore patterns in the If so, I don’t think that's a good idea at all. The current situation is not ideal (even if you use flat config, you still need to keep a |
This is true. I guess I could change it to try again in a catch block if it errors out the first time, so that if you do have an eslintrc it doesn't change the behavior. There's not really a way to get the old |
@guillaumebrunerie or are you suggesting we don't even go this far, and instead just accept that eslintrc is required for this rule and log a more expressive error? If so, i'm ok with that, but then why'd we even wait for me to explore #3079 (comment) I made it clear that whatever came of that wouldn't support ignored files. |
Yes, that's what I would suggest.
|
Hmm. I think that means that #3116 is a breaking change. Following the above suggestion would indeed prevent a crash and still have it work when an eslintrc is present, but that’s weird and we shouldn’t be aiming for that as a goal state. However, it would be a better intermediate state than the status quo. |
It wouldn't really prevent a crash though, if the rc file isn't present, it would just emit a better / more informative error message, right? |
ah, fair point. 🤔 |
I updated #3116 with what we talked about. It no longer attempts to avoid the error and instead throws an error with a more meaningful message if flat config is enabled and |
I have seen various discussions about this rule, but not quite in the exact same context, so I am unsure if that could be merged with an existing issue:
I upgraded to
eslint-plugin-import
v2.31.0, which officially supports ESLint V9. Enabling theimport/no-unused-modules
with the existingunusedExports
option results in the ESLint CLI not recognizing theeslint.config.js
unless there's a.eslintrc
file next to it (the.eslintrc
file can be empty; it just ignores it).As long as the
.eslintrc
exists, the rule works as expected.The text was updated successfully, but these errors were encountered: