Class: RuboCop::Cop::RBS::Layout::EmptyLines

Inherits:
RBS::CopBase
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/rbs/layout/empty_lines.rb

Overview

Checks for two or more consecutive blank lines.

Examples:


# bad - It has two empty lines.
def foo: () -> void
# one empty line
# two empty lines
def bar: () -> void

# good
def foo: () -> void
# one empty line
def bar: () -> void

Constant Summary collapse

MSG =
'Extra blank line detected.'

Instance Attribute Summary

Attributes inherited from RBS::CopBase

#processed_rbs_source

Instance Method Summary collapse

Methods inherited from RBS::CopBase

#investigation_rbs, #location_to_range, #on_new_investigation, #on_other_file, #on_rbs_attribute, #on_rbs_class, #on_rbs_constant, #on_rbs_def, #on_rbs_global, #on_rbs_interface, #on_rbs_module, #on_rbs_parsing_error, #on_rbs_private, #on_rbs_public, #on_rbs_type_alias, #on_rbs_var, #parse_rbs, #rbs_buffer, #tokenize, #walk

Methods included from RBS::OnTypeHelper

#on_not_type, #on_type

Instance Method Details

#on_rbs_new_investigationObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubocop/cop/rbs/layout/empty_lines.rb', line 28

def on_rbs_new_investigation
  # Quick check if we possibly have consecutive blank lines.
  return unless processed_source.raw_source.include?("\n\n\n")

  source = processed_source.raw_source
  pos = 0
  while index = source.index("\n\n\n", pos)
    range = range_between(index + 2, index + 3)
    add_offense(range) do |corrector|
      corrector.remove(range)
    end
    pos = index + 1
  end
end