class RuboCop::Cop::Layout::ConditionPosition
Checks for conditions that are not on the same line as if/while/until.
@example
# bad if some_condition do_something end
@example
# good if some_condition do_something end
Constants
- MSG
Public Instance Methods
on_if(node)
click to toggle source
# File lib/rubocop/cop/layout/condition_position.rb, line 31 def on_if(node) return if node.ternary? check(node) end
on_while(node)
click to toggle source
# File lib/rubocop/cop/layout/condition_position.rb, line 37 def on_while(node) check(node) end
Also aliased as: on_until
Private Instance Methods
check(node)
click to toggle source
# File lib/rubocop/cop/layout/condition_position.rb, line 44 def check(node) return if node.modifier_form? || node.single_line_condition? condition = node.condition message = message(condition) add_offense(condition, message: message) do |corrector| range = range_by_whole_lines(condition.source_range, include_final_newline: true) corrector.insert_after(condition.parent.loc.keyword, " #{condition.source}") corrector.remove(range) end end
message(condition)
click to toggle source
# File lib/rubocop/cop/layout/condition_position.rb, line 58 def message(condition) format(MSG, keyword: condition.parent.keyword) end