mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-05-17 10:30:35 +00:00
Remove spaces around :: module selection operator in spaceAroundOperators (#2402)
Co-authored-by: calda <1811727+calda@users.noreply.github.com>
This commit is contained in:
@@ -44,6 +44,13 @@ public extension FormatRule {
|
||||
{
|
||||
formatter.insert(.space(" "), at: i + 1)
|
||||
}
|
||||
case .operator("::", _):
|
||||
if formatter.token(at: i + 1)?.isSpace == true {
|
||||
formatter.removeToken(at: i + 1)
|
||||
}
|
||||
if formatter.token(at: i - 1)?.isSpace == true {
|
||||
formatter.removeToken(at: i - 1)
|
||||
}
|
||||
case .operator(".", _):
|
||||
if formatter.token(at: i + 1)?.isSpace == true {
|
||||
formatter.removeToken(at: i + 1)
|
||||
|
||||
@@ -1170,4 +1170,28 @@ final class SpaceAroundOperatorsTests: XCTestCase {
|
||||
options: options
|
||||
)
|
||||
}
|
||||
|
||||
func testNoSpaceAroundDoubleColonOperator() {
|
||||
let input = """
|
||||
let x = Module::TypeName
|
||||
"""
|
||||
testFormatting(for: input, rule: .spaceAroundOperators)
|
||||
}
|
||||
|
||||
func testSpaceRemovedAroundDoubleColonOperator() {
|
||||
let input = """
|
||||
let x = Module :: TypeName
|
||||
"""
|
||||
let output = """
|
||||
let x = Module::TypeName
|
||||
"""
|
||||
testFormatting(for: input, output, rule: .spaceAroundOperators)
|
||||
}
|
||||
|
||||
func testNoSpaceAroundDoubleColonInMemberAccess() {
|
||||
let input = """
|
||||
let x = foo.Module::functionName()
|
||||
"""
|
||||
testFormatting(for: input, rule: .spaceAroundOperators)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -839,18 +839,12 @@ final class WrapTests: XCTestCase {
|
||||
let input = """
|
||||
NationalAeronauticsAndSpaceAdministration::RocketEngine
|
||||
"""
|
||||
// wrap-only output (no spaceAroundOperators)
|
||||
let output = """
|
||||
NationalAeronauticsAndSpaceAdministration
|
||||
::RocketEngine
|
||||
"""
|
||||
// all-rules output (spaceAroundOperators adds space after ::)
|
||||
let output2 = """
|
||||
NationalAeronauticsAndSpaceAdministration
|
||||
:: RocketEngine
|
||||
"""
|
||||
let options = FormatOptions(maxWidth: 50)
|
||||
testFormatting(for: input, [output, output2], rules: [.wrap], options: options)
|
||||
testFormatting(for: input, output, rule: .wrap, options: options)
|
||||
}
|
||||
|
||||
func testWrapDoubleColonWithSpacesBreaksBeforeOperator() {
|
||||
@@ -861,7 +855,11 @@ final class WrapTests: XCTestCase {
|
||||
NationalAeronauticsAndSpaceAdministration
|
||||
:: RocketEngine
|
||||
"""
|
||||
let output2 = """
|
||||
NationalAeronauticsAndSpaceAdministration
|
||||
::RocketEngine
|
||||
"""
|
||||
let options = FormatOptions(maxWidth: 50)
|
||||
testFormatting(for: input, output, rule: .wrap, options: options)
|
||||
testFormatting(for: input, [output, output2], rules: [.wrap], options: options)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user