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
Preserve multiline semantics on Style/SymbolArray
and Style/WordArray
#10784
Preserve multiline semantics on Style/SymbolArray
and Style/WordArray
#10784
Conversation
@@ -39,7 +39,7 @@ class SymbolArray < Base | |||
minimum_target_ruby_version 2.0 | |||
|
|||
PERCENT_MSG = 'Use `%i` or `%I` for an array of symbols.' | |||
ARRAY_MSG = 'Use `%<prefer>s` for an array of symbols.' | |||
ARRAY_MSG = 'Use `[...]` for an array of symbols.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you tweak the message?
ARRAY_MSG = 'Use `[...]` for an array of symbols.' | |
ARRAY_MSG = 'Use array brackets `[...]` for an array of symbols.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, thank you for pointing that out. I too was afraid that this [...]
might be a bit confusing.
lib/rubocop/cop/style/word_array.rb
Outdated
@@ -44,7 +44,7 @@ class WordArray < Base | |||
extend AutoCorrector | |||
|
|||
PERCENT_MSG = 'Use `%w` or `%W` for an array of words.' | |||
ARRAY_MSG = 'Use `%<prefer>s` for an array of words.' | |||
ARRAY_MSG = 'Use `[...]` for an array of words.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
ARRAY_MSG = 'Use `[...]` for an array of words.' | |
ARRAY_MSG = 'Use array brackets`[...]` for an array of words.' |
022fa36
to
7758a4c
Compare
…ray` To fix rubocop#10455. Note that this commit also changes the offense message like this: ```ruby \# Before %w( ^^^ Use `[ 'foo', 'bar' ]` for an array of words. foo bar ) \# After %w( ^^^ Use `[...]` for an array of words. foo bar ) ``` This means that the auto-corrected code no longer appears in the offense message. I think this is a reasonable change because the message to enforce the percent styles (`'Use `%w` or `%W` for an array of words.'`) is already using this format.
a3d6672
to
074f294
Compare
Looks good. Thanks! |
Similar issue: rubocop/rubocop#10784 Before ```diff if a.present? +^^^^^^^^^^^^^ Use `a.presence || b.to_f * 12.0` instead of `if a.present? + a +else + b +end`. a else b end ``` After ```diff if a.present? +^^^^^^^^^^^^^ Use `a.presence || b` instead of `if a.present? ... end`. a else b.to_f + 12.0 end ```
Similar issue: rubocop/rubocop#10784 Before ```diff if a.present? +^^^^^^^^^^^^^ Use `a.presence || b.to_f * 12.0` instead of `if a.present? + a +else + b +end`. a else b end ``` After ```diff if a.present? +^^^^^^^^^^^^^ Use `a.presence || b` instead of `if a.present? ... end`. a else b end ```
Similar issue: rubocop/rubocop#10784 Before ```diff if a.present? +^^^^^^^^^^^^^ Use `a.presence || b.to_f * 12.0` instead of `if a.present? + a +else + b +end`. a else b end ``` After ```diff if a.present? +^^^^^^^^^^^^^ Use `a.presence || b` instead of `if a.present? ... end`. a else b end ```
To fix #10455.
Example:
To mimic the original whitespace semantics, I decided to extract three types of whitespace and reuse them in autocorrection.
Note that this commit also changes the offense message like this (on multiline case):
This means that the auto-corrected code no longer appears in the offense message (on multiline case). I think this is a reasonable change because this format is already used for percent styles:
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.