Module: RuboCop::Cop::FirstElementLineBreak
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/rubocop/cop/mixin/first_element_line_break.rb |
Overview
Common functionality for checking for a line break before the first element in a multi-line collection.
Instance Method Summary
Instance Method Details
#check_children_line_break(node, children, start = node, ignore_last: false) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/first_element_line_break.rb', line 23
def check_children_line_break(node, children, start = node, ignore_last: false) return if children.empty? line = start.first_line min = first_by_line(children) return if line != min.first_line max_line = last_line(children, ignore_last: ignore_last) return if line == max_line add_offense(min) { |corrector| EmptyLineCorrector.insert_before(corrector, min) } end
#check_method_line_break(node, children, ignore_last: false) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/first_element_line_break.rb', line 10
def check_method_line_break(node, children, ignore_last: false) return if children.empty? return unless method_uses_parens?(node, children.first) check_children_line_break(node, children, ignore_last: ignore_last) end
#first_by_line(nodes) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/first_element_line_break.rb', line 37
def first_by_line(nodes) nodes.min_by(&:first_line) end
#last_line(nodes, ignore_last:) (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/first_element_line_break.rb', line 41
def last_line(nodes, ignore_last:) if ignore_last nodes.map(&:first_line) else nodes.map(&:last_line) end.max end