Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private final class TokenStreamCreator: SyntaxVisitor {
arrangeBracesAndContents(of: members, contentsKeyPath: \.members)

if let genericWhereClause = genericWhereClause {
before(genericWhereClause.firstToken, tokens: .break(.same), .open)
before(genericWhereClause.firstToken, tokens: .break(.continue), .open)
after(members.leftBrace, tokens: .close)
}

Expand Down Expand Up @@ -310,7 +310,7 @@ private final class TokenStreamCreator: SyntaxVisitor {
arrangeAttributeList(node.attributes)

if let genericWhereClause = node.genericWhereClause {
before(genericWhereClause.firstToken, tokens: .break(.same), .open)
before(genericWhereClause.firstToken, tokens: .break(.continue), .open)
after(genericWhereClause.lastToken, tokens: .close)
}

Expand Down Expand Up @@ -360,7 +360,7 @@ private final class TokenStreamCreator: SyntaxVisitor {
arrangeBracesAndContents(of: body, contentsKeyPath: bodyContentsKeyPath)

if let genericWhereClause = genericWhereClause {
before(genericWhereClause.firstToken, tokens: .break(.same), .open)
before(genericWhereClause.firstToken, tokens: .break(.continue), .open)
after(body?.leftBrace ?? genericWhereClause.lastToken, tokens: .close)
}

Expand Down Expand Up @@ -1182,7 +1182,7 @@ private final class TokenStreamCreator: SyntaxVisitor {
after(node.typealiasKeyword, tokens: .break)

if let genericWhereClause = node.genericWhereClause {
before(genericWhereClause.firstToken, tokens: .break(.same), .open)
before(genericWhereClause.firstToken, tokens: .break(.continue), .open)
after(node.lastToken, tokens: .close)
}
return .visitChildren
Expand Down Expand Up @@ -1344,7 +1344,7 @@ private final class TokenStreamCreator: SyntaxVisitor {
after(node.associatedtypeKeyword, tokens: .break)

if let genericWhereClause = node.genericWhereClause {
before(genericWhereClause.firstToken, tokens: .break(.same), .open)
before(genericWhereClause.firstToken, tokens: .break(.continue), .open)
after(node.lastToken, tokens: .close)
}
return .visitChildren
Expand Down
16 changes: 9 additions & 7 deletions Tests/SwiftFormatPrettyPrintTests/ClassDeclTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ public class ClassDeclTests: PrettyPrintTestCase {
let B: Double
}
class MyClass<S, T>
where S: Collection, T: ReallyLongClassName {
where S: Collection, T: ReallyLongClassName
{
let A: Int
let B: Double
}
class MyClass<S, T>
where S: Collection, T: ReallyLongClassName,
U: LongerClassName
where S: Collection, T: ReallyLongClassName,
U: LongerClassName
{
let A: Int
let B: Double
Expand Down Expand Up @@ -226,7 +227,8 @@ public class ClassDeclTests: PrettyPrintTestCase {
let B: Double
}
class MyClass<S, T>: SuperOne, SuperTwo
where S: Collection, T: Protocol {
where S: Collection, T: Protocol
{
let A: Int
let B: Double
}
Expand Down Expand Up @@ -301,9 +303,9 @@ public class ClassDeclTests: PrettyPrintTestCase {
>: MyContainerSuperclass, MyContainerProtocol,
SomeoneElsesContainerProtocol,
SomeFrameworkContainerProtocol
where BaseCollection: Collection,
BaseCollection.Element: Equatable,
BaseCollection.Element: SomeOtherProtocol
where BaseCollection: Collection,
BaseCollection.Element: Equatable,
BaseCollection.Element: SomeOtherProtocol
{
let A: Int
let B: Double
Expand Down
16 changes: 9 additions & 7 deletions Tests/SwiftFormatPrettyPrintTests/EnumDeclTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,14 @@ public class EnumDeclTests: PrettyPrintTestCase {
let B: Double
}
enum MyEnum<S, T>
where S: Collection, T: ReallyLongEnumName {
where S: Collection, T: ReallyLongEnumName
{
case firstCase
let B: Double
}
enum MyEnum<S, T>
where S: Collection, T: ReallyLongEnumName,
U: AnotherLongEnum
where S: Collection, T: ReallyLongEnumName,
U: AnotherLongEnum
{
case firstCase
let B: Double
Expand Down Expand Up @@ -305,7 +306,8 @@ public class EnumDeclTests: PrettyPrintTestCase {
let B: Double
}
enum MyEnum<S, T>: ProtoOne, ProtoTwo
where S: Collection, T: Protocol {
where S: Collection, T: Protocol
{
case firstCase
let B: Double
}
Expand Down Expand Up @@ -380,9 +382,9 @@ public class EnumDeclTests: PrettyPrintTestCase {
>: MyContainerProtocolOne, MyContainerProtocolTwo,
SomeoneElsesContainerProtocol,
SomeFrameworkContainerProtocol
where BaseCollection: Collection,
BaseCollection.Element: Equatable,
BaseCollection.Element: SomeOtherProtocol
where BaseCollection: Collection,
BaseCollection.Element: Equatable,
BaseCollection.Element: SomeOtherProtocol
{
case firstCase
let B: Double
Expand Down
16 changes: 9 additions & 7 deletions Tests/SwiftFormatPrettyPrintTests/ExtensionDeclTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ public class ExtensionDeclTests: PrettyPrintTestCase {
let B: Double
}
extension MyExtension
where S: Collection, T: ReallyLongExtensionName {
where S: Collection, T: ReallyLongExtensionName
{
let A: Int
let B: Double
}
extension MyExtension
where S: Collection, T: ReallyLongExtensionName,
U: AnotherLongExtension
where S: Collection, T: ReallyLongExtensionName,
U: AnotherLongExtension
{
let A: Int
let B: Double
Expand Down Expand Up @@ -138,7 +139,8 @@ public class ExtensionDeclTests: PrettyPrintTestCase {
let B: Double
}
extension MyExtension: ProtoOne, ProtoTwo
where S: Collection, T: Protocol {
where S: Collection, T: Protocol
{
let A: Int
let B: Double
}
Expand Down Expand Up @@ -214,9 +216,9 @@ public class ExtensionDeclTests: PrettyPrintTestCase {
MyContainerProtocolTwo,
SomeoneElsesContainerProtocol,
SomeFrameworkContainerProtocol
where BaseCollection: Collection,
BaseCollection.Element: Equatable,
BaseCollection.Element: SomeOtherProtocol
where BaseCollection: Collection,
BaseCollection.Element: Equatable,
BaseCollection.Element: SomeOtherProtocol
{
let A: Int
let B: Double
Expand Down
27 changes: 15 additions & 12 deletions Tests/SwiftFormatPrettyPrintTests/FunctionDeclTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ public class FunctionDeclTests: PrettyPrintTestCase {
public func index<Elements: Collection, Element>(
of element: Element, in collection: Elements
) -> Elements.Index?
where Elements.Element == Element {
where Elements.Element == Element
{
let a = 123
let b = "abc"
}
Expand All @@ -305,8 +306,8 @@ public class FunctionDeclTests: PrettyPrintTestCase {
of element: Element,
in collection: Elements
) -> Elements.Index?
where Elements.Element == Element,
Element: Equatable
where Elements.Element == Element,
Element: Equatable
{
let a = 123
let b = "abc"
Expand Down Expand Up @@ -466,9 +467,10 @@ public class FunctionDeclTests: PrettyPrintTestCase {
of element: Element,
in collection: Elements
) -> Elements.Index?
where
Elements.Element == Element,
Element: Equatable
where
Elements.Element
== Element,
Element: Equatable
{
let a = 123
let b = "abc"
Expand Down Expand Up @@ -600,11 +602,12 @@ public class FunctionDeclTests: PrettyPrintTestCase {
"""
func name<R>(_ x: Int)
throws -> R
where Foo == Bar
where Foo == Bar

func name<R>(_ x: Int)
throws -> R
where Foo == Bar {
where Foo == Bar
{
statement
statement
}
Expand All @@ -626,13 +629,13 @@ public class FunctionDeclTests: PrettyPrintTestCase {
"""
func name<R>(_ x: Int)
throws -> R
where
Fooooooo == Barrrrr
where
Fooooooo == Barrrrr

func name<R>(_ x: Int)
throws -> R
where
Fooooooo == Barrrrr
where
Fooooooo == Barrrrr
{
statement
statement
Expand Down
8 changes: 4 additions & 4 deletions Tests/SwiftFormatPrettyPrintTests/InitializerDeclTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ public class InitializerDeclTests: PrettyPrintTestCase {
public init<Elements: Collection, Element>(
element: Element, in collection: Elements
)
where Elements.Element == Element,
Element: Equatable
where Elements.Element == Element,
Element: Equatable
{
let a = 123
let b = "abc"
Expand Down Expand Up @@ -312,8 +312,8 @@ public class InitializerDeclTests: PrettyPrintTestCase {
element: Element,
in collection: Elements
)
where Elements.Element == Element,
Element: Equatable
where Elements.Element == Element,
Element: Equatable
{
let a = 123
let b = "abc"
Expand Down
16 changes: 9 additions & 7 deletions Tests/SwiftFormatPrettyPrintTests/StructDeclTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ public class StructDeclTests: PrettyPrintTestCase {
let B: Double
}
struct MyStruct<S, T>
where S: Collection, T: ReallyLongStructName {
where S: Collection, T: ReallyLongStructName
{
let A: Int
let B: Double
}
struct MyStruct<S, T>
where S: Collection, T: ReallyLongStructName,
U: AnotherLongStruct
where S: Collection, T: ReallyLongStructName,
U: AnotherLongStruct
{
let A: Int
let B: Double
Expand Down Expand Up @@ -226,7 +227,8 @@ public class StructDeclTests: PrettyPrintTestCase {
let B: Double
}
struct MyStruct<S, T>: ProtoOne, ProtoTwo
where S: Collection, T: Protocol {
where S: Collection, T: Protocol
{
let A: Int
let B: Double
}
Expand Down Expand Up @@ -301,9 +303,9 @@ public class StructDeclTests: PrettyPrintTestCase {
>: MyContainerProtocolOne, MyContainerProtocolTwo,
SomeoneElsesContainerProtocol,
SomeFrameworkContainerProtocol
where BaseCollection: Collection,
BaseCollection.Element: Equatable,
BaseCollection.Element: SomeOtherProtocol
where BaseCollection: Collection,
BaseCollection.Element: Equatable,
BaseCollection.Element: SomeOtherProtocol
{
let A: Int
let B: Double
Expand Down
12 changes: 6 additions & 6 deletions Tests/SwiftFormatPrettyPrintTests/SubscriptDeclTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ public class SubscriptDeclTests: PrettyPrintTestCase {
subscript<Elements: Collection, Element>(
var1: Element, var2: Elements
) -> Double
where Elements.Element == Element,
Element: Equatable
where Elements.Element == Element,
Element: Equatable
{
return 1.23
}
Expand Down Expand Up @@ -248,10 +248,10 @@ public class SubscriptDeclTests: PrettyPrintTestCase {
var1: Element,
var2: ManyElements
) -> ManyElements.Index?
where
ManyElements.Element
== Element,
Element: Equatable
where
ManyElements.Element
== Element,
Element: Equatable
{
get {
let out = vals[var1][var2]
Expand Down