Skip to content
This repository was archived by the owner on May 3, 2024. It is now read-only.

Commit f892f88

Browse files
author
Alex Evanczuk
authored
Fix bug with root package protections (#12)
* Fix bug where root package protections have false failures * bump version
1 parent 0280038 commit f892f88

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
package_protections (1.1.0)
4+
package_protections (1.1.1)
55
activesupport
66
parse_packwerk
77
rubocop
@@ -67,7 +67,7 @@ GEM
6767
parser (>= 3.0.1.1)
6868
rubocop-rspec (2.8.0)
6969
rubocop (~> 1.19)
70-
rubocop-sorbet (0.6.10)
70+
rubocop-sorbet (0.6.11)
7171
rubocop (>= 0.90.0)
7272
ruby-progressbar (1.11.0)
7373
sorbet (0.5.9588)

lib/package_protections/rubocop_protection_interface.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def get_offenses_for_existing_violations(protected_packages)
108108
T.absurd(violation_behavior)
109109
end
110110

111-
package.original_package.directory.glob('**/**/*.*').each do |relative_path_to_file|
111+
package.original_package.directory.glob(included_globs_for_pack).each do |relative_path_to_file|
112112
next unless exclude_list.include?(relative_path_to_file.to_s)
113113

114114
file = relative_path_to_file.to_s

package_protections.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = 'package_protections'
3-
spec.version = '1.1.0'
3+
spec.version = '1.1.1'
44
spec.authors = ['Gusto Engineers']
55
spec.email = ['[email protected]']
66
spec.summary = 'Package protections for Rails apps'

sorbet/rbi/manual.rbi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# typed: true
2+
3+
class Pathname
4+
sig do
5+
params(p1: T::Array[String], p2: Integer).returns(T::Array[Pathname])
6+
end
7+
def glob(p1, p2=0, &blk); end
8+
end

spec/package_protections_spec.rb

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,7 @@ def offense(
665665
expect(offenses).to contain_exactly(0).offenses
666666
end
667667

668-
# Note -- to simplify implementation, we look at *any* files in the exclude list.
669-
# There shouldn't be much of a reason to add to this list with files that the cop doesn't look at in the first place
670-
it 'fails when there are files from private implementation in the rubocop TODO list' do
668+
it 'succeeds when there are files from private implementation in the rubocop TODO list' do
671669
apples_package_yml_with_typed_api_protection_set_to_fail_on_any
672670
write_file('packs/apples/app/services/tool.rb', '')
673671
write_file('.rubocop_todo.yml', <<~YML.strip)
@@ -677,11 +675,7 @@ def offense(
677675
YML
678676

679677
offenses = PackageProtections.get_offenses(packages: get_packages, new_violations: [])
680-
expect(offenses).to contain_exactly(1).offense
681-
expect(offenses).to include_offense offense(
682-
'packs/apples',
683-
'packs/apples/app/services/tool.rb should be `typed: strict`', 'packs/apples/app/services/tool.rb', 'prevent_this_package_from_exposing_an_untyped_api'
684-
)
678+
expect(offenses).to contain_exactly(0).offense
685679
end
686680

687681
it 'fails if there is a public API file in the rubocop TODO list' do
@@ -715,6 +709,23 @@ def offense(
715709
offenses = PackageProtections.get_offenses(packages: get_packages, new_violations: [])
716710
expect(offenses).to contain_exactly(0).offenses
717711
end
712+
713+
context 'when the pack with the protection is the root pack' do
714+
it 'succeeds if there is a different pack\'s public API file in the rubocop TODO list' do
715+
write_package_yml('.', protections: { 'prevent_this_package_from_exposing_an_untyped_api' => 'fail_on_any' })
716+
717+
write_file('app/public/tool.rb', '')
718+
write_file('packs/other_pack/app/public/tool.rb', '')
719+
write_file('.rubocop_todo.yml', <<~YML.strip)
720+
PackageProtections/TypedPublicApi:
721+
Exclude:
722+
- packs/other_pack/app/public/tool.rb
723+
YML
724+
725+
offenses = PackageProtections.get_offenses(packages: get_packages, new_violations: [])
726+
expect(offenses).to contain_exactly(0).offenses
727+
end
728+
end
718729
end
719730
end
720731

0 commit comments

Comments
 (0)