Skip to content

Commit 7c480d6

Browse files
authored
Enable more workflow checks (#17)
Enable more checks, update whitespace/formatting fixes
1 parent 35b8321 commit 7c480d6

File tree

11 files changed

+34
-33
lines changed

11 files changed

+34
-33
lines changed

.github/workflows/pull_request.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ jobs:
3434
name: Soundness
3535
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
3636
with:
37-
format_check_enabled: false # bug: https://github.com/swiftlang/swift-format/issues/1028
38-
shell_check_enabled: false
39-
yamllint_check_enabled: false
37+
format_check_enabled: false # bug: https://github.com/swiftlang/swift-format/issues/1028
38+
shell_check_enabled: true
39+
yamllint_check_enabled: true
4040
api_breakage_check_enabled: false
41-
docs_check_enabled: false
42-
41+
docs_check_enabled: false # doc check runs using 6.0.3 compiler

Scripts/format.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,3 @@ echo "Formatting Swift sources in $(pwd)"
1818
# Run the format / lint commands
1919
git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place
2020
git ls-files -z '*.swift' | xargs -0 swift format lint --strict --parallel
21-
22-
sed -i '' 's/borrowbuffer/borrow buffer/g' "Sources/BinaryParsing/Parser Types/ParserSpan.swift"

Sources/BinaryParsing/Operations/OptionalOperations.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension Collection {
1919
}
2020
return self[i]
2121
}
22-
22+
2323
/// Returns the subsequence at the given range, or `nil` if the range is out
2424
/// of bounds.
2525
@inlinable
@@ -40,14 +40,17 @@ extension Collection where Index == Int {
4040
}
4141
return self[i]
4242
}
43-
43+
4444
/// Returns the subsequence at the given range after converting the bounds
4545
/// to `Int`, or `nil` if the range is out of bounds.
4646
@_alwaysEmitIntoClient
47-
public subscript(ifInBounds bounds: Range<some FixedWidthInteger>) -> SubSequence? {
47+
public subscript(ifInBounds bounds: Range<some FixedWidthInteger>)
48+
-> SubSequence?
49+
{
4850
guard let low = Int(exactly: bounds.lowerBound),
49-
let high = Int(exactly: bounds.upperBound),
50-
low >= startIndex, high <= endIndex else {
51+
let high = Int(exactly: bounds.upperBound),
52+
low >= startIndex, high <= endIndex
53+
else {
5154
return nil
5255
}
5356
return self[low..<high]

Sources/BinaryParsing/Operations/Optionators.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ extension Optional where Wrapped: FixedWidthInteger {
9494
public static func -?= (a: inout Self, b: Self) {
9595
a = a -? b
9696
}
97-
97+
9898
/// Multiplies two values and stores the result in the left-hand-side variable,
9999
/// if the values are non-`nil` and the result is representable.
100100
@inlinable @inline(__always)

Sources/BinaryParsing/Operations/ThrowingOperations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extension Collection {
2121
return self[i]
2222
}
2323
}
24-
24+
2525
/// Returns the subsequence in the given range, throwing an error if the range
2626
/// is not in bounds.
2727
@inlinable

Sources/BinaryParsing/Parser Types/Endianness.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extension Endianness {
4848
public var isBigEndian: Bool {
4949
_isBigEndian
5050
}
51-
51+
5252
/// A Boolean value inidicating whether the endianness is little-endian.
5353
public var isLittleEndian: Bool {
5454
!_isBigEndian

Sources/BinaryParsing/Parsers/Integer.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ extension FixedWidthInteger where Self: BitwiseCopyable {
163163

164164
// 2) Load and store value in `result`.
165165
let result =
166-
unsafe endianness.isBigEndian
166+
unsafe endianness.isBigEndian
167167
? Self(_unchecked: (), _parsingBigEndian: &input)
168168
: Self(_unchecked: (), _parsingLittleEndian: &input)
169169

@@ -207,7 +207,8 @@ extension FixedWidthInteger where Self: BitwiseCopyable {
207207
func consumeZeroPadding() throws(ParsingError) {
208208
var paddingBuffer = input.divide(atOffset: paddingCount)
209209
for _ in 0..<paddingCount {
210-
guard unsafe 0 == paddingBuffer.consumeUnchecked(type: UInt8.self) else {
210+
guard unsafe 0 == paddingBuffer.consumeUnchecked(type: UInt8.self)
211+
else {
211212
throw ParsingError(
212213
status: .invalidValue, location: paddingBuffer.startPosition)
213214
}
@@ -217,12 +218,12 @@ extension FixedWidthInteger where Self: BitwiseCopyable {
217218
if endianness.isBigEndian {
218219
try consumeZeroPadding()
219220
self =
220-
unsafe endianness.isBigEndian
221+
unsafe endianness.isBigEndian
221222
? Self(_unchecked: (), _parsingBigEndian: &input)
222223
: Self(_unchecked: (), _parsingLittleEndian: &input)
223224
} else {
224225
self =
225-
unsafe endianness.isBigEndian
226+
unsafe endianness.isBigEndian
226227
? Self(_unchecked: (), _parsingBigEndian: &input)
227228
: Self(_unchecked: (), _parsingLittleEndian: &input)
228229
try consumeZeroPadding()
@@ -241,7 +242,7 @@ extension FixedWidthInteger where Self: BitwiseCopyable {
241242
let paddingCount = byteCount - MemoryLayout<Self>.size
242243
if paddingCount < 0 {
243244
self =
244-
unsafe Self.isSigned
245+
unsafe Self.isSigned
245246
? Self(
246247
_unchecked: (), _parsingSigned: &input, endianness: endianness,
247248
byteCount: byteCount)
@@ -250,7 +251,7 @@ extension FixedWidthInteger where Self: BitwiseCopyable {
250251
byteCount: byteCount)
251252
} else {
252253
self =
253-
try unsafe Self.isSigned
254+
try unsafe Self.isSigned
254255
? Self(
255256
_unchecked: (), _parsingSigned: &input, endianness: endianness,
256257
paddingCount: paddingCount)
@@ -330,7 +331,7 @@ extension MultiByteInteger {
330331
_unchecked _: Void, parsing input: inout ParserSpan, endianness: Endianness
331332
) {
332333
self =
333-
unsafe endianness.isBigEndian
334+
unsafe endianness.isBigEndian
334335
? Self(_unchecked: (), _parsingBigEndian: &input)
335336
: Self(_unchecked: (), _parsingLittleEndian: &input)
336337
}
@@ -485,8 +486,8 @@ extension FixedWidthInteger where Self: BitwiseCopyable {
485486
/// - Parameters:
486487
/// - input: The `ParserSpan` to parse from. If parsing succeeds, the start
487488
/// position of `input` is moved forward by `byteCount`.
488-
/// - byteCount: The number of bytes to read the value from.
489489
/// - endianness: The endianness to use when interpreting the parsed value.
490+
/// - byteCount: The number of bytes to read the value from.
490491
/// - Throws: A `ParsingError` if `input` contains fewer than `byteCount`
491492
/// bytes, if the parsed value overflows this integer type, or if the
492493
/// padding bytes are invalid.
@@ -601,7 +602,7 @@ extension FixedWidthInteger where Self: BitwiseCopyable {
601602
endianness: Endianness
602603
) throws(ParsingError) {
603604
let result =
604-
unsafe endianness.isBigEndian
605+
unsafe endianness.isBigEndian
605606
? T(_unchecked: (), _parsingBigEndian: &input)
606607
: T(_unchecked: (), _parsingLittleEndian: &input)
607608
self = try Self(_throwing: result)
@@ -654,7 +655,8 @@ extension FixedWidthInteger where Self: BitwiseCopyable {
654655
parsing input: inout ParserSpan,
655656
storedAs: T.Type
656657
) throws(ParsingError) {
657-
self = try unsafe Self(_throwing: T(truncatingIfNeeded: input.consumeUnchecked()))
658+
self = try unsafe Self(
659+
_throwing: T(truncatingIfNeeded: input.consumeUnchecked()))
658660
}
659661

660662
/// Creates an integer by parsing and converting a value of the given
@@ -678,7 +680,6 @@ extension FixedWidthInteger where Self: BitwiseCopyable {
678680
/// position of `input` is moved forward by the size of this integer.
679681
/// - storageType: The integer type to parse from `input` before conversion
680682
/// to the destination type.
681-
/// - endianness: The endianness to use when interpreting the parsed value.
682683
/// - Throws: A `ParsingError` if `input` does not have enough bytes to store
683684
/// `storageType`, or if converting the parsed value to this integer type
684685
/// overflows.

Tests/BinaryParsingTests/EndiannessTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct EndiannessTests {
1818
let endianness = Endianness(isBigEndian: isBigEndian)
1919
#expect(endianness.isBigEndian == isBigEndian)
2020
#expect(endianness.isLittleEndian == !isBigEndian)
21-
21+
2222
let endianness2: Endianness = isBigEndian ? .big : .little
2323
#expect(endianness == endianness2)
2424
}

Tests/BinaryParsingTests/IntegerParsingTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ struct IntegerParsingTests {
274274
let number = T.random(in: .min ... .max, using: &rng)
275275
try runTest(for: number)
276276
}
277-
277+
278278
let empty: [UInt8] = []
279279
empty.withParserSpan { span in
280280
#expect(throws: ParsingError.self) {

Tests/BinaryParsingTests/OptionalOperationsTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ struct OptionalOperationsTests {
143143
let allIndices = str.indices + [str.endIndex]
144144
let validIndices = substr.startIndex..<substr.endIndex
145145
let validBounds = substr.startIndex...substr.endIndex
146-
146+
147147
for low in allIndices.indices {
148148
let i = allIndices[low]
149149
if validIndices.contains(i) {
150150
#expect(substr[ifInBounds: i] == substr[i])
151151
} else {
152152
#expect(substr[ifInBounds: i] == nil)
153153
}
154-
154+
155155
for high in allIndices[low...].indices {
156156
let j = allIndices[high]
157157
if validBounds.contains(i) && validBounds.contains(j) {
@@ -167,14 +167,14 @@ struct OptionalOperationsTests {
167167
let numbers = Array(1...100)
168168
let slice = numbers.dropFirst(14).dropLast(20)
169169
let validBounds = UInt8(slice.startIndex)...UInt8(slice.endIndex)
170-
170+
171171
for i in 0...UInt8.max {
172172
if slice.indices.contains(Int(i)) {
173173
#expect(slice[ifInBounds: i] == slice[Int(i)])
174174
} else {
175175
#expect(slice[ifInBounds: i] == nil)
176176
}
177-
177+
178178
for j in i...UInt8.max {
179179
if validBounds.contains(i) && validBounds.contains(j) {
180180
#expect(slice[ifInBounds: i..<j] == slice[Int(i)..<Int(j)])

0 commit comments

Comments
 (0)