Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preferCountWhere rule #1939

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

calda
Copy link
Collaborator

@calda calda commented Dec 8, 2024

As suggested in #1933, this PR adds a new preferCountWhere rule to prefer count(where:) over filter(_:).count calls in Swift 6.0+:

- planets.filter { !$0.moons.isEmpty }.count
+ planets.count(where: { !$0.moons.isEmpty })

- planets.filter { planet in
-     planet.moons.filter { moon in
-         moon.hasAtmosphere
-     }.count > 1
- }.count
+ planets.count(where: { planet in
+     planet.moons.count(where: { moon in
+         moon.hasAtmosphere
+     }) > 1
+ })

Copy link

codecov bot commented Dec 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.14%. Comparing base (f36187b) to head (8f27d07).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1939      +/-   ##
===========================================
- Coverage    95.18%   95.14%   -0.04%     
===========================================
  Files          137      138       +1     
  Lines        25094    25199     +105     
===========================================
+ Hits         23885    23976      +91     
- Misses        1209     1223      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@miguel-jimenez-0529
Copy link
Contributor

Nice!

@nicklockwood nicklockwood merged commit 81116e0 into nicklockwood:develop Dec 10, 2024
10 of 12 checks passed
@nicklockwood
Copy link
Owner

Amazing! 😍

nicklockwood pushed a commit that referenced this pull request Dec 10, 2024
nicklockwood pushed a commit that referenced this pull request Dec 16, 2024
nicklockwood pushed a commit that referenced this pull request Dec 22, 2024
nicklockwood pushed a commit that referenced this pull request Dec 22, 2024
nicklockwood pushed a commit that referenced this pull request Dec 22, 2024
nicklockwood pushed a commit that referenced this pull request Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants