realm / realm/SwiftLint

Rule Request: Vertical Whitespace Opening/Closing Braces With Configuration

Open
#2,322 13 comments 27 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

This ticket is related to issue #1518 and to PR #2291.

Once #2291 is merged, it'd be good to extend the functionality of the vertical_whitespace_opening_braces and vertical_whitespace_closing_braces so that they can be configured for braces of different types.

  1. Why should this rule be added?

    These rules are great for function braces, but for class/struct braces it might be good to allow 1 empty line to make the code easier to read.

  2. Provide several examples of what would and wouldn't trigger violations.

    // This looks good and wouldn't trigger violations
    class Foo {
    
        func doSomething() {
            let whatever = 1
        }
    
    }
    
    // This is a bit too crowded and would trigger violations
    class Foo {
        func doSomething() {
            let whatever = 1
        }
    }
    
  3. Should the rule be configurable, if so what parameters should be configurable?

    This is an example of possible configurations for these rules:

    vertical_whitespace_opening_braces:
        max_empty_lines_class: 1
        max_empty_lines_struct: 1
        max_empty_lines_protocol: 1
        max_empty_lines_extension: 1
        max_empty_lines_func: 0
    

    The configurations above are just a suggestion, I have only been using this library for a week so there are probably better ways to add such configurations to these rules.

  4. Should the rule be opt-in or enabled by default? Why?

    I would enable this rule by default and set 1 as the default for class, struct, protocol, extension, and 0 for func.

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 the existing vertical_whitespace_opening_braces and vertical_whitespace_closing_braces rules, along with related issue #1518 and PR #2291. Define how configuration should distinguish class, struct, protocol, extension, and function braces, document triggering and non-triggering examples, and verify the proposed defaults and opt-in behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.