package_protections 1.3.0 → 1.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0906fd78fb0cee92c4e34663c700eda94ba7e050636cda905a8fe184e115efb1'
4
- data.tar.gz: c28f5248b823d626875dc5f7ac5ee33b7a533fbb000d0f6f67e439b7aec102cd
3
+ metadata.gz: 7b99c93d81087956b947c89fbede35844a2c973f20e2bee3c8f474383ff99a88
4
+ data.tar.gz: 64ad87cf10597e5fceeefa315dd3e665f7a684ac36db30c206012c15c2a0f3f2
5
5
  SHA512:
6
- metadata.gz: '00937a5119e9589c7ea323c76df2c7ed5feb3334356a99b7cb0308f469ba7af53e1cea358a74736aaf49238e5885741ffdfd54b52fc15316023cacf170bd16d4'
7
- data.tar.gz: '0972c6fab2b22557de1d9e64efe882747c8088d2653869b6fad65f2a7144e012b61c3b15634c450ea375eb646cfe80f3d1bfbfd722342130a912e896eae1f6f4'
6
+ metadata.gz: 9a5a70b90e8ecf6a00e8b22db867e6cec3a83ba34a8fa6f18b45449c96f3eb9fd248c80f9a047d9462e2976d233c8f6b29957837feef224a94d8ce93e008a55d
7
+ data.tar.gz: 500e49a77a3ee17aa2c4cb05edf2806e37010b5168ebb9cf1a13e1addbb5db5eb11c0caaa82f4a10451dbf96d304c7e010400b19ba7240b920b29a4c93780a90
@@ -88,27 +88,6 @@ module PackageProtections
88
88
  end
89
89
  end
90
90
 
91
- sig do
92
- params(
93
- package_names: T::Array[String],
94
- all_packages: T::Array[ParsePackwerk::Package]
95
- ).returns(T::Array[ParsePackwerk::Package])
96
- end
97
- def self.packages_for_names(package_names, all_packages)
98
- all_packages_indexed_by_name = {}
99
- all_packages.each { |package| all_packages_indexed_by_name[package.name] = package }
100
-
101
- package_names.map do |package_name|
102
- clean_pack_name = package_name.gsub(%r{/$}, '')
103
- package = all_packages_indexed_by_name[clean_pack_name]
104
- if package.nil?
105
- raise "Sorry, we couldn't find a package with name #{package_name}. Here are all of the package names we know about: #{all_packages.map(&:name).sort.inspect}"
106
- end
107
-
108
- package
109
- end
110
- end
111
-
112
91
  sig { params(root_pathname: Pathname).returns(String) }
113
92
  def self.rubocop_yml(root_pathname:)
114
93
  protected_packages = Dir.chdir(root_pathname) { all_protected_packages }
@@ -116,16 +116,6 @@ module PackageProtections
116
116
  Private.private_cop_config(identifier)
117
117
  end
118
118
 
119
- sig do
120
- params(
121
- package_names: T::Array[String],
122
- all_packages: T::Array[ParsePackwerk::Package]
123
- ).returns(T::Array[ParsePackwerk::Package])
124
- end
125
- def self.packages_for_names(package_names, all_packages)
126
- Private.packages_for_names(package_names, all_packages)
127
- end
128
-
129
119
  sig { void }
130
120
  def self.bust_cache!
131
121
  Private.bust_cache!
@@ -20,9 +20,7 @@ module RuboCop
20
20
  # This cop only works for files in `app`
21
21
  return if !relative_filename.include?('app/')
22
22
 
23
- match = relative_filename.match(%r{((#{::PackageProtections::EXPECTED_PACK_DIRECTORIES.join("|")})/.*?)/})
24
- package_name = match && match[1]
25
-
23
+ package_name = ParsePackwerk.package_from_path(relative_filename)&.name
26
24
  return if package_name.nil?
27
25
 
28
26
  return if relative_filepath.extname != '.rb'
@@ -105,7 +103,11 @@ module RuboCop
105
103
 
106
104
  # The reason for this is precondition is the `MultipleNamespacesProtection` assumes this to work properly.
107
105
  # To remove this precondition, we need to modify `MultipleNamespacesProtection` to be more generalized!
108
- if ::PackageProtections::EXPECTED_PACK_DIRECTORIES.include?(Pathname.new(package.name).dirname.to_s) || package.name == ParsePackwerk::ROOT_PACKAGE_NAME
106
+ is_root_package = package.name == ParsePackwerk::ROOT_PACKAGE_NAME
107
+ in_allowed_directory = ::PackageProtections::EXPECTED_PACK_DIRECTORIES.any? do |expected_package_directory|
108
+ package.directory.to_s.start_with?(expected_package_directory)
109
+ end
110
+ if in_allowed_directory || is_root_package
109
111
  nil
110
112
  else
111
113
  "Package #{package.name} must be located in one of #{::PackageProtections::EXPECTED_PACK_DIRECTORIES.join(', ')} (or be the root) to use this protection"
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: 1.3.0
4
+ version: 1.4.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-07-01 00:00:00.000000000 Z
11
+ date: 2022-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport