Sha256: d5a12e5f11740b1c44e561a6b8419b28fe4c3a82b8d53a061d9b7043b829f826

Contents?: true

Size: 1023 Bytes

Versions: 7

Compression:

Stored size: 1023 Bytes

Contents

# frozen_string_literal: true

module RailsBestPractices
  module Lexicals
    # Keep lines fewer than 80 characters.
    class LongLineCheck < Core::Check
      interesting_files ALL_FILES

      def initialize(options = {})
        super(options)
        @max_line_length = options['max_line_length'] || 80
      end

      # check if a line is over 80 characters
      #
      # @param [String] filename name of the file
      # @param [String] content content of the file
      def check(filename, content)
        # Only check ruby files
        if /\.rb$/ =~ filename
          line_no = 0
          content.each_line do |line|
            line_no += 1
            actual_line_length = line.sub(/\s+$/, '').length
            next unless actual_line_length > @max_line_length

            add_error(
              "line is longer than #{@max_line_length} characters (#{actual_line_length} characters)",
              filename,
              line_no
            )
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_best_practices-1.23.2 lib/rails_best_practices/lexicals/long_line_check.rb
rails_best_practices-1.23.1 lib/rails_best_practices/lexicals/long_line_check.rb
rails_best_practices-1.23.0 lib/rails_best_practices/lexicals/long_line_check.rb
rails_best_practices-1.22.1 lib/rails_best_practices/lexicals/long_line_check.rb
rails_best_practices-1.22.0 lib/rails_best_practices/lexicals/long_line_check.rb
rails_best_practices-1.21.0 lib/rails_best_practices/lexicals/long_line_check.rb
rails_best_practices-1.20.1 lib/rails_best_practices/lexicals/long_line_check.rb