Skip to content

Instantly share code, notes, and snippets.

@jeromedalbert
Created November 3, 2020 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeromedalbert/cb33f12d310c14b419822fa151ba6aa2 to your computer and use it in GitHub Desktop.
Save jeromedalbert/cb33f12d310c14b419822fa151ba6aa2 to your computer and use it in GitHub Desktop.
Custom Rubocop rule to prevent unless with multiple conditions
require:
- ./.rubocop_custom_cops.rb
AllCops:
# ...
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