Code Monkey home page Code Monkey logo

Comments (10)

nicklockwood avatar nicklockwood commented on May 22, 2024 1

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.

from swiftformat.

nicklockwood avatar nicklockwood commented on May 22, 2024

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.

from swiftformat.

JustinJiaDev avatar JustinJiaDev commented on May 22, 2024

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!

from swiftformat.

JustinJiaDev avatar JustinJiaDev commented on May 22, 2024

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.

from swiftformat.

nicklockwood avatar nicklockwood commented on May 22, 2024

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
    }
}

from swiftformat.

nicklockwood avatar nicklockwood commented on May 22, 2024

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.

from swiftformat.

JustinJiaDev avatar JustinJiaDev commented on May 22, 2024

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

Btw, what about properties?

from swiftformat.

nicklockwood avatar nicklockwood commented on May 22, 2024

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

from swiftformat.

JustinJiaDev avatar JustinJiaDev commented on May 22, 2024

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.

from swiftformat.

icanswiftabit avatar icanswiftabit commented on May 22, 2024

Have you work this case out?

from swiftformat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.