Class: CodeOwnership::Private::Validations::FilesHaveUniqueOwners

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Includes:
Validator
Defined in:
lib/code_ownership/private/validations/files_have_unique_owners.rb

Instance Method Summary collapse

Methods included from Validator

all, included

Instance Method Details

#validation_errors(files:, autocorrect: true, stage_changes: true) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/code_ownership/private/validations/files_have_unique_owners.rb', line 12

def validation_errors(files:, autocorrect: true, stage_changes: true)
  cache = Private.glob_cache
  file_mappings = cache.mapper_descriptions_that_map_files(files)
  files_mapped_by_multiple_mappers = file_mappings.select do |_file, mapper_descriptions|
    mapper_descriptions.count > 1
  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.to_a.join(', ')})" }.join("\n")}
    MSG
  end

  errors
end