package_protections 2.0.0 → 2.1.1

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: 2e7bd9febdd0619b714c112033b8bf61958e04368e8fb0c0e5f3498de54e988c
4
- data.tar.gz: a0f7c5f79f3eb1279d084045c115345424dd2acfa22954eed321d2cf220bd40b
3
+ metadata.gz: f503d714980699ad618258d74bb41489328aedce9e8201bfc7e1a5a086e0bdf9
4
+ data.tar.gz: d3cc2f5d197322d29dff1b794f889bc74b2a79e431e8bf7b70ec1d4e81cfabd4
5
5
  SHA512:
6
- metadata.gz: b8ff41de5e829270999baa91dc8df0fb3e810c6e8be39358cdbc6fd188a9d79ddf138f19b935a13360106c2a5e6c8300edffdf5fedf71e39c52826d2a6050a9e
7
- data.tar.gz: f255780ea5ed693e66edcd028b4b8247419c612afddd1790f53078ecec3ca274e456c6ed16e62a0d83158c853f2be25282250c5b40b93b069da504469d25acf8
6
+ metadata.gz: 6198bc334e103a52eeac5110fab05a21a72b6ed22f33b7ef455b23cb6cbb93fea9ed0b9f2a9ff122ad80ddc587d21fdbb7b7398ed6aef94ad9ad5470666932da
7
+ data.tar.gz: c1fd8d5e56cd37b29304dd467effef8a8cb062ed059ffa434cfff6a4c1300a191612042457139b8715737b7b2a732b44b2d2a0b1c961e934773ae9e4da093544
@@ -35,6 +35,8 @@ module PackageProtections
35
35
 
36
36
  sig { returns(T::Array[ProtectionInterface]) }
37
37
  def default_protections
38
+ require 'rubocop/cop/package_protections'
39
+
38
40
  [
39
41
  Private::OutgoingDependencyProtection.new,
40
42
  Private::IncomingPrivacyProtection.new,
@@ -128,6 +128,39 @@ module PackageProtections
128
128
  protected_packages.map { |p| [p.name, protection.custom_cop_config(p)] }.to_h
129
129
  end
130
130
  end
131
+
132
+ sig { returns(T::Array[T::Hash[T.untyped, T.untyped]]) }
133
+ def self.rubocop_todo_ymls
134
+ @rubocop_todo_ymls = T.let(@rubocop_todo_ymls, T.nilable(T::Array[T::Hash[T.untyped, T.untyped]]))
135
+ @rubocop_todo_ymls ||= begin
136
+ todo_files = Pathname.glob('**/.rubocop_todo.yml')
137
+ todo_files.map do |todo_file|
138
+ YAML.load_file(todo_file)
139
+ end
140
+ end
141
+ end
142
+
143
+ sig { void }
144
+ def self.bust_rubocop_todo_yml_cache
145
+ @rubocop_todo_ymls = nil
146
+ end
147
+
148
+ sig { params(rule: String).returns(T::Set[String]) }
149
+ def self.exclude_for_rule(rule)
150
+ excludes = T.let(Set.new, T::Set[String])
151
+
152
+ Private.rubocop_todo_ymls.each do |todo_yml|
153
+ config = todo_yml[rule]
154
+ next if config.nil?
155
+
156
+ exclude_list = config['Exclude']
157
+ next if exclude_list.nil?
158
+
159
+ excludes += exclude_list
160
+ end
161
+
162
+ excludes
163
+ end
131
164
  end
132
165
 
133
166
  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
- @rubocop_todo_yml = nil
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
@@ -1,20 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # typed: strict
4
+
4
5
  require 'sorbet-runtime'
6
+
5
7
  require 'open3'
6
8
  require 'set'
7
9
  require 'parse_packwerk'
8
- require 'rubocop'
9
- require 'rubocop-sorbet'
10
10
 
11
- #
11
+ require 'zeitwerk'
12
+ loader = T.unsafe(Zeitwerk::Loader).for_gem
13
+ loader.ignore("#{__dir__}/rubocop")
14
+ loader.setup
15
+
12
16
  # Welcome to PackageProtections!
13
17
  # See https://github.com/rubyatscale/package_protections#readme for more info
14
18
  #
15
19
  # This file is a reference for the available API to `package_protections`, but all implementation details are private
16
20
  # (which is why we delegate to `Private` for the actual implementation).
17
- #
18
21
  module PackageProtections
19
22
  extend T::Sig
20
23
 
@@ -27,18 +30,6 @@ module PackageProtections
27
30
  # This is currently the only handled exception that `PackageProtections` will throw.
28
31
  class IncorrectPublicApiUsageError < StandardError; end
29
32
 
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
-
42
33
  class << self
43
34
  extend T::Sig
44
35
 
@@ -128,3 +119,7 @@ module PackageProtections
128
119
  RubocopProtectionInterface.bust_rubocop_todo_yml_cache
129
120
  end
130
121
  end
122
+
123
+ if defined?(Rubocop)
124
+ require 'rubocop/cop/package_protections'
125
+ end
@@ -0,0 +1,13 @@
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
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.0.0
4
+ version: 2.1.1
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-12 00:00:00.000000000 Z
11
+ date: 2022-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,6 +80,20 @@ 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'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rake
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -191,6 +205,7 @@ files:
191
205
  - lib/package_protections/rspec/support.rb
192
206
  - lib/package_protections/rubocop_protection_interface.rb
193
207
  - lib/package_protections/violation_behavior.rb
208
+ - lib/rubocop/cop/package_protections.rb
194
209
  - lib/rubocop/cop/package_protections/namespaced_under_package_name.rb
195
210
  - lib/rubocop/cop/package_protections/namespaced_under_package_name/desired_zeitwerk_api.rb
196
211
  - lib/rubocop/cop/package_protections/typed_public_api.rb