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

[509] Don't add a space between literals and period in BasicFormat #2348

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/SwiftBasicFormat/BasicFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,11 @@ open class BasicFormat: SyntaxRewriter {
(.rawStringPoundDelimiter, .multilineStringQuote), // opening raw string delimiter should never be separate by a space
(.rawStringPoundDelimiter, .singleQuote), // opening raw string delimiter should never be separate by a space
(.rawStringPoundDelimiter, .stringQuote), // opening raw string delimiter should never be separate by a space
(.rawStringPoundDelimiter, .period), // opening raw string delimiter should never be separate by a space
(.regexLiteralPattern, _),
(.regexPoundDelimiter, .period), // #/myRegex/#.someMember
(.regexSlash, .regexPoundDelimiter), // closing extended regex delimiter should never be separate by a space
(.regexSlash, .period), // /myRegex/.someMember
(.rightAngle, .leftParen), // func foo<T>(x: T)
(.rightAngle, .period), // Foo<T>.bar
(.rightBrace, .leftParen), // { return 1 }()
Expand All @@ -317,6 +320,7 @@ open class BasicFormat: SyntaxRewriter {
(.rightSquare, .period), // myArray[1].someProperty
(.singleQuote, .rawStringPoundDelimiter), // closing raw string delimiter should never be separate by a space
(.stringQuote, .rawStringPoundDelimiter), // closing raw string delimiter should never be separate by a space
(.stringQuote, .period), // "test".lowercased
(.stringSegment, _),
(_, .comma),
(_, .ellipsis),
Expand Down
31 changes: 26 additions & 5 deletions Tests/SwiftBasicFormatTest/BasicFormatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,31 @@ final class BasicFormatTest: XCTestCase {
}
}

func testRightAnglePeriodNotFormatted() {
assertFormatted(
tree: ExprSyntax("Foo<T>.bar"),
expected: "Foo<T>.bar"
)
func testPeriodAfterStringLiteral() {
let source = """
"test".lowercased()
"""
assertFormatted(source: source, expected: source)
}

func testPeriodAfterRawStringLiteral() {
let source = """
#"test"#.lowercased()
"""
assertFormatted(source: source, expected: source)
}

func testPeriodAfterRegexLiteral() {
let source = """
/test/.something
"""
assertFormatted(source: source, expected: source)
}

func testPeriodAfterRawRegexLiteral() {
let source = """
/test/.something
"""
assertFormatted(source: source, expected: source)
}
}