Skip to content

Commit

Permalink
Update emptyExtensions rule to support @retroactive extensions (#1943)
Browse files Browse the repository at this point in the history
  • Loading branch information
calda authored and nicklockwood committed Dec 22, 2024
1 parent 332e1cd commit 112174a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Sources/ParsingHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1271,8 +1271,10 @@ extension Formatter {
/// - `some ...`
/// - `borrowing ...`
/// - `consuming ...`
/// - `sending ...`
/// - `@escaping ...`
/// - `@unchecked ...`
/// - `@retroactive ...`
/// - `~...`
/// - `(type).(type)`
/// - `(type) & (type)`
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions Tests/Rules/EmptyExtensionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 112174a

Please sign in to comment.