Skip to content

Commit

Permalink
CONFIG: Add SwiftFormat (#128)
Browse files Browse the repository at this point in the history
* Rules 1

* Rules 2

* CONFIG: Add swiftformat

* Fixed multiline strings for swiftformat and swiftlint

* Fix catch let error warnings

* Update swiftformat header

* Update to Xcode 15.2

* Fix Swift 5.8 warnings

* Update file headers

* Update Linux build to use Swift 5.8 docker image

* Apply swiftformat

* Update lint workflow

* Update swiftformat to swift 5.9

* Try m1 runner

* Revert try m1 runner
  • Loading branch information
adamayoung authored Jan 15, 2024
1 parent 1a5ab1d commit e905229
Show file tree
Hide file tree
Showing 283 changed files with 6,087 additions and 631 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ jobs:
destination: platform=watchOS Simulator,name=Apple Watch Series 9 (45mm),OS=10.2
- name: tvOS
destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=17.2

steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ jobs:
- name: Swiftlint
run: swiftlint --strict --reporter github-actions-logging

swiftformt:
name: SwiftFormat
runs-on: ubuntu-latest
container:
image: docker://ghcr.io/nicklockwood/swiftformat:latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: SwiftFormat
run: swiftformat --lint .

markdownlint:
name: Markdownlint
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.9
11 changes: 11 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--typeblanklines preserve
--indent 4
--commas inline
--self init-only
--wraparguments before-first
--xcodeindentation enabled

--disable wrapMultilineStatementBraces
--disable redundantLetError

--header \n {file}\n TMDb\n\n Copyright © 2023 Adam Young.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an "AS IS" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n
21 changes: 20 additions & 1 deletion Sources/TMDb/Certifications/CertificationService.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
//
// CertificationService.swift
// TMDb
//
// Copyright © 2023 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

///
Expand Down Expand Up @@ -29,7 +48,7 @@ public final class CertificationService {
/// - Throws: TMDb error ``TMDbError``.
///
/// - Returns: A dictionary of movie certifications.
///
///
public func movieCertifications() async throws -> [String: [Certification]] {
let certifications: Certifications
do {
Expand Down
23 changes: 21 additions & 2 deletions Sources/TMDb/Certifications/Endpoints/CertificationsEndpoint.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
//
// CertificationsEndpoint.swift
// TMDb
//
// Copyright © 2023 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

enum CertificationsEndpoint {
Expand All @@ -14,12 +33,12 @@ extension CertificationsEndpoint: Endpoint {
var path: URL {
switch self {
case .movie:
return Self.basePath
Self.basePath
.appendingPathComponent("movie")
.appendingPathComponent("list")

case .tvSeries:
return Self.basePath
Self.basePath
.appendingPathComponent("tv")
.appendingPathComponent("list")
}
Expand Down
19 changes: 19 additions & 0 deletions Sources/TMDb/Company/CompanyService.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
//
// CompanyService.swift
// TMDb
//
// Copyright © 2023 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

///
Expand Down
23 changes: 21 additions & 2 deletions Sources/TMDb/Company/Endpoints/CompanyEndpoint.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
//
// CompanyEndpoint.swift
// TMDb
//
// Copyright © 2023 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

enum CompanyEndpoint {
Expand All @@ -12,8 +31,8 @@ extension CompanyEndpoint: Endpoint {

var path: URL {
switch self {
case .details(let companyID):
return Self.basePath
case let .details(companyID):
Self.basePath
.appendingPathComponent(companyID)
}
}
Expand Down
25 changes: 22 additions & 3 deletions Sources/TMDb/Configuration/ConfigurationService.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
//
// ConfigurationService.swift
// TMDb
//
// Copyright © 2023 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

///
Expand Down Expand Up @@ -30,7 +49,7 @@ public final class ConfigurationService {
/// - Throws: TMDb error ``TMDbError``.
///
/// - Returns: The API configuration.
///
///
public func apiConfiguration() async throws -> APIConfiguration {
let apiConfiguration: APIConfiguration
do {
Expand All @@ -50,7 +69,7 @@ public final class ConfigurationService {
/// - Throws: TMDb error ``TMDbError``.
///
/// - Returns: Countries used throughout TMDb,
///
///
public func countries() async throws -> [Country] {
let countries: [Country]
do {
Expand All @@ -70,7 +89,7 @@ public final class ConfigurationService {
/// - Throws: TMDb error ``TMDbError``.
///
/// - Returns: Jobs and departments used on TMDb.
///
///
public func jobsByDepartment() async throws -> [Department] {
let departments: [Department]
do {
Expand Down
27 changes: 23 additions & 4 deletions Sources/TMDb/Configuration/Endpoint/ConfigurationEndpoint.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
//
// ConfigurationEndpoint.swift
// TMDb
//
// Copyright © 2023 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

enum ConfigurationEndpoint {
Expand All @@ -16,18 +35,18 @@ extension ConfigurationEndpoint: Endpoint {
var path: URL {
switch self {
case .api:
return Self.basePath
Self.basePath

case .countries:
return Self.basePath
Self.basePath
.appendingPathComponent("countries")

case .jobs:
return Self.basePath
Self.basePath
.appendingPathComponent("jobs")

case .languages:
return Self.basePath
Self.basePath
.appendingPathComponent("languages")
}
}
Expand Down
28 changes: 25 additions & 3 deletions Sources/TMDb/Discover/DiscoverService.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
//
// DiscoverService.swift
// TMDb
//
// Copyright © 2023 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

///
Expand Down Expand Up @@ -36,9 +55,12 @@ public final class DiscoverService {
/// - Throws: TMDb error ``TMDbError``.
///
/// - Returns: Matching movies as a pageable list.
///
public func movies(sortedBy: MovieSort? = nil, withPeople people: [Person.ID]? = nil,
page: Int? = nil) async throws -> MoviePageableList {
///
public func movies(
sortedBy: MovieSort? = nil,
withPeople people: [Person.ID]? = nil,
page: Int? = nil
) async throws -> MoviePageableList {
let movieList: MoviePageableList
do {
movieList = try await apiClient.get(
Expand Down
27 changes: 23 additions & 4 deletions Sources/TMDb/Discover/Endpoints/DiscoverEndpoint.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
//
// DiscoverEndpoint.swift
// TMDb
//
// Copyright © 2023 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

enum DiscoverEndpoint {
Expand All @@ -13,15 +32,15 @@ extension DiscoverEndpoint: Endpoint {

var path: URL {
switch self {
case .movies(let sortedBy, let people, let page):
return Self.basePath
case let .movies(sortedBy, people, page):
Self.basePath
.appendingPathComponent("movie")
.appendingSortBy(sortedBy)
.appendingWithPeople(people)
.appendingPage(page)

case .tvSeries(let sortedBy, let page):
return Self.basePath
case let .tvSeries(sortedBy, page):
Self.basePath
.appendingPathComponent("tv")
.appendingSortBy(sortedBy)
.appendingPage(page)
Expand Down
19 changes: 19 additions & 0 deletions Sources/TMDb/Extensions/DateFormatter+TMDb.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
//
// DateFormatter+TMDb.swift
// TMDb
//
// Copyright © 2023 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

extension DateFormatter {
Expand Down
19 changes: 19 additions & 0 deletions Sources/TMDb/Extensions/JSONDecoder+TMDb.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
//
// JSONDecoder+TMDb.swift
// TMDb
//
// Copyright © 2023 Adam Young.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an AS IS BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

extension JSONDecoder {
Expand Down
Loading

0 comments on commit e905229

Please sign in to comment.