Skip to content

Commit 0ddb4c0

Browse files
committed
Move syntax tree lint/format rules into @_spi(Rules).
1 parent 615c2bc commit 0ddb4c0

File tree

74 files changed

+128
-37
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+128
-37
lines changed

Sources/SwiftFormat/Rules/AllPublicDeclarationsHaveDocumentation.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import SwiftSyntax
1515
/// All public or open declarations must have a top-level documentation comment.
1616
///
1717
/// Lint: If a public declaration is missing a documentation comment, a lint error is raised.
18+
@_spi(Rules)
1819
public final class AllPublicDeclarationsHaveDocumentation: SyntaxLintRule {
1920

2021
/// Identifies this rule as being opt-in. While docs on most public declarations are beneficial,
@@ -86,6 +87,7 @@ public final class AllPublicDeclarationsHaveDocumentation: SyntaxLintRule {
8687
}
8788

8889
extension Finding.Message {
90+
@_spi(Rules)
8991
public static func declRequiresComment(_ name: String) -> Finding.Message {
9092
"add a documentation comment for '\(name)'"
9193
}

Sources/SwiftFormat/Rules/AlwaysUseLowerCamelCase.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import SwiftSyntax
2020
///
2121
/// Lint: If an identifier contains underscores or begins with a capital letter, a lint error is
2222
/// raised.
23+
@_spi(Rules)
2324
public final class AlwaysUseLowerCamelCase: SyntaxLintRule {
2425
/// Stores function decls that are test cases.
2526
private var testCaseFuncs = Set<FunctionDeclSyntax>()
@@ -213,6 +214,7 @@ extension ReturnClauseSyntax {
213214
}
214215

215216
extension Finding.Message {
217+
@_spi(Rules)
216218
public static func nameMustBeLowerCamelCase(
217219
_ name: String, description: String
218220
) -> Finding.Message {

Sources/SwiftFormat/Rules/AmbiguousTrailingClosureOverload.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import SwiftSyntax
1616
///
1717
/// Lint: If two overloaded functions with one closure parameter appear in the same scope, a lint
1818
/// error is raised.
19+
@_spi(Rules)
1920
public final class AmbiguousTrailingClosureOverload: SyntaxLintRule {
2021

2122
private func diagnoseBadOverloads(_ overloads: [String: [FunctionDeclSyntax]]) {
@@ -72,10 +73,12 @@ public final class AmbiguousTrailingClosureOverload: SyntaxLintRule {
7273
}
7374

7475
extension Finding.Message {
76+
@_spi(Rules)
7577
public static func ambiguousTrailingClosureOverload(_ decl: String) -> Finding.Message {
7678
"rename '\(decl)' so it is no longer ambiguous when called with a trailing closure"
7779
}
7880

81+
@_spi(Rules)
7982
public static func otherAmbiguousOverloadHere(_ decl: String) -> Finding.Message {
8083
"ambiguous overload '\(decl)' is here"
8184
}

Sources/SwiftFormat/Rules/BeginDocumentationCommentWithOneLineSummary.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import SwiftSyntax
1616
/// All documentation comments must begin with a one-line summary of the declaration.
1717
///
1818
/// Lint: If a comment does not begin with a single-line summary, a lint error is raised.
19+
@_spi(Rules)
1920
public final class BeginDocumentationCommentWithOneLineSummary: SyntaxLintRule {
2021

2122
/// Unit tests can testably import this module and set this to true in order to force the rule
@@ -194,12 +195,14 @@ public final class BeginDocumentationCommentWithOneLineSummary: SyntaxLintRule {
194195
}
195196

196197
extension Finding.Message {
198+
@_spi(Rules)
197199
public static func terminateSentenceWithPeriod<Sentence: StringProtocol>(_ text: Sentence)
198200
-> Finding.Message
199201
{
200202
"terminate this sentence with a period: \"\(text)\""
201203
}
202204

205+
@_spi(Rules)
203206
public static func addBlankLineAfterFirstSentence<Sentence: StringProtocol>(_ text: Sentence)
204207
-> Finding.Message
205208
{

Sources/SwiftFormat/Rules/DoNotUseSemicolons.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import SwiftSyntax
1717
/// Lint: If a semicolon appears anywhere, a lint error is raised.
1818
///
1919
/// Format: All semicolons will be replaced with line breaks.
20+
@_spi(Rules)
2021
public final class DoNotUseSemicolons: SyntaxFormatRule {
2122

2223
/// Creates a new version of the given node which doesn't contain any semicolons. The node's
@@ -102,8 +103,10 @@ public final class DoNotUseSemicolons: SyntaxFormatRule {
102103
}
103104

104105
extension Finding.Message {
106+
@_spi(Rules)
105107
public static let removeSemicolon: Finding.Message = "remove ';'"
106108

109+
@_spi(Rules)
107110
public static let removeSemicolonAndMove: Finding.Message =
108111
"remove ';' and move the next statement to a new line"
109112
}

Sources/SwiftFormat/Rules/DontRepeatTypeInStaticProperties.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import SwiftSyntax
1919
/// `public class var redColor: UIColor` would trigger this rule.
2020
///
2121
/// Lint: Static properties of a type that return that type will yield a lint error.
22+
@_spi(Rules)
2223
public final class DontRepeatTypeInStaticProperties: SyntaxLintRule {
2324

2425
public override func visit(_ node: ClassDeclSyntax) -> SyntaxVisitorContinueKind {
@@ -101,6 +102,7 @@ public final class DontRepeatTypeInStaticProperties: SyntaxLintRule {
101102
}
102103

103104
extension Finding.Message {
105+
@_spi(Rules)
104106
public static func removeTypeFromName(name: String, type: Substring) -> Finding.Message {
105107
"remove the suffix '\(type)' from the name of the variable '\(name)'"
106108
}

Sources/SwiftFormat/Rules/FileScopedDeclarationPrivacy.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import SwiftSyntax
2020
///
2121
/// Format: File-scoped declarations that have formal access opposite to the desired access level in
2222
/// the formatter's configuration will have their access level changed.
23+
@_spi(Rules)
2324
public final class FileScopedDeclarationPrivacy: SyntaxFormatRule {
2425
public override func visit(_ node: SourceFileSyntax) -> SourceFileSyntax {
2526
let newStatements = rewrittenCodeBlockItems(node.statements)
@@ -169,9 +170,11 @@ public final class FileScopedDeclarationPrivacy: SyntaxFormatRule {
169170
}
170171

171172
extension Finding.Message {
173+
@_spi(Rules)
172174
public static let replacePrivateWithFileprivate: Finding.Message =
173175
"replace 'private' with 'fileprivate' on file-scoped declarations"
174176

177+
@_spi(Rules)
175178
public static let replaceFileprivateWithPrivate: Finding.Message =
176179
"replace 'fileprivate' with 'private' on file-scoped declarations"
177180
}

Sources/SwiftFormat/Rules/FullyIndirectEnum.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import SwiftSyntax
1919
///
2020
/// Format: Enums where all cases are `indirect` will be rewritten such that the enum is marked
2121
/// `indirect`, and each case is not.
22+
@_spi(Rules)
2223
public final class FullyIndirectEnum: SyntaxFormatRule {
2324

2425
public override func visit(_ node: EnumDeclSyntax) -> DeclSyntax {
@@ -109,6 +110,7 @@ public final class FullyIndirectEnum: SyntaxFormatRule {
109110
}
110111

111112
extension Finding.Message {
113+
@_spi(Rules)
112114
public static func moveIndirectKeywordToEnumDecl(name: String) -> Finding.Message {
113115
"move 'indirect' before the enum declaration '\(name)' when all cases are indirect"
114116
}

Sources/SwiftFormat/Rules/GroupNumericLiterals.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import SwiftSyntax
2424
/// TODO: Minimum numeric literal length bounds and numeric groupings have been selected arbitrarily;
2525
/// these could be reevaluated.
2626
/// TODO: Handle floating point literals.
27+
@_spi(Rules)
2728
public final class GroupNumericLiterals: SyntaxFormatRule {
2829
public override func visit(_ node: IntegerLiteralExprSyntax) -> ExprSyntax {
2930
var originalDigits = node.literal.text
@@ -82,6 +83,7 @@ public final class GroupNumericLiterals: SyntaxFormatRule {
8283
}
8384

8485
extension Finding.Message {
86+
@_spi(Rules)
8587
public static func groupNumericLiteral(every stride: Int) -> Finding.Message {
8688
let ending = stride == 3 ? "rd" : "th"
8789
return "group numeric literal using '_' every \(stride)\(ending) number"

Sources/SwiftFormat/Rules/IdentifiersMustBeASCII.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import SwiftSyntax
1515
/// All identifiers must be ASCII.
1616
///
1717
/// Lint: If an identifier contains non-ASCII characters, a lint error is raised.
18+
@_spi(Rules)
1819
public final class IdentifiersMustBeASCII: SyntaxLintRule {
1920

2021
public override func visit(_ node: IdentifierPatternSyntax) -> SyntaxVisitorContinueKind {
@@ -30,6 +31,7 @@ public final class IdentifiersMustBeASCII: SyntaxLintRule {
3031
}
3132

3233
extension Finding.Message {
34+
@_spi(Rules)
3335
public static func nonASCIICharsNotAllowed(
3436
_ invalidCharacters: [String], _ identifierName: String
3537
) -> Finding.Message {

0 commit comments

Comments
 (0)