nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.62k stars 623 forks source link

Add "~" to the allowed operators in generic scopes #1702

Closed Jnosh closed 1 month ago

Jnosh commented 1 month ago

~ is used in generic scopes to suppress conformances (SE-0427).

func foo<T: ~Copyable>() {}

This ensures generic scopes containing ~ are parsed as generic scopes, otherwise the < and >are interpreted as operators.

I added a basic tokenizer test and some tests for the spaceAroundOperators rule for cases that incorrectly add space around < and > without this change. Feel free to let me know if there are other tests I should add as well.

It probably makes sense to hold off on merging this until SE-0427 has been accepted.