diff --git a/Scripts/format.sh b/Scripts/format.sh new file mode 100755 index 00000000..9cf301ab --- /dev/null +++ b/Scripts/format.sh @@ -0,0 +1,20 @@ +#!/bin/bash +##===----------------------------------------------------------------------===## +## +## This source file is part of the Swift Algorithms open source project +## +## Copyright (c) 2025 Apple Inc. and the Swift project authors +## Licensed under Apache License v2.0 with Runtime Library Exception +## +## See https://swift.org/LICENSE.txt for license information +## +##===----------------------------------------------------------------------===## + +# Move to the project root +cd "$(dirname "$0")" || exit +cd .. +echo "Formatting Swift sources in $(pwd)" + +# Run the format / lint commands +git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place +git ls-files -z '*.swift' | xargs -0 swift format lint --strict --parallel diff --git a/Sources/Algorithms/Chunked.swift b/Sources/Algorithms/Chunked.swift index 42e7d6f0..5683d0c9 100644 --- a/Sources/Algorithms/Chunked.swift +++ b/Sources/Algorithms/Chunked.swift @@ -288,9 +288,10 @@ extension EvenlyChunkedCollection: Collection { @usableFromInline internal var baseRange: Range - /// The offset corresponding to the chunk at this position. The first chunk - /// has offset `0` and all other chunks have an offset `1` greater than the - /// previous. + /// The offset corresponding to the chunk at this position. + /// + /// The first chunk has offset `0` and all other chunks have an offset + /// `1` greater than the previous. @usableFromInline internal var offset: Int diff --git a/Sources/Algorithms/Combinations.swift b/Sources/Algorithms/Combinations.swift index 2276fd17..4fe38c8c 100644 --- a/Sources/Algorithms/Combinations.swift +++ b/Sources/Algorithms/Combinations.swift @@ -100,7 +100,7 @@ extension CombinationsSequence: Sequence { @usableFromInline internal var kRange: Range - /// Whether or not iteration is finished (`kRange` is empty) + /// Whether or not iteration is finished (`kRange` is empty). @inlinable internal var isFinished: Bool { kRange.isEmpty diff --git a/Sources/Algorithms/Permutations.swift b/Sources/Algorithms/Permutations.swift index a510675c..7155628b 100644 --- a/Sources/Algorithms/Permutations.swift +++ b/Sources/Algorithms/Permutations.swift @@ -155,7 +155,7 @@ extension PermutationsSequence: Sequence { @usableFromInline internal var kRange: Range - /// Whether or not iteration is finished (`kRange` is empty) + /// Whether or not iteration is finished (`kRange` is empty). @inlinable internal var isFinished: Bool { kRange.isEmpty diff --git a/Tests/SwiftAlgorithmsTests/PartitionTests.swift b/Tests/SwiftAlgorithmsTests/PartitionTests.swift index 142077d6..b1704c91 100644 --- a/Tests/SwiftAlgorithmsTests/PartitionTests.swift +++ b/Tests/SwiftAlgorithmsTests/PartitionTests.swift @@ -179,7 +179,7 @@ final class PartitionTests: XCTestCase { XCTAssertTrue(s0.1.isEmpty) } - /// Test the example given in the `partitioned(by:)` documentation + /// Test the example given in the `partitioned(by:)` documentation. func testPartitionedExample() throws { let cast = ["Vivien", "Marlon", "Kim", "Karl"] let (longNames, shortNames) = cast.partitioned(by: { $0.count < 5 }) diff --git a/Tests/SwiftAlgorithmsTests/RotateTests.swift b/Tests/SwiftAlgorithmsTests/RotateTests.swift index 1533f091..70a2c7bd 100644 --- a/Tests/SwiftAlgorithmsTests/RotateTests.swift +++ b/Tests/SwiftAlgorithmsTests/RotateTests.swift @@ -14,7 +14,7 @@ import XCTest @testable import Algorithms final class RotateTests: XCTestCase { - /// Tests the example given in `_reverse(subrange:until:)`’s documentation + /// Tests the example given in the `_reverse(subrange:until:)` documentation. func testUnderscoreReverse() { var input = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", @@ -33,23 +33,23 @@ final class RotateTests: XCTestCase { XCTAssertEqual(upper, input.endIndex.advanced(by: -limit)) } - /// Tests the example given in `reverse(subrange:)`’s documentation + /// Tests the example given in the `reverse(subrange:)` documentation. func testReverse() { var numbers = [10, 20, 30, 40, 50, 60, 70, 80] numbers.reverse(subrange: 0..<4) XCTAssertEqual(numbers, [40, 30, 20, 10, 50, 60, 70, 80]) } - /// Tests `rotate(subrange:toStartAt:)` with an empty subrange - /// The order of elements are unchanged + /// Tests `rotate(subrange:toStartAt:)` with an empty subrange. func testRotateEmptySubrange() { var numbers = [10, 20, 30, 40, 50, 60, 70, 80] let oldStart = numbers.rotate(subrange: 3..<3, toStartAt: 3) + // The order of elements are unchanged XCTAssertEqual(numbers, [10, 20, 30, 40, 50, 60, 70, 80]) XCTAssertEqual(numbers[oldStart], 40) } - /// Tests `rotate(subrange:toStartAt:)` with an empty collection + /// Tests `rotate(subrange:toStartAt:)` with an empty collection. func testRotateSubrangeOnEmptyCollection() { var numbers: [Int] = [] let oldStart = numbers.rotate(subrange: 0..<0, toStartAt: 0) @@ -57,7 +57,7 @@ final class RotateTests: XCTestCase { XCTAssertEqual(oldStart, numbers.startIndex) } - /// Tests `rotate(subrange:toStartAt:)` with the full range of the collection + /// Tests `rotate(subrange:toStartAt:)` with the full range of the collection. func testRotateFullRange() { var numbers = [10, 20, 30, 40, 50, 60, 70, 80] let oldStart = numbers.rotate(subrange: 0..<8, toStartAt: 1) @@ -65,7 +65,8 @@ final class RotateTests: XCTestCase { XCTAssertEqual(numbers[oldStart], 10) } - /// Tests the example given in `rotate(subrange:toStartAt:)`’s documentation + /// Tests the example given in the `rotate(subrange:toStartAt:)` + /// documentation. func testRotateSubrange() { var numbers = [10, 20, 30, 40, 50, 60, 70, 80] let oldStart = numbers.rotate(subrange: 0..<4, toStartAt: 2) @@ -73,7 +74,7 @@ final class RotateTests: XCTestCase { XCTAssertEqual(numbers[oldStart], 10) } - /// Tests the example given in `rotate(toStartAt:)`’s documentation + /// Tests the example given in the `rotate(toStartAt:)` documentation. func testRotateExample() { var numbers = [10, 20, 30, 40, 50, 60, 70, 80] let oldStart = numbers.rotate(toStartAt: 3) @@ -81,8 +82,8 @@ final class RotateTests: XCTestCase { XCTAssertEqual(numbers[oldStart], 10) } - /// Tests `rotate(toStartAt:)` on collections of varying lengths, at different - /// starting points + /// Tests `rotate(toStartAt:)` on collections of varying lengths, at + /// different starting points. func testRotate() { for length in 0...15 { let a = Array(0..