Sha256: b436bbe29419e7e7afa6dba95fb83799e92199e2f7ce4a27ac0e10a8f8c46cf3
Contents?: true
Size: 1.64 KB
Versions: 12
Compression:
Stored size: 1.64 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module RBS module Layout # @example default # # bad # def foo: () -> void # # # good # def foo: () -> void class ExtraSpacing < RuboCop::RBS::CopBase extend AutoCorrector MSG = 'Unnecessary spacing detected.' 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 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 end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems