packwerk 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -13,6 +13,7 @@ require "better_html/parser"
13
13
  require "constant_resolver"
14
14
  require "minitest/autorun"
15
15
  require "mocha/minitest"
16
+ require "parallel"
16
17
  require "parser"
17
18
  require "parser/ast/node"
18
19
  require "parser/current"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packwerk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-01 00:00:00.000000000 Z
11
+ date: 2021-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: parallel
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: sorbet-runtime
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -187,21 +201,14 @@ files:
187
201
  - lib/packwerk/application_load_paths.rb
188
202
  - lib/packwerk/application_validator.rb
189
203
  - lib/packwerk/association_inspector.rb
190
- - lib/packwerk/cache_deprecated_references.rb
191
204
  - lib/packwerk/checker.rb
192
- - lib/packwerk/checking_deprecated_references.rb
193
205
  - lib/packwerk/cli.rb
194
- - lib/packwerk/commands/detect_stale_violations_command.rb
195
- - lib/packwerk/commands/offense_progress_marker.rb
196
- - lib/packwerk/commands/result.rb
197
- - lib/packwerk/commands/update_deprecations_command.rb
198
206
  - lib/packwerk/configuration.rb
199
207
  - lib/packwerk/const_node_inspector.rb
200
208
  - lib/packwerk/constant_discovery.rb
201
209
  - lib/packwerk/constant_name_inspector.rb
202
210
  - lib/packwerk/dependency_checker.rb
203
211
  - lib/packwerk/deprecated_references.rb
204
- - lib/packwerk/detect_stale_deprecated_references.rb
205
212
  - lib/packwerk/file_processor.rb
206
213
  - lib/packwerk/files_for_processing.rb
207
214
  - lib/packwerk/formatters/offenses_formatter.rb
@@ -224,11 +231,14 @@ files:
224
231
  - lib/packwerk/node_processor_factory.rb
225
232
  - lib/packwerk/node_visitor.rb
226
233
  - lib/packwerk/offense.rb
234
+ - lib/packwerk/offense_collection.rb
235
+ - lib/packwerk/offenses_formatter.rb
227
236
  - lib/packwerk/output_style.rb
228
237
  - lib/packwerk/output_styles/coloured.rb
229
238
  - lib/packwerk/output_styles/plain.rb
230
239
  - lib/packwerk/package.rb
231
240
  - lib/packwerk/package_set.rb
241
+ - lib/packwerk/parse_run.rb
232
242
  - lib/packwerk/parsed_constant_definitions.rb
233
243
  - lib/packwerk/parsers.rb
234
244
  - lib/packwerk/parsers/erb.rb
@@ -237,11 +247,11 @@ files:
237
247
  - lib/packwerk/privacy_checker.rb
238
248
  - lib/packwerk/reference.rb
239
249
  - lib/packwerk/reference_extractor.rb
240
- - lib/packwerk/reference_lister.rb
250
+ - lib/packwerk/reference_offense.rb
251
+ - lib/packwerk/result.rb
241
252
  - lib/packwerk/run_context.rb
242
253
  - lib/packwerk/sanity_checker.rb
243
254
  - lib/packwerk/spring_command.rb
244
- - lib/packwerk/updating_deprecated_references.rb
245
255
  - lib/packwerk/version.rb
246
256
  - lib/packwerk/violation_type.rb
247
257
  - library.yml
@@ -343,7 +353,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
343
353
  - !ruby/object:Gem::Version
344
354
  version: '0'
345
355
  requirements: []
346
- rubygems_version: 3.0.3
356
+ rubygems_version: 3.2.17
347
357
  signing_key:
348
358
  specification_version: 4
349
359
  summary: Packages for applications based on the zeitwerk autoloader
@@ -1,55 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- require "sorbet-runtime"
5
-
6
- require "packwerk/deprecated_references"
7
- require "packwerk/reference"
8
- require "packwerk/reference_lister"
9
- require "packwerk/violation_type"
10
-
11
- module Packwerk
12
- class CacheDeprecatedReferences
13
- extend T::Sig
14
- extend T::Helpers
15
- include ReferenceLister
16
- abstract!
17
-
18
- sig do
19
- params(
20
- root_path: String,
21
- deprecated_references: T::Hash[Packwerk::Package, Packwerk::DeprecatedReferences]
22
- ).void
23
- end
24
- def initialize(root_path, deprecated_references = {})
25
- @root_path = root_path
26
- @deprecated_references = T.let(deprecated_references, T::Hash[Packwerk::Package, Packwerk::DeprecatedReferences])
27
- end
28
-
29
- sig do
30
- params(reference: Packwerk::Reference, violation_type: ViolationType)
31
- .returns(T::Boolean)
32
- .override
33
- end
34
- def listed?(reference, violation_type:)
35
- deprecated_references = deprecated_references_for(reference.source_package)
36
- deprecated_references.add_entries(reference, violation_type.serialize)
37
- true
38
- end
39
-
40
- private
41
-
42
- sig { params(package: Packwerk::Package).returns(Packwerk::DeprecatedReferences) }
43
- def deprecated_references_for(package)
44
- @deprecated_references[package] ||= Packwerk::DeprecatedReferences.new(
45
- package,
46
- deprecated_references_file_for(package),
47
- )
48
- end
49
-
50
- sig { params(package: Packwerk::Package).returns(String) }
51
- def deprecated_references_file_for(package)
52
- File.join(@root_path, package.name, "deprecated_references.yml")
53
- end
54
- end
55
- end
@@ -1,43 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- require "sorbet-runtime"
5
-
6
- require "packwerk/reference_lister"
7
-
8
- module Packwerk
9
- class CheckingDeprecatedReferences
10
- extend T::Sig
11
- include ReferenceLister
12
-
13
- sig { params(root_path: String).void }
14
- def initialize(root_path)
15
- @root_path = root_path
16
- @deprecated_references = T.let({}, T::Hash[Packwerk::Package, Packwerk::DeprecatedReferences])
17
- end
18
-
19
- sig do
20
- params(reference: Packwerk::Reference, violation_type: ViolationType)
21
- .returns(T::Boolean)
22
- .override
23
- end
24
- def listed?(reference, violation_type:)
25
- deprecated_references_for(reference.source_package).listed?(reference, violation_type: violation_type)
26
- end
27
-
28
- private
29
-
30
- sig { params(source_package: Packwerk::Package).returns(Packwerk::DeprecatedReferences) }
31
- def deprecated_references_for(source_package)
32
- @deprecated_references[source_package] ||= Packwerk::DeprecatedReferences.new(
33
- source_package,
34
- deprecated_references_file_for(source_package),
35
- )
36
- end
37
-
38
- sig { params(package: Packwerk::Package).returns(String) }
39
- def deprecated_references_file_for(package)
40
- File.join(@root_path, package.name, "deprecated_references.yml")
41
- end
42
- end
43
- end
@@ -1,60 +0,0 @@
1
- # typed: true
2
- # frozen_string_literal: true
3
- require "sorbet-runtime"
4
- require "benchmark"
5
- require "packwerk/run_context"
6
- require "packwerk/detect_stale_deprecated_references"
7
- require "packwerk/commands/offense_progress_marker"
8
- require "packwerk/commands/result"
9
-
10
- module Packwerk
11
- module Commands
12
- class DetectStaleViolationsCommand
13
- extend T::Sig
14
- include OffenseProgressMarker
15
- def initialize(files:, configuration:, run_context: nil, progress_formatter: nil, reference_lister: nil)
16
- @configuration = configuration
17
- @run_context = run_context
18
- @reference_lister = reference_lister
19
- @progress_formatter = progress_formatter
20
- @files = files
21
- end
22
-
23
- sig { returns(Result) }
24
- def run
25
- @progress_formatter.started(@files)
26
-
27
- execution_time = Benchmark.realtime do
28
- @files.flat_map do |path|
29
- run_context.process_file(file: path).tap do |offenses|
30
- mark_progress(offenses: offenses, progress_formatter: @progress_formatter)
31
- end
32
- end
33
- end
34
-
35
- @progress_formatter.finished(execution_time)
36
- calculate_result
37
- end
38
-
39
- private
40
-
41
- def run_context
42
- @run_context ||= Packwerk::RunContext.from_configuration(@configuration, reference_lister: reference_lister)
43
- end
44
-
45
- def reference_lister
46
- @reference_lister ||= ::Packwerk::DetectStaleDeprecatedReferences.new(@configuration.root_path)
47
- end
48
-
49
- sig { returns(Result) }
50
- def calculate_result
51
- result_status = !reference_lister.stale_violations?
52
- message = "There were stale violations found, please run `packwerk update-deprecations`"
53
- if result_status
54
- message = "No stale violations detected"
55
- end
56
- Result.new(message: message, status: result_status)
57
- end
58
- end
59
- end
60
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
- # typed: strict
3
- require "sorbet-runtime"
4
- require "packwerk/formatters/progress_formatter"
5
-
6
- module Packwerk
7
- module OffenseProgressMarker
8
- extend T::Sig
9
-
10
- sig do
11
- params(
12
- offenses: T::Array[T.nilable(::Packwerk::Offense)],
13
- progress_formatter: ::Packwerk::Formatters::ProgressFormatter
14
- ).void
15
- end
16
- def mark_progress(offenses:, progress_formatter:)
17
- if offenses.empty?
18
- progress_formatter.mark_as_inspected
19
- else
20
- progress_formatter.mark_as_failed
21
- end
22
- end
23
- end
24
- end
@@ -1,13 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- require "sorbet-runtime"
5
-
6
- module Packwerk
7
- module Commands
8
- class Result < T::Struct
9
- prop :message, String
10
- prop :status, T::Boolean
11
- end
12
- end
13
- end
@@ -1,81 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- require "sorbet-runtime"
5
- require "benchmark"
6
-
7
- require "packwerk/commands/offense_progress_marker"
8
- require "packwerk/commands/result"
9
- require "packwerk/run_context"
10
- require "packwerk/updating_deprecated_references"
11
-
12
- module Packwerk
13
- module Commands
14
- class UpdateDeprecationsCommand
15
- extend T::Sig
16
- include OffenseProgressMarker
17
-
18
- sig do
19
- params(
20
- files: T::Enumerable[String],
21
- configuration: Configuration,
22
- offenses_formatter: Formatters::OffensesFormatter,
23
- progress_formatter: Formatters::ProgressFormatter
24
- ).void
25
- end
26
- def initialize(files:, configuration:, offenses_formatter:, progress_formatter:)
27
- @files = files
28
- @configuration = configuration
29
- @progress_formatter = progress_formatter
30
- @offenses_formatter = offenses_formatter
31
- @updating_deprecated_references = T.let(nil, T.nilable(UpdatingDeprecatedReferences))
32
- @run_context = T.let(nil, T.nilable(RunContext))
33
- end
34
-
35
- sig { returns(Result) }
36
- def run
37
- @progress_formatter.started(@files)
38
-
39
- all_offenses = T.let([], T.untyped)
40
- execution_time = Benchmark.realtime do
41
- all_offenses = @files.flat_map do |path|
42
- run_context.process_file(file: path).tap do |offenses|
43
- mark_progress(offenses: offenses, progress_formatter: @progress_formatter)
44
- end
45
- end
46
-
47
- updating_deprecated_references.dump_deprecated_references_files
48
- end
49
-
50
- @progress_formatter.finished(execution_time)
51
- calculate_result(all_offenses)
52
- end
53
-
54
- private
55
-
56
- sig { returns(RunContext) }
57
- def run_context
58
- @run_context ||= RunContext.from_configuration(
59
- @configuration,
60
- reference_lister: updating_deprecated_references
61
- )
62
- end
63
-
64
- sig { returns(UpdatingDeprecatedReferences) }
65
- def updating_deprecated_references
66
- @updating_deprecated_references ||= UpdatingDeprecatedReferences.new(@configuration.root_path)
67
- end
68
-
69
- sig { params(all_offenses: T::Array[T.nilable(::Packwerk::Offense)]).returns(Result) }
70
- def calculate_result(all_offenses)
71
- result_status = all_offenses.empty?
72
- message = <<~EOS
73
- #{@offenses_formatter.show_offenses(all_offenses)}
74
- ✅ `deprecated_references.yml` has been updated.
75
- EOS
76
-
77
- Result.new(message: message, status: result_status)
78
- end
79
- end
80
- end
81
- end
@@ -1,14 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- require "packwerk/cache_deprecated_references"
5
-
6
- module Packwerk
7
- class DetectStaleDeprecatedReferences < CacheDeprecatedReferences
8
- extend T::Sig
9
- sig { returns(T::Boolean) }
10
- def stale_violations?
11
- @deprecated_references.values.any?(&:stale_violations?)
12
- end
13
- end
14
- end
@@ -1,23 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- require "sorbet-runtime"
5
-
6
- require "packwerk/reference"
7
- require "packwerk/violation_type"
8
-
9
- module Packwerk
10
- module ReferenceLister
11
- extend T::Sig
12
- extend T::Helpers
13
-
14
- interface!
15
-
16
- sig do
17
- params(reference: Packwerk::Reference, violation_type: ViolationType)
18
- .returns(T::Boolean)
19
- .abstract
20
- end
21
- def listed?(reference, violation_type:); end
22
- end
23
- end
@@ -1,14 +0,0 @@
1
- # typed: true
2
- # frozen_string_literal: true
3
-
4
- require "packwerk/cache_deprecated_references"
5
-
6
- module Packwerk
7
- class UpdatingDeprecatedReferences < CacheDeprecatedReferences
8
- def dump_deprecated_references_files
9
- @deprecated_references.each do |_, deprecated_references_file|
10
- deprecated_references_file.dump
11
- end
12
- end
13
- end
14
- end