Add redundantEmptyView rule#2470
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #2470 +/- ##
===========================================
+ Coverage 95.28% 95.30% +0.01%
===========================================
Files 165 166 +1
Lines 25243 25304 +61
===========================================
+ Hits 24053 24115 +62
+ Misses 1190 1189 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
calda
left a comment
There was a problem hiding this comment.
Yes! Love it! Thank you @mannylopez
| func expressionIsEmptyView(in expressionRange: ClosedRange<Int>) -> Bool { | ||
| var emptyViewIdentifierIndex = expressionRange.lowerBound | ||
|
|
||
| // Handle fully-qualified `SwiftUI.EmptyView()` |
There was a problem hiding this comment.
We're missing a test case for this code path
There was a problem hiding this comment.
Added testRemoveFullyQualifiedSwiftUIEmptyView
|
I ran this on the Airbnb codebase and found one example where it causes a build failure. However the error seems like a compiler bug to me, not a "real" issue (the example uses a trailing closure, and converting the trailing closure to a non-trailing closure avoids the error, which definitely isn't supposed to happen). I think it's ok to leave this enabled by default initially, but I will change it to be disabled by default if we get several bug reports like this. |
Adds a new redundantEmptyView formatting rule that removes redundant
else { EmptyView() }branches in SwiftUI view builders.In SwiftUI view builders, an if statement without an else branch implicitly produces no content when the condition is false, making an explicit
else { EmptyView() }unnecessary.var body: some View { if condition { Text("Hello") - } else { - EmptyView() } }