module Overcommit::Hook::PreCommit # Checks for trailing whitespace in files. class TrailingWhitespace < Base def message "Trailing whitespace detected" end def lint_split output, message = message # Keep lines from the output for files that we actually modified error_lines, warning_lines = output.split("\n").partition do |output_line| _, file, line = output_line.match(/^([^:]+):(\d+)/).to_a modified_lines(file).include?(line.to_i) end return :bad, message + ":\n" + error_lines.join("\n") unless error_lines.empty? return :warn, message + " (on lines you didn't modify):\n" + warning_lines.join("\n")\ unless warning_lines.empty? :good end def run lint_split execute(%w[grep -IHn \s$] + applicable_files).stdout end end end