diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index c07e9d1..b37a158 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -34,9 +34,8 @@ jobs: name: Soundness uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main with: - format_check_enabled: false # bug: https://github.com/swiftlang/swift-format/issues/1028 - shell_check_enabled: false - yamllint_check_enabled: false + format_check_enabled: false # bug: https://github.com/swiftlang/swift-format/issues/1028 + shell_check_enabled: true + yamllint_check_enabled: true api_breakage_check_enabled: false - docs_check_enabled: false - + docs_check_enabled: false # doc check runs using 6.0.3 compiler diff --git a/Scripts/format.sh b/Scripts/format.sh index 86da148..b05c68b 100755 --- a/Scripts/format.sh +++ b/Scripts/format.sh @@ -18,5 +18,3 @@ 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 - -sed -i '' 's/borrowbuffer/borrow buffer/g' "Sources/BinaryParsing/Parser Types/ParserSpan.swift" diff --git a/Sources/BinaryParsing/Operations/OptionalOperations.swift b/Sources/BinaryParsing/Operations/OptionalOperations.swift index 828135a..5a4c8ad 100644 --- a/Sources/BinaryParsing/Operations/OptionalOperations.swift +++ b/Sources/BinaryParsing/Operations/OptionalOperations.swift @@ -19,7 +19,7 @@ extension Collection { } return self[i] } - + /// Returns the subsequence at the given range, or `nil` if the range is out /// of bounds. @inlinable @@ -40,14 +40,17 @@ extension Collection where Index == Int { } return self[i] } - + /// Returns the subsequence at the given range after converting the bounds /// to `Int`, or `nil` if the range is out of bounds. @_alwaysEmitIntoClient - public subscript(ifInBounds bounds: Range) -> SubSequence? { + public subscript(ifInBounds bounds: Range) + -> SubSequence? + { guard let low = Int(exactly: bounds.lowerBound), - let high = Int(exactly: bounds.upperBound), - low >= startIndex, high <= endIndex else { + let high = Int(exactly: bounds.upperBound), + low >= startIndex, high <= endIndex + else { return nil } return self[low...size if paddingCount < 0 { self = - unsafe Self.isSigned + unsafe Self.isSigned ? Self( _unchecked: (), _parsingSigned: &input, endianness: endianness, byteCount: byteCount) @@ -250,7 +251,7 @@ extension FixedWidthInteger where Self: BitwiseCopyable { byteCount: byteCount) } else { self = - try unsafe Self.isSigned + try unsafe Self.isSigned ? Self( _unchecked: (), _parsingSigned: &input, endianness: endianness, paddingCount: paddingCount) @@ -330,7 +331,7 @@ extension MultiByteInteger { _unchecked _: Void, parsing input: inout ParserSpan, endianness: Endianness ) { self = - unsafe endianness.isBigEndian + unsafe endianness.isBigEndian ? Self(_unchecked: (), _parsingBigEndian: &input) : Self(_unchecked: (), _parsingLittleEndian: &input) } @@ -485,8 +486,8 @@ extension FixedWidthInteger where Self: BitwiseCopyable { /// - Parameters: /// - input: The `ParserSpan` to parse from. If parsing succeeds, the start /// position of `input` is moved forward by `byteCount`. - /// - byteCount: The number of bytes to read the value from. /// - endianness: The endianness to use when interpreting the parsed value. + /// - byteCount: The number of bytes to read the value from. /// - Throws: A `ParsingError` if `input` contains fewer than `byteCount` /// bytes, if the parsed value overflows this integer type, or if the /// padding bytes are invalid. @@ -601,7 +602,7 @@ extension FixedWidthInteger where Self: BitwiseCopyable { endianness: Endianness ) throws(ParsingError) { let result = - unsafe endianness.isBigEndian + unsafe endianness.isBigEndian ? T(_unchecked: (), _parsingBigEndian: &input) : T(_unchecked: (), _parsingLittleEndian: &input) self = try Self(_throwing: result) @@ -654,7 +655,8 @@ extension FixedWidthInteger where Self: BitwiseCopyable { parsing input: inout ParserSpan, storedAs: T.Type ) throws(ParsingError) { - self = try unsafe Self(_throwing: T(truncatingIfNeeded: input.consumeUnchecked())) + self = try unsafe Self( + _throwing: T(truncatingIfNeeded: input.consumeUnchecked())) } /// Creates an integer by parsing and converting a value of the given @@ -678,7 +680,6 @@ extension FixedWidthInteger where Self: BitwiseCopyable { /// position of `input` is moved forward by the size of this integer. /// - storageType: The integer type to parse from `input` before conversion /// to the destination type. - /// - endianness: The endianness to use when interpreting the parsed value. /// - Throws: A `ParsingError` if `input` does not have enough bytes to store /// `storageType`, or if converting the parsed value to this integer type /// overflows. diff --git a/Tests/BinaryParsingTests/EndiannessTests.swift b/Tests/BinaryParsingTests/EndiannessTests.swift index 785c5e2..1b3e272 100644 --- a/Tests/BinaryParsingTests/EndiannessTests.swift +++ b/Tests/BinaryParsingTests/EndiannessTests.swift @@ -18,7 +18,7 @@ struct EndiannessTests { let endianness = Endianness(isBigEndian: isBigEndian) #expect(endianness.isBigEndian == isBigEndian) #expect(endianness.isLittleEndian == !isBigEndian) - + let endianness2: Endianness = isBigEndian ? .big : .little #expect(endianness == endianness2) } diff --git a/Tests/BinaryParsingTests/IntegerParsingTests.swift b/Tests/BinaryParsingTests/IntegerParsingTests.swift index 5c47a48..5ed8abf 100644 --- a/Tests/BinaryParsingTests/IntegerParsingTests.swift +++ b/Tests/BinaryParsingTests/IntegerParsingTests.swift @@ -274,7 +274,7 @@ struct IntegerParsingTests { let number = T.random(in: .min ... .max, using: &rng) try runTest(for: number) } - + let empty: [UInt8] = [] empty.withParserSpan { span in #expect(throws: ParsingError.self) { diff --git a/Tests/BinaryParsingTests/OptionalOperationsTests.swift b/Tests/BinaryParsingTests/OptionalOperationsTests.swift index 2c41dc6..f177c2a 100644 --- a/Tests/BinaryParsingTests/OptionalOperationsTests.swift +++ b/Tests/BinaryParsingTests/OptionalOperationsTests.swift @@ -143,7 +143,7 @@ struct OptionalOperationsTests { let allIndices = str.indices + [str.endIndex] let validIndices = substr.startIndex..