SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Vertical Whitespace in between functions

Open danispringer opened this issue 6 years ago • 13 comments

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
    }

danispringer avatar Dec 24 '18 01:12 danispringer

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.

jpsim avatar Dec 24 '18 04:12 jpsim

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 [email protected] 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.

danispringer avatar Dec 24 '18 04:12 danispringer

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.

jpsim avatar Dec 24 '18 04:12 jpsim

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!

stale[bot] avatar Nov 08 '20 08:11 stale[bot]

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

jawwad avatar Nov 08 '20 23:11 jawwad

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!

stale[bot] avatar Jan 07 '21 23:01 stale[bot]

.

danispringer avatar Jan 08 '21 00:01 danispringer

Lack of this feature is the main reason I haven't been using SwiftLint. Perhaps I'll take a try at adding this.

bunnyhero avatar Jan 15 '21 02:01 bunnyhero

Any progress on this topic?

CemYil03 avatar Aug 20 '21 22:08 CemYil03

any update? this seems like many people would want this

andrrrr avatar Oct 02 '21 12:10 andrrrr

What language would a contribution be in?

danispringer avatar Aug 05 '22 16:08 danispringer

bump

danispringer avatar Nov 28 '22 04:11 danispringer

bump

henrypratt avatar Dec 11 '22 00:12 henrypratt

help

aplha98 avatar Jul 10 '23 11:07 aplha98