Class: Rubocop::Cop::Style::WhileUntilModifier
- Includes:
- FavorModifier
- Defined in:
- lib/rubocop/cop/style/favor_modifier.rb
Overview
Checks for while and until statements that would fit on one line if written as a modifier while/until.
Constant Summary collapse
- MSG =
'Favor modifier while/until usage when you have a single-line body.'
Constants inherited from Cop
Instance Attribute Summary
Attributes inherited from Cop
#autocorrect, #corrections, #debug, #disabled_lines, #offences
Instance Method Summary collapse
Methods included from FavorModifier
#body_has_comment?, #body_length, #check, #length
Methods inherited from Cop
#add_offence, all, #autocorrect_action, cop_name, cop_type, #do_autocorrect, full_description, #ignore_node, inherited, #initialize, lint?, #name, rails?, short_description, style?
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#investigate(processed_source) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/rubocop/cop/style/favor_modifier.rb', line 104 def investigate(processed_source) return unless processed_source.ast on_node([:while, :until], processed_source.ast) do |node| # discard modifier while/until next unless node.loc.end if check(node, processed_source.comments) add_offence(:convention, node.loc.keyword, MSG) end end end |