Skip to content

Commit 0aa3733

Browse files
authored
Fix swift-format errors throughout (#266)
1 parent f6ce64a commit 0aa3733

File tree

6 files changed

+38
-16
lines changed

6 files changed

+38
-16
lines changed

Scripts/format.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the Swift Algorithms open source project
5+
##
6+
## Copyright (c) 2025 Apple Inc. and the Swift project authors
7+
## Licensed under Apache License v2.0 with Runtime Library Exception
8+
##
9+
## See https://swift.org/LICENSE.txt for license information
10+
##
11+
##===----------------------------------------------------------------------===##
12+
13+
# Move to the project root
14+
cd "$(dirname "$0")" || exit
15+
cd ..
16+
echo "Formatting Swift sources in $(pwd)"
17+
18+
# Run the format / lint commands
19+
git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place
20+
git ls-files -z '*.swift' | xargs -0 swift format lint --strict --parallel

Sources/Algorithms/Chunked.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,10 @@ extension EvenlyChunkedCollection: Collection {
288288
@usableFromInline
289289
internal var baseRange: Range<Base.Index>
290290

291-
/// The offset corresponding to the chunk at this position. The first chunk
292-
/// has offset `0` and all other chunks have an offset `1` greater than the
293-
/// previous.
291+
/// The offset corresponding to the chunk at this position.
292+
///
293+
/// The first chunk has offset `0` and all other chunks have an offset
294+
/// `1` greater than the previous.
294295
@usableFromInline
295296
internal var offset: Int
296297

Sources/Algorithms/Combinations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ extension CombinationsSequence: Sequence {
100100
@usableFromInline
101101
internal var kRange: Range<Int>
102102

103-
/// Whether or not iteration is finished (`kRange` is empty)
103+
/// Whether or not iteration is finished (`kRange` is empty).
104104
@inlinable
105105
internal var isFinished: Bool {
106106
kRange.isEmpty

Sources/Algorithms/Permutations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ extension PermutationsSequence: Sequence {
155155
@usableFromInline
156156
internal var kRange: Range<Int>
157157

158-
/// Whether or not iteration is finished (`kRange` is empty)
158+
/// Whether or not iteration is finished (`kRange` is empty).
159159
@inlinable
160160
internal var isFinished: Bool {
161161
kRange.isEmpty

Tests/SwiftAlgorithmsTests/PartitionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ final class PartitionTests: XCTestCase {
179179
XCTAssertTrue(s0.1.isEmpty)
180180
}
181181

182-
/// Test the example given in the `partitioned(by:)` documentation
182+
/// Test the example given in the `partitioned(by:)` documentation.
183183
func testPartitionedExample() throws {
184184
let cast = ["Vivien", "Marlon", "Kim", "Karl"]
185185
let (longNames, shortNames) = cast.partitioned(by: { $0.count < 5 })

Tests/SwiftAlgorithmsTests/RotateTests.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import XCTest
1414
@testable import Algorithms
1515

1616
final class RotateTests: XCTestCase {
17-
/// Tests the example given in `_reverse(subrange:until:)`’s documentation
17+
/// Tests the example given in the `_reverse(subrange:until:)` documentation.
1818
func testUnderscoreReverse() {
1919
var input = [
2020
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
@@ -33,56 +33,57 @@ final class RotateTests: XCTestCase {
3333
XCTAssertEqual(upper, input.endIndex.advanced(by: -limit))
3434
}
3535

36-
/// Tests the example given in `reverse(subrange:)`’s documentation
36+
/// Tests the example given in the `reverse(subrange:)` documentation.
3737
func testReverse() {
3838
var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
3939
numbers.reverse(subrange: 0..<4)
4040
XCTAssertEqual(numbers, [40, 30, 20, 10, 50, 60, 70, 80])
4141
}
4242

43-
/// Tests `rotate(subrange:toStartAt:)` with an empty subrange
44-
/// The order of elements are unchanged
43+
/// Tests `rotate(subrange:toStartAt:)` with an empty subrange.
4544
func testRotateEmptySubrange() {
4645
var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
4746
let oldStart = numbers.rotate(subrange: 3..<3, toStartAt: 3)
47+
// The order of elements are unchanged
4848
XCTAssertEqual(numbers, [10, 20, 30, 40, 50, 60, 70, 80])
4949
XCTAssertEqual(numbers[oldStart], 40)
5050
}
5151

52-
/// Tests `rotate(subrange:toStartAt:)` with an empty collection
52+
/// Tests `rotate(subrange:toStartAt:)` with an empty collection.
5353
func testRotateSubrangeOnEmptyCollection() {
5454
var numbers: [Int] = []
5555
let oldStart = numbers.rotate(subrange: 0..<0, toStartAt: 0)
5656
XCTAssertEqual(numbers, [])
5757
XCTAssertEqual(oldStart, numbers.startIndex)
5858
}
5959

60-
/// Tests `rotate(subrange:toStartAt:)` with the full range of the collection
60+
/// Tests `rotate(subrange:toStartAt:)` with the full range of the collection.
6161
func testRotateFullRange() {
6262
var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
6363
let oldStart = numbers.rotate(subrange: 0..<8, toStartAt: 1)
6464
XCTAssertEqual(numbers, [20, 30, 40, 50, 60, 70, 80, 10])
6565
XCTAssertEqual(numbers[oldStart], 10)
6666
}
6767

68-
/// Tests the example given in `rotate(subrange:toStartAt:)`’s documentation
68+
/// Tests the example given in the `rotate(subrange:toStartAt:)`
69+
/// documentation.
6970
func testRotateSubrange() {
7071
var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
7172
let oldStart = numbers.rotate(subrange: 0..<4, toStartAt: 2)
7273
XCTAssertEqual(numbers, [30, 40, 10, 20, 50, 60, 70, 80])
7374
XCTAssertEqual(numbers[oldStart], 10)
7475
}
7576

76-
/// Tests the example given in `rotate(toStartAt:)`’s documentation
77+
/// Tests the example given in the `rotate(toStartAt:)` documentation.
7778
func testRotateExample() {
7879
var numbers = [10, 20, 30, 40, 50, 60, 70, 80]
7980
let oldStart = numbers.rotate(toStartAt: 3)
8081
XCTAssertEqual(numbers, [40, 50, 60, 70, 80, 10, 20, 30])
8182
XCTAssertEqual(numbers[oldStart], 10)
8283
}
8384

84-
/// Tests `rotate(toStartAt:)` on collections of varying lengths, at different
85-
/// starting points
85+
/// Tests `rotate(toStartAt:)` on collections of varying lengths, at
86+
/// different starting points.
8687
func testRotate() {
8788
for length in 0...15 {
8889
let a = Array(0..<length)

0 commit comments

Comments
 (0)