Sha256: de141b8f8903e32ee0925fd73cc8494089980b0de5023bd501be0f706bf518e5

Contents?: true

Size: 1014 Bytes

Versions: 6

Compression:

Stored size: 1014 Bytes

Contents

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
      @errors = []

      find_errors_in_subject(commit_message_lines.first)
      find_errors_in_body(commit_message_lines)

      return :warn, @errors.join("\n") if @errors.any?

      :pass
    end

    private

    def find_errors_in_subject(subject)
      max_subject_width = config['max_subject_width']
      return unless subject.length > max_subject_width

      @errors << "Please keep the subject <= #{max_subject_width} characters"
    end

    def find_errors_in_body(lines)
      return unless lines.count > 2

      max_body_width = config['max_body_width']

      lines[2..-1].each_with_index do |line, index|
        if line.chomp.size > max_body_width
          @errors << "Line #{index + 3} of commit message has > " \
                    "#{max_body_width} characters"
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
overcommit-0.24.0 lib/overcommit/hook/commit_msg/text_width.rb
overcommit-0.23.0 lib/overcommit/hook/commit_msg/text_width.rb
overcommit-0.22.0 lib/overcommit/hook/commit_msg/text_width.rb
jawshooah-overcommit-0.22.0 lib/overcommit/hook/commit_msg/text_width.rb
overcommit-0.21.0 lib/overcommit/hook/commit_msg/text_width.rb
overcommit-0.20.0 lib/overcommit/hook/commit_msg/text_width.rb