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
#config, #corrections, #offences, #processed_source
Instance Method Summary collapse
Methods included from FavorModifier
#body_has_comment?, #body_length, #check, #length, #max_line_length
Methods inherited from Cop
#add_offence, all, #autocorrect?, #convention, #cop_config, cop_name, #cop_name, cop_type, #debug?, #ignore_node, inherited, #initialize, lint?, #message, rails?, style?, #support_autocorrect?, #warning
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#investigate(processed_source) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rubocop/cop/style/favor_modifier.rb', line 108 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) convention(node, :keyword) end end end |