Skip to content

Balance spacing around = #1694

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

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
changes.append(
FixIt.MultiNodeChange.makePresent(
correctToken,
leadingTrivia: misplacedToken.leadingTrivia,
trailingTrivia: misplacedToken.trailingTrivia
// Transfer any existing trivia. If there is no trivia in the misplaced token, pass `nil` so that `makePresent` can add required trivia, if necessary.
leadingTrivia: misplacedToken.leadingTrivia.isEmpty ? nil : misplacedToken.leadingTrivia,
trailingTrivia: misplacedToken.trailingTrivia.isEmpty ? nil : misplacedToken.trailingTrivia
)
)
} else {
Expand Down Expand Up @@ -978,7 +979,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
fixIts: [
FixIt(
message: ReplaceTokensFixIt(replaceTokens: [.binaryOperator("==")], replacements: [node.equal]),
changes: [.makeMissing(unexpected), .makePresent(node.equal, leadingTrivia: [])]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found two places where we don't need to add trivia

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I suspect there might be a few more as well. Haven’t checked though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to do a quick look, didn't find any

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, maybe there aren’t any more left. Even better. It was just a gut feeling without looking at the code.

changes: [.makeMissing(unexpected), .makePresent(node.equal)]
)
],
handledNodes: [unexpected.id, node.equal.id]
Expand Down Expand Up @@ -1333,7 +1334,7 @@ public class ParseDiagnosticsGenerator: SyntaxAnyVisitor {
node.statements,
.allStatmentsInSwitchMustBeCoveredByCase,
fixIts: [
FixIt(message: InsertTokenFixIt(missingNodes: [Syntax(node.label)]), changes: .makePresent(node.label, leadingTrivia: .newline))
FixIt(message: InsertTokenFixIt(missingNodes: [Syntax(node.label)]), changes: .makePresent(node.label))
],
handledNodes: [node.label.id]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
diagnostics: [
DiagnosticSpec(message: "unexpected initializer in pattern; did you mean to use '='?", fixIts: ["replace ':' with '='"])
],
fixedSource: "let a=[X]()"
fixedSource: "let a = [X]()"
)
}

Expand All @@ -36,7 +36,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
diagnostics: [
DiagnosticSpec(message: "unexpected initializer in pattern; did you mean to use '='?", fixIts: ["replace ':' with '='"])
],
fixedSource: "let b= [X]()"
fixedSource: "let b = [X]()"
)
}

Expand All @@ -48,7 +48,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
diagnostics: [
DiagnosticSpec(message: "unexpected initializer in pattern; did you mean to use '='?", fixIts: ["replace ':' with '='"])
],
fixedSource: "let c =[X]()"
fixedSource: "let c = [X]()"
)
}

Expand All @@ -72,7 +72,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
diagnostics: [
DiagnosticSpec(message: "unexpected initializer in pattern; did you mean to use '='?", fixIts: ["replace ':' with '='"])
],
fixedSource: "let e= X(), ee: Int"
fixedSource: "let e = X(), ee: Int"
)
}

Expand All @@ -84,7 +84,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
diagnostics: [
DiagnosticSpec(message: "unexpected initializer in pattern; did you mean to use '='?", fixIts: ["replace ':' with '='"])
],
fixedSource: "let f=/*comment*/[X]()"
fixedSource: "let f =/*comment*/[X]()"
)
}

Expand All @@ -96,7 +96,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
diagnostics: [
DiagnosticSpec(message: "unexpected initializer in pattern; did you mean to use '='?", fixIts: ["replace ':' with '='"])
],
fixedSource: "let f/*comment*/=[X]()"
fixedSource: "let f/*comment*/ = [X]()"
)
}

Expand Down Expand Up @@ -129,7 +129,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
DiagnosticSpec(message: "unexpected initializer in pattern; did you mean to use '='?", fixIts: ["replace ':' with '='"])
],
fixedSource: """
let g= X(x)
let g = X(x)
"""
)
}
Expand All @@ -143,7 +143,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
DiagnosticSpec(message: "unexpected initializer in pattern; did you mean to use '='?", fixIts: ["replace ':' with '='"])
],
fixedSource: """
let h= X(x, y)
let h = X(x, y)
"""
)
}
Expand All @@ -157,7 +157,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
DiagnosticSpec(message: "unexpected initializer in pattern; did you mean to use '='?", fixIts: ["replace ':' with '='"])
],
fixedSource: """
let i= X() { foo() }
let i = X() { foo() }
"""
)
}
Expand All @@ -171,7 +171,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
DiagnosticSpec(message: "unexpected initializer in pattern; did you mean to use '='?", fixIts: ["replace ':' with '='"])
],
fixedSource: """
let j= X(x) { foo() }
let j = X(x) { foo() }
"""
)
}
Expand All @@ -185,7 +185,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
DiagnosticSpec(message: "unexpected initializer in pattern; did you mean to use '='?", fixIts: ["replace ':' with '='"])
],
fixedSource: """
let k= X(x, y) { foo() }
let k = X(x, y) { foo() }
"""
)
}
Expand All @@ -202,7 +202,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
],
fixedSource: """
func nonTopLevel() {
let a=[X]()
let a = [X]()
}
"""
)
Expand All @@ -220,7 +220,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
],
fixedSource: """
func nonTopLevel() {
let i= X() { foo() }
let i = X() { foo() }
}
"""
)
Expand All @@ -238,7 +238,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
],
fixedSource: """
func nonTopLevel() {
let j= X(x) { foo() }
let j = X(x) { foo() }
}
"""
)
Expand All @@ -256,7 +256,7 @@ final class DiagnoseInitializerAsTypedPatternTests: XCTestCase {
],
fixedSource: """
func nonTopLevel() {
let k= X(x, y) { foo() }
let k = X(x, y) { foo() }
}
"""
)
Expand Down
8 changes: 4 additions & 4 deletions Tests/SwiftParserTest/translated/TypealiasTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ final class TypealiasTests: XCTestCase {
diagnostics: [
DiagnosticSpec(message: "expected '=' in typealias declaration", fixIts: ["replace ':' with '='"])
],
fixedSource: "typealias Foo2= Int"
fixedSource: "typealias Foo2 = Int"
)
}

Expand All @@ -80,7 +80,7 @@ final class TypealiasTests: XCTestCase {
diagnostics: [
DiagnosticSpec(message: "expected '=' in typealias declaration", fixIts: ["replace ':' with '='"])
],
fixedSource: "typealias Foo3 =Int"
fixedSource: "typealias Foo3 = Int"
)
}

Expand All @@ -92,7 +92,7 @@ final class TypealiasTests: XCTestCase {
diagnostics: [
DiagnosticSpec(message: "expected '=' in typealias declaration", fixIts: ["replace ':' with '='"])
],
fixedSource: "typealias Foo4=/*comment*/Int"
fixedSource: "typealias Foo4 =/*comment*/Int"
)
}

Expand Down Expand Up @@ -120,7 +120,7 @@ final class TypealiasTests: XCTestCase {
DiagnosticSpec(locationMarker: "2️⃣", message: "expected type in typealias declaration", fixIts: ["insert type"]),
],
fixedSource: """
typealias Recovery2 =<#type#>
typealias Recovery2 = <#type#>
"""
)
}
Expand Down