Sha256: 7af149ac751cce8248ee3037e4597f861341119ac6197a95b426e9a4d2bac8b1

Contents?: true

Size: 872 Bytes

Versions: 13

Compression:

Stored size: 872 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Layout
      # This cop checks for missing space between a token and a comment on the
      # same line.
      #
      # @example
      #   # bad
      #   1 + 1# this operation does ...
      #
      #   # good
      #   1 + 1 # this operation does ...
      class SpaceBeforeComment < Base
        extend AutoCorrector

        MSG = 'Put a space before an end-of-line comment.'

        def on_new_investigation
          processed_source.tokens.each_cons(2) do |token1, token2|
            next unless token2.comment?
            next unless token1.line == token2.line
            next unless token1.pos.end == token2.pos.begin

            range = token2.pos

            add_offense(range) { |corrector| corrector.insert_before(range, ' ') }
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rubocop-1.18.3/lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.18.4 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.18.3 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.18.2 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.18.1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.18.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.17.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.16.1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.16.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.15.0 lib/rubocop/cop/layout/space_before_comment.rb
cocRb-0.1.0 .bundle/ruby/3.0.0/gems/rubocop-1.14.0/lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.14.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.13.0 lib/rubocop/cop/layout/space_before_comment.rb