lib/overcommit/hook/commit_msg/text_width.rb in overcommit-0.6.2 vs lib/overcommit/hook/commit_msg/text_width.rb in overcommit-0.6.3

- old
+ new

@@ -1,19 +1,30 @@ module Overcommit::Hook::CommitMsg # Ensures the number of columns the subject and commit message lines occupy is # under the preferred limits. class TextWidth < Base def run - if commit_message_lines.first.size > 60 - return :warn, 'Please keep the subject < ~60 characters' + errors = [] + + max_subject_width = @config['max_subject_width'] + max_body_width = @config['max_body_width'] + + if commit_message_lines.first.size > max_subject_width + errors << "Please keep the subject <= #{max_subject_width} characters" end - commit_message_lines.each do |line| - chomped = line.chomp - if chomped.size > 72 - return :warn, "> 72 characters, please hard wrap: '#{chomped}'" + if commit_message_lines.size > 2 + commit_message_lines[2..-1].each_with_index do |line, index| + chomped = line.chomp + if chomped.size > max_body_width + error = "Line #{index + 3} of commit message has > " << + "#{max_body_width} characters" + errors << error + end end end + + return :warn, errors.join("\n") if errors.any? :good end end end