Skip to content

Commit 5a3c3aa

Browse files
committed
format/lint
1 parent b9f54c7 commit 5a3c3aa

File tree

10 files changed

+49
-28
lines changed

10 files changed

+49
-28
lines changed

Sources/MongoSwift/BSON/BSONDocument+Collection.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ extension BSONDocument: Collection {
5151
return (iter.currentKey, iter.currentValue)
5252
}
5353

54-
/// Allows access to a `KeyValuePair` from the `BSONDocument`, given a range of indices of the desired `KeyValuePair`'s
55-
/// held within. This method does not guarantee constant-time (O(1)) access.
54+
/// Allows access to a `KeyValuePair` from the `BSONDocument`, given a range of indices of the desired
55+
/// `KeyValuePair`'s held within. This method does not guarantee constant-time (O(1)) access.
5656
public subscript(bounds: Range<Index>) -> BSONDocument {
5757
// TODO: SWIFT-252 should provide a more efficient implementation for this.
5858
BSONDocumentIterator.subsequence(of: self, startIndex: bounds.lowerBound, endIndex: bounds.upperBound)

Sources/MongoSwift/BSON/BSONDocumentIterator.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,11 @@ public class BSONDocumentIterator: IteratorProtocol {
116116
// uses an iterator to copy (key, value) pairs of the provided document from range [startIndex, endIndex) into a new
117117
// document. starts at the startIndex-th pair and ends at the end of the document or the (endIndex-1)th index,
118118
// whichever comes first.
119-
internal static func subsequence(of doc: BSONDocument, startIndex: Int = 0, endIndex: Int = Int.max) -> BSONDocument {
119+
internal static func subsequence(
120+
of doc: BSONDocument,
121+
startIndex: Int = 0,
122+
endIndex: Int = Int.max
123+
) -> BSONDocument {
120124
guard endIndex >= startIndex else {
121125
fatalError("endIndex must be >= startIndex")
122126
}

Sources/MongoSwift/BSON/BSONValue.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,8 @@ private func bsonDecodingDirectlyError<T: BSONValue>(type _: T.Type, at codingPa
12531253
*
12541254
* Some example cases:
12551255
* - Decoding directly from the BSONDecoder top-level (e.g. BSONDecoder().decode(BSONObjectID.self, from: ...))
1256-
* - Encountering the wrong type of BSONValue (e.g. expected "_id" to be an `BSONObjectID`, got a `BSONDocument` instead)
1256+
* - Encountering the wrong type of BSONValue (e.g. expected "_id" to be an `BSONObjectID`, got a `BSONDocument`
1257+
* instead)
12571258
* - Attempting to decode a driver-introduced BSONValue with a non-BSONDecoder
12581259
*/
12591260
internal func getDecodingError<T: BSONValue>(type _: T.Type, decoder: Decoder) -> DecodingError {

Sources/MongoSwift/BSON/CodingStrategies.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public struct BSONCoderOptions: CodingStrategyProvider {
3838
/**
3939
* Enum representing the various encoding/decoding strategy pairs for `Date`s.
4040
* Set these on a `MongoClient`, `MongoDatabase`, or `MongoCollection` so that the strategies will be applied when
41-
* converting `Date`s between their BSON representations and their representations in (non `BSONDocument`) `Codable` types.
41+
* converting `Date`s between their BSON representations and their representations in (non `BSONDocument`) `Codable`
42+
* types.
4243
*
4344
* As per the BSON specification, the default strategy is to encode `Date`s as BSON datetime objects.
4445
*
@@ -123,7 +124,8 @@ public enum DateCodingStrategy: RawRepresentable {
123124
/**
124125
* Enum representing the various encoding/decoding strategy pairs for `Date`s.
125126
* Set these on a `MongoClient`, `MongoDatabase`, or `MongoCollection` so that the strategies will be applied when
126-
* converting `UUID`s between their BSON representations and their representations in (non `BSONDocument`) `Codable` types.
127+
* converting `UUID`s between their BSON representations and their representations in (non `BSONDocument`) `Codable`
128+
* types.
127129
*
128130
* As per the BSON specification, the default strategy is to encode `UUID`s as BSON binary types with the UUID
129131
* subtype.
@@ -163,7 +165,8 @@ public enum UUIDCodingStrategy: RawRepresentable {
163165
/**
164166
* Enum representing the various encoding/decoding strategy pairs for `Date`s.
165167
* Set these on a `MongoClient`, `MongoDatabase`, or `MongoCollection` so that the strategies will be applied when
166-
* converting `Data`s between their BSON representations and their representations in (non `BSONDocument`) `Codable` types.
168+
* converting `Data`s between their BSON representations and their representations in (non `BSONDocument`) `Codable`
169+
* types.
167170
*
168171
* As per the BSON specification, the default strategy is to encode `Data`s as BSON binary types with the generic
169172
* binary subtype.

Sources/MongoSwift/ClientSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public final class ClientSession {
227227
}
228228

229229
// swiftlint:disable:next force_unwrapping
230-
self.id = BSONDocument(copying: mongoc_client_session_get_lsid(sessionPtr)!) // always returns a value
230+
self.id = BSONDocument(copying: mongoc_client_session_get_lsid(sessionPtr)!) // never returns nil
231231
}
232232
case .started:
233233
return self.client.operationExecutor.makeSucceededFuture(Void())

Sources/MongoSwift/MongoClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ public class MongoClient {
363363
* Retrieves a list of databases in this client's MongoDB deployment.
364364
*
365365
* - Parameters:
366-
* - filter: Optional `BSONDocument` specifying a filter that the listed databases must pass. This filter can be based
367-
* on the "name", "sizeOnDisk", "empty", or "shards" fields of the output.
366+
* - filter: Optional `BSONDocument` specifying a filter that the listed databases must pass. This filter can be
367+
* based on the "name", "sizeOnDisk", "empty", or "shards" fields of the output.
368368
* - options: Optional `ListDatabasesOptions` specifying options for listing databases.
369369
* - session: Optional `ClientSession` to use when executing this command.
370370
*

Sources/MongoSwift/MongoCollection+Read.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ extension MongoCollection {
139139
*
140140
* - Parameters:
141141
* - fieldName: The field for which the distinct values will be found
142-
* - filter: a `BSONDocument` representing the filter documents must match in order to be considered for the operation
142+
* - filter: a `BSONDocument` representing the filter documents must match in order to be considered for the
143+
* operation
143144
* - options: Optional `DistinctOptions` to use when executing the command
144145
* - session: Optional `ClientSession` to use when executing this command
145146
*

Sources/MongoSwift/Operations/FindAndModifyOperation.swift

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,23 @@ internal struct FindAndModifyOperation<T: Codable>: Operation {
163163

164164
var error = bson_error_t()
165165

166-
let (success, reply) = self.collection.withMongocCollection(from: connection) { collPtr -> (Bool, BSONDocument) in
167-
self.filter.withBSONPointer { filterPtr in
168-
opts.withMongocOptions { optsPtr in
169-
withStackAllocatedMutableBSONPointer { replyPtr in
170-
let success = mongoc_collection_find_and_modify_with_opts(
171-
collPtr,
172-
filterPtr,
173-
optsPtr,
174-
replyPtr,
175-
&error
176-
)
177-
return (success, BSONDocument(copying: replyPtr))
166+
let (success, reply) = self.collection
167+
.withMongocCollection(from: connection) { collPtr -> (Bool, BSONDocument) in
168+
self.filter.withBSONPointer { filterPtr in
169+
opts.withMongocOptions { optsPtr in
170+
withStackAllocatedMutableBSONPointer { replyPtr in
171+
let success = mongoc_collection_find_and_modify_with_opts(
172+
collPtr,
173+
filterPtr,
174+
optsPtr,
175+
replyPtr,
176+
&error
177+
)
178+
return (success, BSONDocument(copying: replyPtr))
179+
}
178180
}
179181
}
180182
}
181-
}
182183

183184
guard success else {
184185
throw extractMongoError(error: error, reply: reply)

Tests/BSONTests/BSONCorpusTests.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ final class BSONCorpusTests: MongoSwiftTestCase {
160160

161161
// for cEJ input:
162162
// native_to_canonical_extended_json( json_to_native(cEJ) ) = cEJ
163-
expect(try BSONDocument(fromJSON: cEJData).canonicalExtendedJSON).to(cleanEqual(test.canonicalExtJSON))
163+
expect(try BSONDocument(fromJSON: cEJData).canonicalExtendedJSON)
164+
.to(cleanEqual(test.canonicalExtJSON))
164165

165166
// native_to_bson( json_to_native(cEJ) ) = cB (unless lossy)
166167
if !lossy {
@@ -187,7 +188,8 @@ final class BSONCorpusTests: MongoSwiftTestCase {
187188
// for dEJ input (if it exists):
188189
if let dEJ = test.degenerateExtJSON {
189190
// native_to_canonical_extended_json( json_to_native(dEJ) ) = cEJ
190-
expect(try BSONDocument(fromJSON: dEJ).canonicalExtendedJSON).to(cleanEqual(test.canonicalExtJSON))
191+
expect(try BSONDocument(fromJSON: dEJ).canonicalExtendedJSON)
192+
.to(cleanEqual(test.canonicalExtJSON))
191193

192194
// native_to_bson( json_to_native(dEJ) ) = cB (unless lossy)
193195
if !lossy {

Tests/BSONTests/BSONValueTests.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ final class BSONValueTests: MongoSwiftTestCase {
3939
// Double
4040
self.checkTrueAndFalse(val: 1.618, alternate: 2.718)
4141
// Decimal128
42-
self.checkTrueAndFalse(val: .decimal128(BSONDecimal128("1.618")!), alternate: .decimal128(BSONDecimal128("2.718")!))
42+
self.checkTrueAndFalse(
43+
val: .decimal128(BSONDecimal128("1.618")!),
44+
alternate: .decimal128(BSONDecimal128("2.718")!)
45+
)
4346
// Bool
4447
self.checkTrueAndFalse(val: true, alternate: false)
4548
// String
@@ -217,7 +220,13 @@ final class BSONValueTests: MongoSwiftTestCase {
217220

218221
let cases = [
219222
BSONNumberTestCase(int: 5, double: 5.0, int32: Int32(5), int64: Int64(5), decimal: BSONDecimal128("5")!),
220-
BSONNumberTestCase(int: -5, double: -5.0, int32: Int32(-5), int64: Int64(-5), decimal: BSONDecimal128("-5")!),
223+
BSONNumberTestCase(
224+
int: -5,
225+
double: -5.0,
226+
int32: Int32(-5),
227+
int64: Int64(-5),
228+
decimal: BSONDecimal128("-5")!
229+
),
221230
BSONNumberTestCase(int: 0, double: 0.0, int32: Int32(0), int64: Int64(0), decimal: BSONDecimal128("0")!),
222231
BSONNumberTestCase(int: nil, double: 1.234, int32: nil, int64: nil, decimal: BSONDecimal128("1.234")!),
223232
BSONNumberTestCase(int: nil, double: -31.234, int32: nil, int64: nil, decimal: BSONDecimal128("-31.234")!)

0 commit comments

Comments
 (0)