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

[Suggestion] Empty Line Inside Out-Most Brackets Rule #20

Closed
JustinJiaDev opened this issue Sep 1, 2016 · 10 comments
Closed

[Suggestion] Empty Line Inside Out-Most Brackets Rule #20

JustinJiaDev opened this issue Sep 1, 2016 · 10 comments

Comments

@JustinJiaDev
Copy link
Contributor

JustinJiaDev commented Sep 1, 2016

Add extra line after { and before } only for brackets without any indentation.

It is common to write code like this:

class Foo {

    func bar() {
        // Do something here
    }

}

or:

enum Foo {

    case a
    case b
    case c

}
@JustinJiaDev JustinJiaDev changed the title [Suggestion [Suggestion] Space Inside Out Most Brackets Sep 1, 2016
@JustinJiaDev JustinJiaDev changed the title [Suggestion] Space Inside Out Most Brackets [Suggestion] Space Inside Out Most Brackets Rule Sep 1, 2016
@JustinJiaDev JustinJiaDev changed the title [Suggestion] Space Inside Out Most Brackets Rule [Suggestion] Empty Line Inside Out-Most Brackets Rule Sep 1, 2016
@nicklockwood
Copy link
Owner

nicklockwood commented Sep 1, 2016

This would be in conflict with the blankLinesAtEndOfScope rule, which removes blank lines before a closing }.

This looks wrong to me.

enum Foo {

    case a
    case b
    case c

}

I feel like it should be

enum Foo {
    case a
    case b
    case c
}

But I haven't managed to come up with a rule for blank lines at the beginning of a scope. Normally I remove them, but there are exceptions, e.g. in a class.

I may need to make this configurable if people feel strongly about it.

@JustinJiaDev
Copy link
Contributor Author

The enum example looks wrong by itself, but people may add functions:

enum Foo {

    case a, b, c

    func bar() {
        // Do something here
    }

    func baz() {
       // Do something else here
    }

}

If I understand it correctly, blankLinesAtEndOfScope will affect all curly brackets? But this rule should be a special case—it will only affect out-most brackets.

Making this configurable sounds like a good idea!

@JustinJiaDev
Copy link
Contributor Author

Sometimes I write functions like this:

class Foo {

    class Bar {
        /// Other Methods
    }

}

I won't add empty line inside Bar. Mainly because Foo is much longer.

@nicklockwood
Copy link
Owner

blankLinesAtEndOfScope currently only removes the blank line at the end - it doesn't add one. So it will change this:

class Foo {

    class Bar {
        /// Other Methods
    }

}

to this:

class Foo {

    class Bar {
        /// Other Methods
    }
}

@nicklockwood
Copy link
Owner

I get what you're saying about scopes at root level possibly requiring different treatment than ones that are nested. You might be right, but I still don't think I know what the rule should be yet. I'll think about it some more.

@nicklockwood
Copy link
Owner

I've decided to take a different approach. I'm now adding space between functions, classes, etc regardless of scope. May not be popular with everyone, but we'll see.

@JustinJiaDev
Copy link
Contributor Author

JustinJiaDev commented Sep 8, 2016

Sounds good. In this case maybe blankLinesAtEndOfScope should be reevaluated? It can be submerged into blankLinesBetweenScopes.

Btw, what about properties?

@nicklockwood
Copy link
Owner

nicklockwood commented Sep 8, 2016

I'm pretty happy with not having a blank line at the end of a scope. Since the scope always ends with a } and a lower indent level than the previous line, there's never any visual overlap:

    last line
}

I'm not sure if I like the blank line at the start of a scope or not, which is why I current ignore it. I may eventually make this configurable though.

Btw, what about properties?

I haven't worked out what to do about those yet. I definitely don't want to put blank lines between them, but I'd like to separate groups of them from a previous function, e.g.

func foo () {
}
               <-- there should always be a blank line here, but I don't enforce that yet
var bar: Int

@JustinJiaDev
Copy link
Contributor Author

I haven't worked out what to do about those yet. I definitely don't want to put blank lines between them, but I'd like to separate groups of them from a previous function

I agree.

@icanswiftabit
Copy link

Have you work this case out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants