Class: RuboCop::Cop::RBS::Layout::ExtraSpacing
- Inherits:
-
RBS::CopBase
- Object
- Base
- RBS::CopBase
- RuboCop::Cop::RBS::Layout::ExtraSpacing
show all
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rbs/layout/extra_spacing.rb
Overview
Constant Summary
collapse
- MSG =
'Unnecessary spacing detected.'
Instance Attribute Summary
Attributes inherited from RBS::CopBase
#processed_rbs_source
Instance Method Summary
collapse
#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
#on_not_type, #on_type
Instance Method Details
#aligned_locations ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/rubocop/cop/rbs/layout/extra_spacing.rb', line 38
def aligned_locations
= processed_rbs_source.tokens.select(&:comment?)
Set.new.tap do |aligned|
.map(&:location).each_cons(2) do |loc1, loc2|
next unless loc1
next unless loc2
if loc1.start_column == loc2.start_column
aligned << loc1.start_line << loc2.start_line
end
end
end
end
|
#on_rbs_new_investigation ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/rubocop/cop/rbs/layout/extra_spacing.rb', line 18
def on_rbs_new_investigation
= aligned_locations()
tokens = processed_rbs_source.tokens.reject { |t| t.type == :tTRIVIA }
tokens.each_cons(2) do |a, b|
next unless a&.location
next unless b&.location
if (b.type == :tCOMMENT || b.type == :tLINECOMMENT)
next if .include?(b.location.start_line)
end
next if a.location.end_line != b.location.start_line
next if a.location.end_pos + 1 >= b.location.start_pos
space = range_between(a.location.end_pos, b.location.start_pos - 1)
add_offense(space) do |corrector|
corrector.remove(space)
end
end
end
|