diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4126439..ab06d02 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ repos: - repo: https://github.com/nicklockwood/SwiftFormat - rev: 0.54.0 + rev: 0.62.1 hooks: - id: swiftformat diff --git a/Demo/Demo/AppConfigs.swift b/Demo/Demo/AppConfigs.swift index e90ef47..707aca0 100644 --- a/Demo/Demo/AppConfigs.swift +++ b/Demo/Demo/AppConfigs.swift @@ -80,8 +80,8 @@ enum Region: String, CaseIterable, RawStringValueRepresentable { case west } -// Wanna make it more readable instead of just showing integer values? -// Then conform to `CustomStringConvertible` +/// Wanna make it more readable instead of just showing integer values? +/// Then conform to `CustomStringConvertible` enum AccountType: Int, CaseIterable, RawStringValueRepresentable, CustomStringConvertible { case guest = 0 case member = 1 diff --git a/Demo/DemoTests/SnapshotTests.swift b/Demo/DemoTests/SnapshotTests.swift index 5a378a7..f471050 100644 --- a/Demo/DemoTests/SnapshotTests.swift +++ b/Demo/DemoTests/SnapshotTests.swift @@ -13,7 +13,7 @@ final class SnapshotTests: XCTestCase { // MARK: - Snapshots ViewControllers - func testInAppModificationDisabled() throws { + func testInAppModificationDisabled() { assertVCSnapshotWithActionFromHost { try? XConfigs.show(from: $0, animated: false) } @@ -32,28 +32,28 @@ final class SnapshotTests: XCTestCase { } } - func testInputValueViewController() throws { + func testInputValueViewController() { let vc = InputValueViewController(viewModel: .init(model: .init(key: "Hello", value: "World", displayName: "Hello"))).wrapInsideNavVC().preferAsHalfSheet() assertVCSnapshotWithActionFromHost { $0.present(vc, animated: false) } } - func testInputValueViewControllerJSON() throws { + func testInputValueViewControllerJSON() { let vc = InputValueViewController(viewModel: .init(model: .init(key: "JSON", value: "{\"name\":\"Kel\", \"city\": \"Melbourne\" }", displayName: "Contact"))).wrapInsideNavVC().preferAsHalfSheet() assertVCSnapshotWithActionFromHost { $0.present(vc, animated: false) } } - func testInputValueViewControllerURL() throws { + func testInputValueViewControllerURL() { let vc = InputValueViewController(viewModel: .init(model: .init(key: "URL", value: "https://google.com", displayName: "URL"))).wrapInsideNavVC().preferAsHalfSheet() assertVCSnapshotWithActionFromHost { $0.present(vc, animated: false) } } - func testOptionViewController() throws { + func testOptionViewController() { let choices = [1, 2, 3, 4].map { "Value\($0)" }.map { Choice(displayName: $0, value: $0) } let vc = OptionViewController(viewModel: .init(model: .init(key: "Name", value: "Value1", choices: choices, displayName: "Name"))).wrapInsideNavVC().preferAsHalfSheet() assertVCSnapshotWithActionFromHost { @@ -63,7 +63,7 @@ final class SnapshotTests: XCTestCase { // MARK: - Snapshots - Views - func testActionView() throws { + func testActionView() { let view = ActionView().apply { $0.configure(with: "Action name") $0.widthAnchor.constraint(equalToConstant: 320).isActive = true @@ -71,7 +71,7 @@ final class SnapshotTests: XCTestCase { assertSnapshot(matching: view, as: .image(precision: 0.95)) } - func testKeyValueView() throws { + func testKeyValueView() { let view = KeyValueView().apply { $0.configure(with: ("Name", "Value")) $0.widthAnchor.constraint(equalToConstant: 320).isActive = true @@ -79,7 +79,7 @@ final class SnapshotTests: XCTestCase { assertSnapshot(matching: view, as: .image(precision: 0.95)) } - func testKeyValueViewWithLongValue() throws { + func testKeyValueViewWithLongValue() { let view = KeyValueView().apply { $0.configure(with: ("Name", "This a long value. Lorem ipsum sit dolor amet.")) $0.widthAnchor.constraint(equalToConstant: 320).isActive = true @@ -87,7 +87,7 @@ final class SnapshotTests: XCTestCase { assertSnapshot(matching: view, as: .image(precision: 0.95)) } - func testToggleView() throws { + func testToggleView() { let view = ToggleView().apply { $0.configure(with: ("Name", false)) $0.widthAnchor.constraint(equalToConstant: 320).isActive = true @@ -95,7 +95,7 @@ final class SnapshotTests: XCTestCase { assertSnapshot(matching: view, as: .image(precision: 0.95)) } - func testToggleViewWithOnValue() throws { + func testToggleViewWithOnValue() { let view = ToggleView().apply { $0.configure(with: ("Name", true)) $0.widthAnchor.constraint(equalToConstant: 320).isActive = true diff --git a/Demo/DemoTests/XConfigsTests.swift b/Demo/DemoTests/XConfigsTests.swift index 6a5359a..9d0a2ea 100644 --- a/Demo/DemoTests/XConfigsTests.swift +++ b/Demo/DemoTests/XConfigsTests.swift @@ -49,7 +49,7 @@ final class XConfigsTests: XCTestCase { )) } - func testTitles() throws { + func testTitles() { var title = "" var searchPlaceholderTitle = "" output.title.sink { title = $0 }.store(in: &subscriptions) diff --git a/Sources/XConfigs/Extensions/UIView++.swift b/Sources/XConfigs/Extensions/UIView++.swift index 8c913e8..015424b 100644 --- a/Sources/XConfigs/Extensions/UIView++.swift +++ b/Sources/XConfigs/Extensions/UIView++.swift @@ -2,7 +2,7 @@ import Combine import UIKit - // Provide a default `reuseIdentifier` equal to the class name. + /// Provide a default `reuseIdentifier` equal to the class name. private extension UITableViewCell { static var reuseIdentifier: String { String(describing: self) diff --git a/Sources/XConfigs/Models/SectionItemsModel.swift b/Sources/XConfigs/Models/SectionItemsModel.swift index 50b61b4..a591bbf 100644 --- a/Sources/XConfigs/Models/SectionItemsModel.swift +++ b/Sources/XConfigs/Models/SectionItemsModel.swift @@ -7,11 +7,7 @@ struct SectionItemsModel: Hashable { // MARK: Equatable -extension SectionItemsModel: Equatable { - public static func == (lhs: Self, rhs: Self) -> Bool { - lhs.section == rhs.section && lhs.items == rhs.items - } -} +extension SectionItemsModel: Equatable {} // MARK: - SectionItemsModel + NSDiffableDataSourceSnapshot diff --git a/Sources/XConfigs/ViewControllers/XConfigsViewController.swift b/Sources/XConfigs/ViewControllers/XConfigsViewController.swift index 2c5f003..ec4148d 100644 --- a/Sources/XConfigs/ViewControllers/XConfigsViewController.swift +++ b/Sources/XConfigs/ViewControllers/XConfigsViewController.swift @@ -119,7 +119,8 @@ return self.datasource.itemIdentifier(for: indexPath) }.eraseToAnyPublisher(), dismissPublisher: doneButton.tapPublisher - )) + ) + ) output.searchPlaceholderTitle.compactMap { $0 }.assign(to: \UISearchBar.placeholder, on: searchController.searchBar).store(in: &subscriptions) output.title.compactMap { $0 }.assign(to: \UIViewController.title, on: self).store(in: &subscriptions) @@ -188,11 +189,10 @@ } private func createCopyAction(_ value: String) -> UIAction { - let copyAction = UIAction(title: "Copy \"\(value)\"") { _ in + UIAction(title: "Copy \"\(value)\"") { _ in let pasteboard = UIPasteboard.general pasteboard.string = value } - return copyAction } @available(iOS 13.0, *) diff --git a/Sources/XConfigs/ViewModels/XConfigsViewModel.swift b/Sources/XConfigs/ViewModels/XConfigsViewModel.swift index 1cefe48..f3df6ff 100644 --- a/Sources/XConfigs/ViewModels/XConfigsViewModel.swift +++ b/Sources/XConfigs/ViewModels/XConfigsViewModel.swift @@ -91,7 +91,7 @@ struct XConfigsViewModel: ViewModelType { ) } - // Transform [ConfigInfo] to [SectionItemModel] + /// Transform [ConfigInfo] to [SectionItemModel] func mapConfigInfosToSectionItemsModels(searchText: String, infos: [ConfigInfo]) -> [SectionItemsModel] { var mainItems: [Item] = [.inAppModification( title: NSLocalizedString("Enable In-app modification?", comment: ""), @@ -127,7 +127,7 @@ struct XConfigsViewModel: ViewModelType { return sections } - // Transform ConfigInfo to Item + /// Transform ConfigInfo to Item func mapConfigInfoToItem(_ info: ConfigInfo) -> Item? { guard !info.readonly else { var value = info.configValue.rawString