-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
To discuss: relaxed "case-by-case consistency" setting for layout cops #7880
Comments
I agree with your suggestion - it certainly makes sense to me. As you pointed out yourself the main complexity of having this comes from the fact that we'll still need to default to something in case of ambiguity. I seem to recall we have a few cops supporting similar behaviour, but no concrete examples come to mind. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding! |
Just in case I'll forget: I plan to do some experimenting in January on those matters. |
StandardRB recommends enforcing styles where multiline hash keys, separator and values are all left aligned. I feel this is constraining and there are many places where `table` alignment is very appropriate. But i don't want to enforce that style either, because that would force all authors to align every hash. What would be ideal is to enforce _consistent_ alignment within a hash, regardless of the alignment style. Unfortunately, this isn't supported in rubocop, though it is being discussed: rubocop/rubocop#7880 In the meantime, disabling the rule with the hope that our authors will tend towards internal consistency. Note that while inspecting rule violations, i did find a handful of inconsistencies, which i cleaned up manually. https://docs.rubocop.org/rubocop/cops_layout.html#layouthashalignment
StandardRB recommends enforcing styles where multiline hash keys, separator and values are all left aligned. I feel this is constraining and there are many places where `table` alignment is very appropriate. But i don't want to enforce that style either, because that would force all authors to align every hash. What would be ideal is to enforce _consistent_ alignment within a hash, regardless of the alignment style. Unfortunately, this isn't supported in rubocop, though it is being discussed: rubocop/rubocop#7880 In the meantime, disabling the rule with the hope that our authors will tend towards internal consistency. Note that while inspecting rule violations, i did find a handful of inconsistencies, which i cleaned up manually. https://docs.rubocop.org/rubocop/cops_layout.html#layouthashalignment
StandardRB recommends enforcing styles where multiline hash keys, separator and values are all left aligned. I feel this is constraining and there are many places where `table` alignment is very appropriate. But i don't want to enforce that style either, because that would force all authors to align every hash. What would be ideal is to enforce _consistent_ alignment within a hash, regardless of the alignment style. Unfortunately, this isn't supported in rubocop, though it is being discussed: rubocop/rubocop#7880 In the meantime, disabling the rule with the hope that our authors will tend towards internal consistency. Note that while inspecting rule violations, i did find a handful of inconsistencies, which i cleaned up manually. https://docs.rubocop.org/rubocop/cops_layout.html#layouthashalignment
StandardRB recommends enforcing styles where multiline hash keys, separator and values are all left aligned. I feel this is constraining and there are many places where `table` alignment is very appropriate. But i don't want to enforce that style either, because that would force all authors to align every hash. What would be ideal is to enforce _consistent_ alignment within a hash, regardless of the alignment style. Unfortunately, this isn't supported in rubocop, though it is being discussed: rubocop/rubocop#7880 In the meantime, disabling the rule with the hope that our authors will tend towards internal consistency. Note that while inspecting rule violations, i did find a handful of inconsistencies, which i cleaned up manually. https://docs.rubocop.org/rubocop/cops_layout.html#layouthashalignment
StandardRB recommends enforcing styles where multiline hash keys, separator and values are all left aligned. I feel this is constraining and there are many places where `table` alignment is very appropriate. But i don't want to enforce that style either, because that would force all authors to align every hash. What would be ideal is to enforce _consistent_ alignment within a hash, regardless of the alignment style. Unfortunately, this isn't supported in rubocop, though it is being discussed: rubocop/rubocop#7880 In the meantime, disabling the rule with the hope that our authors will tend towards internal consistency. Note that while inspecting rule violations, i did find a handful of inconsistencies, which i cleaned up manually. https://docs.rubocop.org/rubocop/cops_layout.html#layouthashalignment
StandardRB recommends enforcing styles where multiline hash keys, separator and values are all left aligned. I feel this is constraining and there are many places where `table` alignment is very appropriate. But i don't want to enforce that style either, because that would force all authors to align every hash. What would be ideal is to enforce _consistent_ alignment within a hash, regardless of the alignment style. Unfortunately, this isn't supported in rubocop, though it is being discussed: rubocop/rubocop#7880 In the meantime, disabling the rule with the hope that our authors will tend towards internal consistency. Note that while inspecting rule violations, i did find a handful of inconsistencies, which i cleaned up manually. https://docs.rubocop.org/rubocop/cops_layout.html#layouthashalignment
StandardRB recommends enforcing styles where multiline hash keys, separator and values are all left aligned. I feel this is constraining and there are many places where `table` alignment is very appropriate. But i don't want to enforce that style either, because that would force all authors to align every hash. What would be ideal is to enforce _consistent_ alignment within a hash, regardless of the alignment style. Unfortunately, this isn't supported in rubocop, though it is being discussed: rubocop/rubocop#7880 In the meantime, disabling the rule with the hope that our authors will tend towards internal consistency. Note that while inspecting rule violations, i did find a handful of inconsistencies, which i cleaned up manually. https://docs.rubocop.org/rubocop/cops_layout.html#layouthashalignment
StandardRB recommends enforcing styles where multiline hash keys, separator and values are all left aligned. I feel this is constraining and there are many places where `table` alignment is very appropriate. But i don't want to enforce that style either, because that would force all authors to align every hash. What would be ideal is to enforce _consistent_ alignment within a hash, regardless of the alignment style. Unfortunately, this isn't supported in rubocop, though it is being discussed: rubocop/rubocop#7880 In the meantime, disabling the rule with the hope that our authors will tend towards internal consistency. Note that while inspecting rule violations, i did find a handful of inconsistencies, which i cleaned up manually. https://docs.rubocop.org/rubocop/cops_layout.html#layouthashalignment
StandardRB recommends enforcing styles where multiline hash keys, separator and values are all left aligned. I feel this is constraining and there are many places where `table` alignment is very appropriate. But i don't want to enforce that style either, because that would force all authors to align every hash. What would be ideal is to enforce _consistent_ alignment within a hash, regardless of the alignment style. Unfortunately, this isn't supported in rubocop, though it is being discussed: rubocop/rubocop#7880 In the meantime, disabling the rule with the hope that our authors will tend towards internal consistency. Note that while inspecting rule violations, i did find a handful of inconsistencies, which i cleaned up manually. https://docs.rubocop.org/rubocop/cops_layout.html#layouthashalignment
I'd like to discuss an idea of the "case-by-case" consistency of layout cops (and probably some other cops of "personal preference" class). I'll show an idea on only one example of
Layout/AlignParameters
cop, but I believe it is relevant for a lot of cases.So, here is what style guide says (abbreviated):
So, style guide's recommendation, basically: "don't do unexplainable indents". Now, if we look at the relevant cop's settings...
There is no way to ask the cop "just check that each call doesn't have unexplainable indentation, either of two styles is OK".
Why is this bad?
1. As "just a matter of personal preference/how it looks" (which existence of the setting clearly shows), the current set of settings makes a hard pressure on "always do the same thing, even if it looks bad". For one, I mostly prefer
with_first_argument
, except some cases like this:TBH, through last year, we switched a large codebase from
with_first_argument
towith_fixed_indentation
and back twice, depending on what part of the system we closely looked at when discussed "which looks better/more readable". With one of the stated goals of Rubocop to "avoid bikeshedding", for our team absence of an option "both are OK, just do the sane thing" led to exactly opposite direction :)2. When introducing Rubocop (or turning on previously disabled cops with codebase maturing), it may happen that some modules were written in one style, and another in another one. Probably it can be fixed with "executive decision"™, but in a lot of cases, when after a brief experiment people see that sticking to either option leads to 100+ files PR (and requires probably some manual tweaking of weirdly shifted comments and such stuff), they frequently choose to do neither, disabling the useful cop.
So, the point is, a lot of cops have "this way or that way" setting, but their main goal is to avoid the unstated third option: "no consistent alignment/spacing", and it would be good to make this option explicit: "do whatever you want, but keep it clear and readable".
One problem with this option would be "what auto-correct should do"? Imagining this code:
...it is hard (and probably unnecessary) to guess what is the best auto-correct -- whether it was previously shorter method name (so first and second argument were aligned), or it was some
foo = ....
(and the second line was two-spaces shifted). I believe in this case it would be OK to do nothing, or just fix cases like this:...to some common indentation, even if it is just to the first carry-over argument's:
Rubocop will be still (rightfully) complaining, but now it would be much easier to fix (just shift everything to the desired column) than before.
Sorry, again, for the long text!
The text was updated successfully, but these errors were encountered: