Sha256: 4e639c2a22e86b0b4fb32ffb9339aa222674f8931d51412aace6d285bcf53137

Contents?: true

Size: 1.09 KB

Versions: 8

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Git
  module Lint
    module Analyzers
      # Analyzes commit trailer collaborator duplication.
      class CommitTrailerCollaboratorDuplication < Abstract
        def initialize commit, parser: Parsers::Trailers::Collaborator, **dependencies
          super commit, **dependencies
          @parser = parser
          @tally = build_tally
        end

        def valid? = affected_commit_trailers.empty?

        def issue
          return {} if valid?

          {
            hint: "Avoid duplication.",
            lines: affected_commit_trailers
          }
        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.trailers.each { |line| collection[line] += 1 if parser.new(line).match? }
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
git-lint-4.6.0 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb
git-lint-4.5.0 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb
git-lint-4.4.0 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb
git-lint-4.3.0 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb
git-lint-4.2.0 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb
git-lint-4.1.0 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb
git-lint-4.0.1 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb
git-lint-4.0.0 lib/git/lint/analyzers/commit_trailer_collaborator_duplication.rb