Sha256: c2783c743bffa439c23eff310d26b07ae6b09b8b9f27ff836decfdc42aec8711

Contents?: true

Size: 827 Bytes

Versions: 12

Compression:

Stored size: 827 Bytes

Contents

# frozen_string_literal: true

module RailsBestPractices
  module Lexicals
    # Make sure there are no trailing whitespace in codes.
    #
    # See the best practice details here https://rails-bestpractices.com/posts/2010/12/02/remove-trailing-whitespace/
    class RemoveTrailingWhitespaceCheck < Core::Check
      interesting_files ALL_FILES
      url 'https://rails-bestpractices.com/posts/2010/12/02/remove-trailing-whitespace/'

      # check if the content of file contain a trailing whitespace.
      #
      # @param [String] filename name of the file
      # @param [String] content content of the file
      def check(filename, content)
        if content =~ / +\n/m
          line_no = $`.count("\n") + 1
          add_error('remove trailing whitespace', filename, line_no)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rails_best_practices-1.23.2 lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb
rails_best_practices-1.23.1 lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb
rails_best_practices-1.23.0 lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb
rails_best_practices-1.22.1 lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb
rails_best_practices-1.22.0 lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb
rails_best_practices-1.21.0 lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb
rails_best_practices-1.20.1 lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb
rails_best_practices-1.20.0 lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb
rails_best_practices-1.19.5 lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb
rails_best_practices-1.19.4 lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb
rails_best_practices-1.19.3 lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb
rails_best_practices-1.19.2 lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb