Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update emptyExtensions rule to support @retroactive extensions (#1943)
Browse files Browse the repository at this point in the history
calda authored and nicklockwood committed Dec 22, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 53fade9 commit d19eb56
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
@@ -1264,8 +1264,10 @@ extension Formatter {
/// - `some ...`
/// - `borrowing ...`
/// - `consuming ...`
/// - `sending ...`
/// - `@escaping ...`
/// - `@unchecked ...`
/// - `@retroactive ...`
/// - `~...`
/// - `(type).(type)`
/// - `(type) & (type)`
@@ -1379,9 +1381,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)
3 changes: 3 additions & 0 deletions Tests/Rules/EmptyExtensionsTests.swift
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit d19eb56

Please sign in to comment.