Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule Request: Vertical Whitespace Opening/Closing Braces With Configuration #2322

Open
francos opened this issue Jul 30, 2018 · 13 comments
Open
Labels
rule-request Requests for a new rules.

Comments

@francos
Copy link

francos commented Jul 30, 2018

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.

@realm-probot realm-probot bot added the O:User label Jul 30, 2018
@ton252
Copy link

ton252 commented Feb 27, 2019

Did someone realise this functionality by custom rules?

@akivab
Copy link

akivab commented Apr 2, 2019

Any update on this issue?

@akivab
Copy link

akivab commented Apr 2, 2019

I can get it to trigger with the following custom_rules:

 custom_rules:
   space_between_functions:
     regex: '\}[^\n]*\n[^\n]*func'
     severity: error
     message: "functions should start with newline"

What I'd like to do is autocorrect it by adding in another newline where the one newline exists. Any suggestions @marcelofabri ?

@NicholasTD07
Copy link

I was looking at possibilities to customize this rule to implement "vertical white space between nested types only". So that

enum A { // this line would give an error because there should be one blank line after this
  enum B {
  }
}

struct S { // however, this is fine
  let a: Int
}

I ended up making this custom rule which works out pretty well.

custom_rules:
  vertical_space_between_nested_types:
    name: "Vertical space between nested types"
    regex: '(class|struct|enum|extension)[^\n]*\{\n[^\n]*(class|struct|enum|extension)'
    message: "Nested types should be separated by a blank line"
    severity: error

Hopefully this can help someone else like me in need of such functionality.

Thanks to everyone involved making SwiftLint project. 👍

@AnthonyMillerSF
Copy link

I would love to have this as well. Anyone looking into making this happen?

@titkov5
Copy link

titkov5 commented Jun 10, 2020

Any updates maybe?

@quinntaylor
Copy link
Contributor

This is a fantastic idea! I'd also love if it could support a minimum or exact number of blank lines before/after a brace. For example, a code style might require a single blank line after the start of a class/struct/enum/protocol, or it could be optional. I'm not familiar with the internals of SwiftLint — is it feasible for config values to support both numbers and ranges, such as 0..1 for example?

@stale
Copy link

stale bot commented Nov 8, 2020

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 stale bot added the wontfix Issues that became stale and were auto-closed by a bot. label Nov 8, 2020
@quinntaylor
Copy link
Contributor

I'm still interested in having this enhancement.

@stale stale bot removed the wontfix Issues that became stale and were auto-closed by a bot. label Nov 9, 2020
@stale
Copy link

stale bot commented Jan 8, 2021

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 stale bot added the wontfix Issues that became stale and were auto-closed by a bot. label Jan 8, 2021
@stale stale bot closed this as completed Jan 15, 2021
@quinntaylor
Copy link
Contributor

This is an annoyingly aggressive bot. Why should people have to keep kicking a bug every 2 months to keep it active?

@jpsim jpsim reopened this Feb 23, 2021
@jpsim
Copy link
Collaborator

jpsim commented Feb 23, 2021

I agree @quinntaylor, after seeing the bot in practice for the last few months, I've decided to remove the bot, rationale here: #3529

Consider this one re-opened.

@truemetal
Copy link

Should this have a wontfix label?

@SimplyDanny SimplyDanny added rule-request Requests for a new rules. and removed wontfix Issues that became stale and were auto-closed by a bot. labels May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule-request Requests for a new rules.
Projects
None yet
Development

No branches or pull requests