Skip to content

Commit 000b9d5

Browse files
authored
Merge pull request swiftlang#136 from allevato/access-audit
Various visibility (and other) cleanup.
2 parents f9bd95a + e0bbba8 commit 000b9d5

File tree

143 files changed

+698
-1077
lines changed

Some content is hidden

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

143 files changed

+698
-1077
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/SwiftFormatCore/SyntaxProtocol+Convenience.swift

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -13,66 +13,6 @@
1313
import SwiftSyntax
1414

1515
extension SyntaxProtocol {
16-
/// Walks up from the current node to find the nearest node that is an
17-
/// Expr, Stmt, or Decl.
18-
public var containingExprStmtOrDecl: Syntax? {
19-
var node: Syntax? = Syntax(self)
20-
while let parent = node?.parent {
21-
if parent.is(ExprSyntax.self) || parent.is(StmtSyntax.self) || parent.is(DeclSyntax.self) {
22-
return parent
23-
}
24-
node = parent
25-
}
26-
return nil
27-
}
28-
29-
/// Returns true if the node occupies a single line.
30-
///
31-
/// - Parameters:
32-
/// - includingLeadingComment: If true, factor any possible leading comments into the
33-
/// determination of whether the node occupies a single line.
34-
/// - sourceLocationConverter: Used to convert source positions to line/column locations.
35-
/// - Returns: True if the node occupies a single line.
36-
public func isSingleLine(
37-
includingLeadingComment: Bool,
38-
sourceLocationConverter: SourceLocationConverter
39-
) -> Bool {
40-
guard let firstToken = firstToken, let lastToken = lastToken else { return true }
41-
42-
let startPosition: AbsolutePosition
43-
if includingLeadingComment {
44-
// Iterate over the trivia, stopping at the first comment, and using that as the start
45-
// position.
46-
var currentPosition = firstToken.position
47-
var sawNewline = false
48-
loop: for piece in firstToken.leadingTrivia {
49-
switch piece {
50-
case .docLineComment,
51-
.docBlockComment,
52-
.lineComment where sawNewline,
53-
.blockComment where sawNewline:
54-
// Non-doc line or block comments before we've seen the first newline should actually be
55-
// considered trailing comments of the previous line.
56-
break loop
57-
case .newlines, .carriageReturns, .carriageReturnLineFeeds:
58-
sawNewline = true
59-
fallthrough
60-
default:
61-
currentPosition += piece.sourceLength
62-
}
63-
}
64-
startPosition = currentPosition
65-
} else {
66-
startPosition = firstToken.positionAfterSkippingLeadingTrivia
67-
}
68-
69-
let startLocation = sourceLocationConverter.location(for: startPosition)
70-
let endLocation = sourceLocationConverter.location(
71-
for: lastToken.endPositionBeforeTrailingTrivia)
72-
73-
return startLocation.line == endLocation.line
74-
}
75-
7616
/// Returns the absolute position of the trivia piece at the given index in the receiver's leading
7717
/// trivia collection.
7818
///

Sources/SwiftFormatCore/Trivia+Convenience.swift

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,6 @@
1313
import SwiftSyntax
1414

1515
extension Trivia {
16-
/// Returns the number of non-newline whitespace characters in this trivia.
17-
public var numberOfSpaces: Int {
18-
var count = 0
19-
for piece in self {
20-
switch piece {
21-
case .tabs(let n), .spaces(let n): count += n
22-
default: continue
23-
}
24-
}
25-
return count
26-
}
27-
28-
/// Returns the number of newlines in this trivia.
29-
public var numberOfNewlines: Int {
30-
var count = 0
31-
for piece in self {
32-
if case .newlines(let n) = piece {
33-
count += n
34-
}
35-
}
36-
return count
37-
}
38-
39-
/// Returns the number of leading newlines in this trivia.
40-
public var numberOfLeadingNewlines: Int {
41-
var count = 0
42-
loop: for piece in self {
43-
switch piece {
44-
case .newlines(let n): count += n
45-
case .carriageReturns(let n): count += n
46-
case .carriageReturnLineFeeds(let n): count += n
47-
default: break loop
48-
}
49-
}
50-
return count
51-
}
52-
5316
public var numberOfComments: Int {
5417
var count = 0
5518
for piece in self {
@@ -71,14 +34,6 @@ extension Trivia {
7134
}
7235
}
7336

74-
public var hasSpaces: Bool {
75-
for piece in self {
76-
if case .tabs = piece { return true }
77-
if case .spaces = piece { return true }
78-
}
79-
return false
80-
}
81-
8237
/// Returns this set of trivia, without any whitespace characters.
8338
public func withoutSpaces() -> Trivia {
8439
return Trivia(
@@ -89,50 +44,6 @@ extension Trivia {
8944
})
9045
}
9146

92-
/// Returns this set of trivia without any trailing whitespace characters.
93-
public func withoutTrailingSpaces() -> Trivia {
94-
var pieces = [TriviaPiece]()
95-
guard var prev = first else { return self }
96-
for piece in dropFirst() {
97-
switch (prev, piece) {
98-
case (.spaces(_), .newlines(_)),
99-
(.tabs(_), .newlines(_)):
100-
prev = piece
101-
default:
102-
pieces.append(prev)
103-
prev = piece
104-
}
105-
}
106-
pieces.append(prev)
107-
return Trivia(pieces: pieces).condensed()
108-
}
109-
110-
/// Returns this set of trivia, without any leading newline characters.
111-
public func withoutLeadingNewlines() -> Trivia {
112-
let triviaCondensed = self.condensed()
113-
guard let firstPieceOfTrivia = triviaCondensed.first else { return self }
114-
if case .newlines(_) = firstPieceOfTrivia {
115-
var pieces = [TriviaPiece]()
116-
for piece in triviaCondensed.dropFirst() {
117-
pieces.append(piece)
118-
}
119-
return Trivia(pieces: pieces)
120-
} else {
121-
return self
122-
}
123-
}
124-
125-
/// Returns this set of trivia, without any trailing newline characters.
126-
public func withoutTrailingNewlines() -> Trivia {
127-
let triviaCondensed = self.condensed()
128-
guard let lastPieceOfTrivia = triviaCondensed.suffix(1).first else { return self }
129-
if case .newlines(_) = lastPieceOfTrivia {
130-
return Trivia(pieces: triviaCondensed.dropLast())
131-
} else {
132-
return self
133-
}
134-
}
135-
13647
/// Returns this set of trivia, without any newlines.
13748
public func withoutNewlines() -> Trivia {
13849
return Trivia(

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: 4 additions & 10 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]]]()
@@ -2435,7 +2435,7 @@ private final class TokenStreamCreator: SyntaxVisitor {
24352435
{
24362436
let nextToken = token.nextToken
24372437
guard let trivia = nextToken?.leadingTrivia,
2438-
let firstPiece = trivia[safe: 0]
2438+
let firstPiece = trivia.first
24392439
else {
24402440
return (false, [])
24412441
}
@@ -3186,12 +3186,6 @@ class CommentMovingRewriter: SyntaxRewriter {
31863186
}
31873187
}
31883188

3189-
extension Collection {
3190-
subscript(safe index: Index) -> Element? {
3191-
return index < endIndex ? self[index] : nil
3192-
}
3193-
}
3194-
31953189
extension TriviaPiece {
31963190
/// True if the trivia piece is garbage text.
31973191
fileprivate var isGarbageText: Bool {
@@ -3205,7 +3199,7 @@ extension TriviaPiece {
32053199
/// Returns whether the given trivia includes a directive to ignore formatting for the next node.
32063200
///
32073201
/// - Parameter trivia: Leading trivia for a node that the formatter supports ignoring.
3208-
private func isFormatterIgnorePresent(inTrivia trivia: Trivia) -> Bool {
3202+
fileprivate func isFormatterIgnorePresent(inTrivia trivia: Trivia) -> Bool {
32093203
func isFormatterIgnore(in commentText: String, prefix: String, suffix: String) -> Bool {
32103204
let trimmed =
32113205
commentText.dropFirst(prefix.count)
@@ -3237,7 +3231,7 @@ private func isFormatterIgnorePresent(inTrivia trivia: Trivia) -> Bool {
32373231
/// be safely ignored.
32383232
///
32393233
/// - Parameter node: A node that can be safely ignored.
3240-
private func shouldFormatterIgnore(node: Syntax) -> Bool {
3234+
fileprivate func shouldFormatterIgnore(node: Syntax) -> Bool {
32413235
// Regardless of the level of nesting, if the ignore directive is present on the first token
32423236
// contained within the node then the entire node is eligible for ignoring.
32433237
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)