Method: RuboCop::Cop::Layout::EmptyLineBetweenDefs#autocorrect

Defined in:
lib/rubocop/cop/layout/empty_line_between_defs.rb

#autocorrect(corrector, prev_def, node, count) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/rubocop/cop/layout/empty_line_between_defs.rb', line 151

def autocorrect(corrector, prev_def, node, count)
  # finds position of first newline
  end_pos = end_loc(prev_def).end_pos
  source_buffer = end_loc(prev_def).source_buffer
  newline_pos = source_buffer.source.index("\n", end_pos)

  # Handle the case when multiple one-liners are on the same line.
  begin_pos = node.source_range.begin_pos
  newline_pos = begin_pos - 1 if newline_pos > begin_pos

  if count > maximum_empty_lines
    autocorrect_remove_lines(corrector, newline_pos, count)
  else
    autocorrect_insert_lines(corrector, newline_pos, count)
  end
end