1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import Foundation
/// Generates the rule registry file used to populate the default configuration.
final class RuleNameCacheGenerator: FileGenerator {
/// The rules collected by scanning the formatter source code.
let ruleCollector: RuleCollector
/// Creates a new rule registry generator.
init(ruleCollector: RuleCollector) {
self.ruleCollector = ruleCollector
}
func write(into handle: FileHandle) throws {
handle.write(
"""
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// This file is automatically generated with generate-swift-format. Do not edit!
/// By default, the `Rule.ruleName` should be the name of the implementing rule type.
@_spi(Testing)
public let ruleNameCache: [ObjectIdentifier: String] = [
"""
)
for detectedRule in ruleCollector.allLinters.sorted(by: { $0.typeName < $1.typeName }) {
handle.write(" ObjectIdentifier(\(detectedRule.typeName).self): \"\(detectedRule.typeName)\",\n")
}
handle.write("]\n")
}
}
|