Skip to content

Commit

Permalink
chore: run SwiftLint and SwiftFormat against the project
Browse files Browse the repository at this point in the history
  • Loading branch information
pepicrft committed Aug 8, 2024
1 parent 951e939 commit 789e4f4
Show file tree
Hide file tree
Showing 108 changed files with 630 additions and 607 deletions.
3 changes: 3 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tools]
swiftlint = "0.54.0"
swiftformat = "0.54.3"
6 changes: 6 additions & 0 deletions .mise/tasks/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# mise description="Lint the workspace"
set -euo pipefail

swiftformat $MISE_PROJECT_ROOT --lint
swiftlint lint --quiet --config $MISE_PROJECT_ROOT/.swiftlint.yml $MISE_PROJECT_ROOT/Sources
6 changes: 6 additions & 0 deletions .mise/tasks/lint-fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# mise description="Lint the workspace fixing issues"
set -euo pipefail

swiftformat $MISE_PROJECT_ROOT
swiftlint lint --fix --quiet --config $MISE_PROJECT_ROOT/.swiftlint.yml $MISE_PROJECT_ROOT/Sources
4 changes: 3 additions & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

# format options

--disable wrapMultilineStatementBraces
--disable braces
--allman false
--binarygrouping 4,8
--commas always
Expand Down Expand Up @@ -32,4 +34,4 @@
--stripunusedargs always
--trimwhitespace always
--wraparguments preserve
--wrapcollections preserve
--wrapcollections preserve
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import XCTest
@testable import FileSharedAcrossTargets

final class FileSharedAcrossTargetsTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
Expand All @@ -21,9 +20,8 @@ final class FileSharedAcrossTargetsTests: XCTestCase {

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
measure {
// Put the code you want to measure the time of here.
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

@UIApplicationMain
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
Expand Down
2 changes: 1 addition & 1 deletion Fixtures/iOS/iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

@UIApplicationMain
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/tadija/AEXML.git", .upToNextMinor(from: "4.6.1")),
.package(url: "https://github.com/kylef/PathKit.git", .upToNextMinor(from: "1.0.1")),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0")
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
],
targets: [
.target(name: "XcodeProj",
Expand All @@ -19,7 +19,7 @@ let package = Package(
.product(name: "AEXML", package: "AEXML"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
.enableExperimentalFeature("StrictConcurrency"),
]),
.testTarget(name: "XcodeProjTests", dependencies: ["XcodeProj"]),
]
Expand Down
8 changes: 4 additions & 4 deletions Sources/XcodeProj/Extensions/AEXML+XcodeFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ let attributesOrder: [String: [String]] = [
"RemoteRunnable": [
"runnableDebuggingMode",
"BundleIdentifier",
"RemotePath"
"RemotePath",
],
"Scheme": [
"LastUpgradeVersion",
"wasCreatedForAppExtension",
"version"
]
"version",
],
]

extension AEXMLElement {
Expand All @@ -128,7 +128,7 @@ extension AEXMLElement {

if !attributes.isEmpty {
// insert known attributes in the specified order.
var attributes = self.attributes
var attributes = attributes
for key in attributesOrder[name] ?? [] {
if let value = attributes.removeValue(forKey: key) {
print(key: key, value: value)
Expand Down
4 changes: 2 additions & 2 deletions Sources/XcodeProj/Extensions/Array+Extras.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Foundation

extension Array where Element: Hashable {
public extension Array where Element: Hashable {
/// Return the array with all duplicates removed.
///
/// i.e. `[ 1, 2, 3, 1, 2 ].uniqued() == [ 1, 2, 3 ]`
///
/// - note: Taken from stackoverflow.com/a/46354989/3141234, as
/// per @Alexander's comment.
public func uniqued() -> [Element] {
func uniqued() -> [Element] {
var seen = Set<Element>()
return filter { seen.insert($0).inserted }
}
Expand Down
17 changes: 8 additions & 9 deletions Sources/XcodeProj/Extensions/Path+Extras.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import Foundation

// swiftlint:disable all
import PathKit

// MARK: - Path extras.



func systemGlob(_ pattern: UnsafePointer<CChar>!, _ flags: Int32, _ errfunc: (@convention(c) (UnsafePointer<CChar>?, Int32) -> Int32)!, _ vector_ptr: UnsafeMutablePointer<glob_t>!) -> Int32 {
#if os(macOS)
return Darwin.glob(pattern, flags, errfunc, vector_ptr)
#else
return Glibc.glob(pattern, flags, errfunc, vector_ptr)
#endif
#if os(macOS)
return Darwin.glob(pattern, flags, errfunc, vector_ptr)
#else
return Glibc.glob(pattern, flags, errfunc, vector_ptr)
#endif
}

extension Path {
Expand Down Expand Up @@ -39,9 +38,9 @@ extension Path {
let flags = GLOB_TILDE | GLOB_BRACE | GLOB_MARK
if systemGlob(cPattern, flags, nil, &gt) == 0 {
#if os(macOS)
let matchc = gt.gl_matchc
let matchc = gt.gl_matchc
#else
let matchc = gt.gl_pathc
let matchc = gt.gl_pathc
#endif
return (0 ..< Int(matchc)).compactMap { index in
if let path = String(validatingUTF8: gt.gl_pathv[index]!) {
Expand Down
12 changes: 6 additions & 6 deletions Sources/XcodeProj/Extensions/String+Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import Foundation
import SwiftGlibc

public func arc4random_uniform(_ max: UInt32) -> Int32 {
(SwiftGlibc.rand() % Int32(max - 1))
SwiftGlibc.rand() % Int32(max - 1)
}
#endif

extension String {
public var quoted: String {
public extension String {
var quoted: String {
"\"\(self)\""
}

public var isQuoted: Bool {
var isQuoted: Bool {
hasPrefix("\"") && hasSuffix("\"")
}

public static func random(length: Int = 20) -> String {
static func random(length: Int = 20) -> String {
let base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
var randomString: String = ""
var randomString = ""

for _ in 0 ..< length {
let randomValue = arc4random_uniform(UInt32(base.count))
Expand Down
32 changes: 16 additions & 16 deletions Sources/XcodeProj/Extensions/String+md5.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// swiftlint:disable all
//
// String+MD5.swift
// String+md5.swift
// Kingfisher
//
// To date, adding CommonCrypto to a Swift framework is problematic. See:
Expand All @@ -22,7 +22,7 @@

import Foundation
#if canImport(CryptoKit)
import CryptoKit
import CryptoKit
#endif

extension String {
Expand All @@ -31,14 +31,14 @@ extension String {
return self
}
#if canImport(CryptoKit)
if #available(OSX 10.15, *) {
return Insecure.MD5.hash(data: data)
.withUnsafeBytes { Array($0) }.hexString
} else {
return data.slowMD5
}
if #available(OSX 10.15, *) {
return Insecure.MD5.hash(data: data)
.withUnsafeBytes { Array($0) }.hexString
} else {
return data.slowMD5
}
#else
return data.slowMD5
return data.slowMD5
#endif
}
}
Expand All @@ -48,11 +48,11 @@ private let char0 = UInt8(UnicodeScalar("0").value)

private extension DataProtocol {
var hexString: String {
let hexLen = self.count * 2
let hexLen = count * 2
var hexChars = [UInt8](repeating: 0, count: hexLen)
var offset = 0

self.regions.forEach { (_) in
for _ in regions {
for i in self {
hexChars[Int(offset * 2)] = itoh((i >> 4) & 0xF)
hexChars[Int(offset * 2 + 1)] = itoh(i & 0xF)
Expand All @@ -64,7 +64,7 @@ private extension DataProtocol {
}

func itoh(_ value: UInt8) -> UInt8 {
return (value > 9) ? (charA + value - 10) : (char0 + value)
(value > 9) ? (charA + value - 10) : (char0 + value)
}
}

Expand All @@ -91,7 +91,7 @@ func arrayOfBytes<T>(_ value: T, length: Int? = nil) -> [UInt8] {
let valuePointer = UnsafeMutablePointer<T>.allocate(capacity: 1)
valuePointer.pointee = value

let bytes = valuePointer.withMemoryRebound(to: UInt8.self, capacity: totalBytes) { (bytesPointer) -> [UInt8] in
let bytes = valuePointer.withMemoryRebound(to: UInt8.self, capacity: totalBytes) { bytesPointer -> [UInt8] in
var bytes = [UInt8](repeating: 0, count: totalBytes)
for j in 0 ..< min(MemoryLayout<T>.size, totalBytes) {
bytes[totalBytes - 1 - j] = (bytesPointer + j).pointee
Expand Down Expand Up @@ -282,7 +282,7 @@ class MD5: HashProtocol {
F = B ^ C ^ D
g = (3 * j + 5) % 16
case 48 ... 63:
F = C ^ (B | (~D))
F = C ^ (B | ~D)
g = (7 * j) % 16
default:
break
Expand All @@ -303,8 +303,8 @@ class MD5: HashProtocol {
var result = [UInt8]()
result.reserveCapacity(hh.count / 4)

hh.forEach {
let itemLE = $0.littleEndian
for item in hh {
let itemLE = item.littleEndian
let r1 = UInt8(itemLE & 0xFF)
let r2 = UInt8((itemLE >> 8) & 0xFF)
let r3 = UInt8((itemLE >> 16) & 0xFF)
Expand Down
16 changes: 8 additions & 8 deletions Sources/XcodeProj/Objects/BuildPhase/PBXBuildFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,28 @@ extension PBXBuildFile {
/// - Returns: build phase type.
/// - Throws: an error if this method is called before the build file is added to any project.
func getBuildPhase() throws -> PBXBuildPhase? {
if let buildPhase = buildPhase {
if let buildPhase {
return buildPhase
}
let projectObjects = try objects()
if let buildPhase = projectObjects.sourcesBuildPhases.values
.first(where: { $0.fileReferences?.map { $0.value }.contains(reference.value) == true }) {
.first(where: { $0.fileReferences?.map(\.value).contains(reference.value) == true }) {
return buildPhase
} else if let buildPhase = projectObjects.frameworksBuildPhases
.values.first(where: { $0.fileReferences?.map { $0.value }.contains(reference.value) == true }) {
.values.first(where: { $0.fileReferences?.map(\.value).contains(reference.value) == true }) {
return buildPhase
} else if let buildPhase = projectObjects
.resourcesBuildPhases.values
.first(where: { $0.fileReferences?.map { $0.value }.contains(reference.value) == true }) {
.first(where: { $0.fileReferences?.map(\.value).contains(reference.value) == true }) {
return buildPhase
} else if let buildPhase = projectObjects.copyFilesBuildPhases
.values.first(where: { $0.fileReferences?.map { $0.value }.contains(reference.value) == true }) {
.values.first(where: { $0.fileReferences?.map(\.value).contains(reference.value) == true }) {
return buildPhase
} else if let buildPhase = projectObjects.headersBuildPhases
.values.first(where: { $0.fileReferences?.map { $0.value }.contains(reference.value) == true }) {
.values.first(where: { $0.fileReferences?.map(\.value).contains(reference.value) == true }) {
return buildPhase
} else if let buildPhase = projectObjects.carbonResourcesBuildPhases
.values.first(where: { $0.fileReferences?.map { $0.value }.contains(reference.value) == true }) {
.values.first(where: { $0.fileReferences?.map(\.value).contains(reference.value) == true }) {
return buildPhase
}
return nil
Expand Down Expand Up @@ -186,7 +186,7 @@ final class PBXBuildPhaseFile: PlistSerializable, Equatable {
if let platformFilters = buildFile.platformFilters {
dictionary["platformFilters"] = .array(platformFilters.map { .string(.init($0)) })
}
let comment = try buildPhase.name().flatMap { "\(try buildFile.fileName() ?? "(null)") in \($0)" }
let comment = try buildPhase.name().flatMap { try "\(buildFile.fileName() ?? "(null)") in \($0)" }
return (key: CommentedString(reference, comment: comment),
value: .dictionary(dictionary))
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/XcodeProj/Objects/BuildPhase/PBXBuildPhase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class PBXBuildPhase: PBXContainerItem {
override func plistValues(proj: PBXProj, reference: String) throws -> [CommentedString: PlistValue] {
var dictionary = try super.plistValues(proj: proj, reference: reference)
dictionary["buildActionMask"] = .string(CommentedString("\(buildActionMask)"))
if let fileReferences = fileReferences {
if let fileReferences {
let files: PlistValue = .array(fileReferences.map { fileReference in
let buildFile: PBXBuildFile? = fileReference.getObject()
let name = buildFile.flatMap { try? $0.fileName() } ?? nil
Expand All @@ -97,10 +97,10 @@ public class PBXBuildPhase: PBXContainerItem {
})
dictionary["files"] = files
}
if let inputFileListPaths = inputFileListPaths {
if let inputFileListPaths {
dictionary["inputFileListPaths"] = .array(inputFileListPaths.map { .string(CommentedString($0)) })
}
if let outputFileListPaths = outputFileListPaths {
if let outputFileListPaths {
dictionary["outputFileListPaths"] = .array(outputFileListPaths.map { .string(CommentedString($0)) })
}
dictionary["runOnlyForDeploymentPostprocessing"] = .string(CommentedString("\(runOnlyForDeploymentPostprocessing.int)"))
Expand Down
16 changes: 8 additions & 8 deletions Sources/XcodeProj/Objects/BuildPhase/PBXBuildRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class PBXBuildRule: PBXObject {

/// Element name.
public var name: String?

/// The discovered dependency file to use
public var dependencyFile: String?

Expand Down Expand Up @@ -111,28 +111,28 @@ extension PBXBuildRule: PlistSerializable {
var dictionary: [CommentedString: PlistValue] = [:]
dictionary["isa"] = .string(CommentedString(PBXBuildRule.isa))
dictionary["compilerSpec"] = .string(CommentedString(compilerSpec))
if let dependencyFile = dependencyFile {
if let dependencyFile {
dictionary["dependencyFile"] = .string(CommentedString(dependencyFile))
}
if let filePatterns = filePatterns {
if let filePatterns {
dictionary["filePatterns"] = .string(CommentedString(filePatterns))
}
dictionary["fileType"] = .string(CommentedString(fileType))
dictionary["isEditable"] = .string(CommentedString("\(isEditable.int)"))
if let name = name {
if let name {
dictionary["name"] = .string(CommentedString(name))
}
dictionary["outputFiles"] = .array(outputFiles.map { .string(CommentedString($0)) })
if let inputFiles = inputFiles {
if let inputFiles {
dictionary["inputFiles"] = .array(inputFiles.map { .string(CommentedString($0)) })
}
if let outputFilesCompilerFlags = outputFilesCompilerFlags {
if let outputFilesCompilerFlags {
dictionary["outputFilesCompilerFlags"] = .array(outputFilesCompilerFlags.map { PlistValue.string(CommentedString($0)) })
}
if let script = script {
if let script {
dictionary["script"] = .string(CommentedString(script))
}
if let runOncePerArchitecture = runOncePerArchitecture {
if let runOncePerArchitecture {
dictionary["runOncePerArchitecture"] = .string(CommentedString("\(runOncePerArchitecture.int)"))
}
return (key: CommentedString(reference, comment: PBXBuildRule.isa),
Expand Down
Loading

0 comments on commit 789e4f4

Please sign in to comment.