Sha256: c394481d277840752874c72f0f0fd8be67b5e054c1b47dec52fb48a6a8249188

Contents?: true

Size: 928 Bytes

Versions: 11

Compression:

Stored size: 928 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for Windows-style line endings in the source code.
      class EndOfLine < Cop
        MSG = 'Carriage return character detected.'

        def investigate(processed_source)
          last_token = processed_source.tokens.last
          last_line =
            last_token ? last_token.pos.line : processed_source.lines.length

          processed_source.raw_source.each_line.with_index do |line, index|
            break if index >= last_line
            next unless line =~ /\r$/

            range =
              source_range(processed_source.buffer, index + 1, 0, line.length)
            add_offense(nil, range, MSG)
            # Usually there will be carriage return characters on all or none
            # of the lines in a file, so we report only one offense.
            break
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

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