Sha256: 86b2e6d32cd5e071e8a0e8216aa68020d811e3ff008790ad5f68b98eaa0275db

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cops checks for indentation of the first non-blank non-comment
      # line in a file.
      class InitialIndentation < Cop
        MSG = 'Indentation of first line in file detected.'

        def investigate(processed_source)
          first_token = processed_source.tokens.find do |t|
            !t.text.start_with?('#')
          end
          return unless first_token
          return if first_token.pos.column == 0

          with_space = range_with_surrounding_space(first_token.pos, :left,
                                                    nil, !:with_newline)
          space = Parser::Source::Range.new(processed_source.buffer,
                                            with_space.begin_pos,
                                            first_token.pos.begin_pos)
          add_offense(space, first_token.pos)
        end

        def autocorrect(range)
          ->(corrector) { corrector.remove(range) }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.33.0 lib/rubocop/cop/style/initial_indentation.rb