Sha256: b8e85fc39d1c6b55e38a744a6e95bcb088c36bd8264710a38716aa5f538c02b1

Contents?: true

Size: 859 Bytes

Versions: 11

Compression:

Stored size: 859 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for tabs inside the source code.
      class Tab < Cop
        MSG = 'Tab detected.'

        def investigate(processed_source)
          processed_source.lines.each_with_index do |line, index|
            match = line.match(/^( *)[\t ]*\t/)
            next unless match

            spaces = match.captures[0]

            range = source_range(processed_source.buffer,
                                 index + 1,
                                 (spaces.length)...(match.end(0)))

            add_offense(range, range, MSG)
          end
        end

        private

        def autocorrect(range)
          @corrections << lambda do |corrector|
            corrector.replace(range, range.source.gsub(/\t/, '  '))
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/tab.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/tab.rb
rubocop-0.30.1 lib/rubocop/cop/style/tab.rb
rubocop-0.30.0 lib/rubocop/cop/style/tab.rb
rubocop-0.29.1 lib/rubocop/cop/style/tab.rb
rubocop-0.29.0 lib/rubocop/cop/style/tab.rb
rubocop-0.28.0 lib/rubocop/cop/style/tab.rb
rubocop-0.27.1 lib/rubocop/cop/style/tab.rb
rubocop-0.27.0 lib/rubocop/cop/style/tab.rb
rubocop-0.26.1 lib/rubocop/cop/style/tab.rb
rubocop-0.26.0 lib/rubocop/cop/style/tab.rb