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