Sha256: 122526de1c891a98746e4c3192906aff4ed1094120bf4c73185cbc05880814cf

Contents?: true

Size: 976 Bytes

Versions: 5

Compression:

Stored size: 976 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for extra/unnecessary whitespace.
      #
      # @example
      #
      #   name     = "RuboCop"
      #   website  = "https://github.com/bbatsov/rubocop"
      class ExtraSpacing < Cop
        MSG = 'Unnecessary spacing detected.'

        def investigate(processed_source)
          processed_source.tokens.each_cons(2) do |t1, t2|
            next unless t1.pos.line == t2.pos.line
            next unless t2.pos.begin_pos - 1 > t1.pos.end_pos
            buffer = processed_source.buffer
            start_pos = t1.pos.end_pos
            end_pos = t2.pos.begin_pos - 1
            range = Parser::Source::Range.new(buffer, start_pos, end_pos)
            add_offense(range, range, MSG)
          end
        end

        def autocorrect(range)
          @corrections << lambda do |corrector|
            corrector.remove(range)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-0.30.1 lib/rubocop/cop/style/extra_spacing.rb
rubocop-0.30.0 lib/rubocop/cop/style/extra_spacing.rb
rubocop-0.29.1 lib/rubocop/cop/style/extra_spacing.rb
rubocop-0.29.0 lib/rubocop/cop/style/extra_spacing.rb
rubocop-0.28.0 lib/rubocop/cop/style/extra_spacing.rb