Swiftlint: Vertical Whitespace in between functions

Created on 24 Dec 2018  Â·  5Comments  Â·  Source: realm/SwiftLint

I like to have a single empty line in between logical blocks, and two empty lines in between functions, at the top of a class, and at the bottom of a class (between the last function and the class's closing bracket).

In order not to get the warning about having too much vertical whitespace, I had to customize to the rule to allow up to two lines, but that is of course not specific to inside and outside of functions, so SL won't catch such inconsistencies.

It would be nice to be able to customize this.

Example:

// MARK: Life Cycle

    override func viewDidLoad() {
        super.viewDidLoad()

        let myButton = Button

        let myTable = Table
    }


    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        let myButton = Button

        let myTable = Table
    }
enhancement

Most helpful comment

Commenting to avoid this issue from being closed since an issue I'm watching for a feature I'd love to have.

All 5 comments

That's absolutely something I'd be in favor of allowing configuring. Is this something you'd be interested in contributing yourself or are you asking for someone else to build this? I'm happy to point you in the right direction if you're unsure where to start.

I’m very interested in helping out and unsure where to start just as much 😄

Thanks
—

On Dec 24, 2018, at 5:09 AM, JP Simard notifications@github.com wrote:

That's absolutely something I'd be in favor of allowing configuring. Is this something you'd be interested in contributing yourself or are you asking for someone else to build this? I'm happy to point you in the right direction if you're unsure where to start.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub https://github.com/realm/SwiftLint/issues/2526#issuecomment-449683691, or mute the thread https://github.com/notifications/unsubscribe-auth/ASWtSUiH4hka4LCu-Fqrh_9Cctk1rGD2ks5u8FNvgaJpZM4ZgDhp.

Here's roughly the steps you'd take to build this:

  1. Add a configuration option for how many lines of whitespace should be between functions in VerticalWhitespaceConfiguration.swift. This is the file where configuration options for the vertical_whitespace rule are defined.
  2. In VerticalWhitespaceRule.swift, add a check for your new configuration option and validate that there's the right amount of spacing for the code style you want to enforce.
  3. Add tests to VerticalWhitespaceRuleTests.swift following how the other tests in that file are set up.

This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!

Commenting to avoid this issue from being closed since an issue I'm watching for a feature I'd love to have.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Tableau-David-Potter picture Tableau-David-Potter  Â·  3Comments

larslockefeer picture larslockefeer  Â·  3Comments

ziryanov picture ziryanov  Â·  3Comments

jszumski picture jszumski  Â·  3Comments

Den-Ree picture Den-Ree  Â·  3Comments