realm / realm/SwiftLint

Rule Request: swiftui_private_var_func `private vars` before `var body`

Open
#4,614 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

rule-request
Dominant language
Swift
Stars
19.7k
Forks
2.3k
Avg merge
1d 1h
Merged PRs (30d)
11

Description

New Issue Checklist
New rule request
  1. 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 {
   }
}
  1. I can't think of any configuration rules.
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.