diff --git a/Sources/Tokenizer.swift b/Sources/Tokenizer.swift index d85ae1c66..d2a327567 100644 --- a/Sources/Tokenizer.swift +++ b/Sources/Tokenizer.swift @@ -1756,7 +1756,12 @@ public func tokenize(_ source: String) -> [Token] { case "case": if let keywordIndex = index(of: .keyword, before: scopeIndex) { var keyword = tokens[keywordIndex] - if case .keyword("where") = keyword, + if keyword == .keyword("where"), + let keywordIndex = index(of: .keyword, before: keywordIndex) + { + keyword = tokens[keywordIndex] + } + if keyword.isAttribute, let keywordIndex = index(of: .keyword, before: keywordIndex) { keyword = tokens[keywordIndex] diff --git a/Tests/RulesTests+Spacing.swift b/Tests/RulesTests+Spacing.swift index 61db126ac..281d1d822 100644 --- a/Tests/RulesTests+Spacing.swift +++ b/Tests/RulesTests+Spacing.swift @@ -62,6 +62,15 @@ class SpacingTests: RulesTests { testFormatting(for: input, rule: FormatRules.spaceAroundParens) } + func testSpaceBetweenUncheckedAndSendable() { + let input = """ + enum Foo: @unchecked Sendable { + case bar + } + """ + testFormatting(for: input, rule: FormatRules.spaceAroundParens) + } + func testSpaceBetweenParenAndAs() { let input = "(foo.bar) as? String" testFormatting(for: input, rule: FormatRules.spaceAroundParens, exclude: ["redundantParens"]) diff --git a/Tests/TokenizerTests.swift b/Tests/TokenizerTests.swift index cfa0ce777..350828433 100644 --- a/Tests/TokenizerTests.swift +++ b/Tests/TokenizerTests.swift @@ -3935,6 +3935,29 @@ class TokenizerTests: XCTestCase { XCTAssertEqual(tokenize(input), output) } + func testUncheckedSendableEnum() { + let input = "enum Foo: @unchecked Sendable { case bar }" + let output: [Token] = [ + .keyword("enum"), + .space(" "), + .identifier("Foo"), + .delimiter(":"), + .space(" "), + .keyword("@unchecked"), + .space(" "), + .identifier("Sendable"), + .space(" "), + .startOfScope("{"), + .space(" "), + .keyword("case"), + .space(" "), + .identifier("bar"), + .space(" "), + .endOfScope("}"), + ] + XCTAssertEqual(tokenize(input), output) + } + // MARK: dot prefix func testEnumValueInDictionaryLiteral() {