package_protections 2.1.0 → 2.2.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 +4 -4
- data/lib/package_protections/private/configuration.rb +0 -2
- data/lib/package_protections/private.rb +46 -0
- data/lib/package_protections/rubocop_protection_interface.rb +2 -23
- data/lib/package_protections.rb +17 -11
- metadata +2 -17
- data/lib/rubocop/cop/package_protections.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 209662f8b4bb58c12b998627275107715b1b92f72250dd57275a830db2b3ee28
|
4
|
+
data.tar.gz: 72dfeeca3bc2e0d83af7d7274fb7574b9d50fa41df594a56673a997b7ca5c63f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f21c828d5523d288a4b4bbc297efc15ef54cbc8e34871d3338cbeccf12254b5c21e20613a22f7a950edaf27f4052b27db4ffc86d34378eb254760618895245d2
|
7
|
+
data.tar.gz: 6cf01a48f348a4d297a3153b6129bb139f78206d46daf29bc5b543a84debc309780645ddb6979e8375b8cdf8affcdd4f70af3eea02eb33d07a2445b3ec8f1ba9
|
@@ -117,6 +117,9 @@ module PackageProtections
|
|
117
117
|
@protected_packages_indexed_by_name = nil
|
118
118
|
@private_cop_config = nil
|
119
119
|
PackageProtections.config.bust_cache!
|
120
|
+
# This comes explicitly after `PackageProtections.config.bust_cache!` because
|
121
|
+
# otherwise `PackageProtections.config` will attempt to reload the client configuratoin.
|
122
|
+
@loaded_client_configuration = false
|
120
123
|
end
|
121
124
|
|
122
125
|
sig { params(identifier: Identifier).returns(T::Hash[T.untyped, T.untyped]) }
|
@@ -128,6 +131,49 @@ module PackageProtections
|
|
128
131
|
protected_packages.map { |p| [p.name, protection.custom_cop_config(p)] }.to_h
|
129
132
|
end
|
130
133
|
end
|
134
|
+
|
135
|
+
sig { returns(T::Array[T::Hash[T.untyped, T.untyped]]) }
|
136
|
+
def self.rubocop_todo_ymls
|
137
|
+
@rubocop_todo_ymls = T.let(@rubocop_todo_ymls, T.nilable(T::Array[T::Hash[T.untyped, T.untyped]]))
|
138
|
+
@rubocop_todo_ymls ||= begin
|
139
|
+
todo_files = Pathname.glob('**/.rubocop_todo.yml')
|
140
|
+
todo_files.map do |todo_file|
|
141
|
+
YAML.load_file(todo_file)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
sig { void }
|
147
|
+
def self.bust_rubocop_todo_yml_cache
|
148
|
+
@rubocop_todo_ymls = nil
|
149
|
+
end
|
150
|
+
|
151
|
+
sig { params(rule: String).returns(T::Set[String]) }
|
152
|
+
def self.exclude_for_rule(rule)
|
153
|
+
excludes = T.let(Set.new, T::Set[String])
|
154
|
+
|
155
|
+
Private.rubocop_todo_ymls.each do |todo_yml|
|
156
|
+
config = todo_yml[rule]
|
157
|
+
next if config.nil?
|
158
|
+
|
159
|
+
exclude_list = config['Exclude']
|
160
|
+
next if exclude_list.nil?
|
161
|
+
|
162
|
+
excludes += exclude_list
|
163
|
+
end
|
164
|
+
|
165
|
+
excludes
|
166
|
+
end
|
167
|
+
|
168
|
+
sig { void }
|
169
|
+
def self.load_client_configuration
|
170
|
+
@loaded_client_configuration ||= T.let(false, T.nilable(T::Boolean))
|
171
|
+
return if @loaded_client_configuration
|
172
|
+
|
173
|
+
@loaded_client_configuration = true
|
174
|
+
client_configuration = Pathname.pwd.join('config/package_protections.rb')
|
175
|
+
require client_configuration.to_s if client_configuration.exist?
|
176
|
+
end
|
131
177
|
end
|
132
178
|
|
133
179
|
private_constant :Private
|
@@ -71,20 +71,7 @@ module PackageProtections
|
|
71
71
|
|
72
72
|
sig { void }
|
73
73
|
def self.bust_rubocop_todo_yml_cache
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
sig { returns(T.untyped) }
|
78
|
-
def self.rubocop_todo_yml
|
79
|
-
@rubocop_todo_yml = T.let(@rubocop_todo_yml, T.untyped)
|
80
|
-
@rubocop_todo_yml ||= begin
|
81
|
-
todo_file = Pathname.new('.rubocop_todo.yml')
|
82
|
-
if todo_file.exist?
|
83
|
-
YAML.load_file(todo_file)
|
84
|
-
else
|
85
|
-
{}
|
86
|
-
end
|
87
|
-
end
|
74
|
+
Private.bust_rubocop_todo_yml_cache
|
88
75
|
end
|
89
76
|
|
90
77
|
sig do
|
@@ -93,7 +80,7 @@ module PackageProtections
|
|
93
80
|
).returns(T::Array[Offense])
|
94
81
|
end
|
95
82
|
def get_offenses_for_existing_violations(protected_packages)
|
96
|
-
exclude_list = exclude_for_rule(cop_name)
|
83
|
+
exclude_list = Private.exclude_for_rule(cop_name)
|
97
84
|
offenses = []
|
98
85
|
|
99
86
|
protected_packages.each do |package|
|
@@ -146,13 +133,5 @@ module PackageProtections
|
|
146
133
|
)
|
147
134
|
]
|
148
135
|
end
|
149
|
-
|
150
|
-
private
|
151
|
-
|
152
|
-
sig { params(rule: String).returns(T::Set[String]) }
|
153
|
-
def exclude_for_rule(rule)
|
154
|
-
rule_config = RubocopProtectionInterface.rubocop_todo_yml[rule] || {}
|
155
|
-
Set.new(rule_config['Exclude'] || [])
|
156
|
-
end
|
157
136
|
end
|
158
137
|
end
|
data/lib/package_protections.rb
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# typed: strict
|
4
|
-
|
5
4
|
require 'sorbet-runtime'
|
6
|
-
|
7
5
|
require 'open3'
|
8
6
|
require 'set'
|
9
7
|
require 'parse_packwerk'
|
8
|
+
require 'rubocop'
|
9
|
+
require 'rubocop-sorbet'
|
10
10
|
|
11
|
-
|
12
|
-
loader = T.unsafe(Zeitwerk::Loader).for_gem
|
13
|
-
loader.ignore("#{__dir__}/rubocop")
|
14
|
-
loader.setup
|
15
|
-
|
11
|
+
#
|
16
12
|
# Welcome to PackageProtections!
|
17
13
|
# See https://github.com/rubyatscale/package_protections#readme for more info
|
18
14
|
#
|
19
15
|
# This file is a reference for the available API to `package_protections`, but all implementation details are private
|
20
16
|
# (which is why we delegate to `Private` for the actual implementation).
|
17
|
+
#
|
21
18
|
module PackageProtections
|
22
19
|
extend T::Sig
|
23
20
|
|
@@ -30,6 +27,18 @@ module PackageProtections
|
|
30
27
|
# This is currently the only handled exception that `PackageProtections` will throw.
|
31
28
|
class IncorrectPublicApiUsageError < StandardError; end
|
32
29
|
|
30
|
+
require 'package_protections/offense'
|
31
|
+
require 'package_protections/violation_behavior'
|
32
|
+
require 'package_protections/protected_package'
|
33
|
+
require 'package_protections/per_file_violation'
|
34
|
+
require 'package_protections/protection_interface'
|
35
|
+
require 'package_protections/rubocop_protection_interface'
|
36
|
+
require 'package_protections/private'
|
37
|
+
|
38
|
+
# Implementation of rubocop-based protections
|
39
|
+
require 'rubocop/cop/package_protections/namespaced_under_package_name'
|
40
|
+
require 'rubocop/cop/package_protections/typed_public_api'
|
41
|
+
|
33
42
|
class << self
|
34
43
|
extend T::Sig
|
35
44
|
|
@@ -46,6 +55,7 @@ module PackageProtections
|
|
46
55
|
|
47
56
|
sig { returns(Private::Configuration) }
|
48
57
|
def self.config
|
58
|
+
Private.load_client_configuration
|
49
59
|
@config = T.let(@config, T.nilable(Private::Configuration))
|
50
60
|
@config ||= Private::Configuration.new
|
51
61
|
end
|
@@ -119,7 +129,3 @@ module PackageProtections
|
|
119
129
|
RubocopProtectionInterface.bust_rubocop_todo_yml_cache
|
120
130
|
end
|
121
131
|
end
|
122
|
-
|
123
|
-
if defined?(Rubocop)
|
124
|
-
require 'rubocop/cop/package_protections'
|
125
|
-
end
|
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: 2.
|
4
|
+
version: 2.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-09-
|
11
|
+
date: 2022-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: zeitwerk
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: rake
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,7 +191,6 @@ files:
|
|
205
191
|
- lib/package_protections/rspec/support.rb
|
206
192
|
- lib/package_protections/rubocop_protection_interface.rb
|
207
193
|
- lib/package_protections/violation_behavior.rb
|
208
|
-
- lib/rubocop/cop/package_protections.rb
|
209
194
|
- lib/rubocop/cop/package_protections/namespaced_under_package_name.rb
|
210
195
|
- lib/rubocop/cop/package_protections/namespaced_under_package_name/desired_zeitwerk_api.rb
|
211
196
|
- lib/rubocop/cop/package_protections/typed_public_api.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'rubocop'
|
2
|
-
require 'rubocop-sorbet'
|
3
|
-
|
4
|
-
module RuboCop
|
5
|
-
module Cop
|
6
|
-
module PackageProtections
|
7
|
-
autoload :NamespacedUnderPackageName, 'rubocop/cop/package_protections/namespaced_under_package_name'
|
8
|
-
autoload :TypedPublicApi, 'rubocop/cop/package_protections/typed_public_api'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# Implementation of rubocop-based protections
|