Skip to content

Commit 925d00d

Browse files
authored
Enable SwiftLint trailing_whitespace rule in comments (#234)
1 parent 99626bf commit 925d00d

13 files changed

+44
-42
lines changed

.swiftlint.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,7 @@ excluded:
5151
- Sources/libbson
5252
- Sources/libmongoc
5353
- Package.swift
54-
5554
- Examples/*/Package.swift
55+
56+
trailing_whitespace:
57+
ignores_comments: false

Sources/MongoSwift/BSON/AnyBSONValue.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22

33
/// A struct wrapping a `BSONValue` type that allows for encoding/
4-
/// decoding `BSONValue`s of unknown type.
4+
/// decoding `BSONValue`s of unknown type.
55
public struct AnyBSONValue: Codable, Equatable, Hashable {
66
// TODO: conform all `BSONValue` types to `Hashable` (SWIFT-320).
77
// swiftlint:disable:next legacy_hashing
@@ -45,7 +45,7 @@ public struct AnyBSONValue: Codable, Equatable, Hashable {
4545
}
4646

4747
// in this case, we need to wrap each value in an
48-
// `AnyBSONValue`, before we encode, because `[BSONValue]`
48+
// `AnyBSONValue`, before we encode, because `[BSONValue]`
4949
// is not considered `Encodable`
5050
if let arr = self.value as? [BSONValue] {
5151
let mapped = arr.map { AnyBSONValue($0) }

Sources/MongoSwift/BSON/BSONDecoder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ internal struct _BSONDecodingStorage {
305305
self.containers.append(container)
306306
}
307307

308-
/// Pops the top container from the stack.
308+
/// Pops the top container from the stack.
309309
fileprivate mutating func popContainer() {
310310
guard !self.containers.isEmpty else {
311311
fatalError("Empty container stack.")
@@ -657,7 +657,7 @@ private struct _BSONUnkeyedDecodingContainer: UnkeyedDecodingContainer {
657657
// swiftlint:disable:previous force_unwrapping - `.count` always returns a value and is only an `Int?`
658658
// because it's required of the UnkeyedDecodingContainer protocol.
659659

660-
/// A private helper function to check if we're at the end of the container, and if so throw an error.
660+
/// A private helper function to check if we're at the end of the container, and if so throw an error.
661661
private func checkAtEnd() throws {
662662
guard !self.isAtEnd else {
663663
throw DecodingError.valueNotFound(

Sources/MongoSwift/BSON/CodableNumber.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal protocol CodableNumber {
1313
init?(exactly source: Double)
1414

1515
/// Converts this number to a `BSONValue`. Returns `nil` if it cannot
16-
/// be represented exactly.
16+
/// be represented exactly.
1717
var bsonValue: BSONValue? { get }
1818
}
1919

@@ -129,7 +129,7 @@ extension UInt: CodableNumber {
129129
}
130130
// we could consider trying a Decimal128 here. However,
131131
// it's not clear how we could support decoding something
132-
// stored as Decimal128 back to a UInt without access
132+
// stored as Decimal128 back to a UInt without access
133133
// to libbson internals.
134134
return nil
135135
}

Sources/MongoSwift/BSON/Document+Codable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ extension Document: Codable {
2727

2828
/// This method will work with any `Decoder`, but for non-BSON
2929
/// decoders, we do not support decoding `Date`s, because of limitations
30-
/// of decoding to `AnyBSONValue`s. See `AnyBSONValue.init(from:)` for
30+
/// of decoding to `AnyBSONValue`s. See `AnyBSONValue.init(from:)` for
3131
/// more information.
3232
public init(from decoder: Decoder) throws {
33-
// if it's a `BSONDecoder` we should just short-circuit and
33+
// if it's a `BSONDecoder` we should just short-circuit and
3434
// return the container `Document`
3535
if let bsonDecoder = decoder as? _BSONDecoder {
3636
let topContainer = bsonDecoder.storage.topContainer

Sources/MongoSwift/ReadPreference.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ public final class ReadPreference {
1010
public enum Mode: String {
1111
/// Default mode. All operations read from the current replica set primary.
1212
case primary
13-
/// In most situations, operations read from the primary but if it is
13+
/// In most situations, operations read from the primary but if it is
1414
/// unavailable, operations read from secondary members.
1515
case primaryPreferred
1616
/// All operations read from the secondary members of the replica set.
1717
case secondary
18-
/// In most situations, operations read from secondary members but if no
18+
/// In most situations, operations read from secondary members but if no
1919
/// secondary members are available, operations read from the primary.
2020
case secondaryPreferred
2121
/// Operations read from member of the replica set with the least network

Tests/MongoSwiftTests/CodecTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ final class CodecTests: MongoSwiftTestCase {
4747
let s: NestedStruct
4848
}
4949

50-
/// Test encoding/decoding a variety of structs containing simple types that have
50+
/// Test encoding/decoding a variety of structs containing simple types that have
5151
/// built in Codable support (strings, arrays, ints, and structs composed of them.)
5252
func testStructs() throws {
5353
let encoder = BSONEncoder()
@@ -63,7 +63,7 @@ final class CodecTests: MongoSwiftTestCase {
6363

6464
expect(try encoder.encode(TestClass())).to(equal(expected))
6565

66-
// a basic struct
66+
// a basic struct
6767
let basic1 = BasicStruct(int: 1, string: "hello")
6868
let basic1Doc: Document = ["int": 1, "string": "hello"]
6969
expect(try encoder.encode(basic1)).to(equal(basic1Doc))
@@ -444,7 +444,7 @@ final class CodecTests: MongoSwiftTestCase {
444444
func testDocumentIsCodable() throws {
445445
#if os(macOS) // presently skipped on linux due to nondeterministic key ordering
446446
// note: instead of doing this, one can and should just initialize a Document with the `init(fromJSON:)`
447-
// constructor, and conver to JSON using the .extendedJSON property. this test is just to demonstrate
447+
// constructor, and conver to JSON using the .extendedJSON property. this test is just to demonstrate
448448
// that a Document can theoretically work with any encoder/decoder.
449449
let encoder = JSONEncoder()
450450
let decoder = JSONDecoder()

Tests/MongoSwiftTests/CrudTests.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final class CrudTests: MongoSwiftTestCase {
3939

4040
// for each test case:
4141
// 1) create a unique collection to use
42-
// 2) insert the data specified by this test file
42+
// 2) insert the data specified by this test file
4343
// 3) execute the test according to the type's execute method
4444
// 4) verify that expected data is present
4545
// 5) drop the collection to clean up
@@ -82,7 +82,7 @@ final class CrudTests: MongoSwiftTestCase {
8282
}
8383
}
8484

85-
/// A container for the data from a single .json file.
85+
/// A container for the data from a single .json file.
8686
private struct CrudTestFile: Decodable {
8787
let data: [Document]
8888
let testDocs: [Document]
@@ -95,7 +95,7 @@ private struct CrudTestFile: Decodable {
9595
}
9696
}
9797

98-
/// Initializes a new `CrudTest` of the appropriate subclass from a `Document`
98+
/// Initializes a new `CrudTest` of the appropriate subclass from a `Document`
9999
private func makeCrudTest(_ doc: Document) throws -> CrudTest {
100100
let operation: Document = try doc.get("operation")
101101
let opName: String = try operation.get("name")
@@ -105,7 +105,7 @@ private func makeCrudTest(_ doc: Document) throws -> CrudTest {
105105
return try type.init(doc)
106106
}
107107

108-
// Maps operation names to the appropriate test class to use for them.
108+
// Maps operation names to the appropriate test class to use for them.
109109
private var testTypeMap: [String: CrudTest.Type] = [
110110
"aggregate": AggregateTest.self,
111111
"bulkWrite": BulkWriteTest.self,
@@ -125,7 +125,7 @@ private var testTypeMap: [String: CrudTest.Type] = [
125125
]
126126

127127
/// An abstract class to represent a single test within a CrudTestFile. Subclasses must
128-
/// implement the `execute` method themselves.
128+
/// implement the `execute` method themselves.
129129
private class CrudTest {
130130
let description: String
131131
let operationName: String
@@ -164,7 +164,7 @@ private class CrudTest {
164164
}
165165
var upsert: Bool? { return self.args["upsert"] as? Bool }
166166

167-
/// Initializes a new `CrudTest` from a `Document`.
167+
/// Initializes a new `CrudTest` from a `Document`.
168168
required init(_ test: Document) throws {
169169
self.description = try test.get("description")
170170
let operation: Document = try test.get("operation")
@@ -176,11 +176,11 @@ private class CrudTest {
176176
self.collection = outcome["collection"] as? Document
177177
}
178178

179-
// Subclasses should implement `execute` according to the particular operation(s) they are for.
179+
// Subclasses should implement `execute` according to the particular operation(s) they are for.
180180
func execute(usingCollection coll: MongoCollection<Document>) throws { XCTFail("Unimplemented") }
181181

182182
// If the test has a `collection` field in its `outcome`, verify that the expected
183-
// data is present. If there is no `collection` field, do nothing.
183+
// data is present. If there is no `collection` field, do nothing.
184184
func verifyData(testCollection coll: MongoCollection<Document>, db: MongoDatabase) throws {
185185
// only some tests have data to verify
186186
guard let collection = self.collection else {
@@ -194,9 +194,9 @@ private class CrudTest {
194194
expect(Array(try collToCheck.find([:]))).to(equal(try collection.get("data")))
195195
}
196196

197-
// Given an `UpdateResult`, verify that it matches the expected results in this `CrudTest`.
198-
// Meant for use by subclasses whose operations return `UpdateResult`s, such as `UpdateTest`
199-
// and `ReplaceOneTest`.
197+
// Given an `UpdateResult`, verify that it matches the expected results in this `CrudTest`.
198+
// Meant for use by subclasses whose operations return `UpdateResult`s, such as `UpdateTest`
199+
// and `ReplaceOneTest`.
200200
func verifyUpdateResult(_ result: UpdateResult?) throws {
201201
let expected = try BSONDecoder().decode(UpdateResult.self, from: self.result as! Document)
202202
expect(result?.matchedCount).to(equal(expected.matchedCount))
@@ -211,7 +211,7 @@ private class CrudTest {
211211
}
212212

213213
/// Given the response to a findAndModify command, verify that it matches the expected
214-
/// results for this `CrudTest`. Meant for use by findAndModify subclasses, i.e. findOneAndX.
214+
/// results for this `CrudTest`. Meant for use by findAndModify subclasses, i.e. findOneAndX.
215215
func verifyFindAndModifyResult(_ result: Document?) {
216216
guard self.result != nil else {
217217
return
@@ -232,13 +232,13 @@ private class AggregateTest: CrudTest {
232232
let options = AggregateOptions(batchSize: self.batchSize, collation: self.collation)
233233
let cursor = try coll.aggregate(pipeline, options: options)
234234
if self.collection != nil {
235-
// this is $out case - we need to iterate the cursor once in
235+
// this is $out case - we need to iterate the cursor once in
236236
// order to make the aggregation happen. there is nothing in
237237
// the cursor to verify, but verifyData() will check that the
238238
// $out collection has the new data.
239239
expect(cursor.next()).to(beNil())
240240
} else {
241-
// if not $out, verify that the cursor contains the expected documents.
241+
// if not $out, verify that the cursor contains the expected documents.
242242
expect(Array(cursor)).to(equal(self.result as? [Document]))
243243
}
244244
}

Tests/MongoSwiftTests/Document+SequenceTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ final class Document_SequenceTests: MongoSwiftTestCase {
7777
expect(k).to(equal(expectedKeys.removeFirst()))
7878
// we can't compare `BSONValue`s for equality, nor can we cast v
7979
// to a dynamically determined equatable type, so just verify
80-
// it's a `BSONValue` anyway
80+
// it's a `BSONValue` anyway
8181
expect(v).to(beAKindOf(BSONValue.self))
8282
}
8383
}

Tests/MongoSwiftTests/DocumentTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ final class DocumentTests: MongoSwiftTestCase {
9797
return
9898
}
9999

100-
// splitting this out is necessary because the swift 4.0 compiler
100+
// splitting this out is necessary because the swift 4.0 compiler
101101
// can't handle all the keys being declared together
102102

103103
let binaryData: Document = [
@@ -530,7 +530,7 @@ final class DocumentTests: MongoSwiftTestCase {
530530
"datetime": Date(msSinceEpoch: 2000)
531531
]))
532532

533-
// return early as we will to use an Int requiring > 32 bits after this
533+
// return early as we will to use an Int requiring > 32 bits after this
534534
if MongoSwiftTestCase.is32Bit {
535535
return
536536
}
@@ -636,7 +636,7 @@ final class DocumentTests: MongoSwiftTestCase {
636636

637637
["double", "int32", "int64", "bool", "decimal", "oid", "timestamp", "datetime"].forEach {
638638
overwritableDoc[$0] = BSONNull()
639-
// the storage should change every time
639+
// the storage should change every time
640640
expect(overwritableDoc.data).toNot(equal(overwritablePointer))
641641
overwritablePointer = overwritableDoc.data
642642
}
@@ -646,7 +646,7 @@ final class DocumentTests: MongoSwiftTestCase {
646646

647647
["string", "doc", "arr"].forEach {
648648
nonOverwritableDoc[$0] = BSONNull()
649-
// the storage should change every time
649+
// the storage should change every time
650650
expect(nonOverwritableDoc.data).toNot(equal(nonOverwritablePointer))
651651
nonOverwritablePointer = nonOverwritableDoc.data
652652
}

0 commit comments

Comments
 (0)