realm / realm/SwiftLint

Add optional rule to prevent empty lines at the start of methods or closures

Open
#1,659 2 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

So far we have vertical_whitespace with the max_empty_lines parameter.

There are plenty of places where empty lines are good to increase grouping.

One thing we have observed though and would like to prevent in our projects are empty lines at the beginning, like in

func startDoingStuff() -> Result {

    print("Now doing stuff")
    // ...

    return someResult
}

or

[0...1].map { number in

    print("number: \(number)")
    // ...
    return number* number
}

we don't think there is any reason to allow empty lines at the start of methods so I would like to propose a new rule disallowing this.

I'm about to make a PR too, but since I haven't used sourcery yet I might need a few minutes to get it right (and make all tests pass).

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 with SwiftLint's existing vertical_whitespace rule and its tests, then trace how an optional rule is configured and applied to methods and closures. Done means leading empty lines are rejected when enabled while allowed internal grouping remains valid, with tests covering both methods and closures.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.