Skip to content

Commit 20bd867

Browse files
committed
Add empty? and any?
1 parent 130aed4 commit 20bd867

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lib/query_packwerk/packages.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ def initialize(original_collection)
5656
@original_collection = original_collection
5757
end
5858

59+
sig { returns(T::Boolean) }
60+
def empty?
61+
@original_collection.empty?
62+
end
63+
64+
sig { params(arg0: T.proc.params(arg0: QueryPackwerk::Package).returns(T::Boolean)).returns(T::Boolean) }
65+
def any?(&block)
66+
@original_collection.any?(&block)
67+
end
68+
5969
# You can query for packages rather than violations to get a broader view, and
6070
# the violations returned from this will be related to all packs in this class rather than just
6171
# one.

lib/query_packwerk/violations.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ def file_count
121121
@original_collection.sum(&:file_count)
122122
end
123123

124+
sig { returns(T::Boolean) }
125+
def empty?
126+
@original_collection.empty?
127+
end
128+
129+
sig { returns(T::Boolean) }
130+
def any?
131+
!empty?
132+
end
133+
124134
# Gets all sources and their receiving chains grouped by the constant they've violated.
125135
sig { returns(T.untyped) }
126136
def raw_sources

spec/query_packwerk/violations_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
end
1919
end
2020

21+
describe '#empty? and #any?' do
22+
it 'returns true for empty? when there are no violations' do
23+
empty_violations = described_class.new([])
24+
expect(empty_violations.empty?).to be true
25+
expect(empty_violations.any?).to be false
26+
end
27+
28+
it 'returns false for empty? when there are violations' do
29+
expect(described_class.all.empty?).to be false
30+
expect(described_class.all.any?).to be true
31+
end
32+
end
33+
2134
describe '#anonymous_sources_with_locations' do
2235
it 'can get anonymized sources with their file locations' do
2336
# { constant => { violating code shape => [where it happened] } }

0 commit comments

Comments
 (0)