packwerk-extensions 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1317a98d7569bfe1b33cc9a816e768ddbe0dd8a6ab33f3e746f15870a533704
4
- data.tar.gz: ee91aae5d17e4ac4408440da88fe92982a8c114e11d9d7026087f13afaff5ebf
3
+ metadata.gz: 03a304b3c407316bea35a2939967a2cdcbdd30a2459652b96992acd40e49be5a
4
+ data.tar.gz: 5703efe5318e73495845b5d6f5d7f8bf042e0066cf9b2122697fff6dd9cbfc34
5
5
  SHA512:
6
- metadata.gz: ba36bca58d779e3c10960b4193bb14abd7d2d57c3866d0097094cffd508391bf72264466ca1095a7e16aac410b954c4ce53cc677b824b528866a9d8bf6822c85
7
- data.tar.gz: 7d7b3a5f57229dc7578ea31e98b04ea73036fe39087235181185792fb2f2b7213e8659c9c3d3b70e6a2d38f0ca7ba6e2dd6fc7af3c15d22e75a9220ea072dc19
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
- return false if enforcement_disabled?(privacy_option)
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')
@@ -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)
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.3
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-16 00:00:00.000000000 Z
11
+ date: 2022-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: packwerk