Class: RuboCop::Cop::RBS::Layout::SpaceAfterComma

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

Overview

Examples:

default

# bad
def foo: (Integer,String) -> void

# good
def foo: (Integer, String) -> void

Constant Summary collapse

MSG =
'Space missing after comma.'

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



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubocop/cop/rbs/layout/space_after_comma.rb', line 18

def on_rbs_new_investigation
  processed_rbs_source.tokens.each_cons(2) do |comma, after|
    next unless comma.type == :pCOMMA
    next unless comma.location
    next unless comma.location.end_line == after.location.start_line
    next unless after.type != :tTRIVIA

    range = location_to_range(comma.location)
    add_offense(range) do |corrector|
      corrector.insert_after(range, ' ')
    end
  end
end