Class: FeatureMap::Private::Validations::FilesHaveFeatures

Inherits:
Object
  • Object
show all
Includes:
Validator
Defined in:
lib/feature_map/private/validations/files_have_features.rb

Instance Method Summary collapse

Methods included from Validator

all, included

Instance Method Details

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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/feature_map/private/validations/files_have_features.rb', line 9

def validation_errors(files:, autocorrect: true, stage_changes: true)
  cache = Private.glob_cache
  file_mappings = cache.mapper_descriptions_that_map_files(files)
  files_not_mapped_at_all = file_mappings.select do |_file, mapper_descriptions|
    mapper_descriptions.none?
  end

  errors = []

  # When a set of teams are configured that require assignments, ignore any files NOT
  # assigned to one of these teams.
  unless Private.configuration.require_assignment_for_teams.nil?
    files_not_mapped_at_all.filter! do |file, _mappers|
      file_team = CodeOwnership.for_file(file)
      file_team && Private.configuration.require_assignment_for_teams.include?(file_team.name)
    end
  end

  if files_not_mapped_at_all.any?
    errors << <<~MSG
      Some files are missing a feature assignment:

      #{files_not_mapped_at_all.map { |file, _mappers| "- #{file}" }.join("\n")}
    MSG
  end

  errors
end