Sha256: ae766390392fdff6328b611107352c386ecdee4456485cac69929d22d19b826b

Contents?: true

Size: 843 Bytes

Versions: 9

Compression:

Stored size: 843 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)
          lambda do |corrector|
            corrector.replace(range, range.source.gsub(/\t/, '  '))
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/style/tab.rb
rubocop-0.35.0 lib/rubocop/cop/style/tab.rb
rubocop-0.34.2 lib/rubocop/cop/style/tab.rb
rubocop-0.34.1 lib/rubocop/cop/style/tab.rb
rubocop-0.34.0 lib/rubocop/cop/style/tab.rb
rubocop-0.33.0 lib/rubocop/cop/style/tab.rb
rubocop-0.32.1 lib/rubocop/cop/style/tab.rb
rubocop-0.32.0 lib/rubocop/cop/style/tab.rb
rubocop-0.31.0 lib/rubocop/cop/style/tab.rb