`trailing_closure` rule disagrees with Swift 5.8 forward-scan matching
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
New Issue Checklist
- Updated SwiftLint to the latest version
- I searched for existing GitHub issues
Describe the bug
With changes made between SwiftLint 0.54.0 and 0.55.1 the trailing_closure rule now enforces a practice that the Swift compiler considers as deprecated.
Consider a function (or method) whose signature involves several trailing closures with default arguments, like:
func trailingClosures(closure1: () -> Void = {}, closure2: () -> Void = {}) {}
Swift 5.8 introduced changes which lead to a warning being reported when calling the above function as follows:
func someCode() {
// Xcode warning: "Backward matching of the unlabeled trailing closure is deprecated; label the argument
// with 'closure2' to suppress this warning"
trailingClosures {}
}
When fixing the code to silence the Xcode warning:
func someCode() {
// swiftlint 0.55.1 warning: "Trailing closure syntax should be used whenever possible"
trailingClosures(closure2: {})
}
SwiftLint 0.55.1 reports a warning. This was not the case with SwiftLint 0.54.0.
Complete output when running SwiftLint, including the stack trace and command used
$ swiftlint lint
Environment
- SwiftLint version (run
swiftlint versionto be sure)? 0.55.1 - Installation method used (Homebrew, CocoaPods, building from source, etc)? Homebrew / Mint
- Paste your configuration file:
opt_in_rules:
- trailing_closure
- Are you using nested configurations? No
- Which Xcode version are you using (check
xcodebuild -version)? 15.4 (15F31c) - Do you have a sample that shows the issue?
func trailingClosures(closure1: () -> Void = {}, closure2: () -> Void = {}) {}
func someCode() {
trailingClosures(closure2: {})
}
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 at the trailing_closure rule entry point and reproduce the reported behavior with swiftlint lint using the sample configuration and Swift code. Check how labeled trailing closures are classified under Swift 5.8 forward-scan matching; done means the closure2: call no longer produces an incorrect warning while the rule still handles applicable trailing-closure cases.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100