`redundant_self` false positive with Logger
Open
Nobody has claimed this yet.
acceptable-false-positive
bug
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- I've Updated SwiftLint to the latest version.
- I've searched for existing GitHub issues.
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 versionto be sure): 0.63.2 - Xcode version (run
xcodebuild -versionto 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the SwiftLint 0.63.2 report with the sample code and the shown redundant_self configuration. Trace the redundant_self rule's handling of the Logger interpolation and compare it with Swift's requirement for explicit self in the closure. Done means the required self.test is no longer reported as redundant while other redundant_self violations remain covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100