archspec 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -3
- data/lib/archspec/analyzer.rb +149 -60
- data/lib/archspec/architectures.rb +61 -32
- data/lib/archspec/cli.rb +1 -73
- data/lib/archspec/definition.rb +1 -6
- data/lib/archspec/dsl.rb +34 -43
- data/lib/archspec/formatters/explanation.rb +93 -0
- data/lib/archspec/model.rb +23 -10
- data/lib/archspec/rules/cycle_rule.rb +1 -1
- data/lib/archspec/rules/dependency_rules.rb +1 -1
- data/lib/archspec/rules/naming_rules.rb +209 -0
- data/lib/archspec/rules/protocol_rules.rb +1 -1
- data/lib/archspec/version.rb +1 -1
- data/lib/archspec.rb +2 -2
- metadata +4 -4
- data/lib/archspec/presets.rb +0 -14
- data/lib/archspec/rules/zeitwerk_rule.rb +0 -51
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ArchSpec
|
|
4
|
-
module Rules
|
|
5
|
-
# Backs ArchSpec::DSL::Context#verify_zeitwerk_names!. Flags files that do
|
|
6
|
-
# not define the constant their path implies under Zeitwerk.
|
|
7
|
-
class ZeitwerkNamingRule
|
|
8
|
-
attr_reader :only
|
|
9
|
-
|
|
10
|
-
# only: globs restricting which files are checked. Default is every file
|
|
11
|
-
# ArchSpec can name, but lib autoloading is opt-in, so apps that require
|
|
12
|
-
# lib manually scope this to app/.
|
|
13
|
-
def initialize(only: nil)
|
|
14
|
-
@only = Array(only).flatten.compact.map(&:to_s)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def id
|
|
18
|
-
'zeitwerk.naming'
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def evaluate(graph)
|
|
22
|
-
scoped_paths = scoped_paths(graph)
|
|
23
|
-
|
|
24
|
-
graph.files.values.filter_map do |file|
|
|
25
|
-
next unless file.expected_constant
|
|
26
|
-
next if scoped_paths && !scoped_paths.include?(file.path)
|
|
27
|
-
|
|
28
|
-
defined = graph.constants_for_path(file.path).map(&:name)
|
|
29
|
-
next if defined.include?(file.expected_constant)
|
|
30
|
-
|
|
31
|
-
Diagnostic.new(
|
|
32
|
-
rule: id,
|
|
33
|
-
message: "#{file.relative_path} should define #{file.expected_constant}",
|
|
34
|
-
location: SourceLocation.new(file.path, 1, 1),
|
|
35
|
-
evidence: "defined constants: #{defined.empty? ? '(none)' : defined.join(', ')}"
|
|
36
|
-
)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
private
|
|
41
|
-
|
|
42
|
-
def scoped_paths(graph)
|
|
43
|
-
return nil if only.empty?
|
|
44
|
-
|
|
45
|
-
only.flat_map { |pattern| Dir.glob(File.absolute_path(pattern, graph.root)) }
|
|
46
|
-
.map { |path| File.expand_path(path) }
|
|
47
|
-
.to_set
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|