Rule Request: swiftui_private_var_func `private vars` before `var body`
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
-
This rule should be added to help with coding conventions so that all variables are before the body of a SwiftUI View..
Triggers
struct ListView: View {
var body: some View {
}
private var title: String {
"My Title
}
}
Won't trigger
struct ListView: View {
private var title: String {
"My Title
}
var body: some View {
}
}
- I can't think of any configuration rules.
- This rule should be opt-in
To be honest, I'd be happy to just create a custom rule for this, but I'm not sure how that could be achieved, maybe someone could give me a few tips, like what match_kinds I'd need if it were possible ?
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 reviewing SwiftLint's existing opt-in rules and how custom rules use match_kinds. Compare the requested trigger and non-trigger examples with existing rule tests, then define coverage for SwiftUI View declarations and private variables. Done means the rule enforces variables before var body, remains opt-in, and has tests for both examples.
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
- Mostly clear
- Newbie friendliness
- 35/100