Skip to content

Commit 6d0df8e

Browse files
hbhabl
hbh
authored andcommitted
Fix lint errors for missing documentation comments.
PiperOrigin-RevId: 194941919
1 parent 935336a commit 6d0df8e

File tree

7 files changed

+48
-14
lines changed

7 files changed

+48
-14
lines changed

tools/swift-format/Sources/Configuration/Configuration.swift

+24-14
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,62 @@ public class Configuration: Codable {
33
/// The version of the configuration; used in case of breaking changes in the future.
44
public let version = 1
55

6-
// MARK: Common configuration
6+
/// MARK: Common configuration
77

88
/// The maximum number of consecutive blank lines that may appear in a file.
99
public let maximumBlankLines = 1
1010

11-
// The width of the horizontal tab in spaces.
12-
// Used when converting indentation type.
11+
/// The width of the horizontal tab in spaces.
12+
/// Used when converting indentation type.
1313
public let tabWidth = 8
1414

15-
// A string that represents a single level of indentation.
16-
// All indentation will be conducted in multiples of this string.
15+
/// A string that represents a single level of indentation.
16+
/// All indentation will be conducted in multiples of this string.
1717
public let indentation = " "
1818

19-
// MARK: Rule-specific configuration
19+
/// MARK: Rule-specific configuration
2020

21+
/// Rules for limiting blank lines between members.
2122
public let blankLineBetweenMembers = BlankLineBetweenMembersConfiguration()
2223

24+
/// Rules for adding backticks around special symbols in documentation comments.
2325
public let surroundSymbolsWithBackticks = SurroundSymbolsWithBackticksConfiguration()
2426

2527
/// Constructs a Configuration with all default values.
2628
public init() {}
2729
}
2830

31+
/// Configuration for the BlankLineBetweenMembers rule.
2932
public struct BlankLineBetweenMembersConfiguration: Codable {
30-
// If true, blank lines are not required between single-line properties.
33+
/// If true, blank lines are not required between single-line properties.
3134
public let ignoreSingleLineProperties = true
3235
}
3336

3437
// TODO(abl): Expand the whitelist and blacklist.
38+
/// Configuration for the SurroundSymbolsWithBackticks rule.
3539
public struct SurroundSymbolsWithBackticksConfiguration: Codable {
36-
// List of global symbols; added to the list of file-local symbols. Case-sensitive.
40+
/// List of global symbols; added to the list of file-local symbols. Case-sensitive.
3741
public let symbolWhitelist = ["String"]
3842

39-
// List of symbols to ignore. Case-sensitive.
43+
/// List of symbols to ignore. Case-sensitive.
4044
public let symbolBlacklist = [
41-
"URL" // symbol name and capitalization is the same as the term.
45+
"URL", // symbol name and capitalization is the same as the term.
4246
]
4347
}
4448

49+
/// Configuration for the NoPlaygroundLiterals rule.
4550
public struct NoPlaygroundLiteralsConfiguration: Codable {
4651
public enum ResolveBehavior: String, Codable {
47-
case useUIColor // if not sure, use `UIColor` to replace `#colorLiteral`
48-
case useNSColor // if not sure, use `NSColor` to replace `#colorLiteral`
49-
case error // if not sure, raise an error
52+
/// If not sure, use `UIColor` to replace `#colorLiteral`.
53+
case useUIColor
54+
55+
/// If not sure, use `NSColor` to replace `#colorLiteral`.
56+
case useNSColor
57+
58+
/// If not sure, raise an error.
59+
case error
5060
}
5161

52-
// Resolution behavior to use when encountering an ambiguous `#colorLiteral`
62+
/// Resolution behavior to use when encountering an ambiguous `#colorLiteral`.
5363
public let resolveAmbiguousColor: ResolveBehavior = .useUIColor
5464
}

tools/swift-format/Sources/Core/Context.swift

+6
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ import SwiftSyntax
77
/// Specifically, it is the container for the shared configuration, diagnostic engine, and URL of
88
/// the current file.
99
public class Context {
10+
/// The configuration for this run of the pipeline, provided by a configuration JSON file.
1011
public let configuration: Configuration
12+
13+
/// The engine in which to emit diagnostics, if running in Lint mode.
1114
public let diagnosticEngine: DiagnosticEngine?
15+
16+
/// The URL of the file being linted or formatted.
1217
public let fileURL: URL
1318

19+
/// Creates a new Context with the provided configuration, diagnostic engine, and file URL.
1420
public init(configuration: Configuration, diagnosticEngine: DiagnosticEngine?, fileURL: URL) {
1521
self.configuration = configuration
1622
self.diagnosticEngine = diagnosticEngine

tools/swift-format/Sources/Core/FileRule.swift

+4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import Configuration
22
import SwiftSyntax
33

4+
/// A linting rule that does not parse the file, but instead runs analyses over the raw text of
5+
/// the file.
46
open class FileRule: Rule {
7+
/// The context in which this rule in run.
58
public let context: Context
69

10+
/// Creates a new FileRule executing in the provided context.
711
public required init(context: Context) {
812
self.context = context
913
}

tools/swift-format/Sources/Core/Rule.swift

+7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
/// A Rule is a linting or formatting pass that executes in a given context.
12
public protocol Rule {
3+
/// The context in which the rule is executed.
24
var context: Context { get }
5+
6+
/// The human-readable name of the rule. This defaults to the class name.
37
var ruleName: String { get }
8+
9+
/// Creates a new Rule in a given context.
410
init(context: Context)
511
}
612

713
private var nameCache = [ObjectIdentifier: String]()
814

915
extension Rule {
16+
/// By default, the `ruleName` is just the name of the implementing rule class.
1017
public var ruleName: String {
1118
let myType = type(of: self)
1219
// TODO(abl): Test and potentially replace with static initialization.

tools/swift-format/Sources/Core/SyntaxFormatRule.swift

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import SwiftSyntax
22

3+
/// A rule that both formats and lints a given file.
34
open class SyntaxFormatRule: SyntaxRewriter, Rule {
5+
/// The context in which the rule is executed.
46
public let context: Context
57

8+
/// Creates a new SyntaxFormatRule in the given context.
69
public required init(context: Context) {
710
self.context = context
811
}

tools/swift-format/Sources/Core/SyntaxLintRule.swift

+3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import SwiftSyntax
22

3+
/// A rule that lints a given file.
34
open class SyntaxLintRule: SyntaxVisitor, Rule {
5+
/// The context in which the rule is executed.
46
public let context: Context
57

8+
/// Creates a new SyntaxLintRule in the given context.
69
public required init(context: Context) {
710
self.context = context
811
}

tools/swift-format/Sources/generate-pipeline/main.swift

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ for baseName in fm.enumerator(atPath: rulesDir.path)! {
8787
}
8888

8989
extension FileHandle: TextOutputStream {
90+
/// Writes the provided string as data to a file output stream.
9091
public func write(_ string: String) {
9192
guard let data = string.data(using: .utf8) else { return }
9293
write(data)

0 commit comments

Comments
 (0)