Skip to content

redundant_self false positive with Logger #6542

@Nef10

Description

@Nef10

New Issue Checklist

Bug Description

Sample Code

import os

class Name {
    private let test = ""

    func testLog() {
        Logger(subsystem: "sub", category: "cat").warning("test: \(self.test, privacy: .private(mask: .hash))")
    }
}

SwiftLint output:

$ swiftlint    
Linting Swift files in current working directory
Linting 'a.swift' (1/1)
~/Desktop/a.swift:7:68: warning: Redundant Self Violation: Explicit use of 'self' is not required (redundant_self)
Done linting! Found 1 violation, 0 serious in 1 file.

When removing the self. from the self.test:

$ swift a.swift
a.swift:7:68: error: reference to property 'test' in closure requires explicit use of 'self' to make capture semantics explicit
 5 | 
 6 |     func testLog() {
 7 |         Logger(subsystem: "sub", category: "cat").warning("test: \(test, privacy: .private(mask: .hash))")
   |                                                                    |- error: reference to property 'test' in closure requires explicit use of 'self' to make capture semantics explicit
   |                                                                    `- note: reference 'self.' explicitly
 8 |     }
 9 | }

Environment

  • SwiftLint version (run swiftlint version to be sure): 0.63.2
  • Xcode version (run xcodebuild -version to be sure): Xcode 26.3 Build version 17C529
  • Installation method used (Homebrew, CocoaPods, building from source, etc): Homebrew
  • Configuration file:
opt_in_rules:
  - redundant_self

redundant_self:
  only_in_closures: false

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptable-false-positiveFalse positives caused by rules that are unavoidable due to missing type information.bugUnexpected and reproducible misbehavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions