From 112174aad8cabcb4cad108c56e93ebf8a6e1eb48 Mon Sep 17 00:00:00 2001 From: Cal Stephens Date: Tue, 10 Dec 2024 10:28:30 -0800 Subject: [PATCH] Update emptyExtensions rule to support @retroactive extensions (#1943) --- Sources/ParsingHelpers.swift | 8 +++++--- Tests/Rules/EmptyExtensionsTests.swift | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/ParsingHelpers.swift b/Sources/ParsingHelpers.swift index 17fb7e3b8..2478d8fff 100644 --- a/Sources/ParsingHelpers.swift +++ b/Sources/ParsingHelpers.swift @@ -1271,8 +1271,10 @@ extension Formatter { /// - `some ...` /// - `borrowing ...` /// - `consuming ...` + /// - `sending ...` /// - `@escaping ...` /// - `@unchecked ...` + /// - `@retroactive ...` /// - `~...` /// - `(type).(type)` /// - `(type) & (type)` @@ -1386,9 +1388,9 @@ extension Formatter { return (name: tokens[typeRange].stringExcludingLinebreaks, range: typeRange) } - // Parse types of the form `any ...`, `some ...`, `borrowing ...`, `consuming ...`, - // `@unchecked ...`, `@escaping ...`, `~...`, - let typePrefixes = Set(["any", "some", "borrowing", "consuming", "@unchecked", "@escaping", "~"]) + // Parse types of the form `any ...`, `some ...`, `borrowing ...`, `consuming ...`, `sending ...`, + // `@unchecked ...`, `@escaping ...`, `~...`, `@retroactive ...`, + let typePrefixes = Set(["any", "some", "borrowing", "consuming", "sending", "@unchecked", "@escaping", "~", "@retroactive"]) if typePrefixes.contains(startToken.string), let nextToken = index(of: .nonSpaceOrCommentOrLinebreak, after: startOfTypeIndex), let followingType = parseType(at: nextToken) diff --git a/Tests/Rules/EmptyExtensionsTests.swift b/Tests/Rules/EmptyExtensionsTests.swift index 2abdb72f2..a51900a6f 100644 --- a/Tests/Rules/EmptyExtensionsTests.swift +++ b/Tests/Rules/EmptyExtensionsTests.swift @@ -35,6 +35,9 @@ class EmptyExtensionsTests: XCTestCase { func testDoNotRemoveEmptyConformingExtension() { let input = """ extension String: Equatable {} + extension Foo: @unchecked Sendable {} + extension Bar: @retroactive @unchecked Sendable {} + extension Module.Bar: @retroactive @unchecked Swift.Sendable {} """ testFormatting(for: input, rule: .emptyExtensions) }