Skip to content

Commit aec41dd

Browse files
committed
Delete some dead code.
1 parent d8aaff1 commit aec41dd

File tree

4 files changed

+1
-193
lines changed

4 files changed

+1
-193
lines changed

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/TokenStreamCreator.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,7 +2435,7 @@ fileprivate 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 {

Sources/SwiftFormatRules/TokenKind+Convenience.swift

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)