Class: Rubocop::Cop::IfUnlessModifier
- Includes:
- FavorModifier
- Defined in:
- lib/rubocop/cop/favor_modifier.rb
Instance Attribute Summary
Attributes inherited from Cop
#debug, #disabled_lines, #offences
Instance Method Summary collapse
Methods included from FavorModifier
Methods inherited from Cop
#add_offence, cop_name, #has_report?, #ignore_node, inherited, #initialize, #inspect, #name, #on_comment
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#error_message ⇒ Object
45 46 47 48 |
# File 'lib/rubocop/cop/favor_modifier.rb', line 45 def 'Favor modifier if/unless usage when you have a single-line body. ' + 'Another good alternative is the usage of control flow &&/||.' end |
#on_if(node) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/rubocop/cop/favor_modifier.rb', line 50 def on_if(node) # discard ternary ops and modifier if/unless nodes return unless node.loc.respond_to?(:keyword) && node.loc.respond_to?(:else) add_offence(:convention, node.loc.line, ) if check(node) super end |