packwerk-extensions 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/packwerk/privacy/checker.rb +1 -18
- data/lib/packwerk/privacy/validator.rb +1 -70
- data/lib/packwerk/visibility/checker.rb +0 -12
- data/lib/packwerk/visibility/validator.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03a304b3c407316bea35a2939967a2cdcbdd30a2459652b96992acd40e49be5a
|
4
|
+
data.tar.gz: 5703efe5318e73495845b5d6f5d7f8bf042e0066cf9b2122697fff6dd9cbfc34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a680df43f37a36afc61a43ef2bc4e91fd5f8d3763aded52dc51cd3acb712d799079447ed5d0d6a9ac366b4d71edd51c13cc284962e320e1c69206533c7f56ed
|
7
|
+
data.tar.gz: 6bcc586c29c90097340cd1bc3322a7e16f9b2b6b2ba8176284da216175333a97b98d80f6572ace6209cb3a333974dd81bd6bbed7928162a839b5f2c9a4a44220
|
@@ -27,12 +27,7 @@ module Packwerk
|
|
27
27
|
return false if privacy_package.public_path?(reference.constant.location)
|
28
28
|
|
29
29
|
privacy_option = privacy_package.enforce_privacy
|
30
|
-
|
31
|
-
|
32
|
-
return false unless privacy_option == true || privacy_option == 'strict' ||
|
33
|
-
explicitly_private_constant?(reference.constant, explicitly_private_constants: T.unsafe(privacy_option))
|
34
|
-
|
35
|
-
true
|
30
|
+
!enforcement_disabled?(privacy_option)
|
36
31
|
end
|
37
32
|
|
38
33
|
sig do
|
@@ -65,18 +60,6 @@ module Packwerk
|
|
65
60
|
|
66
61
|
private
|
67
62
|
|
68
|
-
sig do
|
69
|
-
params(
|
70
|
-
constant: ConstantContext,
|
71
|
-
explicitly_private_constants: T::Array[String]
|
72
|
-
).returns(T::Boolean)
|
73
|
-
end
|
74
|
-
def explicitly_private_constant?(constant, explicitly_private_constants:)
|
75
|
-
explicitly_private_constants.include?(constant.name) ||
|
76
|
-
# nested constants
|
77
|
-
explicitly_private_constants.any? { |epc| constant.name.start_with?("#{epc}::") }
|
78
|
-
end
|
79
|
-
|
80
63
|
sig do
|
81
64
|
params(privacy_option: T.nilable(T.any(T::Boolean, String, T::Array[String])))
|
82
65
|
.returns(T::Boolean)
|
@@ -13,30 +13,10 @@ module Packwerk
|
|
13
13
|
def call(package_set, configuration)
|
14
14
|
privacy_settings = package_manifests_settings_for(configuration, 'enforce_privacy')
|
15
15
|
|
16
|
-
resolver = ConstantResolver.new(
|
17
|
-
root_path: configuration.root_path,
|
18
|
-
load_paths: configuration.load_paths
|
19
|
-
)
|
20
|
-
|
21
16
|
results = T.let([], T::Array[Result])
|
22
17
|
|
23
18
|
privacy_settings.each do |config_file_path, setting|
|
24
19
|
results << check_enforce_privacy_setting(config_file_path, setting)
|
25
|
-
next unless setting.is_a?(Array)
|
26
|
-
|
27
|
-
constants = setting
|
28
|
-
|
29
|
-
results += assert_constants_can_be_loaded(constants, config_file_path)
|
30
|
-
|
31
|
-
constant_locations = constants.map { |c| [c, resolver.resolve(c)&.location] }
|
32
|
-
|
33
|
-
constant_locations.each do |name, location|
|
34
|
-
results << if location
|
35
|
-
check_private_constant_location(configuration, package_set, name, location, config_file_path)
|
36
|
-
else
|
37
|
-
private_constant_unresolvable(name, config_file_path)
|
38
|
-
end
|
39
|
-
end
|
40
20
|
end
|
41
21
|
|
42
22
|
public_path_settings = package_manifests_settings_for(configuration, 'public_path')
|
@@ -72,7 +52,7 @@ module Packwerk
|
|
72
52
|
params(config_file_path: String, setting: T.untyped).returns(Result)
|
73
53
|
end
|
74
54
|
def check_enforce_privacy_setting(config_file_path, setting)
|
75
|
-
if [TrueClass, FalseClass, Array, NilClass].include?(setting.class)
|
55
|
+
if [TrueClass, FalseClass, Array, NilClass].include?(setting.class) || setting == 'strict'
|
76
56
|
Result.new(ok: true)
|
77
57
|
else
|
78
58
|
Result.new(
|
@@ -81,55 +61,6 @@ module Packwerk
|
|
81
61
|
)
|
82
62
|
end
|
83
63
|
end
|
84
|
-
|
85
|
-
sig do
|
86
|
-
params(configuration: Configuration, package_set: PackageSet, name: T.untyped, location: T.untyped,
|
87
|
-
config_file_path: T.untyped).returns(Result)
|
88
|
-
end
|
89
|
-
def check_private_constant_location(configuration, package_set, name, location, config_file_path)
|
90
|
-
declared_package = package_set.package_from_path(relative_path(configuration, config_file_path))
|
91
|
-
constant_package = package_set.package_from_path(location)
|
92
|
-
|
93
|
-
if constant_package == declared_package
|
94
|
-
Result.new(ok: true)
|
95
|
-
else
|
96
|
-
Result.new(
|
97
|
-
ok: false,
|
98
|
-
error_value: "'#{name}' is declared as private in the '#{declared_package}' package but appears to be " \
|
99
|
-
"defined\nin the '#{constant_package}' package. Packwerk resolved it to #{location}."
|
100
|
-
)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
sig { params(constants: T.untyped, config_file_path: String).returns(T::Array[Result]) }
|
105
|
-
def assert_constants_can_be_loaded(constants, config_file_path)
|
106
|
-
constants.map do |constant|
|
107
|
-
if constant.start_with?('::')
|
108
|
-
constant.try(&:constantize) && Result.new(ok: true)
|
109
|
-
else
|
110
|
-
error_value = "'#{constant}', listed in the 'enforce_privacy' option " \
|
111
|
-
"in #{config_file_path}, is invalid.\nPrivate constants need to be " \
|
112
|
-
'prefixed with the top-level namespace operator `::`.'
|
113
|
-
Result.new(
|
114
|
-
ok: false,
|
115
|
-
error_value: error_value
|
116
|
-
)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
sig { params(name: T.untyped, config_file_path: T.untyped).returns(Result) }
|
122
|
-
def private_constant_unresolvable(name, config_file_path)
|
123
|
-
explicit_filepath = "#{(name.start_with?('::') ? name[2..] : name).underscore}.rb"
|
124
|
-
|
125
|
-
Result.new(
|
126
|
-
ok: false,
|
127
|
-
error_value: "'#{name}', listed in #{config_file_path}, could not be resolved.\n" \
|
128
|
-
"This is probably because it is an autovivified namespace - a namespace module that doesn't have a\n" \
|
129
|
-
"file explicitly defining it. Packwerk currently doesn't support declaring autovivified namespaces as\n" \
|
130
|
-
"private. Add a #{explicit_filepath} file to explicitly define the constant."
|
131
|
-
)
|
132
|
-
end
|
133
64
|
end
|
134
65
|
end
|
135
66
|
end
|
@@ -59,18 +59,6 @@ module Packwerk
|
|
59
59
|
|
60
60
|
private
|
61
61
|
|
62
|
-
sig do
|
63
|
-
params(
|
64
|
-
constant: ConstantContext,
|
65
|
-
explicitly_private_constants: T::Array[String]
|
66
|
-
).returns(T::Boolean)
|
67
|
-
end
|
68
|
-
def explicitly_private_constant?(constant, explicitly_private_constants:)
|
69
|
-
explicitly_private_constants.include?(constant.name) ||
|
70
|
-
# nested constants
|
71
|
-
explicitly_private_constants.any? { |epc| constant.name.start_with?("#{epc}::") }
|
72
|
-
end
|
73
|
-
|
74
62
|
sig do
|
75
63
|
params(visibility_option: T.nilable(T.any(T::Boolean, String)))
|
76
64
|
.returns(T::Boolean)
|
@@ -19,7 +19,7 @@ module Packwerk
|
|
19
19
|
package_manifests_settings_for(configuration, 'enforce_visibility').each do |config, setting|
|
20
20
|
next if setting.nil?
|
21
21
|
|
22
|
-
next if [TrueClass, FalseClass
|
22
|
+
next if [TrueClass, FalseClass].include?(setting.class) || setting == 'strict'
|
23
23
|
|
24
24
|
results << Result.new(
|
25
25
|
ok: false,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: packwerk-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gusto Engineers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: packwerk
|