Files
SwiftFormat/Sources/Rules/RedundantBackticks.swift
T
2024-11-09 11:26:22 +00:00

24 lines
714 B
Swift

//
// RedundantBackticks.swift
// SwiftFormat
//
// Created by Nick Lockwood on 3/7/17.
// Copyright © 2024 Nick Lockwood. All rights reserved.
//
import Foundation
public extension FormatRule {
/// Remove redundant backticks around non-keywords, or in places where keywords don't need escaping
static let redundantBackticks = FormatRule(
help: "Remove redundant backticks around identifiers."
) { formatter in
formatter.forEach(.identifier) { i, token in
guard token.string.first == "`", !formatter.backticksRequired(at: i) else {
return
}
formatter.replaceToken(at: i, with: .identifier(token.unescaped()))
}
}
}