Class: RuboCop::Cop::RBS::Layout::ExtraSpacing
- Inherits:
-
RBS::CopBase
- Object
- Base
- RBS::CopBase
- RuboCop::Cop::RBS::Layout::ExtraSpacing
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rbs/layout/extra_spacing.rb
Overview
Checks for unnecessary spacing between tokens.
Constant Summary collapse
- MSG =
'Unnecessary spacing detected.'
Instance Attribute Summary
Attributes inherited from RBS::CopBase
Instance Method Summary collapse
Methods inherited from RBS::CopBase
documentation_url, #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
Instance Method Details
#aligned_locations ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubocop/cop/rbs/layout/extra_spacing.rb', line 41 def aligned_locations comments = processed_rbs_source.tokens.select(&:comment?) Set.new.tap do |aligned| comments.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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rubocop/cop/rbs/layout/extra_spacing.rb', line 21 def on_rbs_new_investigation aligned_comments = 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 aligned_comments.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 |