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



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

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



6
7
8
# File 'lib/archspec/rules/zeitwerk_rule.rb', line 6

def id
  'zeitwerk.naming'
end