profile
viewpoint

natestedman/morrowind 14

ports of the tango-based gedit "Oblivion" theme to other editors/ides

natestedman/drag 11

CLI utility for macOS drag & drop

natestedman/Observatory 9

A Python based dashboard for the Rensselaer Center for Open Source Software. For continued development, please see http://github.com/rcos/observatory

natestedman/Attributed 5

Structural NSAttributedString

natestedman/Average-Lapse 3

Averages time lapse photos and videos (creating what is essentially a very long exposure)

natestedman/KeyboardShuffle 3

Randomly shuffle your keyboard layouts every now and then!

natestedman/nyct-json 2

Write subway departure times to JSON files

natestedman/ArrayLoader 1

Retrieving paginated data with ReactiveCocoa

natestedman/Endpoint 1

A minimal Swift framework for representing API endpoints

natestedman/imageset 1

Creates functions, categories, or constants for Xcode assets

pull request commentapple/swift-format

Allow more required line breaks

So, the main thing that I'd want is deterministic output based on the code structure (thus no respectsExistingLineBreaks), but without the "squishing" that comes with a line limit of 120 (pretty typical for iOS) for simple classes, extensions, etc.

But, I don't know that nested braces alone get exactly my ideal formatting. It's pretty subjective, but single-line functions:

func example(arg: Int) -> Int { return arg }

and single line if:

if something { print("something!") }

Don't feel "normal" (whereas single-line computed var and guard/else do... can't explain it!). Maybe the former is different with implicit single-expression returns from func being allowed now though!

But, it's less important than avoiding the excessive squishing. I think overall I prefer the result of this, but:

  1. If the complexity of special-casing so many constructs is too much, a simpler approach is definitely valid, and will get most of the way there.
  2. I made them all separate settings, just going off everything existing being a pretty small config option. But, to reduce complexity somewhat (in config, not so much in the implementation), they could just be one "more line breaks!" option to reduce the number of variations in outputs. Depends whether you value consistency or flexibility in swift-format (e.g. black is very inflexible, clang-format is very flexible).
natestedman

comment created time in 2 days

push eventnatestedman/swift-format

Nate Stedman

commit sha 2feea581f98ce153cf67ae67fe7f75048bc9ee75

Add lineBreakBeforeControlFlowBodies configuration option

view details

Nate Stedman

commit sha 95e315eb07852667db3378c61f31ba361a89ba5e

Add lineBreakBeforeTypeBodies configuration option

view details

push time in 16 days

push eventnatestedman/swift-format

Nate Stedman

commit sha 6484579a8ef120e469134e4fe39933fbc3e63eaf

Add lineBreakBeforeFuncBodies configuration option

view details

Nate Stedman

commit sha f8f803260378842419c9d9daa60697bcbec871ba

Add lineBreakBeforeControlFlowBodies configuration option

view details

Nate Stedman

commit sha 500f325b947bead7a432f51dd8dbc1300bd331d7

Add lineBreakBeforeTypeBodies configuration option

view details

push time in 16 days

push eventnatestedman/swift-format

Nate Stedman

commit sha c62e45aee1a817a87a6d0c44e97fc354a7c4a330

Add lineBreakBeforeEachSwitchCaseOrDefaultBody configuration option

view details

Nate Stedman

commit sha fee799f33916f85552c7b2bb93559924c24be5fc

Add lineBreakBeforeFuncBodies configuration option

view details

Nate Stedman

commit sha 0683ba70c2655087c2d4713823394cb6e822396f

Add lineBreakBeforeControlFlowBodies configuration option

view details

push time in 16 days

PR opened apple/swift-format

Allow more required line breaks

Currently, when respectsExistingLineBreaks is set to false, swift-format squishes most of code onto single lines when it will fit under the line length limit. I'd like to use respectsExistingLineBreaks so that output is fully deterministic based on the source code structure, but I've found readability is negative impacted by formatting like this:

func foo(bar: Bool) { if bar { print("Bar!") } }

Instead, I'd prefer more line breaks:

func foo(bar: Bool) {
    if bar {
        print("Bar!")
    }
}

So, I want to add more options to force the addition of line breaks. Specifically, the ones that I'm currently looking at are:

  • lineBreakBeforeEachFuncBody: after the opening { of a func, always use a line break.
  • lineBreakBeforeEachIfElseBody: after the { following if or else, always use a line break.
  • lineBreakBeforeEachLoopBody: same, but for loops.
    • This could be configurable per-loop-type, but would anyone want that?
  • lineBreakBeforeEachSwitchCaseOrDefaultBody: after case ...: or default:, always use a line break.

The other constructs I can think of are guard and var. I don't need these, as I think the squished style is more typical for simple, short cases of these, but they could be added as well for the sake of completeness.

I think that this is basically https://bugs.swift.org/browse/SR-13458, though these changes won't add more flexibility, only more required line breaks.

I'm putting this up with just lineBreakBeforeEachSwitchCaseOrDefaultBody so that the idea and the implementation can be discussed, if moving forward, I'll stack the other commits and also add tests (testing locally by formatting my Swift code, it appears to work).

I'm also currently targeting the swift-5.3-branch because I'm using Xcode 12 locally, but I expect later on I'll need to rebase to target the main branch?

I also noticed that running the compiled swift-format, like this:

find Sources -name '*.swift' | xargs ./.build/debug/swift-format -i

...against all of the Swift files made a lot of changes, so I manually formatted the code (just the now-long after call). Is swift-format being used on the repo, and if so, how should I run it?

+19 -1

0 comment

2 changed files

pr created time in 16 days

create barnchnatestedman/swift-format

branch : more-line-breaks

created branch time in 16 days

fork natestedman/swift-format

Formatting technology for Swift source code

fork in 16 days

more