apple / swift-format Goto Github PK
View Code? Open in Web Editor NEWFormatting technology for Swift source code
License: Apache License 2.0
Formatting technology for Swift source code
License: Apache License 2.0
Previous ID | SR-12484 |
Radar | rdar://problem/62201593 |
Original Reporter | @allevato |
Type | Bug |
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.
Previous ID | SR-12521 |
Radar | rdar://problem/62201696 |
Original Reporter | killectro (JIRA User) |
Type | Bug |
Xcode 11.4
Swift 5.2
Branch: `swift-5.2-branch`
Commit SHA: `1fda39893d3652a9a3f1673565a227f843d59f3c`
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
}
Previous ID | SR-11195 |
Radar | None |
Original Reporter | @benlangmuir |
Type | Improvement |
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.
Previous ID | SR-12110 |
Radar | None |
Original Reporter | @ahoppen |
Type | Bug |
Status | Resolved |
Resolution | Done |
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
}
Previous ID | SR-11113 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
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
}
Previous ID | SR-12782 |
Radar | None |
Original Reporter | @tcldr |
Type | Bug |
Status | Resolved |
Resolution | Done |
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
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
Previous ID | SR-11170 |
Radar | None |
Original Reporter | @tonyarnold |
Type | Bug |
Status | Resolved |
Resolution | Done |
macOS 10.14.5, Xcode 11 beta 4
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 #​3, queue = 'com.apple.NSXPCConnection.user.16716', stop reason = EXC_BAD_ACCESS (code=2, address=0x70000b360ff8)
frame #​0: 0x00000001087ac09b SwiftFormatter`initializeBufferWithCopyOfBuffer for IdentifierPatternSyntax at <compiler-generated>:0
frame #​1: 0x0000000108311bf8 SwiftFormatter`outlined init with copy of SyntaxData at <compiler-generated>:0
* frame #​2: 0x00000001084e47aa SwiftFormatter`makeSyntax(data=SwiftSyntax.SyntaxData @ 0x000070000b365370) at SyntaxKind.swift:456:15
frame #​3: 0x00000001087d3698 SwiftFormatter`closure #​1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b365418, node=SwiftSyntax.IdentifierPatternSyntax @ 0x00007fea3ed0dbb0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:20
frame #​4: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​5: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​6: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
frame #​7: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.IdentifierPatternSyntax @ 0x00007fea3ed0db60, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
frame #​8: 0x00000001087c275f SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.IdentifierPatternSyntax @ 0x000070000b36fc10, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:862:12
frame #​9: 0x00000001087d1af4 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.IdentifierPatternSyntax @ 0x00007fea3ed0dae0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1155:37
frame #​10: 0x00000001087d3761 SwiftFormatter`closure #​1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b370568, node=SwiftSyntax.PatternBindingSyntax @ 0x00007fea3ed0da40, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
frame #​11: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​12: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​13: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
frame #​14: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.PatternBindingSyntax @ 0x00007fea3ed0d9f0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
frame #​15: 0x00000001087bb648 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.PatternBindingSyntax @ 0x000070000b3780e0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:486:12
frame #​16: 0x00000001087cbb1a SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.PatternBindingSyntax @ 0x00007fea3ed0d7c0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1061:34
frame #​17: 0x00000001087d3761 SwiftFormatter`closure #​1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b37b658, node=SwiftSyntax.PatternBindingListSyntax @ 0x00007fea3ed0d720, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
frame #​18: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​19: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​20: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
frame #​21: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.PatternBindingListSyntax @ 0x00007fea3ed0d6d0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
frame #​22: 0x00000001087bb748 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.PatternBindingListSyntax @ 0x000070000b383238, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:490:12
frame #​23: 0x00000001087cbbe2 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.PatternBindingListSyntax @ 0x00007fea3ed0d8d0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1062:38
frame #​24: 0x00000001087d3761 SwiftFormatter`closure #​1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b386748, node=SwiftSyntax.VariableDeclSyntax @ 0x00007fea3ed0d650, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
frame #​25: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​26: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​27: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
frame #​28: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.VariableDeclSyntax @ 0x00007fea3ed0d600, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
frame #​29: 0x00000001087bb85f SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.VariableDeclSyntax @ 0x000070000b38e3f0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:494:12
frame #​30: 0x00000001087cbcaa SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.VariableDeclSyntax @ 0x00007fea3ed0d580, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1063:32
frame #​31: 0x00000001087d3761 SwiftFormatter`closure #​1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b391898, node=SwiftSyntax.MemberDeclListItemSyntax @ 0x00007fea3ed0d0f0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
frame #​32: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​33: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​34: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
frame #​35: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.MemberDeclListItemSyntax @ 0x00007fea3ed0d0a0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
frame #​36: 0x00000001087ba248 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.MemberDeclListItemSyntax @ 0x000070000b398c38, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:418:12
frame #​37: 0x00000001087caa48 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.MemberDeclListItemSyntax @ 0x00007fea3ed0d050, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1044:38
frame #​38: 0x00000001087d3761 SwiftFormatter`closure #​1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b39c988, node=SwiftSyntax.MemberDeclListSyntax @ 0x00007fea3ed0cfb0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
frame #​39: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​40: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​41: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
frame #​42: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.MemberDeclListSyntax @ 0x00007fea3ed0d450, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
frame #​43: 0x00000001087ba148 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.MemberDeclListSyntax @ 0x000070000b3a3cc0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:414:12
frame #​44: 0x00000001087ca980 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.MemberDeclListSyntax @ 0x00007fea3ed0d3d0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1043:34
frame #​45: 0x00000001087d3761 SwiftFormatter`closure #​1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b3a7a78, node=SwiftSyntax.MemberDeclBlockSyntax @ 0x00007fea3ed0c660, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
frame #​46: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​47: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​48: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
frame #​49: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.MemberDeclBlockSyntax @ 0x00007fea3ed0cea0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
frame #​50: 0x00000001087ba048 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.MemberDeclBlockSyntax @ 0x000070000b3aed48, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:410:12
frame #​51: 0x00000001087ca8b8 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.MemberDeclBlockSyntax @ 0x00007fea3ed0d220, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1042:35
frame #​52: 0x00000001087d3761 SwiftFormatter`closure #​1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b3b2b68, node=SwiftSyntax.ClassDeclSyntax @ 0x00007fea3ed0c610, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
frame #​53: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​54: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​55: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
frame #​56: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.ClassDeclSyntax @ 0x00007fea3ed0c5c0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
frame #​57: 0x00000001087b9a5f SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.ClassDeclSyntax @ 0x000070000b3b9c58, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:394:12
frame #​58: 0x00000001087ca33c SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.ClassDeclSyntax @ 0x00007fea3ed0c910, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1038:29
frame #​59: 0x00000001087d3761 SwiftFormatter`closure #​1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b3bdcb8, node=SwiftSyntax.CodeBlockItemSyntax @ 0x00007fea3ed0c870, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
frame #​60: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​61: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​62: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
frame #​63: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.CodeBlockItemSyntax @ 0x00007fea3ed0c7d0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
frame #​64: 0x00000001087b2ac8 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.CodeBlockItemSyntax @ 0x000070000b3c2248, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:46:12
frame #​65: 0x00000001087c425d SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.CodeBlockItemSyntax @ 0x00007fea3ed0cb90, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:951:33
frame #​66: 0x00000001087d3761 SwiftFormatter`closure #​1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b3c8da8, node=SwiftSyntax.CodeBlockItemListSyntax @ 0x00007fea3ed0c570, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
frame #​67: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​68: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​69: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
frame #​70: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.CodeBlockItemListSyntax @ 0x00007fea3ed0c520, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
frame #​71: 0x00000001087b2bc8 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.CodeBlockItemListSyntax @ 0x000070000b3cd3a0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:50:12
frame #​72: 0x00000001087c4325 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.CodeBlockItemListSyntax @ 0x00007fea3ed0c4d0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:952:37
frame #​73: 0x00000001087d3761 SwiftFormatter`closure #​1 in SyntaxRewriter.visitChildren(n=(Swift.Optional<SwiftSyntax.RawSyntax>, SwiftSyntax.AbsoluteSyntaxInfo) @ 0x000070000b3d3e98, node=SwiftSyntax.SourceFileSyntax @ 0x00007fea3ed0bb80, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1182:14
frame #​74: 0x00000001087d393d SwiftFormatter`thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​75: 0x00000001087d39b4 SwiftFormatter`partial apply for thunk for @callee_guaranteed (@guaranteed RawSyntax?, @unowned AbsoluteSyntaxInfo) -> (@owned RawSyntax?, @error @owned Error) at <compiler-generated>:0
frame #​76: 0x00007fff639bdc23 libswiftCore.dylib`(extension in Swift):Swift.Sequence.map<A>((A.Element) throws -> A1) throws -> Swift.Array<A1> + 1331
frame #​77: 0x00000001087d2ee4 SwiftFormatter`SyntaxRewriter.visitChildren(nodeS=SwiftSyntax.SourceFileSyntax @ 0x00007fea3ed0b8b0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1177:45
frame #​78: 0x00000001087ba348 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.SourceFileSyntax @ 0x000070000b3db2a0, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:422:12
frame #​79: 0x00000001087cab10 SwiftFormatter`SyntaxRewriter.visit(node=SwiftSyntax.SourceFileSyntax @ 0x00007fea3ed03420, self=0x00007fea3ed019c0) at SyntaxRewriter.swift:1045:30
frame #​80: 0x00000001082cd468 SwiftFormatter`FormatPipeline.visit(node=SwiftSyntax.SourceFileSyntax @ 0x00007fea3ed060f0, self=SwiftFormat.FormatPipeline @ 0x000070000b3df878) at Pipelines+Generated.swift:280:48
frame #​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 #​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 #​83: 0x00000001081bf2fb SwiftFormatter`@objc FormatEntireFileCommand.perform(with:completionHandler:) at <compiler-generated>:0
frame #​84: 0x0000000109b80ba1 XcodeKit`-[_XCSourceEditorService performCommandInvocation:commandIdentifier:request:reply:] + 469
frame #​85: 0x00007fff3a4b3efb Foundation`__NSXPCCONNECTION_IS_CALLING_OUT_TO_EXPORTED_OBJECT_S4__ + 12
frame #​86: 0x00007fff3a458e7f Foundation`-[NSXPCConnection _decodeAndInvokeMessageWithEvent:flags:] + 2499
frame #​87: 0x00007fff3a458253 Foundation`message_handler + 215
frame #​88: 0x00007fff64350f08 libxpc.dylib`_xpc_connection_call_event_handler + 56
frame #​89: 0x00007fff6434ee9e libxpc.dylib`_xpc_connection_mach_event + 933
frame #​90: 0x00007fff640cf6dd libdispatch.dylib`_dispatch_client_callout4 + 9
frame #​91: 0x00007fff640e40d6 libdispatch.dylib`_dispatch_mach_msg_invoke + 436
frame #​92: 0x00007fff640d5792 libdispatch.dylib`_dispatch_lane_serial_drain + 268
frame #​93: 0x00007fff640e4c19 libdispatch.dylib`_dispatch_mach_invoke + 481
frame #​94: 0x00007fff640d5792 libdispatch.dylib`_dispatch_lane_serial_drain + 268
frame #​95: 0x00007fff640d63c6 libdispatch.dylib`_dispatch_lane_invoke + 433
frame #​96: 0x00007fff640de6ed libdispatch.dylib`_dispatch_workloop_worker_thread + 598
frame #​97: 0x00007fff6430f611 libsystem_pthread.dylib`_pthread_wqthread + 421
frame #​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!
Previous ID | SR-11201 |
Radar | None |
Original Reporter | @allevato |
Type | Improvement |
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.
Previous ID | SR-11289 |
Radar | None |
Original Reporter | kitasuke (JIRA User) |
Type | Improvement |
Status | Closed |
Resolution | Won't Do |
Votes | 0 |
Component/s | swift-format |
Labels | Improvement |
Assignee | None |
Priority | Medium |
md5: 5e4d000558f77f1d06c1e68edf21a975
is duplicated by:
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
Previous ID | SR-12360 |
Radar | rdar://problem/60832848 |
Original Reporter | cukier (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
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") } } }
}
Previous ID | SR-11205 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
swift-format 79bb590
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
}
Previous ID | SR-11109 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
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
^
Previous ID | SR-11110 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
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() {}
^
Previous ID | SR-12948 |
Radar | None |
Original Reporter | mplewis (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Invalid |
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()
Previous ID | SR-11291 |
Radar | None |
Original Reporter | kitasuke (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
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 }
}
Previous ID | SR-11169 |
Radar | None |
Original Reporter | kitasuke (JIRA User) |
Type | Improvement |
Status | Resolved |
Resolution | Done |
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?
Previous ID | SR-13011 |
Radar | None |
Original Reporter | leisurehound (JIRA User) |
Type | Bug |
Attachment: Download
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.
Previous ID | SR-11203 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
swift-format 79bb590
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
Previous ID | SR-11293 |
Radar | None |
Original Reporter | cukier (JIRA User) |
Type | Bug |
ubuntu 19.04
swift in my $PATH
Swift version 5.1-dev (LLVM 8d110eebee, Swift 89382f712a)
Target: x86_64-unknown-linux-gnu
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.
Previous ID | SR-11106 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
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
Previous ID | SR-11823 |
Radar | None |
Original Reporter | gwk (JIRA User) |
Type | Improvement |
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:
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!
Previous ID | SR-11206 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
swift-format 79bb590
Votes | 0 |
Component/s | swift-format |
Labels | Bug |
Assignee | @allevato |
Priority | Medium |
md5: c2dcf7cc03d1a9e8fe9a9e23ed845919
Issue Description:
With this code:
foo
.map {
}
swift-format produces:
foo
.map {
}
I would have expected it to leave the `}` aligned with the `.`
Previous ID | SR-11815 |
Radar | None |
Original Reporter | SDGGiesbrecht (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
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
Previous ID | SR-12785 |
Radar | None |
Original Reporter | @tcldr |
Type | Bug |
Attachment: Download
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
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
Previous ID | SR-11211 |
Radar | None |
Original Reporter | @aciidb0mb3r |
Type | Bug |
Status | Resolved |
Resolution | Done |
Attachment: Download
swift-format 79bb590
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
Previous ID | SR-11123 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
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
Previous ID | SR-12414 |
Radar | None |
Original Reporter | @dan-zheng |
Type | Bug |
Status | Resolved |
Resolution | Done |
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.
Previous ID | SR-11111 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
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
Previous ID | SR-11202 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
swift-format 79bb590
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")
}
Previous ID | SR-11772 |
Radar | rdar://problem/57241776 |
Original Reporter | SDGGiesbrecht (JIRA User) |
Type | Bug |
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”
Previous ID | SR-12844 |
Radar | None |
Original Reporter | freak4pc (JIRA User) |
Type | New Feature |
Votes | 0 |
Component/s | swift-format |
Labels | New Feature |
Assignee | None |
Priority | Medium |
md5: 52ad6d881cad12a71f7111c93476b884
is duplicated by:
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 🙂
Previous ID | SR-12947 |
Radar | None |
Original Reporter | mplewis (JIRA User) |
Type | Improvement |
Status | Resolved |
Resolution | Done |
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
.
Previous ID | SR-11290 |
Radar | None |
Original Reporter | kitasuke (JIRA User) |
Type | Improvement |
Status | Closed |
Resolution | Duplicate |
Votes | 0 |
Component/s | swift-format |
Labels | Improvement |
Assignee | None |
Priority | Medium |
md5: e99e19192fe6acc686e2c167f7f8e7ae
duplicates:
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:
Previous ID | SR-11204 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
swift-format 79bb590
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.
Previous ID | SR-11771 |
Radar | rdar://problem/57176570 |
Original Reporter | SDGGiesbrecht (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
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??
Previous ID | SR-12002 |
Radar | None |
Original Reporter | @dan-zheng |
Type | Bug |
Status | Resolved |
Resolution | Done |
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)
.
Previous ID | SR-12111 |
Radar | None |
Original Reporter | @ahoppen |
Type | Bug |
Status | Resolved |
Resolution | Done |
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
),
]
}
Previous ID | SR-11167 |
Radar | None |
Original Reporter | kitasuke (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
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
Previous ID | SR-11105 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
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`
Previous ID | SR-11116 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
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
}
Previous ID | SR-11115 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
Votes | 0 |
Component/s | swift-format |
Labels | Bug |
Assignee | kitasuke (JIRA) |
Priority | Medium |
md5: fe4d8ddce7823ac6780b567ad2544a06
Issue Description:
with this code:
let a, b: Int
swift-format produces:
let a
let b: Int
Previous ID | SR-11773 |
Radar | rdar://problem/57242761 |
Original Reporter | SDGGiesbrecht (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
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
Previous ID | SR-11830 |
Radar | None |
Original Reporter | SDGGiesbrecht (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
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.
Previous ID | SR-12804 |
Radar | None |
Original Reporter | @tcldr |
Type | Bug |
Status | Closed |
Resolution | Invalid |
Attachment: Download
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
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.
Previous ID | SR-11798 |
Radar | None |
Original Reporter | SDGGiesbrecht (JIRA User) |
Type | Bug |
Status | Resolved |
Resolution | Done |
swift-5.1-branch as of 2019‐11‐17
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.
Previous ID | SR-11107 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
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
Previous ID | SR-11112 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
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 [] {
}
Previous ID | SR-12713 |
Radar | rdar://problem/62895080 |
Original Reporter | @weissi |
Type | New Feature |
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.
Previous ID | SR-11114 |
Radar | None |
Original Reporter | @keith |
Type | Bug |
Status | Resolved |
Resolution | Done |
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.
Previous ID | SR-12714 |
Radar | None |
Original Reporter | @weissi |
Type | New Feature |
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.