Sha256: 077a031c75959adc6251963e345811c03ca36c58b69b3a07172aa0f739673269

Contents?: true

Size: 1.05 KB

Versions: 18

Compression:

Stored size: 1.05 KB

Contents

require 'pre-commit/checks/plugin'

module PreCommit
  module Checks
    class Whitespace < Plugin

      def self.aliases
        [:white_space]
      end

      def files_filter(staged_files)
        if
          @list.map(&:name).include?("PreCommit::Checks::Rubocop")
        then
          staged_files.reject{|name| name =~ /\.rb$/ }
        else
          staged_files
        end
      end

      def files_string(staged_files)
        files_filter(staged_files).map{|file| "'#{file}'" }.join(" ")
      end

      def call(staged_files)
        return if staged_files.empty?

        errors = `git diff-index --check --cached HEAD -- #{files_string(staged_files)} 2>&1`
        return if $?.success?

        # Initial commit: diff against the empty tree object
        if errors =~ /fatal: bad revision 'HEAD'/
          errors = `git diff-index --check --cached 4b825dc642cb6eb9a060e54bf8d69288fbee4904 -- 2>&1`
          return if $?.success?
        end

        errors
      end

      def self.description
        "Finds white space."
      end

    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
pre-commit-0.40.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.39.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.38.1 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.38.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.37.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.36.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.35.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.34.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.33.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.32.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.31.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.30.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.29.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.28.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.27.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.26.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.25.0 lib/plugins/pre_commit/checks/whitespace.rb
pre-commit-0.24.0 lib/plugins/pre_commit/checks/whitespace.rb