Add option to the `explicit_self` rule to only enforce using self in initializers
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
Continued from https://github.com/realm/SwiftLint/issues/321.
I would like to see an option to only enforce self in initializers. I generally prefer using implicit self, but in initializers, it makes more sense to use self for consistency, as some properties might need self to differentiate them from the initializer arguments.
To illustrate, I would like to enforce:
class Unicorn {
init(foo: String, goat: String) {
self.foo = foo
bar = goat
}
}
To be:
class Unicorn {
init(foo: String, goat: String) {
self.foo = foo
self.bar = goat
}
}
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 the existing explicit_self rule, its configuration, and its tests. Add coverage for an initializer-only option using the two examples in the issue, and consider the work done when the rule enforces self in initializers without changing behavior elsewhere.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100