Skip to content

prefer_self_in_static_references false positive for Generics type in extensions #6674

Closed

Description

@just-holger

New Issue Checklist

Bug Description

When specifying the type a Generics type placeholder should conform to, the prefer_self_in_static_references falsely demands to use Self instead. This only seems to happen in extensions though. Example:

struct TrailingViewModifier<V>: ViewModifier where V: View {
    @ViewBuilder let content: () -> V

    func body(content leadingContent: Content) -> some View {
        HStack {
            leadingContent
            content()
        }
    }
}

extension View {
    func trailing<V>(@ViewBuilder content: @escaping () -> V) -> some View where V: View {
        modifier(TrailingViewModifier(content: content))
    }
}

struct LeadingViewModifier<V: View>: ViewModifier {
    @ViewBuilder let content: () -> V

    func body(content trailingContent: Content) -> some View {
        HStack {
            content()
            trailingContent
        }
    }
}

extension View {
    func leading<V: View>(@ViewBuilder content: @escaping () -> V) -> some View {
        modifier(LeadingViewModifier(content: content))
    }
}

The rule flags the use of the View type in the extensions (specifically where V: View and <V: View>), but not in the declarations of the corresponding structs.

Command:

$ swiftlint

Error message:

warning: Prefer Self in Static References Violation: Use `Self` to refer to the surrounding type name (prefer_self_in_static_references)`

Environment

  • SwiftLint version 0.63.3
  • Xcode version 26.5 (17F42)
  • Installation method used: Homebrew
  • Configuration file:
opt_in_rules:
    - prefer_self_in_static_references

Activity

  1. added
    bug
    on May 28, 2026
  2. self-assigned this
    on May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions