Rule Request: Prefer returning `Self` in value types instead of the value type's name
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
This rule is similar to https://github.com/realm/SwiftLint/issues/2921 but I don't think it's a duplicate.
New rule request
Please describe the rule idea, format
this issue's title as Rule Request: [Rule Name] and describe:
- Why should this rule be added?
I can't find the exact Swift proposal but in Swift 5.1 (I think) you can return Self in value types instead of the value type's name.
e.g.
struct Foo {
static func someFunc() -> Self { ... }
}
- Provide several examples of what would and wouldn't trigger violations.
would trigger:
struct Foo {
static func someFunc() -> Foo { ... }
}
struct Foo {
func someFunc() -> Foo { ... }
}
struct Foo {
var someComputedProperty: Foo { ... }
}
wouldn't trigger:
struct Foo {
func someFunc() -> Self { ... }
}
class Foo {
func someFunc() -> Foo { ... }
}
- Should the rule be configurable, if so what parameters should be configurable?
I don't think so
- Should the rule be opt-in or enabled by default? Why?
See README.md for guidelines on when to mark a rule as opt-in.
Safer to opt-in I guess.
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 README.md's opt-in-rules guidance and compare the related issue #2921. Use the Swift examples in this issue to define which value-type return annotations should trigger and which class or Self cases should not. Done means an opt-in rule with coverage for these examples.
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
- 42/100