Rule Request: Bound method references
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
New rule request
The idea for the rule would be to disallow usage of the language feature.
-
Why should this rule be added? Share links to existing discussion about what
the community thinks about this.We have had a few instances of memory leaks in our app that were caused by bound method references, as described in this implemented Swift Evolution proposal 0269. These are fairly difficult to debug, and it is not obviously clear to the engineer that writes the code that they are doing something that will likely cause a retain cycle.
-
Provide several examples of what would and wouldn't trigger violations.
class Test {
var x = 0
func execute(_ work: @escaping () -> Void) {
work()
}
func method() {
execute(inc) // This should cause a violation
execute(self.inc) // This should also cause a violation
execute({ self.inc() }) // This explicit use of a closure should not trigger a violation
}
func inc() {
x += 1
}
}
-
Should the rule be configurable, if so what parameters should be configurable?
I don't think this needs configuration.
-
Should the rule be opt-in or enabled by default? Why?
There is not yet general consensus on this rule.
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 with Swift Evolution proposal 0269 and the bound-method reference examples in this issue. Determine how the requested rule should distinguish direct references such as inc and self.inc from an explicit closure, and resolve whether it should be opt-in or enabled by default. Done means the behavior and configuration decision are sufficiently specified for implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100