Skip to content

False positive on redundant_discardable_let rule in SwiftUI @ViewBuilder #6063

Open
@ObjectiveCesar

Description

@ObjectiveCesar

New Issue Checklist

Bug Description

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:
@ViewBuilder
func viewBuilder() -> some View {
    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)

Environment

  • SwiftLint version: 0.59.1
  • Xcode version: Xcode 16.2, Build version 16C5032a
  • Installation via Homebrew
  • Configuration file:
# Default rule configuration
redundant_discardable_let:
    ignore_swiftui_view_bodies: true

No nested configurations.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions