Sha256: ec87e8714f5a53bad6b179ec1ee512a6152eb9cdb1a1690fa8f568b7e1595ee0

Contents?: true

Size: 947 Bytes

Versions: 13

Compression:

Stored size: 947 Bytes

Contents

# frozen_string_literal: true

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.'.freeze

        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

13 entries across 13 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/end_of_line.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/end_of_line.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/end_of_line.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/end_of_line.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/end_of_line.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/end_of_line.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/end_of_line.rb
rubocop-0.47.1 lib/rubocop/cop/style/end_of_line.rb
rubocop-0.47.0 lib/rubocop/cop/style/end_of_line.rb
rubocop-0.46.0 lib/rubocop/cop/style/end_of_line.rb
rubocop-0.45.0 lib/rubocop/cop/style/end_of_line.rb
rubocop-0.44.1 lib/rubocop/cop/style/end_of_line.rb
rubocop-0.44.0 lib/rubocop/cop/style/end_of_line.rb