mirror of
https://github.com/mas-cli/mas
synced 2024-11-21 19:23:01 +00:00
🧹 Lint with periphery
This commit is contained in:
parent
4848f422d6
commit
0b8acab235
35 changed files with 69 additions and 87 deletions
3
Brewfile
3
Brewfile
|
@ -7,3 +7,6 @@ brew "swiftformat"
|
||||||
|
|
||||||
tap "kylef/formulae"
|
tap "kylef/formulae"
|
||||||
brew "swiftenv"
|
brew "swiftenv"
|
||||||
|
|
||||||
|
tap "peripheryapp/periphery"
|
||||||
|
cask "periphery"
|
||||||
|
|
|
@ -96,6 +96,17 @@
|
||||||
"tap": {
|
"tap": {
|
||||||
"kylef/formulae": {
|
"kylef/formulae": {
|
||||||
"revision": "00757e80d6861651d3dc18bbc978edf9a5d0a8a9"
|
"revision": "00757e80d6861651d3dc18bbc978edf9a5d0a8a9"
|
||||||
|
},
|
||||||
|
"peripheryapp/periphery": {
|
||||||
|
"revision": "85922da2070aec89444ade214be45271f33286a1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cask": {
|
||||||
|
"periphery": {
|
||||||
|
"version": "2.4.3",
|
||||||
|
"options": {
|
||||||
|
"full_name": "periphery"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -104,7 +115,7 @@
|
||||||
"big_sur": {
|
"big_sur": {
|
||||||
"HOMEBREW_VERSION": "3.1.5-146-g64b6846",
|
"HOMEBREW_VERSION": "3.1.5-146-g64b6846",
|
||||||
"HOMEBREW_PREFIX": "/opt/homebrew",
|
"HOMEBREW_PREFIX": "/opt/homebrew",
|
||||||
"Homebrew/homebrew-core": "625fbbcc0d7c16be8838dc2c309714dd553ccbd1",
|
"Homebrew/homebrew-core": "9c6af5030d41978a1714f1c1dc5f0a8e452e308b",
|
||||||
"CLT": "12.5.0.22.9",
|
"CLT": "12.5.0.22.9",
|
||||||
"Xcode": "12.5",
|
"Xcode": "12.5",
|
||||||
"macOS": "11.3.1"
|
"macOS": "11.3.1"
|
||||||
|
|
|
@ -10,10 +10,6 @@ import CommerceKit
|
||||||
import StoreFoundation
|
import StoreFoundation
|
||||||
|
|
||||||
extension ISStoreAccount: StoreAccount {
|
extension ISStoreAccount: StoreAccount {
|
||||||
static var primaryAccountIsPresentAndSignedIn: Bool {
|
|
||||||
CKAccountStore.shared().primaryAccountIsPresentAndSignedIn
|
|
||||||
}
|
|
||||||
|
|
||||||
static var primaryAccount: StoreAccount? {
|
static var primaryAccount: StoreAccount? {
|
||||||
var account: ISStoreAccount?
|
var account: ISStoreAccount?
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,5 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
protocol StoreAccount {
|
protocol StoreAccount {
|
||||||
static var primaryAccountIsPresentAndSignedIn: Bool { get }
|
|
||||||
static var primaryAccount: StoreAccount? { get }
|
|
||||||
static func signIn(username: String, password: String, systemDialog: Bool) throws -> StoreAccount
|
|
||||||
|
|
||||||
var identifier: String { get set }
|
var identifier: String { get set }
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ protocol ExternalCommand {
|
||||||
|
|
||||||
var process: Process { get }
|
var process: Process { get }
|
||||||
|
|
||||||
var stdout: String { get }
|
|
||||||
var stderr: String { get }
|
var stderr: String { get }
|
||||||
var stdoutPipe: Pipe { get }
|
var stdoutPipe: Pipe { get }
|
||||||
var stderrPipe: Pipe { get }
|
var stderrPipe: Pipe { get }
|
||||||
|
@ -29,11 +28,6 @@ protocol ExternalCommand {
|
||||||
|
|
||||||
/// Common implementation
|
/// Common implementation
|
||||||
extension ExternalCommand {
|
extension ExternalCommand {
|
||||||
var stdout: String {
|
|
||||||
let data = stdoutPipe.fileHandleForReading.readDataToEndOfFile()
|
|
||||||
return String(data: data, encoding: .utf8) ?? ""
|
|
||||||
}
|
|
||||||
|
|
||||||
var stderr: String {
|
var stderr: String {
|
||||||
let data = stderrPipe.fileHandleForReading.readDataToEndOfFile()
|
let data = stderrPipe.fileHandleForReading.readDataToEndOfFile()
|
||||||
return String(data: data, encoding: .utf8) ?? ""
|
return String(data: data, encoding: .utf8) ?? ""
|
||||||
|
|
|
@ -18,16 +18,7 @@ protocol SoftwareProduct {
|
||||||
var itemIdentifier: NSNumber { get set }
|
var itemIdentifier: NSNumber { get set }
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Equatable
|
|
||||||
extension SoftwareProduct {
|
extension SoftwareProduct {
|
||||||
static func == (lhs: Self, rhs: Self) -> Bool {
|
|
||||||
lhs.appName == rhs.appName
|
|
||||||
&& lhs.bundleIdentifier == rhs.bundleIdentifier
|
|
||||||
&& lhs.bundlePath == rhs.bundlePath
|
|
||||||
&& lhs.bundleVersion == rhs.bundleVersion
|
|
||||||
&& lhs.itemIdentifier == rhs.itemIdentifier
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns bundleIdentifier if appName is empty string.
|
/// Returns bundleIdentifier if appName is empty string.
|
||||||
var appNameOrBundleIdentifier: String {
|
var appNameOrBundleIdentifier: String {
|
||||||
appName.isEmpty ? bundleIdentifier : appName
|
appName.isEmpty ? bundleIdentifier : appName
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class AccountCommandSpec: QuickSpec {
|
public class AccountCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("Account command") {
|
describe("Account command") {
|
||||||
it("displays active account") {
|
it("displays active account") {
|
||||||
let cmd = AccountCommand()
|
let cmd = AccountCommand()
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class HomeCommandSpec: QuickSpec {
|
public class HomeCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
let result = SearchResult(
|
let result = SearchResult(
|
||||||
trackId: 1111,
|
trackId: 1111,
|
||||||
trackViewUrl: "mas preview url",
|
trackViewUrl: "mas preview url",
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class InfoCommandSpec: QuickSpec {
|
public class InfoCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
let result = SearchResult(
|
let result = SearchResult(
|
||||||
currentVersionReleaseDate: "2019-01-07T18:53:13Z",
|
currentVersionReleaseDate: "2019-01-07T18:53:13Z",
|
||||||
fileSizeBytes: "1024",
|
fileSizeBytes: "1024",
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class InstallCommandSpec: QuickSpec {
|
public class InstallCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("install command") {
|
describe("install command") {
|
||||||
it("installs apps") {
|
it("installs apps") {
|
||||||
let cmd = InstallCommand()
|
let cmd = InstallCommand()
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class ListCommandSpec: QuickSpec {
|
public class ListCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("list command") {
|
describe("list command") {
|
||||||
it("lists stuff") {
|
it("lists stuff") {
|
||||||
let list = ListCommand()
|
let list = ListCommand()
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class LuckyCommandSpec: QuickSpec {
|
public class LuckyCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("lucky command") {
|
describe("lucky command") {
|
||||||
it("installs the first app matching a search") {
|
it("installs the first app matching a search") {
|
||||||
let cmd = LuckyCommand()
|
let cmd = LuckyCommand()
|
||||||
|
|
|
@ -12,8 +12,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class OpenCommandSpec: QuickSpec {
|
public class OpenCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
let result = SearchResult(
|
let result = SearchResult(
|
||||||
trackId: 1111,
|
trackId: 1111,
|
||||||
trackViewUrl: "fakescheme://some/url",
|
trackViewUrl: "fakescheme://some/url",
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class OutdatedCommandSpec: QuickSpec {
|
public class OutdatedCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("outdated command") {
|
describe("outdated command") {
|
||||||
it("displays apps with pending updates") {
|
it("displays apps with pending updates") {
|
||||||
let cmd = OutdatedCommand()
|
let cmd = OutdatedCommand()
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class PurchaseCommandSpec: QuickSpec {
|
public class PurchaseCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("purchase command") {
|
describe("purchase command") {
|
||||||
it("purchases apps") {
|
it("purchases apps") {
|
||||||
let cmd = PurchaseCommand()
|
let cmd = PurchaseCommand()
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class ResetCommandSpec: QuickSpec {
|
public class ResetCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("reset command") {
|
describe("reset command") {
|
||||||
it("updates stuff") {
|
it("updates stuff") {
|
||||||
let cmd = ResetCommand()
|
let cmd = ResetCommand()
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class SearchCommandSpec: QuickSpec {
|
public class SearchCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
let result = SearchResult(
|
let result = SearchResult(
|
||||||
trackId: 1111,
|
trackId: 1111,
|
||||||
trackName: "slack",
|
trackName: "slack",
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class SignInCommandSpec: QuickSpec {
|
public class SignInCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("signn command") {
|
describe("signn command") {
|
||||||
it("updates stuff") {
|
it("updates stuff") {
|
||||||
let cmd = SignInCommand()
|
let cmd = SignInCommand()
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class SignOutCommandSpec: QuickSpec {
|
public class SignOutCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("signout command") {
|
describe("signout command") {
|
||||||
it("updates stuff") {
|
it("updates stuff") {
|
||||||
let cmd = SignOutCommand()
|
let cmd = SignOutCommand()
|
||||||
|
|
|
@ -12,8 +12,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class UninstallCommandSpec: QuickSpec {
|
public class UninstallCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("uninstall command") {
|
describe("uninstall command") {
|
||||||
let appId = 12345
|
let appId = 12345
|
||||||
let app = SoftwareProductMock(
|
let app = SoftwareProductMock(
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class UpgradeCommandSpec: QuickSpec {
|
public class UpgradeCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("upgrade command") {
|
describe("upgrade command") {
|
||||||
it("updates stuff") {
|
it("updates stuff") {
|
||||||
let cmd = UpgradeCommand()
|
let cmd = UpgradeCommand()
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class VendorCommandSpec: QuickSpec {
|
public class VendorCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
let result = SearchResult(
|
let result = SearchResult(
|
||||||
trackId: 1111,
|
trackId: 1111,
|
||||||
trackViewUrl: "https://awesome.app",
|
trackViewUrl: "https://awesome.app",
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class VersionCommandSpec: QuickSpec {
|
public class VersionCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("version command") {
|
describe("version command") {
|
||||||
it("displays the current version") {
|
it("displays the current version") {
|
||||||
let cmd = VersionCommand()
|
let cmd = VersionCommand()
|
||||||
|
|
|
@ -11,14 +11,6 @@
|
||||||
class AppLibraryMock: AppLibrary {
|
class AppLibraryMock: AppLibrary {
|
||||||
var installedApps = [SoftwareProduct]()
|
var installedApps = [SoftwareProduct]()
|
||||||
|
|
||||||
/// Finds an app using a bundle identifier.
|
|
||||||
///
|
|
||||||
/// - Parameter bundleId: Bundle identifier of app.
|
|
||||||
/// - Returns: Software Product of app if found; nil otherwise.
|
|
||||||
func installedApp(forBundleId _: String) -> SoftwareProduct? {
|
|
||||||
nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func uninstallApp(app: SoftwareProduct) throws {
|
func uninstallApp(app: SoftwareProduct) throws {
|
||||||
if !installedApps.contains(where: { product -> Bool in
|
if !installedApps.contains(where: { product -> Bool in
|
||||||
app.itemIdentifier == product.itemIdentifier
|
app.itemIdentifier == product.itemIdentifier
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class MasAppLibrarySpec: QuickSpec {
|
public class MasAppLibrarySpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
let library = MasAppLibrary(softwareMap: SoftwareMapMock(products: apps))
|
let library = MasAppLibrary(softwareMap: SoftwareMapMock(products: apps))
|
||||||
|
|
||||||
describe("mas app library") {
|
describe("mas app library") {
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class MasStoreSearchSpec: QuickSpec {
|
public class MasStoreSearchSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("store") {
|
describe("store") {
|
||||||
context("when searched") {
|
context("when searched") {
|
||||||
it("can find slack") {
|
it("can find slack") {
|
||||||
|
|
|
@ -21,8 +21,8 @@ struct StoreSearchForTesting: StoreSearch {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class StoreSearchSpec: QuickSpec {
|
public class StoreSearchSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
let storeSearch = StoreSearchForTesting()
|
let storeSearch = StoreSearchForTesting()
|
||||||
|
|
||||||
describe("url string") {
|
describe("url string") {
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class OpenSystemCommandSpec: QuickSpec {
|
public class OpenSystemCommandSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("open system command") {
|
describe("open system command") {
|
||||||
context("binary path") {
|
context("binary path") {
|
||||||
it("defaults to the macOS open command") {
|
it("defaults to the macOS open command") {
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class AppListsFormatterSpec: QuickSpec {
|
public class AppListsFormatterSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
// static func reference
|
// static func reference
|
||||||
let format = AppListFormatter.format(products:)
|
let format = AppListFormatter.format(products:)
|
||||||
var products: [SoftwareProduct] = []
|
var products: [SoftwareProduct] = []
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class SearchResultsFormatterSpec: QuickSpec {
|
public class SearchResultsFormatterSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
// static func reference
|
// static func reference
|
||||||
let format = SearchResultFormatter.format(results:includePrice:)
|
let format = SearchResultFormatter.format(results:includePrice:)
|
||||||
var results: [SearchResult] = []
|
var results: [SearchResult] = []
|
||||||
|
|
|
@ -12,8 +12,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class SearchResultListSpec: QuickSpec {
|
public class SearchResultListSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("search result list") {
|
describe("search result list") {
|
||||||
it("can parse bbedit") {
|
it("can parse bbedit") {
|
||||||
let data = Data(from: "search/bbedit.json")
|
let data = Data(from: "search/bbedit.json")
|
||||||
|
|
|
@ -12,8 +12,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class SearchResultSpec: QuickSpec {
|
public class SearchResultSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("search result") {
|
describe("search result") {
|
||||||
it("can parse things") {
|
it("can parse things") {
|
||||||
let data = Data(from: "search/things-that-go-bump.json")
|
let data = Data(from: "search/things-that-go-bump.json")
|
||||||
|
|
|
@ -12,8 +12,6 @@ import Foundation
|
||||||
|
|
||||||
/// Mock NetworkSession for testing.
|
/// Mock NetworkSession for testing.
|
||||||
class NetworkSessionMock: NetworkSession {
|
class NetworkSessionMock: NetworkSession {
|
||||||
typealias CompletionHandler = (Data?, URLResponse?, Error?) -> Void
|
|
||||||
|
|
||||||
// Properties that enable us to set exactly what data or error
|
// Properties that enable us to set exactly what data or error
|
||||||
// we want our mocked URLSession to return for any request.
|
// we want our mocked URLSession to return for any request.
|
||||||
var data: Data?
|
var data: Data?
|
||||||
|
|
|
@ -11,8 +11,8 @@ import Quick
|
||||||
|
|
||||||
@testable import MasKit
|
@testable import MasKit
|
||||||
|
|
||||||
class OutputListenerSpec: QuickSpec {
|
public class OutputListenerSpec: QuickSpec {
|
||||||
override func spec() {
|
public override func spec() {
|
||||||
describe("output listener") {
|
describe("output listener") {
|
||||||
it("can intercept a single line written stdout") {
|
it("can intercept a single line written stdout") {
|
||||||
let output = OutputListener()
|
let output = OutputListener()
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
echo "==> 🚨 Linting mas"
|
echo "==> 🚨 Linting mas"
|
||||||
|
|
||||||
for LINTER in git markdownlint shfmt swiftformat swiftlint; do
|
for LINTER in git markdownlint periphery shfmt swiftformat swiftlint; do
|
||||||
if [[ ! -x "$(command -v ${LINTER})" ]]; then
|
if [[ ! -x "$(command -v ${LINTER})" ]]; then
|
||||||
echo "error: ${LINTER} is not installed. Run 'script/bootstrap' or 'brew install ${LINTER}'."
|
echo "error: ${LINTER} is not installed. Run 'script/bootstrap' or 'brew install ${LINTER}'."
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -33,6 +33,7 @@ for SOURCE in Package.swift Sources Tests; do
|
||||||
swift run swift-format lint --recursive ${SOURCE}
|
swift run swift-format lint --recursive ${SOURCE}
|
||||||
swiftlint lint --strict ${SOURCE}
|
swiftlint lint --strict ${SOURCE}
|
||||||
done
|
done
|
||||||
|
periphery scan --retain-public --strict
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "--> 📜 Bash"
|
echo "--> 📜 Bash"
|
||||||
|
|
Loading…
Reference in a new issue