From e7b3ddceb513687175485f180bdc57c9ed35d9c7 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Sat, 12 Jul 2025 13:39:19 -0500 Subject: [PATCH 1/4] Enable more checks --- .github/workflows/pull_request.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index c07e9d1..804f8b2 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -35,8 +35,8 @@ jobs: 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 + shell_check_enabled: true + yamllint_check_enabled: true api_breakage_check_enabled: false - docs_check_enabled: false + docs_check_enabled: true From 8d9db851f8176c441079436f53aa3f874e876118 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Sat, 12 Jul 2025 13:50:21 -0500 Subject: [PATCH 2/4] Whitespace/formatting fixes --- .../Operations/OptionalOperations.swift | 13 ++++++++----- Sources/BinaryParsing/Operations/Optionators.swift | 2 +- .../Operations/ThrowingOperations.swift | 2 +- Sources/BinaryParsing/Parser Types/Endianness.swift | 2 +- Tests/BinaryParsingTests/EndiannessTests.swift | 2 +- Tests/BinaryParsingTests/IntegerParsingTests.swift | 2 +- .../OptionalOperationsTests.swift | 8 ++++---- .../ThrowingOperationsTests.swift | 2 +- 8 files changed, 18 insertions(+), 15 deletions(-) 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.. Date: Sat, 12 Jul 2025 13:50:35 -0500 Subject: [PATCH 3/4] Fix yaml format --- .github/workflows/pull_request.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 804f8b2..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 + 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: true - + docs_check_enabled: false # doc check runs using 6.0.3 compiler From a371afbbb67726dd658c7f1dbee239cf1fa2a409 Mon Sep 17 00:00:00 2001 From: Nate Cook Date: Sat, 12 Jul 2025 13:54:06 -0500 Subject: [PATCH 4/4] More formatting, update local script --- Scripts/format.sh | 2 -- Sources/BinaryParsing/Parsers/Integer.swift | 23 +++++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) 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/Parsers/Integer.swift b/Sources/BinaryParsing/Parsers/Integer.swift index 4e57250..693229c 100644 --- a/Sources/BinaryParsing/Parsers/Integer.swift +++ b/Sources/BinaryParsing/Parsers/Integer.swift @@ -163,7 +163,7 @@ extension FixedWidthInteger where Self: BitwiseCopyable { // 2) Load and store value in `result`. let result = - unsafe endianness.isBigEndian + unsafe endianness.isBigEndian ? Self(_unchecked: (), _parsingBigEndian: &input) : Self(_unchecked: (), _parsingLittleEndian: &input) @@ -207,7 +207,8 @@ extension FixedWidthInteger where Self: BitwiseCopyable { func consumeZeroPadding() throws(ParsingError) { var paddingBuffer = input.divide(atOffset: paddingCount) for _ in 0...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.