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, #conditional_length, #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, non_rails, rails?, style?, #support_autocorrect?, #warning
Constructor Details
This class inherits a constructor from Rubocop::Cop::Cop
Instance Method Details
#investigate(processed_source) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/rubocop/cop/style/favor_modifier.rb', line 118 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 |