-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Feature request: Layout/AlignHash option to allow for key
and table
styles to both be permissible
#6410
Comments
key
and table
styles to both be permissiblekey
and table
styles to both be permissible
I agree 100%, and was about to open an issue myself. What I noticed after seeing the changes to this repository, and two others where I tried upgrading to rubocop v0.60.0 was: it seems that the |
I disagree with the recent changes in AlignHash, so a combination of `key` and `table` styles is no longer allowed. The issue is very well desribed in rubocop/rubocop#6410 .
I disagree with the recent changes in AlignHash, so a combination of `key` and `table` styles is no longer allowed. The issue is very well described in rubocop/rubocop#6410 .
I expected a ticket like this, as the change was somewhat controversial. :) Maybe we can add something which behaved like the old style, but I'm not sure about the naming there (or the exact behaviour it should have). |
I disagree with the recent changes in AlignHash, so a combination of `key` and `table` styles is no longer allowed. The issue is very well described in rubocop/rubocop#6410 .
Fully agree with the original post. I had to disable What I found useful of this cop was that the key alignment was consistent. Via the AST that should be possible, right? After having collected the Hash literal, one could query the source ranges for key and value and match them against these criterias? Not sure what the naming should be. |
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! |
@bquorning have you been able to find the time to do your experiment? |
I did a small experiment, but as I recall, the results were inconclusive. |
I think I have created a PR where you can allow both key and table at the same time. Take a look at #6649. The rubocop yaml will look like: |
Closing as fixed by #6649 |
I disagree with the recent changes in AlignHash, so a combination of `key` and `table` styles is no longer allowed. The issue is very well described in rubocop/rubocop#6410 .
I disagree with the recent changes in AlignHash, so a combination of `key` and `table` styles is no longer allowed. The issue is very well described in rubocop/rubocop#6410 .
I disagree with the recent changes in AlignHash, so a combination of `key` and `table` styles is no longer allowed. The issue is very well described in rubocop/rubocop#6410 .
I disagree with the recent changes in AlignHash, so a combination of `key` and `table` styles is no longer allowed. The issue is very well described in rubocop/rubocop#6410 .
I disagree with the recent changes in AlignHash, so a combination of `key` and `table` styles is no longer allowed. The issue is very well described in rubocop/rubocop#6410 .
Is your feature request related to a problem? Please describe.
The changes to
Layout/AlignHash
in 0.60 mean that you can no longer mix thekey
andtable
style without one of them being reported as a violation. For example:Before 0.60, if you chose the
key
style, both hashes would be allowed, because in both cases the keys are left-aligned.However starting with 0.60, RuboCop strictly enforces the whitespace to the right of the keys. If you set the enforced style to
key
, the second hash will get marked as a violation. If you choosetable
, then the first will be a violation.I believe that there is room for both styles in a single codebase. For small hashes,
key
is appropriate. But for large hashes thetable
style is much easier to read. Take a look at the changes introduced by 0.60 to RuboCop's own codebase. I think many people would agree that readability has been decreased.Describe the solution you'd like
I am open to ideas. A naive solution would be a
key_or_table
option that allows for both styles of whitespace to be accepted. I.e.Describe alternatives you've considered
Currently the only way to mix key and table styles in the same codebase is to turn off
AlignHash
altogether. This is a big step backwards, though, because now even blatantly bad alignments will be allowed without any violations, like this:Or I could set the enforced style to
key
, and then use a# rubocop:disable
comment around every hash where I want to use table syntax. That is a bit tedious, and again, it disables alignment checking completely. To my knowledge there is not a way to change the enforced style with a# rubocop
comment; you can only disable the cop.The text was updated successfully, but these errors were encountered: