Sha256: 8cdbaca560195c91eb565932979bbdc5be44f2483cdcb55c84d94a1183c943c1

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

# typed: strict

module CodeOwnership
  module Private
    module Validations
      class FilesHaveUniqueOwners
        extend T::Sig
        extend T::Helpers
        include Validator

        sig { override.params(files: T::Array[String], autocorrect: T::Boolean, stage_changes: T::Boolean).returns(T::Array[String]) }
        def validation_errors(files:, autocorrect: true, stage_changes: true)
          files_by_mapper = Private.glob_cache.files_by_mapper

          files_mapped_by_multiple_mappers = {}
          files.each do |file|
            mappers = files_by_mapper.fetch(file, [])
            if mappers.count > 1
              files_mapped_by_multiple_mappers[file] = mappers
            end
          end

          errors = T.let([], T::Array[String])

          if files_mapped_by_multiple_mappers.any?
            errors << <<~MSG
              Code ownership should only be defined for each file in one way. The following files have declared ownership in multiple ways.

              #{files_mapped_by_multiple_mappers.map { |file, descriptions| "- #{file} (#{descriptions.join(', ')})" }.join("\n")}
            MSG
          end

          errors
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
code_ownership-1.32.8 lib/code_ownership/private/validations/files_have_unique_owners.rb
code_ownership-1.32.7 lib/code_ownership/private/validations/files_have_unique_owners.rb
code_ownership-1.32.6 lib/code_ownership/private/validations/files_have_unique_owners.rb
code_ownership-1.32.5 lib/code_ownership/private/validations/files_have_unique_owners.rb
code_ownership-1.32.4 lib/code_ownership/private/validations/files_have_unique_owners.rb