Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.
Add SwiftLint (#104)
Kabir Oberai0425f9edeb40
diff --git a/.github/workflows/swiftlint.yml b/.github/workflows/swiftlint.ymlnew file mode 100644index 0000000..d2e5482--- /dev/null+++ b/.github/workflows/swiftlint.yml@@ -0,0 +1,19 @@+on:+ push:+ branches:+ - main+ pull_request:+ paths:+ - '.github/workflows/swiftlint.yml'+ - '.swiftlint.yml'+ - '**/*.swift'+jobs:+ swiftlint:+ runs-on: ubuntu-latest+ steps:+ - uses: actions/checkout@v4+ - name: Lint+ run: |+ make lint SWIFTLINT_FLAGS='--reporter=github-actions-logging' | tee swiftlint.log+ # fail if there are any errors or warnings+ ! grep -Eq '^::(error|warning)' swiftlint.logdiff --git a/.gitignore b/.gitignoreindex 590a95c..49a0693 100644--- a/.gitignore+++ b/.gitignore@@ -12,3 +12,4 @@ DerivedData/.docc-build/openapi+/tmpdiff --git a/.swiftlint.yml b/.swiftlint.ymlnew file mode 100644index 0000000..e685069--- /dev/null+++ b/.swiftlint.yml@@ -0,0 +1,70 @@+swiftlint_version: 0.59.1+disabled_rules:+ - trailing_comma+ - nesting+ - fallthrough+ - shorthand_operator+ - todo+ - large_tuple+ - identifier_name+ - type_name+ - unneeded_override+ - optional_data_string_conversion+ - for_where+ - blanket_disable_command+opt_in_rules:+ - closure_end_indentation+ - closure_spacing+ - empty_count+ - explicit_init+ - fatal_error_message+ - first_where+ - implicit_return+ - joined_default_parameter+ - literal_expression_end_indentation+ - overridden_super_call+ - prohibited_super_call+ - sorted_first_last+ - unneeded_parentheses_in_closure_argument+ - vertical_parameter_alignment_on_call+ - yoda_condition+ - nslocalizedstring_key+ - unused_setter_value+ - optional_enum_case_matching+ - prefer_self_type_over_type_of_self+ - contains_over_range_nil_comparison+ - flatmap_over_map_reduce+ - empty_collection_literal+ - contains_over_first_not_nil+ - contains_over_filter_count+ - contains_over_filter_is_empty+ - reduce_into+analyzer_rules:+ - unused_import+custom_rules:+ spaces_not_tabs:+ name: "Spaces not Tabs"+ regex: ^\t+ message: "Use four spaces, not tabs"+ point_zero:+ name: "Point Zero"+ regex: '(?<!iOS\s)(?<!macOS\s)(?<!\.)\b[\d_]+\.0\b'+ match_kinds:+ - number+ - attribute.builtin+ message: "Don't add a .0 to the end of floating point literals"+force_try: warning+force_cast: warning+function_body_length: 100+line_length: 135+file_length: 1000+type_body_length: 500+cyclomatic_complexity: 12+function_parameter_count: 7+implicit_return:+ included:+ - closure+excluded:+ - .build+ - macOS/Build+ - Sources/DeveloperAPI/Generateddiff --git a/Makefile b/Makefileindex a7bd312..edd2f9f 100644--- a/Makefile+++ b/Makefile@@ -126,6 +126,22 @@ docs:docs-preview:./Documentation/build.sh preview+SWIFTLINT_VERSION = $(shell head -1 .swiftlint.yml | cut -d' ' -f2)+SWIFTLINT_BIN = tmp/swiftlint/swiftlint-$(SWIFTLINT_VERSION)+SWIFTLINT_URL = https://github.com/realm/SwiftLint/releases/download/$(SWIFTLINT_VERSION)/$(if $(IS_MAC),portable_swiftlint,swiftlint_linux).zip++.PHONY: lint+lint: $(SWIFTLINT_BIN)+ $(SWIFTLINT_BIN) $(SWIFTLINT_FLAGS)++$(SWIFTLINT_BIN):+ @rm -rf tmp/swiftlint+ @mkdir -p tmp/swiftlint+ curl -fSL $(SWIFTLINT_URL) -o tmp/swiftlint/swiftlint.zip+ unzip -q tmp/swiftlint/swiftlint.zip swiftlint -d tmp/swiftlint+ @rm -f tmp/swiftlint/swiftlint.zip+ @mv tmp/swiftlint/swiftlint $@+SPEC_URL = https://developer.apple.com/sample-code/app-store-connect/app-store-connect-openapi-specification.zip.PHONY: apidiff --git a/Sources/PackLib/PackSchema.swift b/Sources/PackLib/PackSchema.swiftindex 030ef30..b7f1f80 100644--- a/Sources/PackLib/PackSchema.swift+++ b/Sources/PackLib/PackSchema.swift@@ -60,6 +60,7 @@ public struct PackSchema: Sendable {}}+ // swiftlint:disable:next force_trypublic static let `default` = try! PackSchema(validating: .init(version: .v1,orgID: "com.example"diff --git a/Sources/PackLib/Packer.swift b/Sources/PackLib/Packer.swiftindex a81f9ac..266c4b7 100644--- a/Sources/PackLib/Packer.swift+++ b/Sources/PackLib/Packer.swift@@ -104,6 +104,7 @@ public struct Packer: Sendable {let bytes = try FileHandle(forReadingFrom: src).read(upToCount: magic.count)// if the magic matches one of these it's a static archive; don't embed it.// https://github.com/apple/llvm-project/blob/e716ff14c46490d2da6b240806c04e2beef01f40/llvm/include/llvm/Object/Archive.h#L33+ // swiftlint:disable:previous line_lengthif bytes != magic && bytes != thinMagic {try await packFile(srcName: "\(name).framework", dstName: "Frameworks/\(name).framework", sign: true)}diff --git a/Sources/PackLib/Planner.swift b/Sources/PackLib/Planner.swiftindex ae87063..19b4ff8 100644--- a/Sources/PackLib/Planner.swift+++ b/Sources/PackLib/Planner.swift@@ -18,6 +18,7 @@ public struct Planner: Sendable {return decoder}()+ // swiftlint:disable:next function_body_length cyclomatic_complexitypublic func createPlan() async throws -> Plan {// TODO: cache plan using (Package.swift+Package.resolved) as the key?diff --git a/Sources/PackLib/XcodePacker.swift b/Sources/PackLib/XcodePacker.swiftindex 80bb1b5..af39c5c 100644--- a/Sources/PackLib/XcodePacker.swift+++ b/Sources/PackLib/XcodePacker.swift@@ -13,6 +13,7 @@ public struct XcodePacker {self.plan = plan}+ // swiftlint:disable:next function_body_lengthpublic func createProject() async throws -> URL {let targetName = "\(plan.product)-App"diff --git a/Sources/XKit/DeveloperServices/OpenAPI/DeveloperServices+OpenAPI.swift b/Sources/XKit/DeveloperServices/OpenAPI/DeveloperServices+OpenAPI.swiftindex ccd08ca..9065325 100644--- a/Sources/XKit/DeveloperServices/OpenAPI/DeveloperServices+OpenAPI.swift+++ b/Sources/XKit/DeveloperServices/OpenAPI/DeveloperServices+OpenAPI.swift@@ -13,6 +13,7 @@ extension DeveloperAPIClient {) {@Dependency(\.httpClient) var httpClientself.init(+ // swiftlint:disable:next force_tryserverURL: try! Servers.Server1.url(),configuration: .init(dateTranscoder: .iso8601WithFractionalSecondsdiff --git a/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift b/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swiftindex 5197bea..88658fc 100644--- a/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift+++ b/Sources/XKit/GrandSlam/Anisette/ADIDataProvider.swift@@ -225,7 +225,11 @@ public struct ADIDataProvider: AnisetteDataProvider {) async throws -> AnisetteData {let requestTime = Date()var routingInfo = routingInfo- let (mid, otp) = try await rawProvider.requestOTP(userID: localUserUID, routingInfo: &routingInfo, provisioningInfo: provisioningInfo)+ let (mid, otp) = try await rawProvider.requestOTP(+ userID: localUserUID,+ routingInfo: &routingInfo,+ provisioningInfo: provisioningInfo+ )return AnisetteData(clientTime: requestTime,routingInfo: routingInfo,diff --git a/Sources/XKit/GrandSlam/Anisette/XADIProvider.swift b/Sources/XKit/GrandSlam/Anisette/XADIProvider.swiftindex 107c83f..cf5f9d6 100644--- a/Sources/XKit/GrandSlam/Anisette/XADIProvider.swift+++ b/Sources/XKit/GrandSlam/Anisette/XADIProvider.swift@@ -153,7 +153,7 @@ public actor XADIProvider: RawADIProvider {var midLen: UInt32 = 0var otpBytes: UnsafeMutableRawPointer?var otpLen: UInt32 = 0-+let adiDirectory = directory.appending(path: "adi")try? FileManager.default.createDirectory(at: adiDirectory, withIntermediateDirectories: true)let adiFile = adiDirectory.appending(path: "adi.pb")diff --git a/Sources/XKit/GrandSlam/Crypto/SRPClient.swift b/Sources/XKit/GrandSlam/Crypto/SRPClient.swiftindex 20b26af..7b829e1 100644--- a/Sources/XKit/GrandSlam/Crypto/SRPClient.swift+++ b/Sources/XKit/GrandSlam/Crypto/SRPClient.swift@@ -111,7 +111,7 @@ struct SRPClient {let hashedPassword = Data(SHA256.hash(data: Data(password.utf8)))let pbkdfInput = if isLegacyProtocol {- Data(hashedPassword.map { String(format: "%02hhx", $0) }.joined(separator: "").utf8)+ Data(hashedPassword.map { String(format: "%02hhx", $0) }.joined().utf8)} else {hashedPassword}diff --git a/Sources/XKit/GrandSlam/Model/GrandSlamLoginData.swift b/Sources/XKit/GrandSlam/Model/GrandSlamLoginData.swiftindex 006bacd..627b1e0 100644--- a/Sources/XKit/GrandSlam/Model/GrandSlamLoginData.swift+++ b/Sources/XKit/GrandSlam/Model/GrandSlamLoginData.swift@@ -15,7 +15,7 @@ struct GrandSlamLoginData: Decodable {let cookie: Datavar identityToken: String {- "\(adsid):\(idmsToken)".data(using: .utf8)!.base64EncodedString()+ Data("\(adsid):\(idmsToken)".utf8).base64EncodedString()}private enum CodingKeys: String, CodingKey {diff --git a/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift b/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swiftindex 9a116bf..281241f 100644--- a/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift+++ b/Sources/XKit/GrandSlam/Requests/Concrete/GrandSlamValidateRequest.swift@@ -46,4 +46,3 @@ struct GrandSlamValidateSMSRequest: GrandSlamTwoFactorRequest {])}}-diff --git a/Sources/XKit/Installation/HeartbeatHandler.swift b/Sources/XKit/Installation/HeartbeatHandler.swiftindex 58f4de5..bf2add6 100644--- a/Sources/XKit/Installation/HeartbeatHandler.swift+++ b/Sources/XKit/Installation/HeartbeatHandler.swift@@ -10,7 +10,7 @@ import Foundationimport SwiftyMobileDeviceimport ConcurrencyExtras-public actor HeartbeatHandler: Sendable {+public actor HeartbeatHandler {private struct Error: Swift.Error {}private struct ReceivedPacket: Decodable {diff --git a/Sources/XKit/Signer/SignerImpl.swift b/Sources/XKit/Signer/SignerImpl.swiftindex 4afc9e6..6dda1e9 100644--- a/Sources/XKit/Signer/SignerImpl.swift+++ b/Sources/XKit/Signer/SignerImpl.swift@@ -130,7 +130,6 @@ public actor Signer {privBase, lengthOverride ?? priv.count,entsArray, entsArray.count,{- // swiftlint:disable:previous opening_brace(Unmanaged<AnyObject>.fromOpaque($0).takeUnretainedValue()diff --git a/Sources/XKit/Utilities/SigningInfo.swift b/Sources/XKit/Utilities/SigningInfo.swiftindex 2791e01..e75a512 100644--- a/Sources/XKit/Utilities/SigningInfo.swift+++ b/Sources/XKit/Utilities/SigningInfo.swift@@ -47,7 +47,7 @@ private struct UnimplementedSigningInfoManager: SigningInfoManager {func info(forIdentityID identityID: String) throws -> SigningInfo? {unimplemented(placeholder: nil)}-+func setInfo(_ info: SigningInfo?, forIdentityID identityID: String) throws {unimplemented()}diff --git a/Sources/XToolSupport/AuthCommand.swift b/Sources/XToolSupport/AuthCommand.swiftindex 3b2a33e..40f8657 100644--- a/Sources/XToolSupport/AuthCommand.swift+++ b/Sources/XToolSupport/AuthCommand.swift@@ -21,7 +21,7 @@ struct AuthOperation {var password: String?var logoutFromExisting: Bool- var mode: AuthMode? = nil+ var mode: AuthMode?var quiet = falsefunc run() async throws {diff --git a/Sources/XToolSupport/DSCommands/DSCertificatesCommand.swift b/Sources/XToolSupport/DSCommands/DSCertificatesCommand.swiftindex 569bd34..790c02e 100644--- a/Sources/XToolSupport/DSCommands/DSCertificatesCommand.swift+++ b/Sources/XToolSupport/DSCommands/DSCertificatesCommand.swift@@ -20,6 +20,7 @@ struct DSCertificatesListCommand: AsyncParsableCommand {abstract: "List certificates")+ // swiftlint:disable:next cyclomatic_complexityfunc run() async throws {let client = DeveloperAPIClient(auth: try AuthToken.saved().authData())diff --git a/Sources/XToolSupport/DSCommands/DSProfilesCommand.swift b/Sources/XToolSupport/DSCommands/DSProfilesCommand.swiftindex b9f4556..680c148 100644--- a/Sources/XToolSupport/DSCommands/DSProfilesCommand.swift+++ b/Sources/XToolSupport/DSCommands/DSProfilesCommand.swift@@ -22,6 +22,7 @@ struct DSProfilesListCommand: AsyncParsableCommand {private static let encoder = JSONEncoder()+ // swiftlint:disable:next cyclomatic_complexityfunc run() async throws {let client = DeveloperAPIClient(auth: try AuthToken.saved().authData())diff --git a/Sources/XToolSupport/DevCommand.swift b/Sources/XToolSupport/DevCommand.swiftindex 4a8c685..42d55b0 100644--- a/Sources/XToolSupport/DevCommand.swift+++ b/Sources/XToolSupport/DevCommand.swift@@ -93,7 +93,6 @@ struct DevXcodeCommand: AsyncParsableCommand {}}-struct DevBuildCommand: AsyncParsableCommand {static let configuration = CommandConfiguration(commandName: "build",diff --git a/Sources/XToolSupport/LaunchCommand.swift b/Sources/XToolSupport/LaunchCommand.swiftindex 1cc49a8..c656128 100644--- a/Sources/XToolSupport/LaunchCommand.swift+++ b/Sources/XToolSupport/LaunchCommand.swift@@ -8,7 +8,7 @@ struct LaunchCommand: AsyncParsableCommand {commandName: "launch",abstract: "Launch an installed app")-+@OptionGroup var connectionOptions: ConnectionOptions@Argument(diff --git a/Sources/XToolSupport/NewCommand.swift b/Sources/XToolSupport/NewCommand.swiftindex ca1a24f..68f192b 100644--- a/Sources/XToolSupport/NewCommand.swift+++ b/Sources/XToolSupport/NewCommand.swift@@ -21,6 +21,7 @@ struct NewCommand: AsyncParsableCommand {)) var skipSetup = false+ // swiftlint:disable:next function_body_lengthfunc run() async throws {if !skipSetup {// perform any remaining setup steps first@@ -114,7 +115,7 @@ struct NewCommand: AsyncParsableCommand {.swiftpm/configuration/registries.json.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata.netrc-+/xtool"""),@@ -134,7 +135,7 @@ struct NewCommand: AsyncParsableCommand {"Sources/\(moduleName)/\(moduleName)App.swift","""import SwiftUI-+@mainstruct \(moduleName)App: App {var body: some Scene {@@ -150,7 +151,7 @@ struct NewCommand: AsyncParsableCommand {"Sources/\(moduleName)/ContentView.swift","""import SwiftUI-+struct ContentView: View {var body: some View {VStack {diff --git a/Sources/XToolSupport/SDKBuilder.swift b/Sources/XToolSupport/SDKBuilder.swiftindex 75230cf..40b2dd3 100644--- a/Sources/XToolSupport/SDKBuilder.swift+++ b/Sources/XToolSupport/SDKBuilder.swift@@ -219,6 +219,7 @@ struct SDKBuilder {try await tarExit}+ // swiftlint:disable:next cyclomatic_complexityprivate func installDeveloper(in output: URL) async throws -> URL {let dev = output.appendingPathComponent("Developer")diff --git a/Sources/XToolSupport/SDKCommand.swift b/Sources/XToolSupport/SDKCommand.swiftindex 3508e03..ebb75c6 100644--- a/Sources/XToolSupport/SDKCommand.swift+++ b/Sources/XToolSupport/SDKCommand.swift@@ -172,6 +172,7 @@ struct DarwinSDK {// should be something like// swiftResourcesPath: /home/user/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift+ // swiftlint:disable:previous line_lengthlet resourcesPathPrefix = "swiftResourcesPath: "let outputString = String(decoding: try await outputData, as: UTF8.self)diff --git a/Sources/XToolSupport/SetupCommand.swift b/Sources/XToolSupport/SetupCommand.swiftindex e27be91..3546712 100644--- a/Sources/XToolSupport/SetupCommand.swift+++ b/Sources/XToolSupport/SetupCommand.swift@@ -42,11 +42,11 @@ struct SetupOperation {case nil:let path = try await Console.prompt("""Now generating the Darwin SDK.-+Please download Xcode from http://developer.apple.com/download/all/?q=Xcodeand enter the path to the downloaded Xcode.xip.-- Path to Xcode.xip:++ Path to Xcode.xip: \("" /* pacify swiftlint trailing_whitespace */)""")let expanded = (path as NSString).expandingTildeInPathdiff --git a/Sources/XToolSupport/UninstallCommand.swift b/Sources/XToolSupport/UninstallCommand.swiftindex 57aae09..2bdbc5b 100644--- a/Sources/XToolSupport/UninstallCommand.swift+++ b/Sources/XToolSupport/UninstallCommand.swift@@ -8,7 +8,7 @@ struct UninstallCommand: AsyncParsableCommand {commandName: "uninstall",abstract: "Uninstall an installed app")-+@OptionGroup var connectionOptions: ConnectionOptions@Argument(diff --git a/Sources/xtool/XTool.swift b/Sources/xtool/XTool.swiftindex 916475d..2968919 100644--- a/Sources/xtool/XTool.swift+++ b/Sources/xtool/XTool.swift@@ -7,7 +7,7 @@ import Dependencies@mainenum XToolMain {static func main() async throws {- prepareDependencies { dependencies in+ prepareDependencies { _ in#warning("Improve persistence mechanism")// for Windows, we could use dpapi.h or wincred.h.// for Linux, maybe use libsecret?diff --git a/Tests/XKitTests/Utilities/MockSigner.swift b/Tests/XKitTests/Utilities/MockSigner.swiftindex d4646c7..908eadc 100644--- a/Tests/XKitTests/Utilities/MockSigner.swift+++ b/Tests/XKitTests/Utilities/MockSigner.swift@@ -5,12 +5,10 @@ let addMockSigner: () = {add_signer("MockSigner",{ _, _, _, _, _, _, _, _, _, exception in- // swiftlint:disable:previous opening_braceexception.initialize(to: strdup("Mock signer not implemented"))return 1},{ _, _, exception in- // swiftlint:disable:previous opening_braceexception.initialize(to: strdup("Mock analyzer not implemented"))return nil}