You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The rule redundant_discardable_let is falsely triggered inside SwiftUI @ViewBuilder implementation, although the option ignore_swiftui_view_bodies is set to true.
Using the --fix option for this violation will remove the let, and previews won't compile. The option is working properly inside SwiftUI var body: some View declarations.
// This triggers a violation:
@ViewBuilderfunc viewBuilder()->someView{let _ ="Test Builder"EmptyView()}
Removing the let will break the View conformance. Adding explicit return to EmptyView will break the result builder ViewBuilder.
$ swiftlint --strict --progress
TestFile.swift:60:9: error: Redundant Discardable Let Violation: Prefer `_ = foo()` over `let _ = foo()` when discarding a result from a function(redundant_discardable_let)
Imho the exception for var body: some View should also apply to @ViewBuilder implementations since they follow the same rules as the var body: some View declarations.
The text was updated successfully, but these errors were encountered:
ObjectiveCesar
changed the title
False positive on redundant_discardable_let in SwiftUI @ViewBuilder
False positive on redundant_discardable_let rule in SwiftUI @ViewBuilder
Apr 25, 2025
ObjectiveCesar
changed the title
False positive on redundant_discardable_let rule in SwiftUI @ViewBuilder
False positive on redundant_discardable_let rule in SwiftUI @ViewBuilderApr 25, 2025
New Issue Checklist
Bug Description
The rule
redundant_discardable_let
is falsely triggered inside SwiftUI@ViewBuilder
implementation, although the optionignore_swiftui_view_bodies
is set totrue
.Using the
--fix
option for this violation will remove thelet
, and previews won't compile. The option is working properly inside SwiftUIvar body: some View
declarations.Removing the
let
will break theView
conformance. Adding explicitreturn
toEmptyView
will break the result builderViewBuilder
.$ swiftlint --strict --progress TestFile.swift:60:9: error: Redundant Discardable Let Violation: Prefer `_ = foo()` over `let _ = foo()` when discarding a result from a function (redundant_discardable_let)
Environment
No nested configurations.
Imho the exception for
var body: some View
should also apply to@ViewBuilder
implementations since they follow the same rules as thevar body: some View
declarations.The text was updated successfully, but these errors were encountered: