packwerk 1.1.3 → 1.2.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/Gemfile.lock +6 -5
- data/USAGE.md +17 -16
- data/lib/packwerk.rb +72 -36
- data/lib/packwerk/application_validator.rb +0 -5
- data/lib/packwerk/association_inspector.rb +0 -3
- data/lib/packwerk/checker.rb +2 -8
- data/lib/packwerk/cli.rb +22 -77
- data/lib/packwerk/configuration.rb +5 -0
- data/lib/packwerk/const_node_inspector.rb +0 -2
- data/lib/packwerk/constant_discovery.rb +2 -0
- data/lib/packwerk/constant_name_inspector.rb +0 -1
- data/lib/packwerk/dependency_checker.rb +2 -15
- data/lib/packwerk/deprecated_references.rb +3 -9
- data/lib/packwerk/file_processor.rb +0 -4
- data/lib/packwerk/formatters/offenses_formatter.rb +3 -8
- data/lib/packwerk/formatters/progress_formatter.rb +5 -4
- data/lib/packwerk/generators/configuration_file.rb +0 -1
- data/lib/packwerk/inflector.rb +0 -2
- data/lib/packwerk/node.rb +1 -0
- data/lib/packwerk/node_processor.rb +14 -32
- data/lib/packwerk/node_processor_factory.rb +0 -5
- data/lib/packwerk/node_visitor.rb +1 -4
- data/lib/packwerk/offense.rb +0 -4
- data/lib/packwerk/offense_collection.rb +84 -0
- data/lib/packwerk/offenses_formatter.rb +15 -0
- data/lib/packwerk/package.rb +8 -0
- data/lib/packwerk/package_set.rb +0 -2
- data/lib/packwerk/parse_run.rb +104 -0
- data/lib/packwerk/parsed_constant_definitions.rb +0 -2
- data/lib/packwerk/parsers.rb +0 -2
- data/lib/packwerk/parsers/erb.rb +0 -2
- data/lib/packwerk/parsers/factory.rb +0 -2
- data/lib/packwerk/privacy_checker.rb +2 -15
- data/lib/packwerk/reference_extractor.rb +0 -8
- data/lib/packwerk/reference_offense.rb +49 -0
- data/lib/packwerk/result.rb +9 -0
- data/lib/packwerk/run_context.rb +4 -21
- data/lib/packwerk/sanity_checker.rb +0 -2
- data/lib/packwerk/version.rb +1 -1
- data/lib/packwerk/violation_type.rb +0 -2
- data/packwerk.gemspec +1 -0
- data/service.yml +1 -4
- data/sorbet/rbi/gems/parallel@1.20.1.rbi +111 -2
- data/sorbet/tapioca/require.rb +1 -0
- metadata +22 -12
- data/lib/packwerk/cache_deprecated_references.rb +0 -55
- data/lib/packwerk/checking_deprecated_references.rb +0 -43
- data/lib/packwerk/commands/detect_stale_violations_command.rb +0 -60
- data/lib/packwerk/commands/offense_progress_marker.rb +0 -24
- data/lib/packwerk/commands/result.rb +0 -13
- data/lib/packwerk/commands/update_deprecations_command.rb +0 -81
- data/lib/packwerk/detect_stale_deprecated_references.rb +0 -14
- data/lib/packwerk/reference_lister.rb +0 -23
- data/lib/packwerk/updating_deprecated_references.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ced63ca0995c039913777f3e8ba1aac428970d8fc515b1629c9212f71baab34b
|
4
|
+
data.tar.gz: 331b0a5f30e7104b4eb3e44920739ea592e7e3dc7df3dca339a74260fa13d62b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a487a501ca28d341a888eea2e0ec13c4831897680ce1d17bef2a4943408ff718d75cffe9a50030fd93d7a2388d161c7a3cd946a0764930f89016c2f2c81e5306
|
7
|
+
data.tar.gz: d4685f869617c8b1141125fcaacbde96839be3d239aa2422db6f76dbcb485f42fcde97e0c6aaa580ef4abcd847ebbfd9979fe4896f0bc5c7421d104673346981
|
data/Gemfile.lock
CHANGED
@@ -87,11 +87,12 @@ GIT
|
|
87
87
|
PATH
|
88
88
|
remote: .
|
89
89
|
specs:
|
90
|
-
packwerk (1.
|
90
|
+
packwerk (1.2.0)
|
91
91
|
activesupport (>= 5.2)
|
92
92
|
ast
|
93
93
|
better_html
|
94
94
|
constant_resolver
|
95
|
+
parallel
|
95
96
|
parser
|
96
97
|
sorbet-runtime
|
97
98
|
|
@@ -134,16 +135,16 @@ GEM
|
|
134
135
|
marcel (1.0.0)
|
135
136
|
method_source (1.0.0)
|
136
137
|
mini_mime (1.0.3)
|
137
|
-
mini_portile2 (2.5.
|
138
|
+
mini_portile2 (2.5.1)
|
138
139
|
minitest (5.14.4)
|
139
140
|
minitest-focus (1.2.1)
|
140
141
|
minitest (>= 4, < 6)
|
141
142
|
mocha (1.12.0)
|
142
143
|
nio4r (2.5.7)
|
143
|
-
nokogiri (1.11.
|
144
|
+
nokogiri (1.11.5)
|
144
145
|
mini_portile2 (~> 2.5.0)
|
145
146
|
racc (~> 1.4)
|
146
|
-
nokogiri (1.11.
|
147
|
+
nokogiri (1.11.5-x86_64-darwin)
|
147
148
|
racc (~> 1.4)
|
148
149
|
parallel (1.20.1)
|
149
150
|
parlour (6.0.0)
|
@@ -168,7 +169,7 @@ GEM
|
|
168
169
|
rainbow (3.0.0)
|
169
170
|
rake (13.0.3)
|
170
171
|
regexp_parser (2.1.1)
|
171
|
-
rexml (3.2.
|
172
|
+
rexml (3.2.5)
|
172
173
|
rubocop (1.12.0)
|
173
174
|
parallel (~> 1.10)
|
174
175
|
parser (>= 3.0.0.0)
|
data/USAGE.md
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
# Packwerk usage
|
2
2
|
|
3
3
|
## Table of Contents
|
4
|
-
* [What problem does Packwerk solve?](#
|
5
|
-
* [What is a package?](#
|
6
|
-
* [Package principles](#
|
7
|
-
* [Getting started](#
|
8
|
-
* [Setting up the configuration file](#
|
9
|
-
* [Inflections](#
|
10
|
-
* [Validating the package system](#
|
11
|
-
* [Defining packages](#
|
12
|
-
* [Package metadata](#
|
13
|
-
* [Types of boundary checks](#
|
14
|
-
* [Enforcing privacy boundary](#
|
15
|
-
* [Using public folders](#
|
16
|
-
* [Enforcing dependency boundary](#
|
17
|
-
* [Checking for violations](#
|
18
|
-
* [Recording existing violations](#
|
19
|
-
* [Understanding the list of deprecated references](#
|
4
|
+
* [What problem does Packwerk solve?](#what-problem-does-packwerk-solve)
|
5
|
+
* [What is a package?](#what-is-a-package)
|
6
|
+
* [Package principles](#package-principles)
|
7
|
+
* [Getting started](#getting-started)
|
8
|
+
* [Setting up the configuration file](#setting-up-the-configuration-file)
|
9
|
+
* [Inflections](#inflections)
|
10
|
+
* [Validating the package system](#validating-the-package-system)
|
11
|
+
* [Defining packages](#defining-packages)
|
12
|
+
* [Package metadata](#package-metadata)
|
13
|
+
* [Types of boundary checks](#types-of-boundary-checks)
|
14
|
+
* [Enforcing privacy boundary](#enforcing-privacy-boundary)
|
15
|
+
* [Using public folders](#using-public-folders)
|
16
|
+
* [Enforcing dependency boundary](#enforcing-dependency-boundary)
|
17
|
+
* [Checking for violations](#checking-for-violations)
|
18
|
+
* [Recording existing violations](#recording-existing-violations)
|
19
|
+
* [Understanding the list of deprecated references](#understanding-the-list-of-deprecated-references)
|
20
20
|
|
21
21
|
## What problem does Packwerk solve?
|
22
22
|
Large applications need clear boundaries to avoid turning into a [ball of mud](https://en.wikipedia.org/wiki/Big_ball_of_mud). However, Ruby does not provide a good solution to enforcing boundaries between code.
|
@@ -66,6 +66,7 @@ Packwerk reads from the `packwerk.yml` configuration file in the root directory.
|
|
66
66
|
| package_paths | **/ | a single pattern or a list of patterns to find package configuration files, see: [Defining packages](#Defining-packages) |
|
67
67
|
| load_paths | All application autoload paths | list of load paths |
|
68
68
|
| custom_associations | N/A | list of custom associations, if any |
|
69
|
+
| parallel | true | when true, fork code parsing out to subprocesses |
|
69
70
|
|
70
71
|
### Using a custom ERB parser
|
71
72
|
|
data/lib/packwerk.rb
CHANGED
@@ -3,43 +3,79 @@
|
|
3
3
|
|
4
4
|
require "sorbet-runtime"
|
5
5
|
require "active_support"
|
6
|
-
require "constant_resolver"
|
7
6
|
require "fileutils"
|
8
7
|
|
9
|
-
require "packwerk/offense"
|
10
|
-
|
11
|
-
require "packwerk/application_validator"
|
12
|
-
require "packwerk/association_inspector"
|
13
|
-
require "packwerk/checking_deprecated_references"
|
14
|
-
require "packwerk/cli"
|
15
|
-
require "packwerk/configuration"
|
16
|
-
require "packwerk/const_node_inspector"
|
17
|
-
require "packwerk/constant_discovery"
|
18
|
-
require "packwerk/dependency_checker"
|
19
|
-
require "packwerk/deprecated_references"
|
20
|
-
require "packwerk/files_for_processing"
|
21
|
-
require "packwerk/file_processor"
|
22
|
-
require "packwerk/formatters/progress_formatter"
|
23
|
-
require "packwerk/generators/application_validation"
|
24
|
-
require "packwerk/generators/configuration_file"
|
25
|
-
require "packwerk/generators/inflections_file"
|
26
|
-
require "packwerk/generators/root_package"
|
27
|
-
require "packwerk/graph"
|
28
|
-
require "packwerk/inflector"
|
29
|
-
require "packwerk/node_processor"
|
30
|
-
require "packwerk/node_visitor"
|
31
|
-
require "packwerk/output_style"
|
32
|
-
require "packwerk/output_styles/plain"
|
33
|
-
require "packwerk/output_styles/coloured"
|
34
|
-
require "packwerk/package"
|
35
|
-
require "packwerk/package_set"
|
36
|
-
require "packwerk/parsers"
|
37
|
-
require "packwerk/privacy_checker"
|
38
|
-
require "packwerk/reference_extractor"
|
39
|
-
require "packwerk/run_context"
|
40
|
-
require "packwerk/updating_deprecated_references"
|
41
|
-
require "packwerk/version"
|
42
|
-
require "packwerk/violation_type"
|
43
|
-
|
44
8
|
module Packwerk
|
9
|
+
extend ActiveSupport::Autoload
|
10
|
+
|
11
|
+
autoload :ApplicationLoadPaths
|
12
|
+
autoload :ApplicationValidator
|
13
|
+
autoload :AssociationInspector
|
14
|
+
autoload :OffenseCollection
|
15
|
+
autoload :Checker
|
16
|
+
autoload :Cli
|
17
|
+
autoload :Configuration
|
18
|
+
autoload :ConstantDiscovery
|
19
|
+
autoload :ConstantNameInspector
|
20
|
+
autoload :ConstNodeInspector
|
21
|
+
autoload :DependencyChecker
|
22
|
+
autoload :DeprecatedReferences
|
23
|
+
autoload :FileProcessor
|
24
|
+
autoload :FilesForProcessing
|
25
|
+
autoload :Graph
|
26
|
+
autoload :Inflector
|
27
|
+
autoload :Node
|
28
|
+
autoload :NodeProcessor
|
29
|
+
autoload :NodeProcessorFactory
|
30
|
+
autoload :NodeVisitor
|
31
|
+
autoload :Offense
|
32
|
+
autoload :OffensesFormatter
|
33
|
+
autoload :OutputStyle
|
34
|
+
autoload :Package
|
35
|
+
autoload :PackageSet
|
36
|
+
autoload :ParsedConstantDefinitions
|
37
|
+
autoload :Parsers
|
38
|
+
autoload :ParseRun
|
39
|
+
autoload :PrivacyChecker
|
40
|
+
autoload :Reference
|
41
|
+
autoload :ReferenceExtractor
|
42
|
+
autoload :ReferenceOffense
|
43
|
+
autoload :Result
|
44
|
+
autoload :RunContext
|
45
|
+
autoload :Version
|
46
|
+
autoload :ViolationType
|
47
|
+
|
48
|
+
module Inflections
|
49
|
+
extend ActiveSupport::Autoload
|
50
|
+
|
51
|
+
autoload :Custom
|
52
|
+
autoload :Default
|
53
|
+
end
|
54
|
+
|
55
|
+
module OutputStyles
|
56
|
+
extend ActiveSupport::Autoload
|
57
|
+
|
58
|
+
autoload :Coloured
|
59
|
+
autoload :Plain
|
60
|
+
end
|
61
|
+
|
62
|
+
autoload_under "commands" do
|
63
|
+
autoload :OffenseProgressMarker
|
64
|
+
end
|
65
|
+
|
66
|
+
module Formatters
|
67
|
+
extend ActiveSupport::Autoload
|
68
|
+
|
69
|
+
autoload :OffensesFormatter
|
70
|
+
autoload :ProgressFormatter
|
71
|
+
end
|
72
|
+
|
73
|
+
module Generators
|
74
|
+
extend ActiveSupport::Autoload
|
75
|
+
|
76
|
+
autoload :ApplicationValidation
|
77
|
+
autoload :ConfigurationFile
|
78
|
+
autoload :InflectionsFile
|
79
|
+
autoload :RootPackage
|
80
|
+
end
|
45
81
|
end
|
@@ -6,11 +6,6 @@ require "constant_resolver"
|
|
6
6
|
require "pathname"
|
7
7
|
require "yaml"
|
8
8
|
|
9
|
-
require "packwerk/package_set"
|
10
|
-
require "packwerk/graph"
|
11
|
-
require "packwerk/inflector"
|
12
|
-
require "packwerk/application_load_paths"
|
13
|
-
|
14
9
|
module Packwerk
|
15
10
|
class ApplicationValidator
|
16
11
|
def initialize(config_file_path:, configuration:)
|
data/lib/packwerk/checker.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require "sorbet-runtime"
|
5
|
-
require "packwerk/reference_lister"
|
6
|
-
|
7
4
|
module Packwerk
|
8
5
|
module Checker
|
9
6
|
extend T::Sig
|
@@ -14,10 +11,7 @@ module Packwerk
|
|
14
11
|
sig { returns(ViolationType).abstract }
|
15
12
|
def violation_type; end
|
16
13
|
|
17
|
-
sig { params(reference: Reference
|
18
|
-
def invalid_reference?(reference
|
19
|
-
|
20
|
-
sig { params(reference: Reference).returns(String).abstract }
|
21
|
-
def message_for(reference); end
|
14
|
+
sig { params(reference: Reference).returns(T::Boolean).abstract }
|
15
|
+
def invalid_reference?(reference); end
|
22
16
|
end
|
23
17
|
end
|
data/lib/packwerk/cli.rb
CHANGED
@@ -1,48 +1,32 @@
|
|
1
1
|
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
|
-
require "benchmark"
|
4
|
-
require "sorbet-runtime"
|
5
|
-
|
6
|
-
require "packwerk/application_load_paths"
|
7
|
-
require "packwerk/application_validator"
|
8
|
-
require "packwerk/configuration"
|
9
|
-
require "packwerk/files_for_processing"
|
10
|
-
require "packwerk/formatters/offenses_formatter"
|
11
|
-
require "packwerk/formatters/progress_formatter"
|
12
|
-
require "packwerk/inflector"
|
13
|
-
require "packwerk/output_style"
|
14
|
-
require "packwerk/output_styles/plain"
|
15
|
-
require "packwerk/run_context"
|
16
|
-
require "packwerk/updating_deprecated_references"
|
17
|
-
require "packwerk/checking_deprecated_references"
|
18
|
-
require "packwerk/commands/detect_stale_violations_command"
|
19
|
-
require "packwerk/commands/update_deprecations_command"
|
20
|
-
require "packwerk/commands/offense_progress_marker"
|
21
3
|
|
22
4
|
module Packwerk
|
23
5
|
class Cli
|
24
6
|
extend T::Sig
|
25
|
-
include OffenseProgressMarker
|
26
7
|
|
27
8
|
sig do
|
28
9
|
params(
|
29
|
-
run_context: T.nilable(Packwerk::RunContext),
|
30
10
|
configuration: T.nilable(Configuration),
|
31
11
|
out: T.any(StringIO, IO),
|
32
12
|
err_out: T.any(StringIO, IO),
|
33
|
-
style: Packwerk::OutputStyle
|
13
|
+
style: Packwerk::OutputStyle,
|
14
|
+
offenses_formatter: T.nilable(Packwerk::OffensesFormatter)
|
34
15
|
).void
|
35
16
|
end
|
36
|
-
def initialize(
|
17
|
+
def initialize(
|
18
|
+
configuration: nil,
|
19
|
+
out: $stdout,
|
20
|
+
err_out: $stderr,
|
21
|
+
style: OutputStyles::Plain.new,
|
22
|
+
offenses_formatter: nil
|
23
|
+
)
|
37
24
|
@out = out
|
38
25
|
@err_out = err_out
|
39
26
|
@style = style
|
40
27
|
@configuration = configuration || Configuration.from_path
|
41
|
-
@run_context = run_context || Packwerk::RunContext.from_configuration(
|
42
|
-
@configuration,
|
43
|
-
reference_lister: ::Packwerk::CheckingDeprecatedReferences.new(@configuration.root_path),
|
44
|
-
)
|
45
28
|
@progress_formatter = Formatters::ProgressFormatter.new(@out, style: style)
|
29
|
+
@offenses_formatter = offenses_formatter || Formatters::OffensesFormatter.new(style: @style)
|
46
30
|
end
|
47
31
|
|
48
32
|
sig { params(args: T::Array[String]).returns(T.noreturn) }
|
@@ -60,13 +44,13 @@ module Packwerk
|
|
60
44
|
when "generate_configs"
|
61
45
|
generate_configs
|
62
46
|
when "check"
|
63
|
-
|
47
|
+
output_result(parse_run(args).check)
|
64
48
|
when "detect-stale-violations"
|
65
|
-
|
49
|
+
output_result(parse_run(args).detect_stale_violations)
|
66
50
|
when "update"
|
67
51
|
update(args)
|
68
52
|
when "update-deprecations"
|
69
|
-
|
53
|
+
output_result(parse_run(args).update_deprecations)
|
70
54
|
when "validate"
|
71
55
|
validate(args)
|
72
56
|
when nil, "help"
|
@@ -143,54 +127,10 @@ module Packwerk
|
|
143
127
|
|
144
128
|
def update(paths)
|
145
129
|
warn("`packwerk update` is deprecated in favor of `packwerk update-deprecations`.")
|
146
|
-
|
147
|
-
end
|
148
|
-
|
149
|
-
def update_deprecations(paths)
|
150
|
-
update_deprecations = Commands::UpdateDeprecationsCommand.new(
|
151
|
-
files: fetch_files_to_process(paths),
|
152
|
-
configuration: @configuration,
|
153
|
-
offenses_formatter: offenses_formatter,
|
154
|
-
progress_formatter: @progress_formatter
|
155
|
-
)
|
156
|
-
result = update_deprecations.run
|
157
|
-
@out.puts
|
158
|
-
@out.puts(result.message)
|
159
|
-
result.status
|
160
|
-
end
|
161
|
-
|
162
|
-
def check(paths)
|
163
|
-
files = fetch_files_to_process(paths)
|
164
|
-
|
165
|
-
@progress_formatter.started(files)
|
166
|
-
|
167
|
-
all_offenses = T.let([], T.untyped)
|
168
|
-
execution_time = Benchmark.realtime do
|
169
|
-
files.each do |path|
|
170
|
-
@run_context.process_file(file: path).tap do |offenses|
|
171
|
-
mark_progress(offenses: offenses, progress_formatter: @progress_formatter)
|
172
|
-
all_offenses.concat(offenses)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
rescue Interrupt
|
176
|
-
@out.puts
|
177
|
-
@out.puts("Manually interrupted. Violations caught so far are listed below:")
|
178
|
-
end
|
179
|
-
|
180
|
-
@progress_formatter.finished(execution_time)
|
181
|
-
@out.puts
|
182
|
-
@out.puts(offenses_formatter.show_offenses(all_offenses))
|
183
|
-
|
184
|
-
all_offenses.empty?
|
130
|
+
output_result(parse_run(paths).update_deprecations)
|
185
131
|
end
|
186
132
|
|
187
|
-
def
|
188
|
-
detect_stale_violations = Commands::DetectStaleViolationsCommand.new(
|
189
|
-
files: fetch_files_to_process(paths),
|
190
|
-
configuration: @configuration,
|
191
|
-
progress_formatter: @progress_formatter
|
192
|
-
)
|
193
|
-
result = detect_stale_violations.run
|
133
|
+
def output_result(result)
|
194
134
|
@out.puts
|
195
135
|
@out.puts(result.message)
|
196
136
|
result.status
|
@@ -240,8 +180,13 @@ module Packwerk
|
|
240
180
|
end
|
241
181
|
end
|
242
182
|
|
243
|
-
def
|
244
|
-
|
183
|
+
def parse_run(paths)
|
184
|
+
ParseRun.new(
|
185
|
+
files: fetch_files_to_process(paths),
|
186
|
+
configuration: @configuration,
|
187
|
+
progress_formatter: @progress_formatter,
|
188
|
+
offenses_formatter: @offenses_formatter
|
189
|
+
)
|
245
190
|
end
|
246
191
|
end
|
247
192
|
end
|
@@ -47,8 +47,13 @@ module Packwerk
|
|
47
47
|
@custom_associations = configs["custom_associations"] || []
|
48
48
|
@load_paths = configs["load_paths"] || []
|
49
49
|
@inflections_file = File.expand_path(configs["inflections_file"] || "config/inflections.yml", @root_path)
|
50
|
+
@parallel = configs.key?("parallel") ? configs["parallel"] : true
|
50
51
|
|
51
52
|
@config_path = config_path
|
52
53
|
end
|
54
|
+
|
55
|
+
def parallel?
|
56
|
+
@parallel
|
57
|
+
end
|
53
58
|
end
|
54
59
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require "constant_resolver"
|
5
|
+
|
4
6
|
module Packwerk
|
5
7
|
# Get information about (partially qualified) constants without loading the application code.
|
6
8
|
# Information gathered: Fully qualified name, path to file containing the definition, package,
|