Sha256: 8d68bb9eca210b5a16ee5db66b0ccd32ed06dd5d55a02ff0d7bf44e8ad5de230

Contents?: true

Size: 1.25 KB

Versions: 7

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Git
  module Lint
    module Analyzers
      class CommitTrailerCollaboratorDuplication < Abstract
        def self.defaults
          {
            enabled: true,
            severity: :error
          }
        end

        def initialize commit:,
                       settings: self.class.defaults,
                       parser: Parsers::Trailers::Collaborator
          super commit: commit, settings: settings
          @parser = parser
          @tally = build_tally
        end

        def valid?
          affected_commit_trailer_lines.empty?
        end

        def issue
          return {} if valid?

          {
            hint: "Avoid duplication.",
            lines: affected_commit_trailer_lines
          }
        end

        protected

        def invalid_line? line
          collaborator = parser.new line
          collaborator.match? && tally[line] != 1
        end

        private

        attr_reader :parser, :tally

        def build_tally
          zeros = Hash.new { |new_hash, missing_key| new_hash[missing_key] = 0 }

          zeros.tap do |collection|
            commit.trailer_lines.each { |line| collection[line] += 1 if parser.new(line).match? }
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
git-lint-1.4.0 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb
git-lint-1.3.0 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb
git-lint-1.2.0 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb
git-lint-1.1.1 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb
git-lint-1.1.0 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb
git-lint-1.0.1 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb
git-lint-1.0.0 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb