Class: ArchSpec::Rules::ZeitwerkNamingRule

Inherits:
Object
  • Object
show all
Defined in:
lib/archspec/rules/zeitwerk_rule.rb

Instance Method Summary collapse

Instance Method Details

#evaluate(graph) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/archspec/rules/zeitwerk_rule.rb', line 8

def evaluate(graph)
  graph.files.values.filter_map do |file|
    next unless file.expected_constant

    defined = graph.constants_for_path(file.path).map(&:name)
    next if defined.include?(file.expected_constant)

    Diagnostic.new(
      rule: id,
      message: "#{file.relative_path} should define #{file.expected_constant}",
      location: SourceLocation.new(file.path, 1, 1),
      evidence: "defined constants: #{defined.empty? ? "(none)" : defined.join(", ")}"
    )
  end
end

#idObject



4
5
6
# File 'lib/archspec/rules/zeitwerk_rule.rb', line 4

def id
  "zeitwerk.naming"
end