Created
November 3, 2020 03:56
-
-
Save jeromedalbert/cb33f12d310c14b419822fa151ba6aa2 to your computer and use it in GitHub Desktop.
Custom Rubocop rule to prevent unless with multiple conditions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require: | |
- ./.rubocop_custom_cops.rb | |
AllCops: | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RuboCop | |
module Cop | |
module Custom | |
class UnlessMultipleConditions < Cop | |
MSG = 'Avoid `unless` with multiple conditions. ' \ | |
'Rewrite the conditions with `if` instead.'.freeze | |
def on_if(node) | |
if node.unless? && node.condition.respond_to?(:operator) | |
add_offense(node) | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment