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
Make Style/SymbolArray
cop to enable by default
#4124
Comments
Fine by me. The reason this cop is not enabled by default is that it was developed when we still supported Ruby 1.9. |
…Array` cop Bad code ```ruby [ :foo, :bar, :baz ] ``` Correction ```ruby # before %i[foo bar baz] # after %i[ foo bar baz ] ```
Bad code ```ruby [ :foo, :bar, :baz ] ``` Correction ```ruby # before %i[foo bar baz] # after %i[ foo bar baz ] ```
For the record, I disagree. This seems like a strange thing to force on people by default given there is no inherent advantage, and it adds cognitive overload for developers. |
@LunaCodeGirl I am late but agrees, as a newcomer Ruby is complex enough and I wish this was not enabled by default. Pure preference but the least amount of tokens I have to learn the better, I had to learn what was a Symbol and now rubocop introduces %i on top of it ahah :D |
I just think its purely preferential and is doing nothing to add to code readability and if anything its decreasing it. This should not be enabled by default. |
Thanks for your feedback. By the way, personally I still think this cop should be enabled by default. And, I think not all Cops improve readability directly. Readability is important, but RuboCop also focuses on consistency. We can enforce ourselves that we use |
For anyone here wondering how to disable this madness, here's a snippet copy/paste ready. in your Style/SymbolArray:
Enabled: false |
Expected behavior
Actual behavior
I think the
Style/SymbolArray
cop should be enabled by default, but the cop is disabled by default.https://github.com/bbatsov/rubocop/blob/master/config/disabled.yml#L117-L120
40cf684
When the cop was added,
TargetRubyVersion
config does not exist.However currently
TargetRubyVersion
exists, so we can make the cop to enable by default.However, the cop has some problems in order to make to enable by default.
Handle
TargetRubyVersion
I guess the cop does not properly handle
TargetRubyVersion
config.https://github.com/bbatsov/rubocop/blob/a0f3a8f1223ba8d5b45e1bfbd950ff6f81b275f7/lib/rubocop/cop/style/symbol_array.rb#L27-L38
I think the
validate_config
method is unnecessarily. We should useminimum_target_ruby_version
instead ofvalidate_config
.Bug
The cop has a bug.
For example:
.rubocop.yml
test.rb
$ rubocop --only SmybolArray -a Inspecting 1 file C Offenses: test.rb:1:1: C: [Corrected] Use [] for an array of symbols. %i[a a-b] ^^^^^^^^^ 1 file inspected, 1 offense detected, 1 offense corrected $ cat test.rb [:a, :a-b]
The meaning of
%i(a a-b)
and[:a, :a-b]
is different, but RuboCop add an offense for this code.Auto correct
The cop supports auto correction. However I think the feature is not enough.
For example
The first code is auto-corrected to second code. The second code is not readable. We will need to add lien breaks manually to this code.
Style/WordArray
supports line brakes feature, so, we should support the feature forStyle/SymbolArray
as well.I'll implement the above features, and I'll make to enable by default the cop when finished.
The text was updated successfully, but these errors were encountered: