package_protections 3.0.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/rubocop/cop/package_protections/namespaced_under_package_name.rb +12 -46
- 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: aabad25e536a226f791248e858e8db7fc67410b2d623879326165630bfd0922d
|
4
|
+
data.tar.gz: 64b1d4b5ab05315e9c5ecefdd3105af7485a6f2ed0ba59b9ae456c306b824d72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58aea344a1b283458d878b224c02fd339e27ca541f2ee025a65970ca94fc717ad5b95137e577760cb512fabf4c5657ccb15f8bc57f78330960294a47c2ad1898
|
7
|
+
data.tar.gz: 2700f4963e5fe0c5b987aede413458a7181ee8e471b9689bf0dcd0659bd535e99ffee83487ae88c1acfbcc245e8f62da91c070a77bcbea060a4a59bc00b21e19
|
data/README.md
CHANGED
@@ -56,7 +56,7 @@ This protection only looks at files in `packs/your_pack/app` (it ignores spec fi
|
|
56
56
|
This protection is implemented via Rubocop -- expect to see results for this when running `rubocop` however you normally do. To add to the TODO list, add to `.rubocop_todo.yml`
|
57
57
|
Lastly – this protection can be configured by setting `globally_permitted_namespaces`, e.g.:
|
58
58
|
```ruby
|
59
|
-
|
59
|
+
RuboCop::Packs.configure do |config|
|
60
60
|
config.globally_permitted_namespaces = ['SomeGlobalNamespace']
|
61
61
|
end
|
62
62
|
```
|
@@ -10,36 +10,6 @@ module RuboCop
|
|
10
10
|
extend T::Sig
|
11
11
|
include ::PackageProtections::RubocopProtectionInterface
|
12
12
|
|
13
|
-
# We override `cop_configs` for this protection.
|
14
|
-
# The default behavior disables cops when a package has turned off a protection.
|
15
|
-
# However: namespace violations can occur even when one package has TURNED OFF their namespace protection
|
16
|
-
# but another package has it turned on. Therefore, all packages must always be opted in no matter what.
|
17
|
-
#
|
18
|
-
sig do
|
19
|
-
params(packages: T::Array[::PackageProtections::ProtectedPackage])
|
20
|
-
.returns(T::Array[::PackageProtections::RubocopProtectionInterface::CopConfig])
|
21
|
-
end
|
22
|
-
def cop_configs(packages)
|
23
|
-
include_packs = T.let([], T::Array[String])
|
24
|
-
packages.each do |p|
|
25
|
-
enabled_for_pack = !p.violation_behavior_for(NamespacedUnderPackageName::IDENTIFIER).fail_never?
|
26
|
-
if enabled_for_pack
|
27
|
-
include_packs << p.name
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
[
|
32
|
-
::PackageProtections::RubocopProtectionInterface::CopConfig.new(
|
33
|
-
name: cop_name,
|
34
|
-
enabled: include_packs.any?,
|
35
|
-
metadata: {
|
36
|
-
'IncludePacks' => include_packs,
|
37
|
-
'GloballyPermittedNamespaces' => ::PackageProtections.config.globally_permitted_namespaces
|
38
|
-
}
|
39
|
-
)
|
40
|
-
]
|
41
|
-
end
|
42
|
-
|
43
13
|
sig { override.returns(T::Array[String]) }
|
44
14
|
def included_globs_for_pack
|
45
15
|
[
|
@@ -57,23 +27,19 @@ module RuboCop
|
|
57
27
|
|
58
28
|
sig { override.params(behavior: ::PackageProtections::ViolationBehavior, package: ParsePackwerk::Package).returns(T.nilable(String)) }
|
59
29
|
def unmet_preconditions_for_behavior(behavior, package)
|
60
|
-
if
|
61
|
-
|
62
|
-
else
|
63
|
-
# We don't need to validate if the behavior is currentely fail_never
|
64
|
-
return if behavior.fail_never?
|
30
|
+
# We don't need to validate if the behavior is currentely fail_never
|
31
|
+
return if behavior.fail_never?
|
65
32
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
33
|
+
# The reason for this is precondition is the `MultipleNamespacesProtection` assumes this to work properly.
|
34
|
+
# To remove this precondition, we need to modify `MultipleNamespacesProtection` to be more generalized!
|
35
|
+
is_root_package = package.name == ParsePackwerk::ROOT_PACKAGE_NAME
|
36
|
+
in_allowed_directory = ::PackageProtections::EXPECTED_PACK_DIRECTORIES.any? do |expected_package_directory|
|
37
|
+
package.directory.to_s.start_with?(expected_package_directory)
|
38
|
+
end
|
39
|
+
if in_allowed_directory || is_root_package
|
40
|
+
nil
|
41
|
+
else
|
42
|
+
"Package #{package.name} must be located in one of #{::PackageProtections::EXPECTED_PACK_DIRECTORIES.join(', ')} (or be the root) to use this protection"
|
77
43
|
end
|
78
44
|
end
|
79
45
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: package_protections
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
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-
|
11
|
+
date: 2022-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|