Skip to content

Commit 40c3c99

Browse files
authored
Add new linter rules and format code & comments (#246)
* Improve inline documentation and make doc formatting consistent * Add more opt-in rules to swiftlint and enforce them * Bump version number and update changelog * fixup! Improve inline documentation and make doc formatting consistent
1 parent 63535c9 commit 40c3c99

35 files changed

+1400
-1447
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CONTENTFUL_SDK_VERSION=4.2.0
1+
CONTENTFUL_SDK_VERSION=4.2.1

.swiftlint.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
1+
# Rules for SwiftLint s
2+
# https://github.com/realm/SwiftLint/blob/master/Rules.md
23
excluded:
34
- Carthage
45
- Contentful.playground
@@ -25,14 +26,32 @@ disabled_rules:
2526
- identifier_name
2627
- nesting # Disable warnings about structures nested more than 1 level deep.
2728

29+
opt_in_rules:
30+
- first_where
31+
- fatal_error_message
32+
- attributes
33+
- unused_private_declaration
34+
- closure_end_indentation
35+
- collection_alignment
36+
- contains_over_first_not_nil
37+
- convenience_type
38+
- empty_count
39+
- empty_string
40+
- explicit_acl
41+
- multiline_arguments
42+
- multiline_parameters
43+
- toggle_bool
44+
- unneeded_parentheses_in_closure_argument
45+
2846
# Parameterized
2947
line_length:
3048
warning: 150
3149
ignores_comments: true
3250
ignores_urls: true
3351
ignores_function_declarations: true
52+
ignores_interpolated_strings: true
3453
file_length:
35-
warning: 800
54+
warning: 850
3655
vertical_whitespace:
3756
max_empty_lines: 2
3857
function_body_length: 110

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) starting from
1010
## Table of contents
1111

1212
#### 4.x Releases
13-
- `4.2.0` Releases - [4.2.0](#420)
13+
- `4.2.0` Releases - [4.2.0](#420) | [4.2.1](#421)
1414
- `4.1.0` Releases - [4.1.0](#410) | [4.1.3](#413)
1515
- `4.0.0` Releases - [4.0.0](#400) | [4.0.1](#401)
1616

@@ -38,6 +38,13 @@ This project adheres to [Semantic Versioning](http://semver.org/) starting from
3838
- `0.4.x` Releases - [0.4.0](#040) | [0.4.1](#041)
3939
- `0.3.x` Releases - [0.3.0](#030) | [0.3.1](#031)
4040

41+
---
42+
43+
## [`4.2.1`](https://github.com/contentful/contentful.swift/releases/tag/4.2.1)
44+
Released on 2018-11-22
45+
46+
#### Improved
47+
- All reference documentation has been improved.
4148

4249
---
4350

Config.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CONTENTFUL_SDK_VERSION=4.2.0
1+
CONTENTFUL_SDK_VERSION=4.2.1

Contentful.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@
105105
5D52E2A02193387600C88FC9 /* OHHTTPStubs.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D52E29F2193387600C88FC9 /* OHHTTPStubs.framework */; };
106106
5D52E2A22193388200C88FC9 /* DVR.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D52E2A12193388200C88FC9 /* DVR.framework */; };
107107
5D52E2A62193388200C88FC9 /* OHHTTPStubs.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D52E2A52193388200C88FC9 /* OHHTTPStubs.framework */; };
108+
5DBCEA7821A6DA5A00BA055C /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DBCEA7721A6DA5A00BA055C /* Location.swift */; };
109+
5DBCEA7921A6DA5A00BA055C /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DBCEA7721A6DA5A00BA055C /* Location.swift */; };
110+
5DBCEA7A21A6DA5A00BA055C /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DBCEA7721A6DA5A00BA055C /* Location.swift */; };
111+
5DBCEA7B21A6DA5A00BA055C /* Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DBCEA7721A6DA5A00BA055C /* Location.swift */; };
108112
5DC635C7219997A8001E3174 /* ContentfulLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DC635C6219997A8001E3174 /* ContentfulLogger.swift */; };
109113
5DC635C8219997A8001E3174 /* ContentfulLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DC635C6219997A8001E3174 /* ContentfulLogger.swift */; };
110114
5DC635C9219997A8001E3174 /* ContentfulLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DC635C6219997A8001E3174 /* ContentfulLogger.swift */; };
@@ -289,6 +293,7 @@
289293
5D52E2A12193388200C88FC9 /* DVR.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DVR.framework; sourceTree = BUILT_PRODUCTS_DIR; };
290294
5D52E2A32193388200C88FC9 /* Nimble.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Nimble.framework; sourceTree = BUILT_PRODUCTS_DIR; };
291295
5D52E2A52193388200C88FC9 /* OHHTTPStubs.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = OHHTTPStubs.framework; sourceTree = BUILT_PRODUCTS_DIR; };
296+
5DBCEA7721A6DA5A00BA055C /* Location.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Location.swift; sourceTree = "<group>"; };
292297
5DC635C6219997A8001E3174 /* ContentfulLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentfulLogger.swift; sourceTree = "<group>"; };
293298
5DC635CE219AC0B0001E3174 /* LoggerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoggerTests.swift; sourceTree = "<group>"; };
294299
5DD410462190BC8B003FC01E /* RichText.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RichText.swift; sourceTree = "<group>"; };
@@ -497,6 +502,7 @@
497502
ED5F8F9E1F94D52200C86411 /* QueryOperation.swift */,
498503
ED5F8F901F8F9EA200C86411 /* TypedQuery.swift */,
499504
ED0876D91E1D07B3008E1A06 /* Date.swift */,
505+
5DBCEA7721A6DA5A00BA055C /* Location.swift */,
500506
A114BBBF1C4FD3C300DE6679 /* SyncSpace.swift */,
501507
A1B2E3641BBACF2C00814D63 /* Locale.swift */,
502508
A10FF9D41BBB3676001AA4E9 /* Error.swift */,
@@ -1023,6 +1029,7 @@
10231029
5D52E2492193375300C88FC9 /* Client.swift in Sources */,
10241030
5D52E24A2193375300C88FC9 /* ClientConfiguration.swift in Sources */,
10251031
5D52E24B2193375300C88FC9 /* Endpoints.swift in Sources */,
1032+
5DBCEA7A21A6DA5A00BA055C /* Location.swift in Sources */,
10261033
5D52E24C2193375300C88FC9 /* Sys.swift in Sources */,
10271034
5D52E24D2193375300C88FC9 /* Space.swift in Sources */,
10281035
5D52E24E2193375300C88FC9 /* ContentType.swift in Sources */,
@@ -1084,6 +1091,7 @@
10841091
ED737C941EF1785A00ECB3F1 /* Persistence.swift in Sources */,
10851092
A19CA3E21B8386CC00A0EFCD /* ClientConfiguration.swift in Sources */,
10861093
A10FF9DA1BBB4680001AA4E9 /* ContentType.swift in Sources */,
1094+
5DBCEA7821A6DA5A00BA055C /* Location.swift in Sources */,
10871095
5DD410472190BC8B003FC01E /* RichText.swift in Sources */,
10881096
ED02DC1320E11D0A005EC57B /* Result.swift in Sources */,
10891097
ED02DC1720E11D0A005EC57B /* Util.swift in Sources */,
@@ -1171,6 +1179,7 @@
11711179
ED737C951EF1785A00ECB3F1 /* Persistence.swift in Sources */,
11721180
ED36B7001E3BD052005581FD /* Field.swift in Sources */,
11731181
ED1D789B1F2F96260048E169 /* DataCache.swift in Sources */,
1182+
5DBCEA7921A6DA5A00BA055C /* Location.swift in Sources */,
11741183
5DD410482190BC8B003FC01E /* RichText.swift in Sources */,
11751184
ED02DC1420E11D0A005EC57B /* Result.swift in Sources */,
11761185
ED02DC1820E11D0A005EC57B /* Util.swift in Sources */,
@@ -1206,6 +1215,7 @@
12061215
ED36B7241E3BD053005581FD /* SyncSpace.swift in Sources */,
12071216
ED737C971EF1785A00ECB3F1 /* Persistence.swift in Sources */,
12081217
ED1D789D1F2F96260048E169 /* DataCache.swift in Sources */,
1218+
5DBCEA7B21A6DA5A00BA055C /* Location.swift in Sources */,
12091219
5DD4104A2190BC8B003FC01E /* RichText.swift in Sources */,
12101220
ED02DC1620E11D0A005EC57B /* Result.swift in Sources */,
12111221
ED02DC1A20E11D0A005EC57B /* Util.swift in Sources */,

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// swift-tools-version:4.0
22
import PackageDescription
33

4-
let package = Package(
4+
public let package = Package(
55
name: "Contentful",
66
products: [
77
.library(

Sources/Contentful/AppKit/Client+AppKit.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ import Foundation
1111
import AppKit
1212

1313
extension Client {
14-
/**
15-
Fetch the underlying media file as `NSImage`.
1614

17-
- returns: The signal for the `NSImage` result
18-
*/
19-
@discardableResult public func fetchImage(for asset: Asset,
20-
with imageOptions: [ImageOption] = [],
21-
then completion: @escaping ResultsHandler<NSImage>) -> URLSessionDataTask? {
15+
/// Fetch the underlying media file as `NSImage`.
16+
///
17+
/// - Parameters:
18+
/// - asset: The asset which has the url for the underlying image file.
19+
/// - imageOptions: The image options to transform the image on the server-side.
20+
/// - completion: The completion handler which takes a `Result` wrapping the `Data` returned by the API.
21+
/// - Returns: Returns the `URLSessionDataTask` of the request which can be used for request cancellation.
22+
@discardableResult
23+
public func fetchImage(for asset: Asset,
24+
with imageOptions: [ImageOption] = [],
25+
then completion: @escaping ResultsHandler<NSImage>) -> URLSessionDataTask? {
2226
return fetchData(for: asset, with: imageOptions) { result in
2327
if let imageData = result.value, let image = NSImage(data: imageData) {
2428
completion(Result.success(image))

Sources/Contentful/ArrayResponse.swift

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ private protocol HomogeneousArray: Array {
2828
var items: [ItemType] { get }
2929
}
3030

31-
/**
32-
Sometimes, when links are unresolvable (for instance, when a linked entry is not published), the API
33-
will return an array of errors, one for each unresolvable link.
34-
*/
31+
/// Sometimes, when links are unresolvable (for instance, when a linked entry is not published), the API
32+
/// will return an array of errors, one for each unresolvable link.
3533
public struct ArrayResponseError: Decodable {
3634
/// The system fields of the error.
3735
public struct Sys: Decodable {
38-
let id: String
39-
let type: String
36+
/// The identifer of the error.
37+
public let id: String
38+
/// The type identifier for the error.
39+
public let type: String
4040
}
4141

4242
/// System fields for the unresolvable link.
@@ -45,24 +45,21 @@ public struct ArrayResponseError: Decodable {
4545
public let sys: ArrayResponseError.Sys
4646
}
4747

48-
/**
49-
A list of resources in Contentful
50-
51-
This is the result type for any request of a collection of resources.
52-
See: <https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/collection-resources-and-pagination>
53-
*/
48+
/// A list of resources in Contentful
49+
/// This is the result type for any request of a collection of resources.
50+
/// See: <https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/collection-resources-and-pagination>
5451
public struct ArrayResponse<ItemType>: HomogeneousArray where ItemType: Decodable & EndpointAccessible {
5552

56-
/// The resources which are part of the given array
53+
/// The resources which are part of the array response.
5754
public let items: [ItemType]
5855

59-
/// The maximum number of resources originally requested
56+
/// The maximum number of resources originally requested.
6057
public let limit: UInt
6158

62-
/// The number of elements skipped when performing the request
59+
/// The number of elements skipped when performing the request.
6360
public let skip: UInt
6461

65-
/// The total number of resources which matched the original request
62+
/// The total number of resources which matched the original request.
6663
public let total: UInt
6764

6865
/// An array of errors, or partial errors, which describe links which were returned in the response that
@@ -80,15 +77,15 @@ public struct ArrayResponse<ItemType>: HomogeneousArray where ItemType: Decodabl
8077
}
8178

8279
internal struct Includes: Decodable {
83-
let assets: [Asset]?
84-
let entries: [Entry]?
80+
internal let assets: [Asset]?
81+
internal let entries: [Entry]?
8582

8683
private enum CodingKeys: String, CodingKey {
8784
case assets = "Asset"
8885
case entries = "Entry"
8986
}
9087

91-
init(from decoder: Decoder) throws {
88+
internal init(from decoder: Decoder) throws {
9289
let values = try decoder.container(keyedBy: CodingKeys.self)
9390
assets = try values.decodeIfPresent([Asset].self, forKey: .assets)
9491
entries = try values.decodeIfPresent([Entry].self, forKey: .entries)
@@ -172,15 +169,15 @@ extension ArrayResponse: Decodable {
172169
}
173170

174171
internal struct MappedIncludes: Decodable {
175-
let assets: [Asset]?
176-
let entries: [EntryDecodable]?
172+
internal let assets: [Asset]?
173+
internal let entries: [EntryDecodable]?
177174

178175
private enum CodingKeys: String, CodingKey {
179176
case assets = "Asset"
180177
case entries = "Entry"
181178
}
182179

183-
init(from decoder: Decoder) throws {
180+
internal init(from decoder: Decoder) throws {
184181
let container = try decoder.container(keyedBy: CodingKeys.self)
185182
assets = try container.decodeIfPresent([Asset].self, forKey: .assets)
186183
entries = try container.decodeHeterogeneousEntries(forKey: .entries,
@@ -197,28 +194,24 @@ internal struct MappedIncludes: Decodable {
197194
}
198195
}
199196

200-
201-
/**
202-
A list of Contentful entries that have been mapped to types conforming to `EntryDecodable` instances.
203-
A MixedArrayResponse respresents a heterogeneous collection of EntryDecodables being returned,
204-
for instance if hitting the base /entries endpoint with no additional query parameters. If there is no
205-
user-defined type for a particular entry, that entry will not be serialized at all. It is up to you to
206-
introspect the type of each element in the items array to handle the response data properly.
207-
208-
See: <https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/collection-resources-and-pagination>
209-
*/
197+
/// A list of Contentful entries that have been mapped to types conforming to `EntryDecodable` instances.
198+
/// A `MixedArrayResponse` respresents a heterogeneous collection of `EntryDecodable` being returned,
199+
/// for instance, if hitting the base `/entries` endpoint with no additional query parameters. If there is no
200+
/// user-defined type for a particular entry, that entry will not be deserialized at all. It is up to you to
201+
/// introspect the type of each element in the items array to handle the response data properly.
202+
/// See: <https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/collection-resources-and-pagination>
210203
public struct MixedArrayResponse: Array {
211204

212-
/// The resources which are part of the given array
205+
/// The resources which are part of the given array response.
213206
public let items: [EntryDecodable]
214207

215208
/// The maximum number of resources originally requested
216209
public let limit: UInt
217210

218-
/// The number of elements skipped when performing the request
211+
/// The number of elements skipped when performing the request.
219212
public let skip: UInt
220213

221-
/// The total number of resources which matched the original request
214+
/// The total number of resources which matched the original request.
222215
public let total: UInt
223216

224217
/// An array of errors, or partial errors, which describe links which were returned in the response that
@@ -261,14 +254,14 @@ extension MixedArrayResponse: Decodable {
261254
// Convenience method for grabbing the content type information of a json item in an array of resources.
262255
internal extension Swift.Array where Element == Dictionary<String, Any> {
263256

264-
func contentTypeInfo(at index: Int) -> Link? {
257+
internal func contentTypeInfo(at index: Int) -> Link? {
265258
guard let sys = self[index]["sys"] as? [String: Any], let contentTypeInfo = sys["contentType"] as? Link else {
266259
return nil
267260
}
268261
return contentTypeInfo
269262
}
270263

271-
func nodeType(at index: Int) -> NodeType? {
264+
internal func nodeType(at index: Int) -> NodeType? {
272265
guard let nodeTypeString = self[index]["nodeType"] as? String, let nodeType = NodeType(rawValue: nodeTypeString) else {
273266
return nil
274267
}

Sources/Contentful/Asset.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ public class Asset: LocalizableResource, AssetDecodable {
6060
}
6161

6262
public extension AssetProtocol {
63-
/**
64-
The URL for the underlying media file with additional options for server side manipulations
65-
such as format changes, resizing, cropping, and focusing on different areas including on faces,
66-
among others.
67-
68-
- Parameter imageOptions: An array of `ImageOption` that will be used for server side manipulations.
69-
- Throws: Will throw SDKError if the SDK is unable to generate a valid URL with the desired ImageOptions.
70-
*/
63+
64+
/// The URL for the underlying media file with additional options for server side manipulations
65+
/// such as format changes, resizing, cropping, and focusing on different areas including on faces,
66+
/// among others.
67+
///
68+
/// - Parameter imageOptions: An array of `ImageOption` that will be used for server side manipulations.
69+
/// - Returns: The URL for the image with the image manipulations, represented in the `imageOptions` parameter, applied.
70+
/// - Throws: Will throw `SDKError` if the SDK is unable to generate a valid URL with the desired ImageOptions.
7171
public func url(with imageOptions: [ImageOption] = []) throws -> URL {
7272
guard let url = try urlString?.url(with: imageOptions) else {
7373
throw SDKError.invalidURL(string: urlString ?? "No url string is stored for Asset: \(id)")
@@ -84,7 +84,7 @@ extension Asset {
8484
/// Original filename of the file.
8585
public let fileName: String
8686

87-
/// Content type of the file.
87+
/// Content type of the file.
8888
public let contentType: String
8989

9090
/// Details of the file, depending on it's MIME type.

0 commit comments

Comments
 (0)