Skip to content

Commit

Permalink
remove some redundant returns
Browse files Browse the repository at this point in the history
  • Loading branch information
yonaskolb committed Jan 9, 2024
1 parent 591711f commit 7b385b3
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 36 deletions.
6 changes: 2 additions & 4 deletions Sources/MintCLI/MintCLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ public class MintCLI {
extension MintError: ProcessError {

public var message: String? {
return "🌱 \(description.red)"
"🌱 \(description.red)"
}

public var exitStatus: Int32 {
return 1
}
public var exitStatus: Int32 { 1 }
}
2 changes: 1 addition & 1 deletion Sources/MintKit/Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PathKit
struct Cache: Hashable {
struct PackageInfo: Hashable {
var name: String {
return PackageReference(repo: gitRepo).name
PackageReference(repo: gitRepo).name
}

let gitRepo: String
Expand Down
2 changes: 1 addition & 1 deletion Sources/MintKit/InputReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ extension Input {
}

static func confirmation(_ question: String) -> Bool {
return readBool(prompt: "\(question) (y/n)")
readBool(prompt: "\(question) (y/n)")
}
}
6 changes: 3 additions & 3 deletions Sources/MintKit/InstallStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ struct InstallStatus {

var warning: String? {
switch status {
case .file: return "An executable that was not installed by mint already exists at \(path)."
case let .symlink(symlink): return "An executable that was not installed by mint already exists at \(path) that is symlinked to \(symlink)."
default: return nil
case .file: "An executable that was not installed by mint already exists at \(path)."
case let .symlink(symlink): "An executable that was not installed by mint already exists at \(path) that is symlinked to \(symlink)."
default: nil
}
}
}
4 changes: 2 additions & 2 deletions Sources/MintKit/Mint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class Mint {
public var mintFilePath: Path

var packagesPath: Path {
return path + "packages"
path + "packages"
}

var metadataPath: Path {
return path + "metadata.json"
path + "metadata.json"
}

public var standardOut: WritableStream
Expand Down
26 changes: 13 additions & 13 deletions Sources/MintKit/MintError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ public enum MintError: Error, CustomStringConvertible, Equatable, LocalizedError

public var description: String {
switch self {
case let .packageNotFound(package): return "\(package.quoted) package not found"
case let .repoNotFound(repo): return "Git repo not found at \(repo.quoted)"
case let .cloneError(package): return "Couldn't clone \(package.gitPath) \(package.version)"
case let .mintfileNotFound(path): return "\(path) not found"
case let .invalidExecutable(executable): return "Couldn't find executable \(executable.quoted)"
case let .missingExecutable(package): return "Executable product not found in \(package.namedVersion)"
case let .packageResolveError(package): return "Failed to resolve \(package.namedVersion) with SPM"
case let .packageBuildError(package): return "Failed to build \(package.namedVersion) with SPM"
case let .packageReadError(error): return "Failed to read Package.swift file:\n\(error)"
case let .packageNotInstalled(package): return "\(package.namedVersion) not installed"
case let .inconsistentCache(error): return "Inconsistent cache, clear it up.\nError: \(error)"
case let .packageNotFound(package): "\(package.quoted) package not found"
case let .repoNotFound(repo): "Git repo not found at \(repo.quoted)"
case let .cloneError(package): "Couldn't clone \(package.gitPath) \(package.version)"
case let .mintfileNotFound(path): "\(path) not found"
case let .invalidExecutable(executable): "Couldn't find executable \(executable.quoted)"
case let .missingExecutable(package): "Executable product not found in \(package.namedVersion)"
case let .packageResolveError(package): "Failed to resolve \(package.namedVersion) with SPM"
case let .packageBuildError(package): "Failed to build \(package.namedVersion) with SPM"
case let .packageReadError(error): "Failed to read Package.swift file:\n\(error)"
case let .packageNotInstalled(package): "\(package.namedVersion) not installed"
case let .inconsistentCache(error): "Inconsistent cache, clear it up.\nError: \(error)"
}
}

public static func == (lhs: MintError, rhs: MintError) -> Bool {
return lhs.description == rhs.description
lhs.description == rhs.description
}

public var errorDescription: String? {
return description
description
}
}
2 changes: 1 addition & 1 deletion Sources/MintKit/Mintfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public struct Mintfile {
let packages: [PackageReference]

public func package(for repo: String) -> PackageReference? {
return packages.first { $0.repo.lowercased().contains(repo.lowercased()) }
packages.first { $0.repo.lowercased().contains(repo.lowercased()) }
}

public init(path: Path) throws {
Expand Down
10 changes: 5 additions & 5 deletions Sources/MintKit/PackagePath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ struct PackagePath {
self.executable = executable
}

var packagePath: Path { return path + package.repoPath }
var installPath: Path { return packagePath + "build" + package.version }
var executablePath: Path { return installPath + (executable ?? package.name) }
var packagePath: Path { path + package.repoPath }
var installPath: Path { packagePath + "build" + package.version }
var executablePath: Path { installPath + (executable ?? package.name) }

func getExecutables() throws -> [String] {
return try installPath.children()
try installPath.children()
.filter { $0.isFile && !$0.lastComponent.hasPrefix(".") && $0.extension == nil }
.map { $0.lastComponent }
}

var commandVersion: String {
return "\(executable ?? package.name) \(package.version)"
"\(executable ?? package.name) \(package.version)"
}
}
8 changes: 4 additions & 4 deletions Sources/MintKit/PackageReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public class PackageReference {
}

public var namedVersion: String {
return "\(name) \(version)"
"\(name) \(version)"
}

public var name: String {
return repo.components(separatedBy: "/").last!.replacingOccurrences(of: ".git", with: "")
repo.components(separatedBy: "/").last!.replacingOccurrences(of: ".git", with: "")
}

public var gitPath: String {
Expand Down Expand Up @@ -75,7 +75,7 @@ public class PackageReference {
}

var repoPath: String {
return gitPath
gitPath
.components(separatedBy: "://").last!
.replacingOccurrences(of: "/", with: "_")
.replacingOccurrences(of: ".git", with: "")
Expand All @@ -86,6 +86,6 @@ public class PackageReference {

extension PackageReference: Equatable {
public static func == (lhs: PackageReference, rhs: PackageReference) -> Bool {
return lhs.repo == rhs.repo && lhs.version == rhs.version
lhs.repo == rhs.repo && lhs.version == rhs.version
}
}
2 changes: 1 addition & 1 deletion Sources/MintKit/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import Foundation
public extension String {

var quoted: String {
return "\"\(self)\""
"\"\(self)\""
}
}
2 changes: 1 addition & 1 deletion Tests/MintTests/MintTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MintTests: XCTestCase {
let testPackageDir = "github.com_yonaskolb_SimplePackage"
let fullTestRepo = "https://github.com/yonaskolb/SimplePackage.git"
func expectedExecutablePath(_ version: String) -> Path {
return mintPath.absolute() + "packages" + "github.com_yonaskolb_SimplePackage/build/\(version)/simplepackage"
mintPath.absolute() + "packages" + "github.com_yonaskolb_SimplePackage/build/\(version)/simplepackage"
}

override func setUp() {
Expand Down

0 comments on commit 7b385b3

Please sign in to comment.