Sha256: 01099464b20cbcf02dd3f3ddf9529a54fbd376164f4630fbcfc8d3c879a6f852

Contents?: true

Size: 880 Bytes

Versions: 12

Compression:

Stored size: 880 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 < Cop
        MSG = 'Put a space before an end-of-line comment.'

        def investigate(processed_source)
          processed_source.tokens.each_cons(2) do |token1, token2|
            next unless token2.comment?
            next unless token1.line == token2.line

            add_offense(token2.pos, location: token2.pos) if token1.pos.end == token2.pos.begin
          end
        end

        def autocorrect(range)
          ->(corrector) { corrector.insert_before(range, ' ') }
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 3 rubygems

Version Path
rubocop-0.89.1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-0.89.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-0.88.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-0.87.1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-0.87.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-0.86.0 lib/rubocop/cop/layout/space_before_comment.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/layout/space_before_comment.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-0.85.1 lib/rubocop/cop/layout/space_before_comment.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-0.85.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-0.84.0 lib/rubocop/cop/layout/space_before_comment.rb