Skip to content

Commit d8aaff1

Browse files
committed
Audit visibility throughout the code.
- Reduce things from public to internal if they don't need to be public, like tests. - Use fileprivate, not private, at file scope. - Reduce some things that were internal to fileprivate or private. - Remove @testable imports as a prerequisite for adding CI, making necessary decls public to access them. - Some other random NFC cleanup.
1 parent f9bd95a commit d8aaff1

File tree

139 files changed

+696
-884
lines changed

Some content is hidden

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

139 files changed

+696
-884
lines changed

Sources/SwiftFormatConfiguration/Configuration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Foundation
1414

1515
/// A version number that can be specified in the configuration file, which allows us to change the
1616
/// format in the future if desired and still support older files.
17-
private let highestSupportedConfigurationVersion = 1
17+
fileprivate let highestSupportedConfigurationVersion = 1
1818

1919
/// Holds the complete set of configured values and defaults.
2020
public struct Configuration: Codable, Equatable {

Sources/SwiftFormatCore/Rule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public protocol Rule {
2222
init(context: Context)
2323
}
2424

25-
private var nameCache = [ObjectIdentifier: String]()
25+
fileprivate var nameCache = [ObjectIdentifier: String]()
2626

2727
extension Rule {
2828
/// By default, the `ruleName` is just the name of the implementing rule class.

Sources/SwiftFormatCore/RuleMask.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extension SourceRange {
8686
/// The rule status comment directives implementation intentionally supports exactly the same nodes
8787
/// as `TokenStreamCreator` to disable pretty printing. This ensures ignore comments for pretty
8888
/// printing and for rules are as consistent as possible.
89-
private class RuleStatusCollectionVisitor: SyntaxVisitor {
89+
fileprivate class RuleStatusCollectionVisitor: SyntaxVisitor {
9090
/// Describes the possible matches for ignore directives, in comments.
9191
enum RuleStatusDirectiveMatch {
9292
/// There is a directive that applies to all rules.

Sources/SwiftFormatPrettyPrint/Comment.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct Comment {
4040

4141
let kind: Kind
4242
var text: [String]
43-
public var length: Int
43+
var length: Int
4444

4545
init(kind: Kind, text: String) {
4646
self.kind = kind

Sources/SwiftFormatPrettyPrint/PrettyPrint.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,12 @@ public class PrettyPrinter {
779779

780780
extension Diagnostic.Message {
781781

782-
static let moveEndOfLineComment = Diagnostic.Message(
782+
public static let moveEndOfLineComment = Diagnostic.Message(
783783
.warning, "move end-of-line comment that exceeds the line length")
784784

785-
static let addTrailingComma = Diagnostic.Message(
785+
public static let addTrailingComma = Diagnostic.Message(
786786
.warning, "add trailing comma to the last element in multiline collection literal")
787787

788-
static let removeTrailingComma = Diagnostic.Message(
788+
public static let removeTrailingComma = Diagnostic.Message(
789789
.warning, "remove trailing comma from the last element in single line collection literal")
790790
}

Sources/SwiftFormatPrettyPrint/Token.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import SwiftFormatConfiguration
14-
import SwiftFormatCore
15-
import SwiftSyntax
16-
1713
enum GroupBreakStyle {
1814
/// A consistent break indicates that the break will always be finalized as a newline
1915
/// if wrapping occurs.

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import SwiftSyntax
1717

1818
/// Visits the nodes of a syntax tree and constructs a linear stream of formatting tokens that
1919
/// tell the pretty printer how the source text should be laid out.
20-
private final class TokenStreamCreator: SyntaxVisitor {
20+
fileprivate final class TokenStreamCreator: SyntaxVisitor {
2121
private var tokens = [Token]()
2222
private var beforeMap = [TokenSyntax: [Token]]()
2323
private var afterMap = [TokenSyntax: [[Token]]]()
@@ -3205,7 +3205,7 @@ extension TriviaPiece {
32053205
/// Returns whether the given trivia includes a directive to ignore formatting for the next node.
32063206
///
32073207
/// - Parameter trivia: Leading trivia for a node that the formatter supports ignoring.
3208-
private func isFormatterIgnorePresent(inTrivia trivia: Trivia) -> Bool {
3208+
fileprivate func isFormatterIgnorePresent(inTrivia trivia: Trivia) -> Bool {
32093209
func isFormatterIgnore(in commentText: String, prefix: String, suffix: String) -> Bool {
32103210
let trimmed =
32113211
commentText.dropFirst(prefix.count)
@@ -3237,7 +3237,7 @@ private func isFormatterIgnorePresent(inTrivia trivia: Trivia) -> Bool {
32373237
/// be safely ignored.
32383238
///
32393239
/// - Parameter node: A node that can be safely ignored.
3240-
private func shouldFormatterIgnore(node: Syntax) -> Bool {
3240+
fileprivate func shouldFormatterIgnore(node: Syntax) -> Bool {
32413241
// Regardless of the level of nesting, if the ignore directive is present on the first token
32423242
// contained within the node then the entire node is eligible for ignoring.
32433243
if let firstTrivia = node.firstToken?.leadingTrivia {

Sources/SwiftFormatRules/AddModifierRewriter.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import Foundation
1413
import SwiftFormatCore
1514
import SwiftSyntax
1615

17-
private final class AddModifierRewriter: SyntaxRewriter {
18-
let modifierKeyword: DeclModifierSyntax
16+
fileprivate final class AddModifierRewriter: SyntaxRewriter {
17+
private let modifierKeyword: DeclModifierSyntax
1918

2019
init(modifierKeyword: DeclModifierSyntax) {
2120
self.modifierKeyword = modifierKeyword
@@ -162,7 +161,7 @@ private final class AddModifierRewriter: SyntaxRewriter {
162161
/// this method does nothing and returns the given node as-is.
163162
/// - Parameter node: A node that was updated to include a new modifier.
164163
/// - Parameter modifiersProvider: A closure that returns all modifiers for the given node.
165-
func nodeByRelocatingTrivia<NodeType: DeclSyntaxProtocol>(
164+
private func nodeByRelocatingTrivia<NodeType: DeclSyntaxProtocol>(
166165
in node: NodeType,
167166
for modifiersProvider: (NodeType) -> ModifierListSyntax?
168167
) -> NodeType {

Sources/SwiftFormatRules/AllPublicDeclarationsHaveDocumentation.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import Foundation
1413
import SwiftFormatCore
1514
import SwiftSyntax
1615

@@ -65,7 +64,7 @@ public final class AllPublicDeclarationsHaveDocumentation: SyntaxLintRule {
6564
return .skipChildren
6665
}
6766

68-
func diagnoseMissingDocComment(
67+
private func diagnoseMissingDocComment(
6968
_ decl: DeclSyntax,
7069
name: String,
7170
modifiers: ModifierListSyntax?
@@ -83,7 +82,7 @@ public final class AllPublicDeclarationsHaveDocumentation: SyntaxLintRule {
8382
}
8483

8584
extension Diagnostic.Message {
86-
static func declRequiresComment(_ name: String) -> Diagnostic.Message {
85+
public static func declRequiresComment(_ name: String) -> Diagnostic.Message {
8786
return .init(.warning, "add a documentation comment for '\(name)'")
8887
}
8988
}

Sources/SwiftFormatRules/AlwaysUseLowerCamelCase.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import Foundation
1413
import SwiftFormatCore
1514
import SwiftSyntax
1615

@@ -41,7 +40,7 @@ public final class AlwaysUseLowerCamelCase: SyntaxLintRule {
4140
return .skipChildren
4241
}
4342

44-
func diagnoseLowerCamelCaseViolations(_ identifier: TokenSyntax) {
43+
private func diagnoseLowerCamelCaseViolations(_ identifier: TokenSyntax) {
4544
guard case .identifier(let text) = identifier.tokenKind else { return }
4645
if text.isEmpty { return }
4746
if text.dropFirst().contains("_") || ("A"..."Z").contains(text.first!) {
@@ -53,7 +52,7 @@ public final class AlwaysUseLowerCamelCase: SyntaxLintRule {
5352
}
5453

5554
extension Diagnostic.Message {
56-
static func variableNameMustBeLowerCamelCase(_ name: String) -> Diagnostic.Message {
55+
public static func variableNameMustBeLowerCamelCase(_ name: String) -> Diagnostic.Message {
5756
return .init(.warning, "rename variable '\(name)' using lower-camel-case")
5857
}
5958
}

0 commit comments

Comments
 (0)