Class: Overcommit::Hook::CommitMsg::TextWidth
- Defined in:
- lib/overcommit/hook/commit_msg/text_width.rb
Overview
Ensures the number of columns the subject and commit message lines occupy is under the preferred limits.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#applicable_files, #description, #enabled?, #executable, #execute, #in_path?, #initialize, #install_command, #name, #quiet?, #required?, #run?, #run_and_transform, #skip?
Constructor Details
This class inherits a constructor from Overcommit::Hook::Base
Instance Method Details
#run ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/overcommit/hook/commit_msg/text_width.rb', line 5 def run errors = [] max_subject_width = config['max_subject_width'] max_body_width = config['max_body_width'] if .first.size > max_subject_width errors << "Please keep the subject <= #{max_subject_width} characters" end if .size > 2 [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? :pass end |