mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-05-17 10:30:35 +00:00
32 lines
813 B
Swift
32 lines
813 B
Swift
//
|
|
// SpaceAroundGenerics.swift
|
|
// SwiftFormat
|
|
//
|
|
// Created by Nick Lockwood on 8/22/16.
|
|
// Copyright © 2024 Nick Lockwood. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public extension FormatRule {
|
|
/// Ensure there is no space between an opening chevron and the preceding identifier
|
|
static let spaceAroundGenerics = FormatRule(
|
|
help: "Remove space around angle brackets."
|
|
) { formatter in
|
|
formatter.forEach(.startOfScope("<")) { i, _ in
|
|
if formatter.token(at: i - 1)?.isSpace == true,
|
|
formatter.token(at: i - 2)?.isIdentifierOrKeyword == true
|
|
{
|
|
formatter.removeToken(at: i - 1)
|
|
}
|
|
}
|
|
} examples: {
|
|
"""
|
|
```diff
|
|
- Foo <Bar> ()
|
|
+ Foo<Bar>()
|
|
```
|
|
"""
|
|
}
|
|
}
|