packwerk 2.1.0 → 2.1.1
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 +20 -17
- data/lib/packwerk/application_validator.rb +78 -39
- data/lib/packwerk/cache.rb +2 -1
- data/lib/packwerk/cli.rb +22 -13
- data/lib/packwerk/constant_discovery.rb +17 -1
- data/lib/packwerk/constant_name_inspector.rb +1 -1
- data/lib/packwerk/file_processor.rb +20 -15
- data/lib/packwerk/files_for_processing.rb +49 -22
- data/lib/packwerk/node_processor.rb +5 -5
- data/lib/packwerk/node_processor_factory.rb +3 -3
- data/lib/packwerk/offense.rb +10 -2
- data/lib/packwerk/package_set.rb +2 -2
- data/lib/packwerk/parse_run.rb +37 -17
- data/lib/packwerk/parsers/erb.rb +2 -0
- data/lib/packwerk/parsers/factory.rb +2 -0
- data/lib/packwerk/parsers/parser_interface.rb +17 -0
- data/lib/packwerk/parsers/ruby.rb +2 -0
- data/lib/packwerk/parsers.rb +1 -0
- data/lib/packwerk/reference_checking/checkers/checker.rb +1 -1
- data/lib/packwerk/reference_checking/reference_checker.rb +2 -1
- data/lib/packwerk/reference_extractor.rb +20 -9
- data/lib/packwerk/reference_offense.rb +8 -3
- data/lib/packwerk/result.rb +2 -2
- data/lib/packwerk/run_context.rb +47 -41
- data/lib/packwerk/spring_command.rb +1 -1
- data/lib/packwerk/version.rb +1 -1
- data/sorbet/config +1 -0
- data/sorbet/rbi/gems/tapioca@0.4.19.rbi +1 -1
- data/sorbet/tapioca/require.rb +1 -1
- metadata +3 -2
data/lib/packwerk/run_context.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require "constant_resolver"
|
@@ -8,21 +8,17 @@ module Packwerk
|
|
8
8
|
class RunContext
|
9
9
|
extend T::Sig
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
:inflector,
|
16
|
-
:custom_associations,
|
17
|
-
:checker_classes,
|
18
|
-
)
|
19
|
-
|
20
|
-
DEFAULT_CHECKERS = [
|
21
|
-
::Packwerk::ReferenceChecking::Checkers::DependencyChecker,
|
22
|
-
::Packwerk::ReferenceChecking::Checkers::PrivacyChecker,
|
23
|
-
]
|
11
|
+
DEFAULT_CHECKERS = T.let([
|
12
|
+
::Packwerk::ReferenceChecking::Checkers::DependencyChecker.new,
|
13
|
+
::Packwerk::ReferenceChecking::Checkers::PrivacyChecker.new,
|
14
|
+
], T::Array[ReferenceChecking::Checkers::Checker])
|
24
15
|
|
25
16
|
class << self
|
17
|
+
extend T::Sig
|
18
|
+
|
19
|
+
sig do
|
20
|
+
params(configuration: Configuration).returns(RunContext)
|
21
|
+
end
|
26
22
|
def from_configuration(configuration)
|
27
23
|
inflector = ActiveSupport::Inflector
|
28
24
|
|
@@ -39,36 +35,56 @@ module Packwerk
|
|
39
35
|
end
|
40
36
|
end
|
41
37
|
|
38
|
+
sig do
|
39
|
+
params(
|
40
|
+
root_path: String,
|
41
|
+
load_paths: T::Array[String],
|
42
|
+
inflector: T.class_of(ActiveSupport::Inflector),
|
43
|
+
cache_directory: Pathname,
|
44
|
+
config_path: T.nilable(String),
|
45
|
+
package_paths: T.nilable(T.any(T::Array[String], String)),
|
46
|
+
custom_associations: AssociationInspector::CustomAssociations,
|
47
|
+
checkers: T::Array[ReferenceChecking::Checkers::Checker],
|
48
|
+
cache_enabled: T::Boolean,
|
49
|
+
).void
|
50
|
+
end
|
42
51
|
def initialize(
|
43
52
|
root_path:,
|
44
53
|
load_paths:,
|
54
|
+
inflector:,
|
55
|
+
cache_directory:,
|
56
|
+
config_path: nil,
|
45
57
|
package_paths: nil,
|
46
|
-
inflector: nil,
|
47
58
|
custom_associations: [],
|
48
|
-
|
49
|
-
cache_enabled: false
|
50
|
-
cache_directory: nil,
|
51
|
-
config_path: nil
|
59
|
+
checkers: DEFAULT_CHECKERS,
|
60
|
+
cache_enabled: false
|
52
61
|
)
|
53
62
|
@root_path = root_path
|
54
63
|
@load_paths = load_paths
|
55
64
|
@package_paths = package_paths
|
56
65
|
@inflector = inflector
|
57
66
|
@custom_associations = custom_associations
|
58
|
-
@
|
67
|
+
@checkers = checkers
|
59
68
|
@cache_enabled = cache_enabled
|
60
69
|
@cache_directory = cache_directory
|
61
70
|
@config_path = config_path
|
71
|
+
|
72
|
+
@file_processor = T.let(nil, T.nilable(FileProcessor))
|
73
|
+
@context_provider = T.let(nil, T.nilable(ConstantDiscovery))
|
74
|
+
# We need to initialize this before we fork the process, see https://github.com/Shopify/packwerk/issues/182
|
75
|
+
@cache = T.let(
|
76
|
+
Cache.new(enable_cache: @cache_enabled, cache_directory: @cache_directory, config_path: @config_path), Cache
|
77
|
+
)
|
62
78
|
end
|
63
79
|
|
64
|
-
sig { params(
|
65
|
-
def process_file(
|
66
|
-
unresolved_references_and_offenses = file_processor.call(
|
80
|
+
sig { params(absolute_file: String).returns(T::Array[Packwerk::Offense]) }
|
81
|
+
def process_file(absolute_file:)
|
82
|
+
unresolved_references_and_offenses = file_processor.call(absolute_file)
|
67
83
|
references_and_offenses = ReferenceExtractor.get_fully_qualified_references_and_offenses_from(
|
68
84
|
unresolved_references_and_offenses,
|
69
85
|
context_provider
|
70
86
|
)
|
71
|
-
reference_checker = ReferenceChecking::ReferenceChecker.new(checkers)
|
87
|
+
reference_checker = ReferenceChecking::ReferenceChecker.new(@checkers)
|
72
88
|
references_and_offenses.flat_map { |reference| reference_checker.call(reference) }
|
73
89
|
end
|
74
90
|
|
@@ -76,14 +92,14 @@ module Packwerk
|
|
76
92
|
|
77
93
|
sig { returns(FileProcessor) }
|
78
94
|
def file_processor
|
79
|
-
@file_processor ||= FileProcessor.new(node_processor_factory: node_processor_factory, cache: cache)
|
95
|
+
@file_processor ||= FileProcessor.new(node_processor_factory: node_processor_factory, cache: @cache)
|
80
96
|
end
|
81
97
|
|
82
98
|
sig { returns(NodeProcessorFactory) }
|
83
99
|
def node_processor_factory
|
84
100
|
NodeProcessorFactory.new(
|
85
101
|
context_provider: context_provider,
|
86
|
-
root_path: root_path,
|
102
|
+
root_path: @root_path,
|
87
103
|
constant_name_inspectors: constant_name_inspectors
|
88
104
|
)
|
89
105
|
end
|
@@ -99,32 +115,22 @@ module Packwerk
|
|
99
115
|
sig { returns(ConstantResolver) }
|
100
116
|
def resolver
|
101
117
|
ConstantResolver.new(
|
102
|
-
root_path: root_path,
|
103
|
-
load_paths: load_paths,
|
104
|
-
inflector: inflector,
|
118
|
+
root_path: @root_path,
|
119
|
+
load_paths: @load_paths,
|
120
|
+
inflector: @inflector,
|
105
121
|
)
|
106
122
|
end
|
107
123
|
|
108
|
-
sig { returns(Cache) }
|
109
|
-
def cache
|
110
|
-
@cache ||= Cache.new(enable_cache: @cache_enabled, cache_directory: @cache_directory, config_path: @config_path)
|
111
|
-
end
|
112
|
-
|
113
124
|
sig { returns(PackageSet) }
|
114
125
|
def package_set
|
115
|
-
::Packwerk::PackageSet.load_all_from(root_path, package_pathspec: package_paths)
|
116
|
-
end
|
117
|
-
|
118
|
-
sig { returns(T::Array[ReferenceChecking::Checkers::Checker]) }
|
119
|
-
def checkers
|
120
|
-
checker_classes.map(&:new)
|
126
|
+
::Packwerk::PackageSet.load_all_from(@root_path, package_pathspec: @package_paths)
|
121
127
|
end
|
122
128
|
|
123
129
|
sig { returns(T::Array[ConstantNameInspector]) }
|
124
130
|
def constant_name_inspectors
|
125
131
|
[
|
126
132
|
::Packwerk::ConstNodeInspector.new,
|
127
|
-
::Packwerk::AssociationInspector.new(inflector: inflector, custom_associations: custom_associations),
|
133
|
+
::Packwerk::AssociationInspector.new(inflector: @inflector, custom_associations: @custom_associations),
|
128
134
|
]
|
129
135
|
end
|
130
136
|
end
|
data/lib/packwerk/version.rb
CHANGED
data/sorbet/config
CHANGED
@@ -562,7 +562,7 @@ module Tapioca::GenericTypeRegistry
|
|
562
562
|
def name_of(constant); end
|
563
563
|
sig { params(object: BasicObject).returns(Integer) }
|
564
564
|
def object_id_of(object); end
|
565
|
-
sig { params(constant: T.untyped, type_variable_type: T.
|
565
|
+
sig { params(constant: T.untyped, type_variable_type: T.deprecated_enum([:type_member, :type_template]), type_variable: T::Types::TypeVariable, fixed: T.untyped, lower: T.untyped, upper: T.untyped).void }
|
566
566
|
def register_type_variable(constant, type_variable_type, type_variable, fixed, lower, upper); end
|
567
567
|
sig { params(type_variable_type: Symbol, variance: Symbol, fixed: T.untyped, lower: T.untyped, upper: T.untyped).returns(String) }
|
568
568
|
def serialize_type_variable(type_variable_type, variance, fixed, lower, upper); end
|
data/sorbet/tapioca/require.rb
CHANGED
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: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -269,6 +269,7 @@ files:
|
|
269
269
|
- lib/packwerk/parsers.rb
|
270
270
|
- lib/packwerk/parsers/erb.rb
|
271
271
|
- lib/packwerk/parsers/factory.rb
|
272
|
+
- lib/packwerk/parsers/parser_interface.rb
|
272
273
|
- lib/packwerk/parsers/ruby.rb
|
273
274
|
- lib/packwerk/reference.rb
|
274
275
|
- lib/packwerk/reference_checking/checkers/checker.rb
|