mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-05-17 10:30:35 +00:00
24 lines
714 B
Swift
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()))
|
|
}
|
|
}
|
|
}
|