<commit_before>module Danger
  class DangerCommitLint < Plugin
    ERROR_MESSAGES = {
      subject_length: 'Please limit commit subject line to 50 characters.',
      subject_period: 'Please remove period from end of commit subject line.',
      empty_line: 'Please separate subject from body with newline.',
      noop: 'All checks were disabled, nothing to do.'
    }.freeze

    def check(config = {})
      @config = config

      if all_checks_disabled?
        warn ERROR_MESSAGES[:noop]
        return
      end

      for message in messages
        unless disabled_checks.include? :subject_length
          subject_length_check = SubjectLengthCheck.new(message)
          fail ERROR_MESSAGES[:subject_length] if subject_length_check.fail?
        end

        unless disabled_checks.include? :subject_period
          subject_period_check = SubjectPeriodCheck.new(message)
          fail ERROR_MESSAGES[:subject_period] if subject_period_check.fail?
        end

        unless disabled_checks.include? :empty_line
          empty_line_check = EmptyLineCheck.new(message)
          fail ERROR_MESSAGES[:empty_line] if empty_line_check.fail?
        end
      end
    end

    private

    def all_checks_disabled?
      @config[:disable] == :all || disabled_checks.count == 3
    end

    def disabled_checks
      @config[:disable] || []
    end

    def messages
      git.commits.map do |commit|
        (subject, empty_line) = commit.message.split("\n")
        { subject: subject, empty_line: empty_line }
      end
    end

    class SubjectLengthCheck
      def initialize(message)<commit_msg>DRY up checking for violations<commit_after>module Danger
  class DangerCommitLint < Plugin
    ERROR_MESSAGES = {
      subject_length: 'Please limit commit subject line to 50 characters.',
      subject_period: 'Please remove period from end of commit subject line.',
      empty_line: 'Please separate subject from body with newline.',
      noop: 'All checks were disabled, nothing to do.'
    }.freeze

    def check(config = {})
      @config = config

      if all_checks_disabled?
        warn ERROR_MESSAGES[:noop]
        return
      end

      for message in messages
        for (check, klass) in enabled_checks
          checker = klass.new(message)
          fail ERROR_MESSAGES[check] if checker.fail?
        end
      end
    end

    private

    def checks
      {
        subject_length: SubjectLengthCheck,
        subject_period: SubjectPeriodCheck,
        empty_line: EmptyLineCheck
      }
    end

    def enabled_checks
      checks.delete_if { |key, _| disabled_checks.include? key }
    end

    def all_checks_disabled?
      @config[:disable] == :all || disabled_checks.count == 3
    end

    def disabled_checks
      @config[:disable] || []
    end

    def messages
      git.commits.map do |commit|
        (subject, empty_line) = commit.message.split("\n")
        { subject: subject, empty_line: empty_line }
      end
    end

    class SubjectLengthCheck
      def initialize(message)
{'fraction_non_alphanumeric': 0.07446457990115321, 'fraction_numerical': 0.0019769357495881385, 'mean_word_length': 2.517960602549247, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1429153', 'n_tokens_mistral': 872, 'n_tokens_neox': 813, 'n_words': 237}