Giter Site home page Giter Site logo

swift-format's Introduction

swift-format

swift-format provides the formatting technology for SourceKit-LSP and the building blocks for doing code formatting transformations.

This package can be used as a command line tool or linked into other applications as a Swift Package Manager dependency and invoked via an API.

NOTE: No default Swift code style guidelines have yet been proposed. The style that is currently applied by swift-format is just one possibility, and the code is provided so that it can be tested on real-world code and experiments can be made by modifying it.

Matching swift-format to Your Swift Version

Swift 5.8 and later

As of Swift 5.8, swift-format depends on the version of SwiftSyntax whose parser has been rewritten in Swift and no longer has dependencies on libraries in the Swift toolchain.

This change allows swift-format to be built, developed, and run using any version of Swift that can compile it, decoupling it from the version that supported a particular syntax. However, earlier versions of swift-format will still not be able to recognize new syntax added in later versions of the language and parser.

Note also that the version numbering scheme has changed to match SwiftSyntax; the 5.8 release of swift-format is 508.0.0, not 0.50800.0.

Swift 5.7 and earlier

swift-format versions 0.50700.0 and earlier depend on versions of SwiftSyntax that used a standalone parsing library distributed as part of the Swift toolchain. When using these versions, you should check out and build swift-format from the release tag or branch that is compatible with the version of Swift you are using.

The major and minor version components of swift-format and SwiftSyntax must be the same—this is expressed in the SwiftSyntax dependency in Package.swift—and those version components must match the Swift toolchain that is installed and used to build and run the formatter:

Xcode Release Swift Version swift-format Branch / Tags
Swift at main main
Xcode 14.0 Swift 5.7 release/5.7 / 0.50700.x
Xcode 13.3 Swift 5.6 release/5.6 / 0.50600.x
Xcode 13.0–13.2 Swift 5.5 swift-5.5-branch / 0.50500.x
Xcode 12.5 Swift 5.4 swift-5.4-branch / 0.50400.x
Xcode 12.0–12.4 Swift 5.3 swift-5.3-branch / 0.50300.x
Xcode 11.4–11.7 Swift 5.2 swift-5.2-branch / 0.50200.x
Xcode 11.0–11.3 Swift 5.1 swift-5.1-branch

For example, if you are using Xcode 13.3 (Swift 5.6), you will need swift-format 0.50600.0.

Getting swift-format

If you are mainly interested in using swift-format (rather than developing it), then you can get swift-format either via Homebrew or by checking out the source and building it.

Installing via Homebrew

Run brew install swift-format to install the latest version.

Building from source

Install swift-format using the following commands:

VERSION=510.1.0  # replace this with the version you need
git clone https://github.com/apple/swift-format.git
cd swift-format
git checkout "tags/$VERSION"
swift build -c release

Note that the git checkout command above will leave the repository in a "detached HEAD" state. This is fine if building and running the tool is all you want to do.

Once the build has finished, the swift-format executable will be located at .build/release/swift-format.

To test that the formatter was built successfully and is compatible with your Swift toolchain, you can also run the following command:

swift test --parallel

We recommend using the --parallel flag to speed up the test run since there are a large number of tests.

Command Line Usage

The general invocation syntax for swift-format is as follows:

swift-format [SUBCOMMAND] [OPTIONS...] [FILES...]

The tool supports a number of subcommands, each of which has its own options and are described below. Descriptions of the subcommands that are available can also be obtained by running swift-format --help, and the description of a specific subcommand can be obtained by using the --help flag after the subcommand name; for example, swift-format lint --help.

Formatting

swift-format [format] [OPTIONS...] [FILES...]

The format subcommand formats one or more Swift source files (or source code from standard input if no file paths are given on the command line). Writing out the format subcommand is optional; it is the default behavior if no other subcommand is given.

This subcommand supports all of the common lint and format options, as well as the formatting-only options below:

  • -i/--in-place: Overwrites the input files when formatting instead of printing the results to standard output. No backup of the original file is made before it is overwritten.

Linting

swift-format lint [OPTIONS...] [FILES...]

The lint subcommand checks one or more Swift source files (or source code from standard input if no file paths are given on the command line) for style violations and prints diagnostics to standard error for any violations that are detected.

This subcommand supports all of the common lint and format options, as well as the linting-only options below:

  • -s/--strict: If this option is specified, lint warnings will cause the tool to exit with a non-zero exit code (failure). By default, lint warnings do not prevent a successful exit; only fatal errors (for example, trying to lint a file that does not exist) cause the tool to exit unsuccessfully.

Options Supported by Formatting and Linting

The following options are supported by both the format and lint subcommands:

  • --assume-filename <path>: The file path that should be used in diagnostics when linting or formatting from standard input. If this option is not provided, then <stdin> will be used as the filename printed in diagnostics.

  • --color-diagnostics/--no-color-diagnostics: By default, swift-format will print diagnostics in color if standard error is connected to a terminal and without color otherwise (for example, if standard error is being redirected to a file). These flags can be used to force colors on or off respectively, regardless of whether the output is going to a terminal.

  • --configuration <file>: The path to a JSON file that contains configurable settings for swift-format. If omitted, a default configuration is use (which can be seen by running swift-format dump-configuration).

  • --ignore-unparsable-files: If this option is specified and a source file contains syntax errors or can otherwise not be parsed successfully by the Swift syntax parser, it will be ignored (no diagnostics will be emitted and it will not be formatted). Without this option, an error will be emitted for any unparsable files.

  • -p/--parallel: Process files in parallel, simultaneously across multiple cores.

  • -r/--recursive: If specified, then the tool will process .swift source files in any directories listed on the command line and their descendants. Without this flag, it is an error to list a directory on the command line.

Viewing the Default Configuration

swift-format dump-configuration

The dump-configuration subcommand dumps the default configuration in JSON format to standard output. This can be used to simplify generating a custom configuration, by redirecting it to a file and editing it.

Configuring the Command Line Tool

For any source file being checked or formatted, swift-format looks for a JSON-formatted file named .swift-format in the same directory. If one is found, then that file is loaded to determine the tool's configuration. If the file is not found, then it looks in the parent directory, and so on.

If no configuration file is found, a default configuration is used. The settings in the default configuration can be viewed by running swift-format dump-configuration, which will dump it to standard output.

If the --configuration <file> option is passed to swift-format, then that configuration will be used unconditionally and the file system will not be searched.

See Documentation/Configuration.md for a description of the configuration file format and the settings that are available.

Miscellaneous

Running swift-format -v or swift-format --version will print version information about swift-format version and then exit.

API Usage

swift-format can be easily integrated into other tools written in Swift. Instead of invoking the formatter by spawning a subprocess, users can depend on swift-format as a Swift Package Manager dependency and import the SwiftFormat module, which contains the entry points into the formatter's diagnostic and correction behavior.

Formatting behavior is provided by the SwiftFormatter class and linting behavior is provided by the SwiftLinter class. These APIs can be passed either a Swift source file URL or a Syntax node representing a SwiftSyntax syntax tree. The latter capability is particularly useful for writing code generators, since it significantly reduces the amount of trivia that the generator needs to be concerned about adding to the syntax nodes it creates. Instead, it can pass the in-memory syntax tree to the SwiftFormat API and receive perfectly formatted code as output.

Please see the documentation in the SwiftFormatter and SwiftLinter classes for more information about their usage.

Checking Out the Source Code for Development

The main branch is used for development. Pull requests should be created to merge into the main branch; changes that are low-risk and compatible with the latest release branch may be cherry-picked into that branch after they have been merged into main.

If you are interested in developing swift-format, there is additional documentation about that here.

swift-format's People

Contributors

ahoppen avatar allevato avatar bnbarham avatar brianhenryie avatar codafi avatar compnerd avatar douggregor avatar dylansturg avatar frankus avatar gottesmm avatar hamishknight avatar keith avatar kimdv avatar kitasuke avatar matejkob avatar mlavergn avatar mplew-is avatar mrs1669 avatar natecook1000 avatar natikgadzhi avatar ozumin avatar p4checo avatar shahmishal avatar shawnhyam avatar stackotter avatar stevenwong12 avatar thunderseethe avatar trzyipolkostkicukru avatar ttozzi avatar xedin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-format's Issues

[SR-11201] Create a notion of "experimental" rules

Previous ID SR-11201
Radar None
Original Reporter @allevato
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Improvement
Assignee None
Priority Medium

md5: e64e47dbb1b3dc6bdbe8a5ab524d340f

Issue Description:

We have two fairly ambitious transformations that are currently permanently disabled, because they are explicitly excluded from pipeline generation: UseEarlyExits and UseWhereClausesInForLoops. These have been disabled because they're known to have some fairly destructive bugs right now.

It would be nice to let people more easily enable these without having to rebuild the whole formatter. For this, we could flag those rules as "experimental" somehow (possibly just having a separate subdirectory under SwiftFormatRules would be sufficient for the pipeline to detect them), and have those rules be disabled in the default configuration instead of enabled. Then users can enable them easily for testing.

This would also give us a clean way of accepting new rule submissions; they could go into experimental first, then get promoted once they've been tested thoroughly.

[SR-12360] SwiftFormat uses a SwiftSyntax tag that can cause stack overflow in debug mode

Previous ID SR-12360
Radar rdar://problem/60832848
Original Reporter cukier (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: 4111fa0935f36cb69278ce6ab26c299c

Issue Description:

Stack overflow 2: revenge of the rdar://55929175

After implementing formatting in sourcekit-lsp I was investigating why it wasn't working for things that are nested four levels deep. After fighting with debugger, I had a hunch that it may be stack overflow. I found a comment in the function that was crashing:

    // The implementation of every generated case goes into its own function. This
    // circumvents an issue where the compiler allocates stack space for every
    // case statement next to each other in debug builds, causing it to allocate
    // ~50KB per call to this function. rdar://55929175

It crashes only in debug mode, on macos

To reproduce:

  • clone https://github.com/Trzyipolkostkicukru/sourcekit-lsp/tree/format and checkout commit ed642036f4b9ce7696ad340523ed8e9b4bdb9761

  • get toolchain swift-DEVELOPMENT-SNAPSHOT-2020-01-29-a and set it as your compiler

  • compile and set up sourcekit-lsp

  • try to format a file with 4+ levels of nesting, for example:

    do {
    do { do { do { print("Hello, world") } } } 
    }

[SR-11195] swift-format should allow a trailing array literal without wrapping earlier arguments

Previous ID SR-11195
Radar None
Original Reporter @benlangmuir
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Improvement
Assignee None
Priority Medium

md5: 176b0e1a10655367bcdecb8bcb8a133d

Issue Description:

swift-format makes the following change:

-    XCTAssertEqual(ranges, [
-      FoldingRange(startLine: 0, endLine: 1, kind: .comment),
-      FoldingRange(startLine: 3, endLine: 12, kind: .comment),
-      FoldingRange(startLine: 14, endLine: 26, kind: nil),
-      FoldingRange(startLine: 17, endLine: 18, kind: .comment),
-      FoldingRange(startLine: 22, endLine: 24, kind: nil),
-      FoldingRange(startLine: 29, endLine: 31, kind: .comment),
-      FoldingRange(startLine: 33, endLine: 35, kind: .comment),
-    ])
+    XCTAssertEqual(
+      ranges,
+      [
+        FoldingRange(startLine: 0, endLine: 1, kind: .comment),
+        FoldingRange(startLine: 3, endLine: 12, kind: .comment),
+        FoldingRange(startLine: 14, endLine: 26, kind: nil),
+        FoldingRange(startLine: 17, endLine: 18, kind: .comment),
+        FoldingRange(startLine: 22, endLine: 24, kind: nil),
+        FoldingRange(startLine: 29, endLine: 31, kind: .comment),
+        FoldingRange(startLine: 33, endLine: 35, kind: .comment),
+      ])
   }

I think the original code is preferable, as it visually feels similar to the way a trailing closure would be handled. It also makes it look more like the single-argument case after https://bugs.swift.org/browse/SR-11106 is fixed.

This could be treated as a narrow exception that only applies to the last argument.

[SR-11123] swift-format crash while linting on extension

Previous ID SR-11123
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

#1

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: 21d47ee9246b981a0612b8c4fff818bc

Issue Description:

With this code:

extension A {
    static let b = C()
}

When running swift-format in lint mode, you get a crash:

0   swift-format                    0x0000000102753956 specialized DontRepeatTypeInStaticProperties.withoutPrefix(name:) + 742
1   swift-format                    0x0000000102753b3b specialized DontRepeatTypeInStaticProperties.determinePropertyNameViolations(members:nodeId:) + 475
2   swift-format                    0x000000010274fc7c DontRepeatTypeInStaticProperties.visit(_:) + 140
3   swift-format                    0x00000001026f4e33 LintPipeline.visit(_:) + 51
4   swift-format                    0x00000001026f4ded protocol witness for SyntaxVisitor.visit(_:) in conformance LintPipeline + 13
5   swift-format                    0x0000000102a0eebd doVisit<A>(_:_:) + 51981
6   swift-format                    0x0000000102a10e22 visitChildren<A>(_:parent:_:) + 530
7   swift-format                    0x0000000102a09302 doVisit<A>(_:_:) + 28498
8   swift-format                    0x0000000102a10e22 visitChildren<A>(_:parent:_:) + 530
9   swift-format                    0x0000000102a09400 doVisit<A>(_:_:) + 28752
10  swift-format                    0x0000000102a10e22 visitChildren<A>(_:parent:_:) + 530
11  swift-format                    0x0000000102a0f372 doVisit<A>(_:_:) + 53186
12  swift-format                    0x00000001029bb799 Syntax.walk<A>(_:) + 121
13  swift-format                    0x00000001026f7902 SwiftLinter.lint(syntax:assumingFileURL:) + 274
14  swift-format                    0x00000001026f77ca SwiftLinter.lint(contentsOf:) + 506
15  swift-format                    0x0000000102a1c959 lintMain(configuration:path:) + 361
16  swift-format                    0x0000000102a19592 main(_:) + 3282
17  swift-format                    0x0000000102a188a7 main + 23
18  libdyld.dylib                   0x00007fff6241f3d5 start + 1

[SR-11116] swift-format missing newline with compiler conditional properties

Previous ID SR-11116
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

#1

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: 155f8cc36d074ba4f6ff9948dc528416

Issue Description:

With this code:

class Foo {
#if DEBUG
    var bar: String
    var baz: String
#endif
}

swift-format produces:

enum Foo {
    #if DEBUG
        var bar: Stringvar baz: String
    #endif
}

[SR-12714] Explicit self.

Previous ID SR-12714
Radar None
Original Reporter @weissi
Type New Feature
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels New Feature
Assignee None
Priority Medium

md5: 0eee30a579bfbe4ae0442eb637819834

Issue Description:

AFAIK, swift-format doesn't support adding explicit self. everywhere. It would be great if it could do that.

[SR-11771] UseShorthandTypeNames doesn’t wrap function types in parentheses

Previous ID SR-11771
Radar rdar://problem/57176570
Original Reporter SDGGiesbrecht (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee dylansturg (JIRA)
Priority Medium

md5: 01c69c652d3706456bb342d10b911f73

Issue Description:

UseShorthandTypeNames ends up changing some types when it attempts to contract them:

Optional<(_ nestedInOptional: Bool) -> Void>?

(_ nestedInOptional: Bool) -> Void??

[SR-11169] swift-format inserts new line into chaining closures

Previous ID SR-11169
Radar None
Original Reporter kitasuke (JIRA User)
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Improvement
Assignee @allevato
Priority Medium

md5: 21bfb087661634a307adefc6c75bdc88

Issue Description:

With this code:

let foo = [1, 2]
    .map { $0 * 10 }
    .first(where: { $0 == 10 })

swift-format produces:

let foo = [1, 2]
  .map
{ $0 * 10 }
  .first(where: { $0 == 10
      })

Can we exclude chaining closure to set a new line for trailing closures? Or can we have a new config to turn off starting new line for trailing closure?

[SR-11772] AlwaysUseLowerCamelCase doesn’t understand caseless characters

Previous ID SR-11772
Radar rdar://problem/57241776
Original Reporter SDGGiesbrecht (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee None
Priority Medium

md5: 19996f8d55cc4bcbb38c685119c09809

Issue Description:

“rename variable 'apache2_0' using lower-camel-case”

“rename variable 'gnuGeneralPublic3_0' using lower-camel-case”

“rename variable 'deprecatedPre0_1_1FileName' using lower-camel-case”

[SR-12782] Trailing comma on single-element array causes non-zero exit

Previous ID SR-12782
Radar None
Original Reporter @tcldr
Type Bug
Status Resolved
Resolution Done
Environment

swift-format swift-5.2-branch
Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)
Target: x86_64-apple-darwin19.4.0

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee dylansturg (JIRA)
Priority Medium

md5: cd15c52cf061747e90bea8cc3162cbdf

Issue Description:

A trailing comma on a single-element Array will cause the lint phase to fail with a non-zero exit code:

ExampleBug.swift:

var strings: [String] { ["just me",] }
$ swift-format -m lint ExampleBug.swift
/Users/tcldr/Desktop/ExampleBug.swift:1:36: warning: [Spacing]: add 1 space
/Users/tcldr/Desktop/ExampleBug.swift:1:37: warning: [AddLines]: add 1 line breaks
[1]    27222 illegal hardware instruction  swift-format -m lint ExampleBug.swift

[SR-11113] swift-format removes space from @unknown default

Previous ID SR-11113
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

#1

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: c45c4f26d16e99e9370a4f720544f2cc

Issue Description:

with this code:

switch foo {
@unknown default:
    return
}

swift-format produces:

switch foo {
@unknowndefault:
  return
}

[SR-11203] swift-format single line closure

Previous ID SR-11203
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

swift-format 79bb590

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: 79f0d526c25f4abb2e0ccaac65f0552b

Issue Description:

With this code:

foo = { _ in false }

swift-format re-writes it to:

foo = { _ in
  false
}

I would have expected it to leave this the same

[SR-12002] [swift-format] Incorrect formatting for `@differentiable`, `@derivative`, `@transpose` attributes

Previous ID SR-12002
Radar None
Original Reporter @dan-zheng
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug, Format
Assignee @allevato
Priority Medium

md5: 51a61469373937af2c405988c17ca635

Issue Description:

The spaces between arguments in @differentiable, @derivative, and @transpose attributes gets deleted by swift-format.

Before swift-format (expected correct formatting):

@differentiable(wrt: x, vjp: derivativeFoo where T: Differentiable)
func foo<T>(_ x: T) -> T {
    x
}

@derivative(of: foo, wrt: x)
func derivativeFoo<T>(_ x: T) -> (value: T, pullback: (T.TangentVector) -> T.TangentVector)
where T: Differentiable {
    (x, { $0 })
}

@transpose(of: foo, wrt: 0)
func transposeFoo<T: Differentiable>(_ v: T) -> T where T == T.TangentVector {
    v
}

After swift-format:

$ swift-format test.swift
swift-format test.swift
@differentiable(wrt:x,vjp:derivativeFoowhere T: Differentiable)
func foo<T>(_ x: T) -> T {
    x
}

@derivative(of:foo,wrt:x)
func derivativeFoo<T>(_ x: T) -> (value: T, pullback: (T.TangentVector) -> T.TangentVector)
where T: Differentiable {
    (x, { $0 })
}

@transpose(of:foo,wrt:0)
func transposeFoo<T: Differentiable>(_ v: T) -> T where T == T.TangentVector {
    v
}

The spaces between attribute arguments is incorrectly removed, e.g. @differentiable(wrt:x,vjp:derivativeFoowhere T: Differentiable).

[SR-12713] Only reformat lines affected by a PR anyway

Previous ID SR-12713
Radar rdar://problem/62895080
Original Reporter @weissi
Type New Feature
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels New Feature
Assignee None
Priority Medium

md5: 865a49d6606d030111060220aa1c8631

Issue Description:

It would be really useful to have a mode where swift-format would only touch lines that are anyway affected + ..... by a given diff already.

That way, gradually reformatting projects without a big-bang-reformat-everything commit that keeps git blame etc working is possible.

[SR-11815] swift-format breaks long #if statements

Previous ID SR-11815
Radar None
Original Reporter SDGGiesbrecht (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee dylansturg (JIRA)
Priority Medium

md5: e60c37c6151823b9b5421744407ba149

Issue Description:

Running swift-format breaks the following by inserting an invalid line break:

#if (canImport(SwiftUI) && !(os(iOS) && arch(arm))) && ((canImport(AppKit) || canImport(UIKit)) && !os(watchOS))
// (↑ This is all one line, despite the browser being allowed to wrap it.)
#endif

#if (canImport(SwiftUI) && !(os(iOS) && arch(arm)))
  && ((canImport(AppKit) || canImport(UIKit)) && !os(watchOS))
// (↑ This is the hard line break produced by swift-format)
#endif

[SR-12948] Spaces removed after argument labels in property wrapper constructors

Previous ID SR-12948
Radar None
Original Reporter mplewis (JIRA User)
Type Bug
Status Resolved
Resolution Invalid
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee None
Priority Medium

md5: 79158f393666f0e36ef55daa255abd3d

Issue Description:

swift-format indicates that the following code should have the space between the argument label and the value removed in the property wrapper constructor:

$ swift format lint
@propertyWrapper
struct Wrapper<Value> {
  var wrappedValue: Value

  enum Configuration {
    case first
    case second
  }

  let configuration: Configuration
}

struct Struct {
  @Wrapper(configuration: .first)
  var data: String = "data"
}

let test = Struct()
^D
<stdin>:14:26: warning: [Spacing]: remove 1 space

Applying the recommended formatting results in the following, which breaks from all other recommendations about spacing in argument labels:

@propertyWrapper
struct Wrapper<Value> {
  var wrappedValue: Value

  enum Configuration {
    case first
    case second
  }

  let configuration: Configuration
}

struct Struct {
  @Wrapper(configuration:.first)
  var data: String = "data"
}

let test = Struct()

[SR-11114] swift-format cannot disable rules

Previous ID SR-11114
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

#1

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: d8b8660b51510341cb92f062638ba0a2

Issue Description:

Currently if you pass a --configuration attempting to disable a rule by setting its value to false in the rules dictionary, it doesn't take effect. AFAICT the rules parameter on the Configuration type is never read, which would explain it.

[SR-11112] swift-format removes space in `case let`

Previous ID SR-11112
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

#1

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: 632356d5c37232a7f10de80438b5ee0a

Issue Description:

With this code:

for case let a as String in [] {
}

swift-format produces:

for caselet a as String in [] {
}

[SR-11290] Break rule for where clause in swift-format

Previous ID SR-11290
Radar None
Original Reporter kitasuke (JIRA User)
Type Improvement
Status Closed
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Improvement
Assignee None
Priority Medium

md5: e99e19192fe6acc686e2c167f7f8e7ae

duplicates:

  • SR-11289 Break rule for generic where clause in swift-format

Issue Description:

I assume this is intended, but I thought where clause for `for` and `case` can have `.break(.continue), .open` tokens instead because it's not consistent with `in` keyword in `ForInStmt` for example.

swift-format produces:

for item
  in aVeryLargeContainterObject
where largeObject
  .hasProperty() && condition
{
...
}

Expected:

for item 
  in aVeryLargeContainterObject 
  where largeObject .hasProperty() && condition 
{
...
}

Submitted my draft PR about my ideas:

#34

[SR-12947] Allow case labels to be indented from switch statements

Previous ID SR-12947
Radar None
Original Reporter mplewis (JIRA User)
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Improvement
Assignee mplewis (JIRA)
Priority Medium

md5: 75bab2eb5d0f0ad2281ecdd54bc269e2

Issue Description:

As Xcode now supports having case labels indented from the corresponding switch statement, it would be nice to have the same option in swift-format.

[SR-12521] swift-format 5.2 branch fails with error "Too many unresolved delmiter token lengths"

Previous ID SR-12521
Radar rdar://problem/62201696
Original Reporter killectro (JIRA User)
Type Bug
Environment

Xcode 11.4

Swift 5.2

Branch: `swift-5.2-branch`

Commit SHA: `1fda39893d3652a9a3f1673565a227f843d59f3c`

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee None
Priority Medium

md5: 1363f6c20f83c269551863c5a4f54343

Issue Description:

I was curious about the current state of the project so I decided to clone it and run it on my work codebase.

Running the swift-format 5.2 branch fails with error "Too many unresolved delmiter token lengths" when run on my current project. I was able to narrow it down to the following minimal example:

Broken:

class Foo {
    init(bar: Int) {}
}

Working:

class Foo {
    init() {}
}

I dug through the swift-format source a little bit but wasn't able to figure out the root of the problem since I am pretty unfamiliar with the structure of how it works.

Bonus bug, delimiter is spelled incorrectly in the error message!

.swift-format:

{
  "maximumBlankLines" : 1,
  "lineLength" : 100,
  "lineBreakAroundMultilineExpressionChainComponents" : true,
  "tabWidth" : 4,
  "prioritizeKeepingFunctionOutputTogether" : true,
  "indentConditionalCompilationBlocks" : true,
  "indentation" : {
    "spaces" : 4
  },
  "respectsExistingLineBreaks" : true,
  "lineBreakBeforeEachArgument" : true
}

[SR-12414] Incorrect formatting for `@differentiable` declaration attribute "wrt" clauses

Previous ID SR-12414
Radar None
Original Reporter @dan-zheng
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: a715cc15a2ef229f7493a748950b47d6

Issue Description:

In @differentiable attribute wrt clauses, spaces after commas are incorrectly dropped.
@differentiable(wrt: (x, y)) is wrongly formatted as @differentiable(wrt: (x,y)).


Test case:

@differentiable(wrt: (x, y))
func topLevelFunction(_ x: Float, _ y: Float) -> Float { x }

struct Struct: Differentiable {
    @differentiable(wrt: (self, x, y))
    func method(_ x: Float, _ y: Float) -> Float { x }
}

Actual formatting:

$ swift-format test.swift
@differentiable(wrt: (x,y))
func topLevelFunction(_ x: Float, _ y: Float) -> Float { x }

struct Struct: Differentiable {
    @differentiable(wrt: (self,x,y))
    func method(_ x: Float, _ y: Float) -> Float { x }
}

Expected formatting: original code is correct.

[SR-11823] swift-format: add option to leave intra-expression spacing as is

Previous ID SR-11823
Radar None
Original Reporter gwk (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Improvement
Assignee None
Priority Medium

md5: dd4f120aec6465bd8fc4e18cfdcd6098

Issue Description:

I just tried swift-format for the first time. I am quite pleased with the results, but there are two cases that I wish I could disable to preserve existing spacing:

  • Multiple spaces following commas between items in a list. For example I have a vertical list of (X,Y,Z) vectors and I have added spacing to make the columns line up. More generally, this can be helpful for visually verifying grid-like patterns in code.
  • Lack of spaces in between operators, e.g. `a*x + b`.

I realize that the project must strike a balance between convention and configuration. Regardless of how the developers feel about these style choices, I hope that you will consider this request on the basis of reducing barriers to entry. If it weren't for these points, then adding swift-format to my workflow would be an obvious improvement. As it is, I feel like I am making a compromise. In any case, thank you for your great work!

[SR-12110] swift-format needs two iterations to format case statement

Previous ID SR-12110
Radar None
Original Reporter @ahoppen
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee dylansturg (JIRA)
Priority Medium

md5: bee69ca008e81899123860c15bee660f

Issue Description:

The following code needs two runs of swift-format to converge at a stable state

switch stmt.item {
case let guardStmt as GuardStmtSyntax
where true && guardStmt.body
  .statements.first!.item is ContinueStmtSyntax:
  break
} 

The first run of swift-format outputs

switch stmt.item {
case let guardStmt as GuardStmtSyntax
where true
  && guardStmt.body
    .statements.first!.item is ContinueStmtSyntax
  :
  break
} 

A second run adjusts the indentation of : to

switch stmt.item {
case let guardStmt as GuardStmtSyntax
where true
  && guardStmt.body
    .statements.first!.item is ContinueStmtSyntax
:
  break
} 

[SR-11211] Crash in WhitespaceLinter.swift, line 58

Previous ID SR-11211
Radar None
Original Reporter @aciidb0mb3r
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

swift-format 79bb590

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee dylansturg (JIRA)
Priority Medium

md5: 28277ce1f6ced9184d7825ca5e5c6948

Issue Description:

The attached file crashes swift-format:

/Users/ankit/workspace/swift.org/swift-format/.build/release/swift-format -m lint main.swift
Fatal error: Characters do not match: file /Users/ankit/workspace/swift.org/swift-format/Sources/SwiftFormatWhitespaceLinter/WhitespaceLinter.swift, line 58
[1]    12858 illegal hardware instruction  /Users/ankit/workspace/swift.org/swift-format/.build/release/swift-format -m
Application Specific Information:
Fatal error: Characters do not match: file /Users/ankit/workspace/swift.org/swift-format/Sources/SwiftFormatWhitespaceLinter/WhitespaceLinter.swift, line 58
 

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libswiftCore.dylib              0x00007fff7a8017d8 specialized _assertionFailure(_:_:file:line:flags:) + 376
1   libswiftCore.dylib              0x00007fff7a5ff859 _assertionFailure(_:_:file:line:flags:) + 25
2   swift-format                    0x00000001052edc7a WhitespaceLinter.lint() + 730
3   swift-format                    0x0000000105225eb5 SwiftLinter.lint(syntax:assumingFileURL:) + 1125 (SwiftLinter.swift:92)
4   swift-format                    0x000000010522593b SwiftLinter.lint(contentsOf:) + 923 (SwiftLinter.swift:57)
5   swift-format                    0x0000000105844652 lintMain(configuration:path:) + 386 (Run.swift:32)
6   swift-format                    0x000000010584782e main(_:) + 2222 (main.swift:41)
7   swift-format                    0x0000000105846f60 main + 32 (main.swift:132)
8   libdyld.dylib                   0x00007fff7ae893d5 start + 1

[SR-11291] Missing space after semicolon in swift-format

Previous ID SR-11291
Radar None
Original Reporter kitasuke (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee kitasuke (JIRA)
Priority Medium

md5: e6227ddc38278f85b9d2182de0f6abbc

Issue Description:

swift-format produces:

func foo() {
  guard !bar else { return };defer { bar = true }
}

Expected:

func foo() { 
  guard !bar else { return }; defer { bar = true } 
}

[SR-11773] UseLetInEveryBoundCaseVariable has false positives

Previous ID SR-11773
Radar rdar://problem/57242761
Original Reporter SDGGiesbrecht (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: a2489a4b198fde114394d4d46b74703d

Issue Description:

case let simple as SimpleTypeIdentifierSyntax:

distribute 'let' to each bound case variable

[SR-11204] swift-format multiline functions with single parameter indentation

Previous ID SR-11204
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

swift-format 79bb590

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: b71c2592856e996e6eaea7b1063d8ac9

Issue Description:

With this code:

someRxThing()
  .do(onSuccess: { result in
    print(result)
  })

swift-format rewrites it to:

someRxThing()
  .do(
    onSuccess: { result in
      print(result)
    })

I would have expected it to leave it the same since the extra newline and indention for a single parameter doesn't seem necessary.

[SR-12111] swift-format needs two iterations to format array element

Previous ID SR-12111
Radar None
Original Reporter @ahoppen
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee dylansturg (JIRA)
Priority Medium

md5: 9d728bc3b3dd6dc0d7f24d1452ffd570

Issue Description:

The following code needs two runs of swift-format to converge at a stable state

extension UseSynthesizedInitializerTests {
    static let __allTests__UseSynthesizedInitializerTests = [
        ("testPublicMemberwiseInitializerIsNotDiagnosed", testPublicMemberwiseInitializerIsNotDiagnosed),
    ]
}

The first run of swift-format outputs

extension UseSynthesizedInitializerTests {
  static let __allTests__UseSynthesizedInitializerTests = [
    ("testPublicMemberwiseInitializerIsNotDiagnosed", testPublicMemberwiseInitializerIsNotDiagnosed
    ),
  ]
}

A second run adjusts the position of ( to

extension UseSynthesizedInitializerTests {
  static let __allTests__UseSynthesizedInitializerTests = [
    (
      "testPublicMemberwiseInitializerIsNotDiagnosed", testPublicMemberwiseInitializerIsNotDiagnosed
    ),
  ]
} 

[SR-12844] Scope-based indentation for if/guard/etc

Previous ID SR-12844
Radar None
Original Reporter freak4pc (JIRA User)
Type New Feature
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels New Feature
Assignee None
Priority Medium

md5: 52ad6d881cad12a71f7111c93476b884

is duplicated by:

  • SR-13187 swift-format formats multiline pattern binding strangely

Issue Description:

Today, both Xcode and swift-format perform the following sort of indentation on multi-line guards and ifs:

guard let thing1 = someThing,
    let thing2 = someThing else {
        // Some indented code
}

This feels extremely asymmetrical and unaesthetic. What would be preferable is formatting this way (or providing a way to do so):

guard let thing1 = someThing,
      let thing2 = someThing else {
    // Some indented code
}

This indents the body of the guard 4-spaces (or whatever is defined) away from the scope itself (the guard) and not the last line which might not be the scope. Also it aligns the different conditions which make up the conditional.

Is that achievable with swift-format? Is there a way to make it easily achievable?

Thank you 🙂

[SR-11798] Scrunching of Range Operators Breaks Code

Previous ID SR-11798
Radar None
Original Reporter SDGGiesbrecht (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

swift-5.1-branch as of 2019‐11‐17

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: 0ba030d617ad8d07c00151cd32d99a3e

Issue Description:

Start with this code:

for _ in 1 ... |x| { /* ... */ }
Int.random(in: 10 ... 1)

Run SwiftFormat once and the operators become conjoined, failing to compile:

for _ in 1...|x| { /* ... */ }
Int.random(in: 10...−1)

Run SwiftFormat again and the spaces are restored, but in the wrong places—it’s still broken:

for _ in 1 ...| x| { /* ... */ }
Int.random(in: 10 ...− 1)

I would expect range operators to be spaced with the same uniformity as every other infix operator, but if the scrunched variant is desired, then it should at least be restricted to the situations where it is actually valid code.

[SR-11110] swift-format moves private extension when it's really fileprivate

Previous ID SR-11110
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

#1

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: 358f531ec146af7e4e65c47264980635

Issue Description:

With this code:

private extension String {
  func foo() {}
}

"".foo()

swift-format produces:

extension String {
  private func foo() {}
}

"".foo()

which fails to compile with:

/tmp/bar.swift:5:4: error: 'foo' is inaccessible due to 'private' protection level
"".foo()
   ^~~
/tmp/bar.swift:2:16: note: 'foo()' declared here
  private func foo() {}
               ^

[SR-11106] swift-format adds newline between array argument

Previous ID SR-11106
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

#1

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: b20905f3b614d63b8ae9c0818416ca4e

Issue Description:

With this code:

NSLayoutConstraint.activate([
    view.centerYAnchor.constraint(equalTo: self.bottomAnchor, constant: 1),
    view.centerXAnchor.constraint(equalTo: self.centerXAnchor),
])

You get:

NSLayoutConstraint.activate(
  [
    view.centerYAnchor.constraint(equalTo: self.bottomAnchor, constant: 1),
    view.centerXAnchor.constraint(equalTo: self.centerXAnchor),
  ])

I would have expected it to leave it the way it was originally

[SR-11289] Break rule for generic where clause in swift-format

Previous ID SR-11289
Radar None
Original Reporter kitasuke (JIRA User)
Type Improvement
Status Closed
Resolution Won't Do
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Improvement
Assignee None
Priority Medium

md5: 5e4d000558f77f1d06c1e68edf21a975

is duplicated by:

  • SR-11290 Break rule for where clause in swift-format

Issue Description:

I assume this is intended, but it would be nice to set `.break(.continue), .open` tokens for `where` keyword instead to follow format of Apple's documentation

https://docs.swift.org/swift-book/LanguageGuide/Generics.html#ID192

Input:

func allItemsMatch<C1: Container, C2: Container>(_ someContainer: C1, _ anotherContainer: C2) where C1.Item == C2.Item, C1.Item: Equatable {}

swift-format produces:

func allItemsMatch<C1: Container, C2: Container>(_ someContainer: C1, _ anotherContainer: C2) 
where C1.Item == C2.Item, C1.Item: Equatable {}

Expected:

func allItemsMatch<C1: Container, C2: Container>(_ someContainer: C1, _ anotherContainer: C2) 
  where C1.Item == C2.Item, C1.Item: Equatable 
{}

Submitted my draft PR about my ideas:
#33

[SR-11167] swift-format missing space in SomeTypeSyntax token

Previous ID SR-11167
Radar None
Original Reporter kitasuke (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

df19306

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee kitasuke (JIRA)
Priority Medium

md5: ae886d9b41fc0b7641b8b7c1e8be2f59

Issue Description:

With this code:

var body: some View
func foo() -> some Foo

swift-format produces:

var body: someView
func foo() -> someFoo

[SR-11111] swift-format converts some classes to enums that are used as classes

Previous ID SR-11111
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

#1

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: d611d9d70f2795e37abf775f89a95d42

Issue Description:

This one might not be fixable with the limited knowledge of a formatter, but if you have this code:

import Foundation

class Thing {
  static var bundle: Bundle {
    return Bundle(for: self)
  }
}

swift-format produces:

import Foundation

enum Thing {
  static var bundle: Bundle {
    return Bundle(for: self)
  }
}

Which fails to compile because:

/tmp/bar.swift:5:24: error: cannot convert value of type 'Thing.Type' to expected argument type 'AnyClass' (aka 'AnyObject.Type')
    return Bundle(for: self)
                       ^~~~
                            as! AnyClass

[SR-11105] swift-format adds extra space in closure with no arguments

Previous ID SR-11105
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

#1

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: 00cf2cea819615172daa8383b29b4475

Issue Description:

If you have this source:

let a = { [weak self] in
    print("hi")
}

swift-format produces:

let a = { [weak self]  in
  print("hi")
}

where there are 2 spaces before `in`

[SR-11170] SyntaxRewriter visitation exhausts the stack space that dispatch threads get

Previous ID SR-11170
Radar None
Original Reporter @tonyarnold
Type Bug
Status Resolved
Resolution Done
Environment

macOS 10.14.5, Xcode 11 beta 4

Additional Detail from JIRA
Votes 0
Component/s swift-format, SwiftSyntax
Labels Bug
Assignee @ahoppen
Priority Medium

md5: 1b490d131fc3f34c23c544d465e9bd6f

Issue Description:

I've been working on putting together an Xcode Source Editor Extension that will allow me to format code from within Xcode using the SwiftFormat library, however when I use essentially the same code to reformat the source as the command line `swift-format` utility, I get a crash in SwiftSyntax, as shown in the backtrace below:

* thread #&#8203;3, queue = 'com.apple.NSXPCConnection.user.16716', stop reason = EXC_BAD_ACCESS (code=2, address=0x70000b360ff8)
    frame #&#8203;0: 0x00000001087ac09b SwiftFormatter`initializeBufferWithCopyOfBuffer for IdentifierPatternSyntax at <compiler-generated>:0
    frame #&#8203;1: 0x0000000108311bf8 SwiftFormatter`outlined init with copy of SyntaxData at <compiler-generated>:0
  * frame #&#8203;2: 0x00000001084e47aa SwiftFormatter`makeSyntax(data=SwiftSyntax.SyntaxData @ 0x000070000b365370) at SyntaxKind.swift:456:15
    frame #&#8203;3: 0x00000001087d3698 SwiftFormatter`closure #&#8203;1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b365418, node=SwiftSyntax.IdentifierPatternSyntax @ 0x00007fea3ed0dbb0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:20
    frame #&#8203;4: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;5: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;6: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
    frame #&#8203;7: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.IdentifierPatternSyntax @ 0x00007fea3ed0db60, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
    frame #&#8203;8: 0x00000001087c275f SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.IdentifierPatternSyntax @ 0x000070000b36fc10, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:862:12
    frame #&#8203;9: 0x00000001087d1af4 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.IdentifierPatternSyntax @ 0x00007fea3ed0dae0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1155:37
    frame #&#8203;10: 0x00000001087d3761 SwiftFormatter`closure #&#8203;1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b370568, node=SwiftSyntax.PatternBindingSyntax @ 0x00007fea3ed0da40, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
    frame #&#8203;11: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;12: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;13: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
    frame #&#8203;14: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.PatternBindingSyntax @ 0x00007fea3ed0d9f0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
    frame #&#8203;15: 0x00000001087bb648 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.PatternBindingSyntax @ 0x000070000b3780e0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:486:12
    frame #&#8203;16: 0x00000001087cbb1a SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.PatternBindingSyntax @ 0x00007fea3ed0d7c0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1061:34
    frame #&#8203;17: 0x00000001087d3761 SwiftFormatter`closure #&#8203;1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b37b658, node=SwiftSyntax.PatternBindingListSyntax @ 0x00007fea3ed0d720, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
    frame #&#8203;18: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;19: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;20: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
    frame #&#8203;21: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.PatternBindingListSyntax @ 0x00007fea3ed0d6d0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
    frame #&#8203;22: 0x00000001087bb748 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.PatternBindingListSyntax @ 0x000070000b383238, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:490:12
    frame #&#8203;23: 0x00000001087cbbe2 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.PatternBindingListSyntax @ 0x00007fea3ed0d8d0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1062:38
    frame #&#8203;24: 0x00000001087d3761 SwiftFormatter`closure #&#8203;1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b386748, node=SwiftSyntax.VariableDeclSyntax @ 0x00007fea3ed0d650, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
    frame #&#8203;25: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;26: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;27: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
    frame #&#8203;28: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.VariableDeclSyntax @ 0x00007fea3ed0d600, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
    frame #&#8203;29: 0x00000001087bb85f SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.VariableDeclSyntax @ 0x000070000b38e3f0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:494:12
    frame #&#8203;30: 0x00000001087cbcaa SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.VariableDeclSyntax @ 0x00007fea3ed0d580, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1063:32
    frame #&#8203;31: 0x00000001087d3761 SwiftFormatter`closure #&#8203;1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b391898, node=SwiftSyntax.MemberDeclListItemSyntax @ 0x00007fea3ed0d0f0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
    frame #&#8203;32: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;33: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;34: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
    frame #&#8203;35: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.MemberDeclListItemSyntax @ 0x00007fea3ed0d0a0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
    frame #&#8203;36: 0x00000001087ba248 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.MemberDeclListItemSyntax @ 0x000070000b398c38, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:418:12
    frame #&#8203;37: 0x00000001087caa48 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.MemberDeclListItemSyntax @ 0x00007fea3ed0d050, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1044:38
    frame #&#8203;38: 0x00000001087d3761 SwiftFormatter`closure #&#8203;1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b39c988, node=SwiftSyntax.MemberDeclListSyntax @ 0x00007fea3ed0cfb0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
    frame #&#8203;39: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;40: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;41: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
    frame #&#8203;42: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.MemberDeclListSyntax @ 0x00007fea3ed0d450, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
    frame #&#8203;43: 0x00000001087ba148 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.MemberDeclListSyntax @ 0x000070000b3a3cc0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:414:12
    frame #&#8203;44: 0x00000001087ca980 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.MemberDeclListSyntax @ 0x00007fea3ed0d3d0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1043:34
    frame #&#8203;45: 0x00000001087d3761 SwiftFormatter`closure #&#8203;1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b3a7a78, node=SwiftSyntax.MemberDeclBlockSyntax @ 0x00007fea3ed0c660, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
    frame #&#8203;46: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;47: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;48: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
    frame #&#8203;49: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.MemberDeclBlockSyntax @ 0x00007fea3ed0cea0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
    frame #&#8203;50: 0x00000001087ba048 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.MemberDeclBlockSyntax @ 0x000070000b3aed48, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:410:12
    frame #&#8203;51: 0x00000001087ca8b8 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.MemberDeclBlockSyntax @ 0x00007fea3ed0d220, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1042:35
    frame #&#8203;52: 0x00000001087d3761 SwiftFormatter`closure #&#8203;1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b3b2b68, node=SwiftSyntax.ClassDeclSyntax @ 0x00007fea3ed0c610, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
    frame #&#8203;53: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;54: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;55: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
    frame #&#8203;56: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.ClassDeclSyntax @ 0x00007fea3ed0c5c0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
    frame #&#8203;57: 0x00000001087b9a5f SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.ClassDeclSyntax @ 0x000070000b3b9c58, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:394:12
    frame #&#8203;58: 0x00000001087ca33c SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.ClassDeclSyntax @ 0x00007fea3ed0c910, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1038:29
    frame #&#8203;59: 0x00000001087d3761 SwiftFormatter`closure #&#8203;1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b3bdcb8, node=SwiftSyntax.CodeBlockItemSyntax @ 0x00007fea3ed0c870, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
    frame #&#8203;60: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;61: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;62: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
    frame #&#8203;63: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.CodeBlockItemSyntax @ 0x00007fea3ed0c7d0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
    frame #&#8203;64: 0x00000001087b2ac8 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.CodeBlockItemSyntax @ 0x000070000b3c2248, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:46:12
    frame #&#8203;65: 0x00000001087c425d SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.CodeBlockItemSyntax @ 0x00007fea3ed0cb90, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:951:33
    frame #&#8203;66: 0x00000001087d3761 SwiftFormatter`closure #&#8203;1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b3c8da8, node=SwiftSyntax.CodeBlockItemListSyntax @ 0x00007fea3ed0c570, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
    frame #&#8203;67: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;68: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;69: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
    frame #&#8203;70: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.CodeBlockItemListSyntax @ 0x00007fea3ed0c520, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
    frame #&#8203;71: 0x00000001087b2bc8 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.CodeBlockItemListSyntax @ 0x000070000b3cd3a0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:50:12
    frame #&#8203;72: 0x00000001087c4325 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.CodeBlockItemListSyntax @ 0x00007fea3ed0c4d0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:952:37
    frame #&#8203;73: 0x00000001087d3761 SwiftFormatter`closure #&#8203;1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b3d3e98, node=SwiftSyntax.SourceFileSyntax @ 0x00007fea3ed0bb80, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
    frame #&#8203;74: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;75: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
    frame #&#8203;76: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
    frame #&#8203;77: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.SourceFileSyntax @ 0x00007fea3ed0b8b0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
    frame #&#8203;78: 0x00000001087ba348 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.SourceFileSyntax @ 0x000070000b3db2a0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:422:12
    frame #&#8203;79: 0x00000001087cab10 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.SourceFileSyntax @ 0x00007fea3ed03420, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1045:30
    frame #&#8203;80: 0x00000001082cd468 SwiftFormatter`FormatPipeline.visit(node=SwiftSyntax.SourceFileSyntax @ 0x00007fea3ed060f0, self=SwiftFormat.FormatPipeline @ 0x000070000b3df878) at Pipelines+Generated.swift:280:48
    frame #&#8203;81: 0x00000001082cf54a SwiftFormatter`SwiftFormatter.format<Output>(syntax=SwiftSyntax.SourceFileSyntax @ 0x000070000b3e00d0, url=Foundation.URL @ 0x000070000b3dfb50, outputStream=<no summary available>, self=0x00007fea88a0b590) at SwiftFormatter.swift:79:38
    frame #&#8203;82: 0x00000001081be67c SwiftFormatter`FormatEntireFileCommand.perform(invocation=0x00007fea5ef00d80, completionHandler=0x00000001081bf360 SwiftFormatter`partial apply forwarder for reabstraction thunk helper from @escaping @callee_unowned @convention(block) (@unowned Swift.Optional<__C.NSError>) -> () to @escaping @callee_guaranteed (@guaranteed Swift.Optional<Swift.Error>) -> () at <compiler-generated>, self=0x00007fea5ef04230) at FormatEntireFileCommand.swift:27:27
    frame #&#8203;83: 0x00000001081bf2fb SwiftFormatter`@objc FormatEntireFileCommand.perform(with:completionHandler:) at <compiler-generated>:0
    frame #&#8203;84: 0x0000000109b80ba1 XcodeKit`-[_XCSourceEditorService performCommandInvocation:commandIdentifier:request:reply:] + 469
    frame #&#8203;85: 0x00007fff3a4b3efb Foundation`__NSXPCCONNECTION_IS_CALLING_OUT_TO_EXPORTED_OBJECT_S4__ + 12
    frame #&#8203;86: 0x00007fff3a458e7f Foundation`-[NSXPCConnection _decodeAndInvokeMessageWithEvent:flags:] + 2499
    frame #&#8203;87: 0x00007fff3a458253 Foundation`message_handler + 215
    frame #&#8203;88: 0x00007fff64350f08 libxpc.dylib`_xpc_connection_call_event_handler + 56
    frame #&#8203;89: 0x00007fff6434ee9e libxpc.dylib`_xpc_connection_mach_event + 933
    frame #&#8203;90: 0x00007fff640cf6dd libdispatch.dylib`_dispatch_client_callout4 + 9
    frame #&#8203;91: 0x00007fff640e40d6 libdispatch.dylib`_dispatch_mach_msg_invoke + 436
    frame #&#8203;92: 0x00007fff640d5792 libdispatch.dylib`_dispatch_lane_serial_drain + 268
    frame #&#8203;93: 0x00007fff640e4c19 libdispatch.dylib`_dispatch_mach_invoke + 481
    frame #&#8203;94: 0x00007fff640d5792 libdispatch.dylib`_dispatch_lane_serial_drain + 268
    frame #&#8203;95: 0x00007fff640d63c6 libdispatch.dylib`_dispatch_lane_invoke + 433
    frame #&#8203;96: 0x00007fff640de6ed libdispatch.dylib`_dispatch_workloop_worker_thread + 598
    frame #&#8203;97: 0x00007fff6430f611 libsystem_pthread.dylib`_pthread_wqthread + 421
    frame #&#8203;98: 0x00007fff6430f3fd libsystem_pthread.dylib`start_wqthread + 13

I've uploaded the current state of the project to https://github.com/tonyarnold/XcodeSwiftFormatter as a reproduction of this crash.

Please let me know if you'd like more detail on anything - I'm happy to help!

[SR-11202] swift-format guard else formatted strangely

Previous ID SR-11202
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

swift-format 79bb590

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: 6981cffa82e2d7073c9b7d9029ccc717

Issue Description:

With this code:

guard let foo = something.long.enough.to.force.multiple.lines,
  let bar = aSecondThing else
{
  return XCTFail("Test assumes idle animation has built-in fallback")
}

Swift-format rewrites it to:

guard let foo = something.long.enough.to.force.multiple.lines,
  let bar = aSecondThing
else
  {
    return XCTFail("Test assumes idle animation has built-in fallback")
}

[SR-12785] swift-format -m lint has zero exit code after identifying style violations

Previous ID SR-12785
Radar None
Original Reporter @tcldr
Type Bug

Attachment: Download

Environment

swift-format swift-5.2-branch
Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)
Target: x86_64-apple-darwin19.4.0

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee None
Priority Medium

md5: 309a6cbb23c057de7ad21f94da974b48

Issue Description:

It seems that swift-format should set a non-zero Xcode when it identifies a style violation.

However, violations are returned with a zero error which may complicate integration with other parts of a build pipeline:

$ swift-format -m lint Test.swift
/Users/tcldr/Desktop/Test.swift:1:1: warning: [Indentation] remove all leading whitespace
/Users/tcldr/Desktop/Test.swift:1:8: warning: [Spacing]: remove 1 space
/Users/tcldr/Desktop/Test.swift:1:18: warning: [Spacing]: remove 3 spaces
$ echo $?
0

[SR-12484] Make trailing comma behavior configurable (again)

Previous ID SR-12484
Radar rdar://problem/62201593
Original Reporter @allevato
Type Bug
Additional Detail from JIRA
Votes 2
Component/s swift-format
Labels Bug
Assignee None
Priority Medium

md5: 87a114148682a4a2db0f13538dd1e622

Issue Description:

When we migrated trailing comma correction to the pretty-printer (#120), we unintentionally lost the ability to disable it.

We should make it configurable again and consider a tri-state: do nothing (keep whatever the user wrote), always remove trailing commas, or always add trailing commas.

[SR-12804] swift-format fails to pick up custom configurations

Previous ID SR-12804
Radar None
Original Reporter @tcldr
Type Bug
Status Closed
Resolution Invalid

Attachment: Download

Environment

swift-format swift-5.2-branch
Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)
Target: x86_64-apple-darwin19.4.0

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee None
Priority Medium

md5: 22c9b59e707798dd0bc5db47b2cb6554

Issue Description:

I've noticed that the only way I can get swift-format to use a custom config is to set the '--configuration' flag explicitly.

My understanding from the docs is that if a file named '.swiftformat' exists within the same directory as the file – or any of its parent directories – swift-format should use that configuration instead.

Example: working In a dir named TestFormat are two files: Test.swift and '.swiftformat'. The '.swiftformat' file has its indentation set to four spaces.

Expected:
When you call `swift-format -r -i .`, Test.swift is formatted with indentation of four spaces.

Actual:
When you call `swift-format -r -i .`, Test.swift is formatted with the default configs indentation of two spaces.

Workaround:
Call `swift-format -r -i --configuration .swiftformat .` specifying the config explicitly instead.

[SR-11830] SwiftFormat suggests turning types with #if‐wrapped properties into enumerations

Previous ID SR-11830
Radar None
Original Reporter SDGGiesbrecht (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee kpa (JIRA)
Priority Medium

md5: 9f8deb0542ab451d59b896ce48e8f474

Issue Description:

When run from Linux (at least), the following warning appears for the given source code.

replace struct 'Structure' with an enum when used as a namespace.

struct Structure {

  // ...

  #if canImport(AppKit)
      var native: NSSomething
  #elseif canImport(UIKit)
      var native: UISomething
  #endif

  // ...

}

I don’t know yet if only uncompiled sections hide members, or if all #if statements do.

[SR-11109] swift-format produces invalid enum

Previous ID SR-11109
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

#1

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: 6d29828b9581bf38687101f2191d82ad

Issue Description:

With this code:

enum Foo: Int {
  case a = 0, b, c, d
}

swift-format produces this:

enum Foo: Int {
  case b, c, d
  case a = 0
}

which fails to compile with:

/tmp/bar.swift:3:12: error: raw value for enum case is not unique
  case a = 0
           ^
/tmp/bar.swift:2:8: note: raw value previously used here
  case b, c, d
       ^
/tmp/bar.swift:2:8: note: raw value implicitly auto-incremented from zero
  case b, c, d
       ^

[SR-11205] swift-format comment after enum case indention

Previous ID SR-11205
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

swift-format 79bb590

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: 4cb38fe526170c507ecde18209fa6464

Issue Description:

With this code:

enum Foo {
  case bar
  // Some comment
}

swift-format indents the comment more:

enum Foo {
  case bar
    // Some comment
}

[SR-11107] swift-format dedents inline comment on multiline conditionals

Previous ID SR-11107
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

#1

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: d89e7fd17aae57c749634be8c4bd8fc2

Issue Description:

If you have this code:

func foo() {
  return true
    // comment
    && false
}

You get:

func foo() {
  return true
  // comment
    && false
}

I expected the comment to stay in the same place

[SR-13011] swift-format doesn't approve of standard SwiftUI Button trailing closure syntax.

Previous ID SR-13011
Radar None
Original Reporter leisurehound (JIRA User)
Type Bug

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee None
Priority Medium

md5: d94a19ff926d1ac4c036ad3673897328

Issue Description:

In SwiftUI examples, Apple demonstrates how to utilize the action & view closures for the Button element with two trailing closures:

Button(action: {
// do something
}) {
  Text("Label")
}

But swift-format will suggest to revise function calling signature to remove multiple trailing closures.

[SR-11293] swift-format crashes on ubuntu 19.04

Previous ID SR-11293
Radar None
Original Reporter cukier (JIRA User)
Type Bug
Environment

ubuntu 19.04

swift in my $PATH
Swift version 5.1-dev (LLVM 8d110eebee, Swift 89382f712a)
Target: x86_64-unknown-linux-gnu

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee None
Priority Medium

md5: aad73f8681deb060cc0a19a6b3c5d9bd

Issue Description:

I cloned swift-format, ran `swift build` and after running `/swift-format/.build/debug/swift-format ./test.swift` I was greeted by

Fatal error: Unexpectedly found nil while unwrapping an Optional value: file /home/cukier/Developer/swift-format/.build/checkouts/swift-syntax/Sources/SwiftSyntax/AtomicCounter.swift, line 42
Current stack trace:
0    libswiftCore.so                    0x00007ff502be8f00 swift_reportError + 50
1    libswiftCore.so                    0x00007ff502c581a0 _swift_stdlib_reportFatalErrorInFile + 115
2    libswiftCore.so                    0x00007ff502b826ee <unavailable> + 3626734
3    libswiftCore.so                    0x00007ff502b82867 <unavailable> + 3627111
4    libswiftCore.so                    0x00007ff50295dccd <unavailable> + 1379533
5    libswiftCore.so                    0x00007ff502b55728 <unavailable> + 3442472
6    libswiftCore.so                    0x00007ff50295d099 <unavailable> + 1376409
7    swift-format                       0x000055abd2842087 <unavailable> + 2969735
8    swift-format                       0x000055abd2841f49 <unavailable> + 2969417
9    libpthread.so.0                    0x00007ff5027c4197 <unavailable> + 70039
10   libswiftCore.so                    0x00007ff502c0a560 swift_once + 102
11   swift-format                       0x000055abd2841f37 <unavailable> + 2969399
12   swift-format                       0x000055abd2841f19 <unavailable> + 2969369
13   swift-format                       0x000055abd28a34af <unavailable> + 3368111
14   swift-format                       0x000055abd28a3442 <unavailable> + 3368002
15   swift-format                       0x000055abd28a4a56 <unavailable> + 3373654
16   swift-format                       0x000055abd28a53bd <unavailable> + 3376061
17   swift-format                       0x000055abd28a80f6 <unavailable> + 3387638
18   swift-format                       0x000055abd28a92b0 <unavailable> + 3392176
19   swift-format                       0x000055abd274879b <unavailable> + 1947547
20   swift-format                       0x000055abd2dd0ed2 <unavailable> + 8797906
21   swift-format                       0x000055abd2dd2bd0 <unavailable> + 8805328
22   swift-format                       0x000055abd2dd2630 <unavailable> + 8803888
23   libc.so.6                          0x00007ff5018faa80 __libc_start_main + 235
24   swift-format                       0x000055abd263b87a <unavailable> + 845946
Illegal instruction (core dumped)

It doesn't happen on macos.

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.