Sha256: 1aa01742b2dfb81b610dc5968e13909d3dee5c098bbf614cdd4b03838ae9eadb

Contents?: true

Size: 975 Bytes

Versions: 5

Compression:

Stored size: 975 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
            if 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
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_best_practices-1.20.0 lib/rails_best_practices/lexicals/long_line_check.rb
rails_best_practices-1.19.5 lib/rails_best_practices/lexicals/long_line_check.rb
rails_best_practices-1.19.4 lib/rails_best_practices/lexicals/long_line_check.rb
rails_best_practices-1.19.3 lib/rails_best_practices/lexicals/long_line_check.rb
rails_best_practices-1.19.2 lib/rails_best_practices/lexicals/long_line_check.rb