Sha256: ff9983e007bd86d387427010a01e4ec935847d42bfbf7da6d618c8199b44e80a

Contents?: true

Size: 901 Bytes

Versions: 35

Compression:

Stored size: 901 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) do |corrector|
              corrector.insert_before(range, ' ')
            end
          end
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 3 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_before_comment.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_before_comment.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_before_comment.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_before_comment.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_before_comment.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.12.1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.12.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.11.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.10.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.9.1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.9.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.8.1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.8.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.7.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.6.1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.6.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.5.2 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.5.1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.5.0 lib/rubocop/cop/layout/space_before_comment.rb