Skip to content

Commit 9e9b6ba

Browse files
authored
SwiftLint fixes (#20)
* SwiftLint fixes * Change names for build & lint
1 parent 194470f commit 9e9b6ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+877
-451
lines changed

.github/workflows/build.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Build
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
jobs:
8+
build:
9+
runs-on: macos-12
10+
timeout-minutes: 10 # If a build exceeds 10 mins, it probably isn't ever going to complete
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: MacOS Version
14+
run: sw_vers
15+
- name: Toolchain version
16+
run: swift -version
17+
- name: Build
18+
run: swift build

.github/workflows/workflow.yml renamed to .github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build & Lint
1+
name: SwiftLint
22
on:
33
push:
44
branches: [ main ]

.swiftlint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
disabled_rules:
77
- todo # New project, we have a lot of // TODO:
88
- missing_docs # We miss a lot of docs right now
9-
9+
- identifier_name # This should be fixed in a future version
10+
- force_try # This should be fixed in a future version
1011
# Exclude triggering type names.
1112
type_name:
1213
excluded:

Sources/Version-Control/Base/Actions/GitHub/GitHubActions.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import Foundation
99
import AppKit
1010

1111
public enum GitHubViewType: String {
12-
case tree = "tree"
13-
case compare = "compare"
12+
case tree
13+
case compare
1414
}
1515

1616
public struct GitHubActions {
@@ -22,17 +22,17 @@ public struct GitHubActions {
2222
internal func getCurrentRepositoryGitHubURL(directoryURL: URL) throws -> String {
2323
let remoteUrls: [GitRemote] = try Remote().getRemotes(directoryURL: directoryURL)
2424

25-
for remote in remoteUrls {
26-
if remote.url.contains("github.com") {
27-
return remote.url
28-
}
25+
for remote in remoteUrls where remote.url.contains("github.com") {
26+
return remote.url
2927
}
28+
3029
return ""
3130
}
3231

3332
/// Open a specific branch of a GitHub repository in a web browser.
3433
///
35-
/// This function constructs the URL for a specific branch of a GitHub repository based on the provided parameters and opens it in the default web browser.
34+
/// This function constructs the URL for a specific branch of
35+
/// a GitHub repository based on the provided parameters and opens it in the default web browser.
3636
///
3737
/// - Parameters:
3838
/// - viewType: The type of view to open on GitHub (e.g., code, commits, pulls).
@@ -67,7 +67,8 @@ public struct GitHubActions {
6767

6868
/// Open the GitHub issue creation page for the current repository in a web browser.
6969
///
70-
/// This function constructs the URL for creating a new issue in the current repository on GitHub and opens it in the default web browser.
70+
/// This function constructs the URL for creating a new issue in
71+
/// the current repository on GitHub and opens it in the default web browser.
7172
///
7273
/// - Parameter directoryURL: The local directory URL of the Git repository.
7374
///

Sources/Version-Control/Base/Commands/Apply.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public struct Apply {
1919
///
2020
/// - Parameters:
2121
/// - directoryURL: The URL of the directory containing the git repository.
22-
/// - file: A `WorkingDirectoryFileChange` object representing the file whose changes are to be applied to the index.
22+
/// - file: A `WorkingDirectoryFileChange` object representing the file \
23+
/// whose changes are to be applied to the index.
2324
/// - Throws: An error if the git commands fail to execute.
2425
///
2526
/// # Example:
@@ -28,8 +29,10 @@ public struct Apply {
2829
/// let fileChange = WorkingDirectoryFileChange(path: "newName.txt", status: .renamed(oldName: "oldName.txt"))
2930
/// try await applyPatchToIndex(directoryURL: directoryURL, file: fileChange)
3031
/// ```
31-
func applyPatchToIndex(directoryURL: URL,
32-
file: WorkingDirectoryFileChange) throws {
32+
func applyPatchToIndex( // swiftlint:disable:this function_body_length
33+
directoryURL: URL,
34+
file: WorkingDirectoryFileChange
35+
) throws {
3336
// If the file was a rename we have to recreate that rename since we've
3437
// just blown away the index.
3538
if file.status.kind == .renamed {
@@ -79,9 +82,21 @@ public struct Apply {
7982
if let diff = diff as? TextDiff {
8083
switch diff.kind {
8184
case .image, .binary, .submodule:
82-
throw NSError(domain: "PatchError", code: 0, userInfo: [NSLocalizedDescriptionKey: "Can't create partial commit in binary file: \(file.path)"])
85+
throw NSError(
86+
domain: "com.auroraeditor.versioncontrolkit.patcherror",
87+
code: 0,
88+
userInfo: [
89+
NSLocalizedDescriptionKey: "Can't create partial commit in binary file: \(file.path)"
90+
]
91+
)
8392
case .unrenderable:
84-
throw NSError(domain: "PatchError", code: 1, userInfo: [NSLocalizedDescriptionKey: "File diff is too large to generate a partial commit: \(file.path)"])
93+
throw NSError(
94+
domain: "com.auroraeditor.versioncontrolkit.patcherror",
95+
code: 1,
96+
userInfo: [
97+
NSLocalizedDescriptionKey: "File diff is too large to generate a partial commit: \(file.path)"
98+
]
99+
)
85100
default:
86101
fatalError("Unknown diff kind: \(diff.kind)")
87102
}

Sources/Version-Control/Base/Commands/Branch.swift

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import Foundation
1111

12-
public struct Branch {
12+
public struct Branch { // swiftlint:disable:this type_body_length
1313

1414
public init() {}
1515

@@ -186,6 +186,7 @@ public struct Branch {
186186
/// - Throws: An error if the shell command fails.
187187
public func getRecentBranches(directoryURL: URL, limit: Int) throws -> [String] {
188188
let regex = try NSRegularExpression(
189+
// swiftlint:disable:next line_length
189190
pattern: #"^.*? (renamed|checkout)(?:: moving from|\s*) (?:refs/heads/|\s*)(.*?) to (?:refs/heads/|\s*)(.*?)$"#,
190191
options: []
191192
)
@@ -215,7 +216,11 @@ public struct Branch {
215216
var excludedNames = Set<String>()
216217

217218
for line in lines {
218-
if let match = regex.firstMatch(in: line, options: [], range: NSRange(location: 0, length: line.utf16.count)),
219+
if let match = regex.firstMatch(
220+
in: line,
221+
options: [],
222+
range: NSRange(location: 0, length: line.utf16.count)
223+
),
219224
match.numberOfRanges == 4 {
220225
let operationTypeRange = Range(match.range(at: 1), in: line)!
221226
let excludeBranchNameRange = Range(match.range(at: 2), in: line)!
@@ -243,7 +248,14 @@ public struct Branch {
243248
return Array(names)
244249
}
245250

246-
let noCommitsOnBranchRe = try! NSRegularExpression(pattern: "fatal: your current branch '.*' does not have any commits yet")
251+
func getCommitsOnBranch() {
252+
guard let noCommitsOnBranchRe = try? NSRegularExpression(
253+
pattern: "fatal: your current branch '.*' does not have any commits yet"
254+
) else {
255+
print("Failed to create regular expression")
256+
return
257+
}
258+
}
247259

248260
/// Asynchronously fetches the names and dates of branches checked out after a specified date.
249261
///
@@ -277,8 +289,12 @@ public struct Branch {
277289

278290
let lines = result.stdout.components(separatedBy: "\n")
279291
for line in lines {
280-
if let match = regex.firstMatch(in: line, options: [], range: NSRange(location: 0, length: line.utf16.count)),
281-
match.numberOfRanges == 3 {
292+
if let match = regex.firstMatch(
293+
in: line,
294+
options: [],
295+
range: NSRange(location: 0, length: line.utf16.count)
296+
),
297+
match.numberOfRanges == 3 {
282298
let timestampRange = Range(match.range(at: 1), in: line)!
283299
let branchNameRange = Range(match.range(at: 2), in: line)!
284300

@@ -334,8 +350,8 @@ public struct Branch {
334350
/// - newName: A string representing the new name of the branch.
335351
/// - Throws: An error if the shell command fails.
336352
public func renameBranch(directoryURL: URL,
337-
branch: GitBranch,
338-
newName: String) throws {
353+
branch: GitBranch,
354+
newName: String) throws {
339355
let args = [
340356
"branch",
341357
"-m",
@@ -472,3 +488,4 @@ public struct Branch {
472488
return mergedBranches
473489
}
474490
}
491+
// swiftlint:disable:this file_length

Sources/Version-Control/Base/Commands/Checkout.swift

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ public struct GitCheckout {
2727
return args
2828
}
2929

30-
public func getBranchCheckoutArgs(branch: GitBranch,
31-
enableRecurseSubmodulesFlag: Bool = false) -> [String] {
30+
public func getBranchCheckoutArgs(
31+
branch: GitBranch,
32+
enableRecurseSubmodulesFlag: Bool = false
33+
) -> [String] {
3234
var baseArgs: [String] = []
3335

3436
if enableRecurseSubmodulesFlag {
@@ -64,12 +66,14 @@ public struct GitCheckout {
6466
}
6567
}
6668

67-
public func getCheckoutOpts(directoryURL: URL,
68-
account: IGitAccount?,
69-
title: String,
70-
target: String,
71-
progressCallback: ProgressCallback?,
72-
initialDescription: String?) throws -> IGitExecutionOptions {
69+
public func getCheckoutOpts( // swiftlint:disable:this function_parameter_count
70+
directoryURL: URL,
71+
account: IGitAccount?,
72+
title: String,
73+
target: String,
74+
progressCallback: ProgressCallback?,
75+
initialDescription: String?
76+
) throws -> IGitExecutionOptions {
7377
var options: IGitExecutionOptions = IGitExecutionOptions()
7478

7579
guard let progressCallback = progressCallback else {
@@ -129,10 +133,12 @@ public struct GitCheckout {
129133
/// - Warning:
130134
/// Ensure that the specified `directoryURL` exists and is a valid Git repository directory.
131135
@discardableResult
132-
public func checkoutBranch(directoryURL: URL,
133-
account: IGitAccount?,
134-
branch: GitBranch,
135-
progressCallback: ProgressCallback?) throws -> Bool {
136+
public func checkoutBranch(
137+
directoryURL: URL,
138+
account: IGitAccount?,
139+
branch: GitBranch,
140+
progressCallback: ProgressCallback?
141+
) throws -> Bool {
136142
let opts = try getCheckoutOpts(
137143
directoryURL: directoryURL,
138144
account: account,

Sources/Version-Control/Base/Commands/Cherry-Pick.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public struct CherryPick {
4949
/// - baseOptions: The base options for Git execution.
5050
/// - commits: An array of `CommitOneLine` representing the commits to be cherry-picked.
5151
/// - progressCallback: An escaping closure that is called with the progress of the operation.
52-
/// - cherryPickedCount: An optional integer representing the number of commits already cherry-picked. Defaults to 0.
52+
/// - cherryPickedCount: An optional integer representing the number of commits already cherry-picked. \
53+
/// Defaults to 0.
5354
/// - Returns: An `IGitExecutionOptions` instance with the process callback configured.
5455
internal func configureOptionsWithCallBack(baseOptions: IGitExecutionOptions,
5556
commits: [Commit],
@@ -129,9 +130,11 @@ public struct CherryPick {
129130
}
130131

131132
guard let gitError = result.gitError else {
132-
throw NSError(domain: "com.auroraeditor.editor",
133-
code: 0,
134-
userInfo: [NSLocalizedDescriptionKey: "Unhandled result found: \(result)"])
133+
throw NSError(
134+
domain: "com.auroraeditor.versioncontrolkit.cherrypickerror",
135+
code: 0,
136+
userInfo: [NSLocalizedDescriptionKey: "Unhandled result found: \(result)"]
137+
)
135138
}
136139

137140
switch gitError {
@@ -140,9 +143,11 @@ public struct CherryPick {
140143
case .UnresolvedConflicts:
141144
return .outstandingFilesNotStaged
142145
default:
143-
throw NSError(domain: "com.auroraeditor.editor",
144-
code: 0,
145-
userInfo: [NSLocalizedDescriptionKey: "Unhandled Git error: \(gitError)"])
146+
throw NSError(
147+
domain: "com.auroraeditor.versioncontrolkit.cherrypickerror",
148+
code: 0,
149+
userInfo: [NSLocalizedDescriptionKey: "Unhandled Git error: \(gitError)"]
150+
)
146151
}
147152
}
148153

@@ -208,7 +213,8 @@ public struct CherryPick {
208213
/// - Parameters:
209214
/// - directoryURL: The URL of the directory where the cherry-pick operation is to be continued.
210215
/// - files: An array of `WorkingDirectoryFileChange` representing the changes to be staged.
211-
/// - manualResolutions: A dictionary mapping file paths to `ManualConflictResolution` objects. Defaults to an empty dictionary.
216+
/// - manualResolutions: A dictionary mapping file paths to `ManualConflictResolution` objects. \
217+
/// Defaults to an empty dictionary.
212218
/// - progressCallback: An optional closure called with progress information during the operation.
213219
/// - Throws: An error if the operation cannot start or if a problem occurs during execution.
214220
/// - Returns: A `CherryPickResult` indicating the outcome of the continued operation.

Sources/Version-Control/Base/Commands/Commit.swift

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -92,35 +92,39 @@ public struct GitCommit {
9292

9393
// Create merge commit
9494

95-
let result = try GitShell().git(args: ["commit",
96-
// no-edit here ensures the app does not accidentally invoke the user's editor
97-
"--no-edit",
98-
// By default Git merge commits do not contain any commentary (which
99-
// are lines prefixed with `#`). This works because the Git CLI will
100-
// prompt the user to edit the file in `.git/COMMIT_MSG` before
101-
// committing, and then it will run `--cleanup=strip`.
102-
//
103-
// This clashes with our use of `--no-edit` above as Git will now change
104-
// it's behavior to invoke `--cleanup=whitespace` as it did not ask
105-
// the user to edit the COMMIT_MSG as part of creating a commit.
106-
//
107-
// From the docs on git-commit (https://git-scm.com/docs/git-commit) I'll
108-
// quote the relevant section:
109-
// --cleanup=<mode>
110-
// strip
111-
// Strip leading and trailing empty lines, trailing whitespace,
112-
// commentary and collapse consecutive empty lines.
113-
// whitespace
114-
// Same as `strip` except #commentary is not removed.
115-
// default
116-
// Same as `strip` if the message is to be edited. Otherwise `whitespace`.
117-
//
118-
// We should emulate the behavior in this situation because we don't
119-
// let the user view or change the commit message before making the
120-
// commit.
121-
"--cleanup=strip"],
122-
path: directoryURL,
123-
name: #function)
95+
let result = try GitShell().git(
96+
args: [
97+
"commit",
98+
// no-edit here ensures the app does not accidentally invoke the user's editor
99+
"--no-edit",
100+
// By default Git merge commits do not contain any commentary (which
101+
// are lines prefixed with `#`). This works because the Git CLI will
102+
// prompt the user to edit the file in `.git/COMMIT_MSG` before
103+
// committing, and then it will run `--cleanup=strip`.
104+
//
105+
// This clashes with our use of `--no-edit` above as Git will now change
106+
// it's behavior to invoke `--cleanup=whitespace` as it did not ask
107+
// the user to edit the COMMIT_MSG as part of creating a commit.
108+
//
109+
// From the docs on git-commit (https://git-scm.com/docs/git-commit) I'll
110+
// quote the relevant section:
111+
// --cleanup=<mode>
112+
// strip
113+
// Strip leading and trailing empty lines, trailing whitespace,
114+
// commentary and collapse consecutive empty lines.
115+
// whitespace
116+
// Same as `strip` except #commentary is not removed.
117+
// default
118+
// Same as `strip` if the message is to be edited. Otherwise `whitespace`.
119+
//
120+
// We should emulate the behavior in this situation because we don't
121+
// let the user view or change the commit message before making the
122+
// commit.
123+
"--cleanup=strip"
124+
],
125+
path: directoryURL,
126+
name: #function
127+
)
124128

125129
// Parse the commit SHA from the result
126130
return parseCommitSHA(result: result)

Sources/Version-Control/Base/Commands/Description.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public struct GitDescription {
2929
/// - An error of type `Error` if any issues occur during the description retrieval process.
3030
///
3131
/// - Returns:
32-
/// The project's description as a string, or an empty string if the description is not found or cannot be retrieved.
32+
/// The project's description as a string, or an empty string if the description \
33+
/// is not found or cannot be retrieved.
3334
///
3435
/// - Example:
3536
/// ```swift

Sources/Version-Control/Base/Commands/Diff-Index.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ public struct DiffIndex {
122122

123123
var map = [String: NoRenameIndexStatus]()
124124

125-
for i in stride(from: 0, to: pieces.count - 1, by: 2) {
126-
let statusString = String(pieces[i])
127-
let path = String(pieces[i + 1])
125+
for number in stride(from: 0, to: pieces.count - 1, by: 2) {
126+
let statusString = String(pieces[number])
127+
let path = String(pieces[number + 1])
128128
let status = try getIndexStatus(status: statusString)
129129

130130
switch status {

0 commit comments

Comments
 (0)