-
-
Notifications
You must be signed in to change notification settings - Fork 4.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
Change Request: report unnecessary config overrides #15476
Comments
Interesting idea. I’m thinking through how we could do this in the new config system and I think it could be pretty easy to detect (Famous last words.) but I’m not sure what kind of behavior would make sense. Also, would this apply to rule configuration directive inside a source file? What is the behavior you’d expect if a dupe was found? What would happen if one shared config you extend has the same rule options as another shared config you extend? Note this is different than reporting disable directives because those are in the source file and so they can look like any other linting error. |
I’d expect anything that wasn’t the first definition for a rule, that matched a previously established one, to be warned on - inline or not. i would not expect it to warn on anything from a shared config itself - only on things within the current repo. In other words, if after extending two shared config, i then defined something unnecessary, I’d expect my definition to be reported. |
Gotcha. And how would you expect it to be reported in the output? |
The same way that unused disable directives are - but i suppose the interesting question is “under what filename”? It seems like it’d show up under the file it was in, whether it was inline or a config file. |
Yes, that’s the problem, there’s not always going to be a filename to show (if you’re only using shared configs), and if there is a file, we don’t have any location information for where in the file the rule config is being set. So, I don’t think we can treat this like a linting error. |
There would always be a filename tho - it wouldn’t report the shared config, only in-project config files |
Ah sorry, I missed that earlier. In the new config system, it’s not easy to tell the difference between shared configs and local configs, as it’s just an array of objects. We can detect dupes, but I don’t think we can get exactly what you want. The only real option is to just throw an error for any dupes (not treated like a linting error). |
That seems like a flaw in the new config system that still has time to be corrected? |
It's not a flaw, it's an intentional design decision. We no longer want ESLint to have to load modules. Instead, we want you to use I think the best course forward right now is just to wait until we have the new config system ready for testing and see what would make sense. |
Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update. |
The unfortunate aspect of that design decision is that it will no longer be possible to have a static configuration. |
@JoshuaKGoldberg #18230 is specifically about inline comments. This one is about what's happening in the config file. So if one object in the array has the same rule configuration as another object in the same array. And yes, this isn't blocked anymore, good call out. |
Ah, thanks. In that case I'm in favor of this issue. Config file overrides is a big source of unnecessary cruft. This is especially present in configs and plugins that provide presets. Similar to the OP's user story, what I see often is:
Having warnings for unnecessary config overrides would also be useful when updating to new major versions of ESLint or plugins. Right now, nothing tells people when a config override that used to do something is now unnecessary. Question: would we want an RFC for this, similar to #18230 -> eslint/rfcs#121? And if so, should they be the same RFC to discuss the two likely-to-be-similar options together? |
Yes, we'd want an RFC for this. Because both proposals essentially deal with comparing two configs to find duplication, then I'd agree that they can be combined into a single RFC. |
Another thought: It's worth considering if this use case is better served by the config inspector rather than another CLI option. |
Following up from eslint/rfcs#121: that RFC was accepted with the explicit note:
Should this issue be closed out as wontfix? |
I still think this is something that could be included in the config inspector. I'm not sure we need to locate where each config came from (especially if they have @antfu what do you think? |
Ooh nice! @ljharb do you think that "Overloaded" filter in the config inspector does what you're looking for? |
That seems like it lists all overloaded rules - i want to list only unnecessary overloads, ie, overloads that when removed, don’t change the resulting config. I haven’t used the config inspector before tho, so maybe it’d work for me to be fair - but my goal is to put something in CI, not just expose it to humans, and I’m not sure the config inspector can do that? |
Ah yeah, then that won't work. However, because of flat config, this is something you can probably implement fairly easily yourself. Since the config file just exports an array of objects, you could just write a short script that loops through and checks for duplicates. |
Hmm, I suppose that's true - the OP was asking for eslintrc, which I still use. In flat config, I imagine the recursively nested config potential would make it hard to get right (even though I'm sure it'd be the same code needed in core). |
Yeah I'm sorry, we're not doing any further work on eslintrc. For flat config, there is no nesting of configurations (hence the nickname, "flat"). |
oh hm, good point :-) the config for each rule could be deeply nested, but that shouldn't be too tricky to compare. since i need it for eslintrc too, seems like i'll have to write an external tool anyways. |
ESLint version
v8.5.0
What problem do you want to solve?
The problem is that it's really difficult to figure out when the third step applies.
What do you think is the correct solution?
Like the
reportUnusedDisableDirectives
config option, I would like a config option that reports unnecessary configuration - in other words, any configuration that exists that matches the existing inferred configuration.Participation
Additional comments
I'd need many pointers to submit a PR for this, but I'm happy to help where I can.
(filed based on #15466 (comment))
The text was updated successfully, but these errors were encountered: