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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +6 -5
  3. data/USAGE.md +17 -16
  4. data/lib/packwerk.rb +72 -36
  5. data/lib/packwerk/application_validator.rb +0 -5
  6. data/lib/packwerk/association_inspector.rb +0 -3
  7. data/lib/packwerk/checker.rb +2 -8
  8. data/lib/packwerk/cli.rb +22 -77
  9. data/lib/packwerk/configuration.rb +5 -0
  10. data/lib/packwerk/const_node_inspector.rb +0 -2
  11. data/lib/packwerk/constant_discovery.rb +2 -0
  12. data/lib/packwerk/constant_name_inspector.rb +0 -1
  13. data/lib/packwerk/dependency_checker.rb +2 -15
  14. data/lib/packwerk/deprecated_references.rb +3 -9
  15. data/lib/packwerk/file_processor.rb +0 -4
  16. data/lib/packwerk/formatters/offenses_formatter.rb +3 -8
  17. data/lib/packwerk/formatters/progress_formatter.rb +5 -4
  18. data/lib/packwerk/generators/configuration_file.rb +0 -1
  19. data/lib/packwerk/inflector.rb +0 -2
  20. data/lib/packwerk/node.rb +1 -0
  21. data/lib/packwerk/node_processor.rb +14 -32
  22. data/lib/packwerk/node_processor_factory.rb +0 -5
  23. data/lib/packwerk/node_visitor.rb +1 -4
  24. data/lib/packwerk/offense.rb +0 -4
  25. data/lib/packwerk/offense_collection.rb +84 -0
  26. data/lib/packwerk/offenses_formatter.rb +15 -0
  27. data/lib/packwerk/package.rb +8 -0
  28. data/lib/packwerk/package_set.rb +0 -2
  29. data/lib/packwerk/parse_run.rb +104 -0
  30. data/lib/packwerk/parsed_constant_definitions.rb +0 -2
  31. data/lib/packwerk/parsers.rb +0 -2
  32. data/lib/packwerk/parsers/erb.rb +0 -2
  33. data/lib/packwerk/parsers/factory.rb +0 -2
  34. data/lib/packwerk/privacy_checker.rb +2 -15
  35. data/lib/packwerk/reference_extractor.rb +0 -8
  36. data/lib/packwerk/reference_offense.rb +49 -0
  37. data/lib/packwerk/result.rb +9 -0
  38. data/lib/packwerk/run_context.rb +4 -21
  39. data/lib/packwerk/sanity_checker.rb +0 -2
  40. data/lib/packwerk/version.rb +1 -1
  41. data/lib/packwerk/violation_type.rb +0 -2
  42. data/packwerk.gemspec +1 -0
  43. data/service.yml +1 -4
  44. data/sorbet/rbi/gems/parallel@1.20.1.rbi +111 -2
  45. data/sorbet/tapioca/require.rb +1 -0
  46. metadata +22 -12
  47. data/lib/packwerk/cache_deprecated_references.rb +0 -55
  48. data/lib/packwerk/checking_deprecated_references.rb +0 -43
  49. data/lib/packwerk/commands/detect_stale_violations_command.rb +0 -60
  50. data/lib/packwerk/commands/offense_progress_marker.rb +0 -24
  51. data/lib/packwerk/commands/result.rb +0 -13
  52. data/lib/packwerk/commands/update_deprecations_command.rb +0 -81
  53. data/lib/packwerk/detect_stale_deprecated_references.rb +0 -14
  54. data/lib/packwerk/reference_lister.rb +0 -23
  55. data/lib/packwerk/updating_deprecated_references.rb +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4ac6768688fbeb5f3933d1ec71772d6266b800bbfa51fb3d27131d35eba1dbe
4
- data.tar.gz: f7c6406ca6ab82789410b998415e483f762f2e43a689921457c91e8eca743536
3
+ metadata.gz: ced63ca0995c039913777f3e8ba1aac428970d8fc515b1629c9212f71baab34b
4
+ data.tar.gz: 331b0a5f30e7104b4eb3e44920739ea592e7e3dc7df3dca339a74260fa13d62b
5
5
  SHA512:
6
- metadata.gz: '09a96a3337917f29e5b49440e41457e49d0dcb66fe9d94d428472f80694232bebe8019d0aefe88704ca4284d7b5b3ee21cad001b5338a0978e733ff9752192dc'
7
- data.tar.gz: 7863556c9cf8f9132d522c30e2905df58d7015e314a7d452b642e2eb163bd827fc5ff8947b7f3a926a9a0d647f5cb27ba8eba1a48b6190d6f8bee6f83bb02293
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.1.3)
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.0)
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.2)
144
+ nokogiri (1.11.5)
144
145
  mini_portile2 (~> 2.5.0)
145
146
  racc (~> 1.4)
146
- nokogiri (1.11.2-x86_64-darwin)
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.4)
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?](#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)
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:)
@@ -1,9 +1,6 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "packwerk/constant_name_inspector"
5
- require "packwerk/node"
6
-
7
4
  module Packwerk
8
5
  # Extracts the implicit constant reference from an active record association
9
6
  class AssociationInspector
@@ -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, reference_lister: ReferenceLister).returns(T::Boolean).abstract }
18
- def invalid_reference?(reference, reference_lister); end
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(run_context: nil, configuration: nil, out: $stdout, err_out: $stderr, style: OutputStyles::Plain.new)
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
- check(args)
47
+ output_result(parse_run(args).check)
64
48
  when "detect-stale-violations"
65
- detect_stale_violations(args)
49
+ output_result(parse_run(args).detect_stale_violations)
66
50
  when "update"
67
51
  update(args)
68
52
  when "update-deprecations"
69
- update_deprecations(args)
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
- update_deprecations(paths)
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 detect_stale_violations(paths)
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 offenses_formatter
244
- @offenses_formatter ||= Formatters::OffensesFormatter.new(style: @style)
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,8 +1,6 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "packwerk/constant_name_inspector"
5
-
6
4
  module Packwerk
7
5
  # Extracts a constant name from an AST node of type :const
8
6
  class ConstNodeInspector
@@ -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,