mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
39 lines
1018 B
Swift
39 lines
1018 B
Swift
//
|
|
// SpaceInsideParens.swift
|
|
// SwiftFormat
|
|
//
|
|
// Created by Nick Lockwood on 8/22/16.
|
|
// Copyright © 2024 Nick Lockwood. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public extension FormatRule {
|
|
/// Remove space immediately inside parens
|
|
static let spaceInsideParens = FormatRule(
|
|
help: "Remove space inside parentheses."
|
|
) { formatter in
|
|
formatter.forEach(.startOfScope("(")) { i, _ in
|
|
if formatter.token(at: i + 1)?.isSpace == true,
|
|
formatter.token(at: i + 2)?.isComment == false
|
|
{
|
|
formatter.removeToken(at: i + 1)
|
|
}
|
|
}
|
|
formatter.forEach(.endOfScope(")")) { i, _ in
|
|
if formatter.token(at: i - 1)?.isSpace == true,
|
|
formatter.token(at: i - 2)?.isCommentOrLinebreak == false
|
|
{
|
|
formatter.removeToken(at: i - 1)
|
|
}
|
|
}
|
|
} examples: {
|
|
"""
|
|
```diff
|
|
- ( a, b)
|
|
+ (a, b)
|
|
```
|
|
"""
|
|
}
|
|
}
|