Sha256: 051c88fc9add371f0249da5dcd573f6ab65261d21a9bf2225f45c8eed47546c9

Contents?: true

Size: 870 Bytes

Versions: 186

Compression:

Stored size: 870 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Layout
      # 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.sorted_tokens.each_cons(2) do |token1, token2|
            next unless token2.comment?
            next unless same_line?(token1, token2)
            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

186 entries across 179 versions & 17 rubygems

Version Path
rubocop-1.68.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.67.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.66.1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.66.0 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.65.1 lib/rubocop/cop/layout/space_before_comment.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.65.0 lib/rubocop/cop/layout/space_before_comment.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/space_before_comment.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/space_before_comment.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/layout/space_before_comment.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.64.1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.63.4 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.63.3 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.63.2 lib/rubocop/cop/layout/space_before_comment.rb
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.63.1 lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.63.0 lib/rubocop/cop/layout/space_before_comment.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.62.1/lib/rubocop/cop/layout/space_before_comment.rb
rubocop-1.62.1 lib/rubocop/cop/layout/space_before_comment.rb