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
[Fix #5388] Add new Style/UnlessMultipleConditions
cop
#5400
Conversation
Fixes rubocop#5388 This cop checks that `unless` is not used with multiple conditions. In general, using multiple conditions with `unless` reduces readability.
Because RuboCop currently supports Ruby 2.1. In Ruby 2.1 not implementing `Hash#dig`, the following code is useful. ```ruby return unless hash[:a] && hash[:a][:b] ```
I've got one remark about naming - technically you always have a single condition expression, but it might be "composite"/"complex" when composed from several expressions. I also wonder how this play with the existing cop suggesting the use of |
Maybe, that would be right. However, if the conditional expression is single, In the "style" it is not a problem.
Umm, this is a very difficult problem... I have to think more about these problems. So, I will close this pull request once. Thank you for your opinion! |
flip-flop operator is deprecated since Ruby 2.6.0. > The flip-flop syntax is deprecated. [Feature rubocop#5400] - https://github.com/ruby/ruby/blob/v2_6_0/NEWS#language-changes - https://bugs.ruby-lang.org/issues/5400 ```console % cat example.rb (1..20).each do |x| puts x if (x == 5) .. (x == 10) end % ruby -v ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin17] % ruby example.rb example.rb:2: warning: flip-flop is deprecated 5 6 7 8 9 10 ``` This PR tweaks document and offense message for `Style/FlipFlop` cop. It will more clarify the reason for checking flip-flop operator.
flip-flop operator is deprecated since Ruby 2.6.0. > The flip-flop syntax is deprecated. [Feature #5400] - https://github.com/ruby/ruby/blob/v2_6_0/NEWS#language-changes - https://bugs.ruby-lang.org/issues/5400 ```console % cat example.rb (1..20).each do |x| puts x if (x == 5) .. (x == 10) end % ruby -v ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-darwin17] % ruby example.rb example.rb:2: warning: flip-flop is deprecated 5 6 7 8 9 10 ``` This PR tweaks document and offense message for `Style/FlipFlop` cop. It will more clarify the reason for checking flip-flop operator.
Follow up of rubocop#6635 (comment). flip-flop operator is deprecated since Ruby 2.6.0. > The flip-flop syntax is deprecated. [Feature rubocop#5400] - https://github.com/ruby/ruby/blob/v2_6_0/NEWS#language-changes - https://bugs.ruby-lang.org/issues/5400 This PR moves `FlipFlop` cop from `Style` department to `Lint` department.
Follow up of #6635 (comment). flip-flop operator is deprecated since Ruby 2.6.0. > The flip-flop syntax is deprecated. [Feature #5400] - https://github.com/ruby/ruby/blob/v2_6_0/NEWS#language-changes - https://bugs.ruby-lang.org/issues/5400 This PR moves `FlipFlop` cop from `Style` department to `Lint` department.
Fixes #5388
This cop checks that
unless
is not used with multiple conditions.In general, using multiple conditions with
unless
reduces readability.However, RuboCop itself doesn't use this cop because it currently supports Ruby 2.1 and 2.2.
In Ruby version not implementing
Hash#dig
, the following code is useful.Considering the above example, should this cop be disabled by default?
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
rake default
orrake parallel
. It executes all tests and RuboCop for itself, and generates the documentation.