Rule Request: weak, unowned in noescape closures
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
Rule Request
noescape_captures
- Why should this rule be added? Share links to existing discussion about what
the community thinks about this.
No need to write weak, unowned in capture list in noescape closure.
- Provide several examples of what would and wouldn't trigger violations.
Would trigger:
let modifiedArray = array.map { [weak self] value in
self?.modify(value) ?? ""
}
let modifiedArray2 = array.map { [unowned self] value in
self.modify(value)
}
Would not trigger:
let modifiedArray = array.map { value in
modify(value)
}
- Should the rule be configurable, if so what parameters should be configurable?
-
Probably we can always require not to write self inside noespace closures. As there is no need for it
-
Probably we should allow/disallow to use capture list without ownership
let modifiedArray = array.map { [modifier = transformer.operations.modifier] value in
modifier.modify(value)
}
- Should the rule be opt-in or enabled by default? Why?
For weak and unowned - Yes
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 locating the noescape_captures rule entry point and review how SwiftLint represents noescape closures and capture lists. Before implementation, clarify whether the rule covers only weak and unowned captures, how plain capture lists are handled, and whether it should be enabled by default; done means the agreed examples are consistently diagnosed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100