Sha256: 601199f5ce1af4bdb9f6297d48aa41fd8ab35435bcbefa939cf04b360fdfbfeb

Contents?: true

Size: 1.2 KB

Versions: 12

Compression:

Stored size: 1.2 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 SpaceBeforeColon < RuboCop::RBS::CopBase
          extend AutoCorrector

          MSG = 'Avoid using spaces before `:`.'

          # @sig decl: ::RBS::AST::Members::MethodDefinition
          def on_rbs_def(decl)
            source = processed_source.raw_source
            loc = decl.location
            colon_start_pos = source.index(':', loc.start_pos)
            return unless colon_start_pos

            word_before_colon_pos = source.rindex(/[^\s]/, colon_start_pos - 1)
            return unless word_before_colon_pos

            if word_before_colon_pos + 1 != colon_start_pos
              colon = range_between(colon_start_pos, colon_start_pos + 1)
              add_offense(colon) do |corrector|
                range = range_between(
                  word_before_colon_pos + 1,
                  colon_start_pos,
                )
                corrector.remove(range)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rubocop-on-rbs-1.3.0 lib/rubocop/cop/rbs/layout/space_before_colon.rb
rubocop-on-rbs-1.2.0 lib/rubocop/cop/rbs/layout/space_before_colon.rb
rubocop-on-rbs-1.1.0 lib/rubocop/cop/rbs/layout/space_before_colon.rb
rubocop-on-rbs-1.0.0 lib/rubocop/cop/rbs/layout/space_before_colon.rb
rubocop-on-rbs-0.9.0 lib/rubocop/cop/rbs/layout/space_before_colon.rb
rubocop-on-rbs-0.8.0 lib/rubocop/cop/rbs/layout/space_before_colon.rb
rubocop-on-rbs-0.7.0 lib/rubocop/cop/rbs/layout/space_before_colon.rb
rubocop-on-rbs-0.6.0 lib/rubocop/cop/rbs/layout/space_before_colon.rb
rubocop-on-rbs-0.5.0 lib/rubocop/cop/rbs/layout/space_before_colon.rb
rubocop-on-rbs-0.4.0 lib/rubocop/cop/rbs/layout/space_before_colon.rb
rubocop-on-rbs-0.3.0 lib/rubocop/cop/rbs/layout/space_before_colon.rb
rubocop-on-rbs-0.2.0 lib/rubocop/cop/rbs/layout/space_before_colon.rb