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
Layout/LineEndStringConcatenationIndentation not following EnforcedStyle in hashes #9927
Comments
Unaligned strings in hash literal values is designed to always be aligned with |
Yes, the cop behaves as documented. https://docs.rubocop.org/rubocop/1.18/cops_layout.html#layoutlineendstringconcatenationindentation The exception for hash values is something I added because in my opinion indentation within a hash literal was just too ugly. This is of course very subjective, and other people way find it surprising. It's a small detail though, and perhaps not worth changing? |
In my opinion it makes the "Enforced" style not enforced as there is a (subjective) deviation from it. However, I do have to acknowledge that the deviation is written down in the documentation. It might be a bit clearer if the examples would reflect this deviation as well. I've never written or altered a cop myself, so I can't judge how much work it would be to have an |
I think they already do. Look: # bad
[...]
my_hash = {
first: 'a message' \
'in two parts'
}
# good
[...]
my_hash = {
first: 'a message' \
'in two parts'
} There might be a better way to express it. I'm open to suggestions.
To me, it seems like a clear case of "not worth the effort". There are cops with more than one style parameter today, but it's a bit complicated if you ask me. |
Sorry for my unclear answer @jonas054, I mean under the example of EnforcedStyle: indented, as that only shows the split string and not the exception that exists for hashes. For example, this would clear it up right away I think. # bad
result = 'x' \
'y'
# good
result = 'x' \
'y'
# indented has no effect on hashes
my_hash = {
first: 'a message' \
'in two parts'
} But you could say we should carefully read the paragraph as well 😉
Noted, I'll see that I'm going to inform the team regarding the current use of the cop and the style in our hashes. |
Yes, I think the normal style for the cop documentation is to have very terse comments in the examples ("good" and "bad"), and to put any explanations in the text above them. I'll leave the cop as it is without changes for now, and close the issue. |
I started updating my codebase to conform to the 'indented' style and found this surprising. I think the EnforcedStyle should be applied universally. If not, then another enforced style should be introduced (maybe "indentedExceptHashValues"). |
Looking at this again, I must admit that your expectations are correct, @fuegas and @shanecav84. It's much more reasonable for With the configuration AllCops:
NewCops: enable
Layout/LineEndStringConcatenationIndentation:
EnforcedStyle: indented
Layout/MultilineOperationIndentation:
EnforcedStyle: indented
Style/LineEndConcatenation:
Enabled: false
Style/StringConcatenation:
Enabled: false RuboCop corrects to # frozen_string_literal: true
puts 'Lorem ipsum dolor sit amet, consectetur ' +
'adipiscing elit. Aenean sollicitudin maximus ' +
'lacus eu maximus.'
h = {
abc: 'Lorem ipsum dolor sit amet, consectetur ' +
'adipiscing elit. Aenean sollicitudin maximus ' +
'lacus eu maximus.',
defghi: 'Lorem ipsum dolor sit amet, consectetur ' +
'adipiscing elit.'
}
p h so with backslashes it should be like this: # frozen_string_literal: true
puts 'Lorem ipsum dolor sit amet, consectetur ' \
'adipiscing elit. Aenean sollicitudin maximus ' \
'lacus eu maximus.'
h = {
abc: 'Lorem ipsum dolor sit amet, consectetur ' \
'adipiscing elit. Aenean sollicitudin maximus ' \
'lacus eu maximus.',
defghi: 'Lorem ipsum dolor sit amet, consectetur ' \
'adipiscing elit.'
}
p h Rather than adding another style, I will consider the current behavior a bug, and submit a fix for it. |
Thank you for revisiting this @jonas054 ! I'm looking forward to the fix being merged 👍 |
…nIndentation_indented_hash_values [Fix #9927] Indent hash values in LineEndStringConcatenationIndentation
Thanks for considering our feedback @jonas054! |
Given this source file test.rb:
and .rubocop config:
running rubocop --only Layout/LineEndStringConcatenationIndentation -- test.rb gives the following output:
I would expect no offenses in that file.
When I change the source to
no offense is shown.
As I've set
EnforcedStyle: indented
, I expected the first example to work.RuboCop version
The text was updated successfully, but these errors were encountered: