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
"Repository settings" as a way to share configuration between rules without creating rule-to-rule dependencies? #6298
Comments
Yes yes yes yes yes. I would go a (large) step further and move all rule configuration into one large shared configuration space. Rules themselves shouldn't have options. Projects have preferences which are unrelated to rules. Multiple rules may need to reference the same preference, especially when it is a style preference. We have seen the problems that arise when one rule cannot reference another rule's configuration. Hopefully this proposal pushes the project in that direction. 👍 👍 👍 |
While I'm not in love with current way we are doing autofixing, can you explain what you think this proposal be able to provide other than what we already have? A change as drastic as this should have very clear benefits, but I'm not sure I can see them. I also see a lot of complication in the way configs cascade (as it relates to autofixing and project configuration), and inline configurations. |
The "clear benefit" is that linebreak-style, lines-around-comment, and newline-before-return can look in one shared place for knowing what the correct linebreak should be. I'm not sure I agree about complications in configuration cascade:
|
@platinumazure Let me rephrase it. What does this change allows us to do that we can't do already? Currently we can fix all of the rules you listed above without knowing what the correct linebreak style is supposed to be. Are there any other benefits? |
@ilyavolodin No we can't, not if the user decides not to use |
Ah, OK, now I think I got where you are going with this. So you expect every used to configure every single possible option of |
I may not understand this issue, but 👎 from me. There are 2 reasons. I'm not sure there are what difference between: {
"rules": {
"linebreak-style": ["error", "unix"],
// some rules which inserts linebreak.
}
} And {
"rules": {
"linebreak-style": "error",
// some rules which inserts linebreak.
},
"repositorySettings": {
"lineBreak": "unix"
}
} I think if people turn In short, I think I think a rule should focus on the one responsibility of the rule, then it should leave other matters to other rules. I don't think
I'm afraid that the responsibility of a rule would spread unlimitedly. |
Well, let me just make sure I lay out the motivation behind this proposal, in case it's not clear:
The basic thrust of my proposal is to extract some of those settings into a shared repository, so that rules depend on that repository rather than each other. Maybe @michaelficarra is right and I'm not thinking big enough. 😄 Perhaps he could share his thoughts? I also had an idea about having ESLint support integration with other things, like .editorconfig; maybe that would be less confusing for some users. |
@platinumazure regarding your motivations. Can you give an example of rule that depends on the configuration of another rule? If you forget about fix mode for a second, is there really any case where rules depend on each other? If we are talking purely about fix mode, then multi-pass seems to address majority of the problems. Granted, it's much slower and less efficient, but it does work. What's more, is that if you create |
This recognition is different from me. Why do you think so? |
@ilyavolodin The issue I'm trying to solve is mostly caused by auto-fix. Auto-fix can introduce violations of other rules. Most of the time, we do a good job of figuring out direct rule conflicts (e.g., we made a decision that the space between As I mentioned before, multi-pass cannot be the solution for this issue, simply because a user might not know that a second rule needs to be turned on in order for a given rule to auto-fix "correctly" (after multiple passes). @mysticatea To be clear, I'm talking about auto-fixing without introducing violations. In terms of linting only, the rules generally do not clash with each other, and when they do, we do a pretty good job of designing around that. Right now, auto-fix causes clashing with other rules, because the wrong fix is done (because we don't have enough information available in many cases, because that information is assigned to other rules). |
@platinumazure What would happen in your proposal if I didn't add |
@platinumazure So... I mentioned some questions in my comment above. Your answers seem all yes. If so, I'm afraid that the responsibility of a rule would spread unlimitedly. |
My main concern is with introducing the wrong linebreak in a fix, because they are invisible chars. If I were developing alone on windows (using |
If you don't turn |
I'm not sure, why do you think that separating the setting linebreak style from {
"rules": {
"a-newline-rule": "error"
},
"repositorySettings": {
"linebreak-style": "\n"
}
} {
"rules": {
"a-newline-rule": "error",
"linebreak-style": ["error", "\n"]
}
} I don't think major difference exists between that 2 configs. |
👎 As I noted in this comment, not only would people need to understand how to use the ~200 rules currently available, but they'd also need to be aware of the (often unexpected) side-effects of using certain repository settings along with those rules. The repository settings would effectively become globals, with all of the problems that implies. People will inevitably want rules to respect the global repository settings in some circumstances while ignoring them in others. It's already a struggle to understand how to properly use all of the existing rules, but at least they're self-contained. By creating hidden external dependencies upon global repository settings, rules would become far more complex and difficult to understand or troubleshoot. A better approach would be to allow the user to create a "variables" repository, letting them name their variables however they want, and then giving them a way to pass those variables to rules as if they were regular values. (For instance, the user could define a |
Two questions to make explicit something that I missed until just now:
|
The drawback to this is the need to repeat some of the values (e.g., your line break is referenced in a bunch of rules, so extra typing of either
I had conceived of repositorySettings as being separate from those "settings". And my assumption is that core rules do not use those "settings" at all, possibly for similar reasons as those cited by the folks who are 👎 on my proposal. |
@mysticatea I'm not sure if the solution is to separate it, but allowing access to the defined |
Folks, Bear in mind that the main thrust of this proposal was as a reaction to the architectural direction of "rules cannot know about each other". If we believe it is simpler to simply allow rules to know about each other, then I agree my proposal is overkill, but it is worth noting that there is a very good reason we keep the rules separate and independent. So maybe this question should be answered before we do anything else: Is the directive "rules cannot know about each other" something we should consider an absolute, inviolable directive? Or do we have wiggle room here? |
@platinumazure I, personally, would be very much against anything that breaks "rules cannot know about each other" change. P.S. Keep in mind that all the negative feedback is not directed against you at all, but it seems that this approach is creating more problems that it's solving, at least in the form that it is right now. |
I apologize if I'm too offensive. @alberto Hmm but why do we need that
Maybe, this is the main difference between my thought and yours about this proposal. I think this proposal is the opposite of "rules are independent." I think that "rules are independent" is "a rule doesn't cause to modify other rules." This is one for Single Responsibility Principle. This proposal increases the reason that a rule causes to modify other rules. So I think this proposal decreases the independence of rules. |
No worries, I understand. I would love to see other approaches, though.
I don't know if that was directed at me, but for what it's worth, I don't think anything you said was offensive.
I guess from my perspective, we're already in that position even without my proposal. Rules can already cause fixing logic of other rules to be wrong. @michaelficarra I'm really interested to know what your proposal was, which goes a step farther. Right now, I cannot tell if my proposal is too much in the wrong direction, or if it is a half-measure that might be clarified and improved upon by your proposal. |
But those would be fixed in the next pass of autofix. |
Unfortunately, it looks like consensus couldn't be reached on this issue and so I'm closing it. While we wish we'd be able to accommodate everyone's requests, we do need to prioritize. We've found that issues failing to reach consensus after 21 days tend never to reach consensus, and as such, we close those issues. This doesn't mean the idea isn't interesting, just that it's not something the team can commit to. |
We continue to run into questions about how best to auto-fix rules that appear to have a dependency on other rules.
For example,
lines-around-comment
andnewline-before-return
may introduce blank lines as part of its auto-fix, but it has no way of knowing the correct line break sequence to use (which may be configured inlinebreak-style
).Now that we have multi-pass autofixing available, a common response is that we can let multi-pass autofix take care of it. For example,
lines-around-comment
can arbitrarily choose\n
(without loss of generality) and that will be applied in the first pass, and then the second pass of autofix can fix the line break issues. However, the problem with this reasoning is that not everyone will use those rules that apply second-pass fixes.Noting that no rule can be deemed "too important to turn off" (meaning we really shouldn't be recommending the use of other rules that users might not want to use), I think we need to consider a different approach.
Below is a proposal for how we can better handle this. In terms of scope, I think we can start with something simple, like line breaks; later on, we can augment this proposal to include other repository style elements as needed.
In configuration:
Changes to how the affected rules would work:
linebreak-style
rule uses repository setting lineBreak property if specifiedlines-around-comment
uses repository setting lineBreak property if specified when autofixing\n
if needednewline-before-return
uses repository setting lineBreak property if specified when autofixing\n
if neededOther thoughts:
(N.B. I had created an issue with a similar title in the past, but the discussion there was focused around plugin processors and was correctly closed. I hope the team can agree that this issue is sufficiently different from the old issue and that the motivation for discussion is highly relevant now as we try to avoid over-reliance on multi-pass autofix.)
The text was updated successfully, but these errors were encountered: