Skip to content

Commit b6473e1

Browse files
committed
Suppress buildkite warnings
1 parent 9f2a72a commit b6473e1

File tree

4 files changed

+76
-72
lines changed

4 files changed

+76
-72
lines changed

swift.swiftformat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
--typeattributes prev-line # wrapAttributes
1818

1919
# rules
20-
--rules wrap,todos,anyObjectProtocol,redundantParens,redundantReturn,redundantSelf,sortImports,strongifiedSelf,trailingCommas,trailingSpace,wrapArguments,wrapMultilineStatementBraces,indent,wrapAttributes,void,fileHeader
20+
--rules wrap,todos,anyObjectProtocol,redundantParens,redundantSelf,sortImports,strongifiedSelf,trailingCommas,trailingSpace,wrapArguments,wrapMultilineStatementBraces,indent,wrapAttributes,void,fileHeader
2121
--disable trailingclosures
2222

2323
--exclude **/*_generated.swift

swift/Sources/FlatBuffers/ByteBuffer.swift

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public struct ByteBuffer {
4040

4141
var isOwned: Bool {
4242
switch self {
43-
case .writePointer: true
44-
default: false
43+
case .writePointer: return true
44+
default: return false
4545
}
4646
}
4747
}
@@ -102,17 +102,17 @@ public struct ByteBuffer {
102102
{
103103
switch retainedBlob {
104104
case .byteBuffer(let byteBuffer):
105-
try byteBuffer.withUnsafeBytes(body)
105+
return try byteBuffer.withUnsafeBytes(body)
106106
case .data(let data):
107-
try data.withUnsafeBytes(body)
107+
return try data.withUnsafeBytes(body)
108108
case .bytes(let contiguousBytes):
109-
try contiguousBytes.withUnsafeBytes(body)
109+
return try contiguousBytes.withUnsafeBytes(body)
110110
case .array(let array):
111-
try array.withUnsafeBytes(body)
111+
return try array.withUnsafeBytes(body)
112112
case .pointer(let ptr):
113-
try body(UnsafeRawBufferPointer(start: ptr, count: capacity))
113+
return try body(UnsafeRawBufferPointer(start: ptr, count: capacity))
114114
case .writePointer(let ptr):
115-
try body(UnsafeRawBufferPointer(start: ptr, count: capacity))
115+
return try body(UnsafeRawBufferPointer(start: ptr, count: capacity))
116116
}
117117
}
118118

@@ -123,26 +123,26 @@ public struct ByteBuffer {
123123
{
124124
switch retainedBlob {
125125
case .byteBuffer(let byteBuffer):
126-
try byteBuffer.withUnsafeRawPointer(body)
126+
return try byteBuffer.withUnsafeRawPointer(body)
127127
case .data(let data):
128-
try data
128+
return try data
129129
.withUnsafeBytes {
130130
try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!))
131131
}
132132
case .bytes(let contiguousBytes):
133-
try contiguousBytes
133+
return try contiguousBytes
134134
.withUnsafeBytes {
135135
try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!))
136136
}
137137
case .array(let array):
138-
try array
138+
return try array
139139
.withUnsafeBytes {
140140
try body(UnsafeMutableRawPointer(mutating: $0.baseAddress!))
141141
}
142142
case .pointer(let ptr):
143-
try body(ptr)
143+
return try body(ptr)
144144
case .writePointer(let ptr):
145-
try body(ptr)
145+
return try body(ptr)
146146
}
147147
}
148148

@@ -153,23 +153,23 @@ public struct ByteBuffer {
153153
{
154154
switch retainedBlob {
155155
case .byteBuffer(let byteBuffer):
156-
try byteBuffer.readWithUnsafeRawPointer(position: position, body)
156+
return try byteBuffer.readWithUnsafeRawPointer(position: position, body)
157157
case .data(let data):
158-
try data.withUnsafeBytes {
158+
return try data.withUnsafeBytes {
159159
try body($0.baseAddress!.advanced(by: position))
160160
}
161161
case .bytes(let contiguousBytes):
162-
try contiguousBytes.withUnsafeBytes {
162+
return try contiguousBytes.withUnsafeBytes {
163163
try body($0.baseAddress!.advanced(by: position))
164164
}
165165
case .array(let array):
166-
try array.withUnsafeBytes {
166+
return try array.withUnsafeBytes {
167167
try body($0.baseAddress!.advanced(by: position))
168168
}
169169
case .pointer(let ptr):
170-
try body(ptr.advanced(by: position))
170+
return try body(ptr.advanced(by: position))
171171
case .writePointer(let ptr):
172-
try body(ptr.advanced(by: position))
172+
return try body(ptr.advanced(by: position))
173173
}
174174
}
175175
}
@@ -192,7 +192,9 @@ public struct ByteBuffer {
192192
/// - bytes: Array of UInt8
193193
@inline(__always)
194194
init(byteBuffer: _InternalByteBuffer) {
195-
_storage = Storage(blob: .byteBuffer(byteBuffer), capacity: byteBuffer.capacity)
195+
_storage = Storage(
196+
blob: .byteBuffer(byteBuffer),
197+
capacity: byteBuffer.capacity)
196198
_readerIndex = Int(byteBuffer.size)
197199
}
198200

@@ -449,7 +451,8 @@ extension ByteBuffer: CustomDebugStringConvertible {
449451
"""
450452
buffer located at: \(_storage.retainedBlob),
451453
with capacity of \(_storage.capacity),
452-
{ writerSize: \(_readerIndex), readerSize: \(reader), writerIndex: \(writerIndex) }
454+
{ writerSize: \(_readerIndex), readerSize: \(reader), writerIndex: \(
455+
writerIndex) }
453456
"""
454457
}
455458
}

swift/Sources/FlatBuffers/FlatBufferBuilder.swift

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@ public struct FlatBufferBuilder {
5959
public var capacity: Int { _bb.capacity }
6060

6161
#if !os(WASI)
62-
/// Data representation of the buffer
63-
///
64-
/// Should only be used after ``finish(offset:addPrefix:)`` is called
65-
public var data: Data {
66-
assert(finished, "Data shouldn't be called before finish()")
67-
return _bb.withUnsafeSlicedBytes { ptr in
68-
var data = Data()
69-
data.append(
70-
ptr.baseAddress!.bindMemory(
71-
to: UInt8.self,
72-
capacity: _bb.capacity),
73-
count: _bb.capacity)
74-
return data
75-
}
62+
/// Data representation of the buffer
63+
///
64+
/// Should only be used after ``finish(offset:addPrefix:)`` is called
65+
public var data: Data {
66+
assert(finished, "Data shouldn't be called before finish()")
67+
return _bb.withUnsafeSlicedBytes { ptr in
68+
var data = Data()
69+
data.append(
70+
ptr.baseAddress!.bindMemory(
71+
to: UInt8.self,
72+
capacity: _bb.capacity),
73+
count: _bb.capacity)
74+
return data
7675
}
76+
}
7777
#endif
7878

7979
/// Returns the underlying bytes in the ``ByteBuffer``
@@ -110,7 +110,7 @@ public struct FlatBufferBuilder {
110110
public var sizedBuffer: ByteBuffer {
111111
assert(finished, "Data shouldn't be called before finish()")
112112
return _bb.withUnsafeSlicedBytes { ptr in
113-
return ByteBuffer(
113+
ByteBuffer(
114114
copyingMemoryBound: ptr.baseAddress!,
115115
capacity: ptr.count)
116116
}
@@ -128,8 +128,8 @@ public struct FlatBufferBuilder {
128128
/// however the builder can be force by passing true for `serializeDefaults`
129129
public init(
130130
initialSize: Int32 = 1024,
131-
serializeDefaults force: Bool = false
132-
) {
131+
serializeDefaults force: Bool = false)
132+
{
133133
assert(initialSize > 0, "Size should be greater than zero!")
134134
guard isLitteEndian else {
135135
fatalError(
@@ -196,8 +196,8 @@ public struct FlatBufferBuilder {
196196
mutating public func finish(
197197
offset: Offset,
198198
fileId: String,
199-
addPrefix prefix: Bool = false
200-
) {
199+
addPrefix prefix: Bool = false)
200+
{
201201
let size = MemoryLayout<UOffset>.size
202202
preAlign(
203203
len: size &+ (prefix ? size : 0) &+ FileIdLength,
@@ -226,8 +226,8 @@ public struct FlatBufferBuilder {
226226
/// include the size of the current buffer.
227227
mutating public func finish(
228228
offset: Offset,
229-
addPrefix prefix: Bool = false
230-
) {
229+
addPrefix prefix: Bool = false)
230+
{
231231
notNested()
232232
let size = MemoryLayout<UOffset>.size
233233
preAlign(len: size &+ (prefix ? size : 0), alignment: _minAlignment)
@@ -351,8 +351,8 @@ public struct FlatBufferBuilder {
351351
@usableFromInline
352352
mutating internal func padding(
353353
bufSize: UInt32,
354-
elementSize: UInt32
355-
) -> UInt32 {
354+
elementSize: UInt32) -> UInt32
355+
{
356356
((~bufSize) &+ 1) & (elementSize &- 1)
357357
}
358358

@@ -479,29 +479,29 @@ public struct FlatBufferBuilder {
479479
@inline(__always)
480480
mutating public func createVector<T: Scalar>(
481481
_ elements: [T],
482-
size: Int
483-
) -> Offset {
482+
size: Int) -> Offset
483+
{
484484
let size = size
485485
startVector(size, elementSize: MemoryLayout<T>.size)
486486
_bb.push(elements: elements)
487487
return endVector(len: size)
488488
}
489489

490490
#if swift(>=5.0) && !os(WASI)
491-
@inline(__always)
492-
/// Creates a vector of bytes in the buffer.
493-
///
494-
/// Allows creating a vector from `Data` without copying to a `[UInt8]`
495-
///
496-
/// - Parameter bytes: bytes to be written into the buffer
497-
/// - Returns: ``Offset`` of the vector
498-
mutating public func createVector(bytes: ContiguousBytes) -> Offset {
499-
bytes.withUnsafeBytes {
500-
startVector($0.count, elementSize: MemoryLayout<UInt8>.size)
501-
_bb.push(bytes: $0)
502-
return endVector(len: $0.count)
503-
}
491+
@inline(__always)
492+
/// Creates a vector of bytes in the buffer.
493+
///
494+
/// Allows creating a vector from `Data` without copying to a `[UInt8]`
495+
///
496+
/// - Parameter bytes: bytes to be written into the buffer
497+
/// - Returns: ``Offset`` of the vector
498+
mutating public func createVector(bytes: ContiguousBytes) -> Offset {
499+
bytes.withUnsafeBytes {
500+
startVector($0.count, elementSize: MemoryLayout<UInt8>.size)
501+
_bb.push(bytes: $0)
502+
return endVector(len: $0.count)
504503
}
504+
}
505505
#endif
506506

507507
/// Creates a vector of type ``Enum`` into the ``ByteBuffer``
@@ -539,8 +539,8 @@ public struct FlatBufferBuilder {
539539
@inline(__always)
540540
mutating public func createVector<T: Enum>(
541541
_ elements: [T],
542-
size: Int
543-
) -> Offset {
542+
size: Int) -> Offset
543+
{
544544
let size = size
545545
startVector(size, elementSize: T.byteSize)
546546
for index in stride(from: elements.count, to: 0, by: -1) {
@@ -585,8 +585,8 @@ public struct FlatBufferBuilder {
585585
@inline(__always)
586586
mutating public func createVector(
587587
ofOffsets offsets: [Offset],
588-
len: Int
589-
) -> Offset {
588+
len: Int) -> Offset
589+
{
590590
startVector(len, elementSize: MemoryLayout<Offset>.size)
591591
for index in stride(from: offsets.count, to: 0, by: -1) {
592592
push(element: offsets[index &- 1])
@@ -662,8 +662,8 @@ public struct FlatBufferBuilder {
662662
@inline(__always)
663663
@discardableResult
664664
mutating public func create<T: NativeStruct>(
665-
struct s: T, position: VOffset
666-
) -> Offset {
665+
struct s: T, position: VOffset) -> Offset
666+
{
667667
let offset = create(struct: s)
668668
_vtableStorage.add(
669669
loc: (offset: _bb.size, position: VOffset(position)))
@@ -687,8 +687,8 @@ public struct FlatBufferBuilder {
687687
@inline(__always)
688688
@discardableResult
689689
mutating public func create<T: NativeStruct>(
690-
struct s: T
691-
) -> Offset {
690+
struct s: T) -> Offset
691+
{
692692
let size = MemoryLayout<T>.size
693693
preAlign(len: size, alignment: MemoryLayout<T>.alignment)
694694
_bb.push(struct: s, size: size)
@@ -803,8 +803,8 @@ public struct FlatBufferBuilder {
803803
mutating public func add<T: Scalar>(
804804
element: T,
805805
def: T,
806-
at position: VOffset
807-
) {
806+
at position: VOffset)
807+
{
808808
if element == def && !serializeDefaults { return }
809809
track(offset: push(element: element), at: position)
810810
}

tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersUnionTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ final class FlatBuffersUnionTests: XCTestCase {
9393
// swiftformat:disable all
9494
XCTAssertEqual(builder.sizedByteArray, [12, 0, 0, 0, 0, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 4, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0])
9595
// swiftformat:enable all
96-
let monster = ColorsNameSpace.Monster.getRootAsMonster(bb: builder.sizedBuffer)
96+
let monster = ColorsNameSpace.Monster
97+
.getRootAsMonster(bb: builder.sizedBuffer)
9798
XCTAssertEqual(monster.colorsCount, 2)
9899
XCTAssertEqual(monster.colors(at: 0), .blue)
99100
XCTAssertEqual(monster.colors(at: 1), .green)

0 commit comments

Comments
 (0)