Skip to content

Commit

Permalink
Adding opt-in rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Garfeild committed Nov 2, 2023
1 parent 2d4535b commit 98f585f
Show file tree
Hide file tree
Showing 38 changed files with 198 additions and 124 deletions.
83 changes: 83 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
opt_in_rules:
- anonymous_argument_in_multiline_closure
- array_init
- closure_end_indentation
- closure_spacing
- collection_alignment
- comma_inheritance
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
- contains_over_range_nil_comparison
- convenience_type
- direct_return
- discarded_notification_center_observer
- discouraged_none_name
- discouraged_object_literal
#- discouraged_optional_boolean # needs code change
- empty_collection_literal
- empty_count
- empty_string
- enum_case_associated_values_count
- expiring_todo
- explicit_init
# - explicit_type_interface # nice to have
- fallthrough
- fatal_error_message
- file_name_no_space
- first_where
- flatmap_over_map_reduce
# - force_unwrapping # nice to have
- identical_operands
- implicit_return
# - implicitly_unwrapped_optional # nice to have
- joined_default_parameter
- last_where
- legacy_multiple
- legacy_objc_type
- literal_expression_end_indentation
- local_doc_comment
- modifier_order
- multiline_arguments
- multiline_arguments_brackets
- multiline_function_chains
- multiline_literal_brackets
- multiline_parameters
- multiline_parameters_brackets
# - no_grouping_extension # nice to have
# - no_magic_numbers # nice to have
# - nslocalizedstring_key # nice to have
- number_separator
- operator_usage_whitespace
- optional_enum_case_matching
- overridden_super_call
- prefer_self_type_over_type_of_self
- reduce_into
- redundant_nil_coalescing
- redundant_self_in_closure
- redundant_type_annotation
- return_value_from_void_function
- self_binding
- shorthand_optional_binding
- sorted_first_last
- sorted_imports
- strict_fileprivate
- superfluous_else
- switch_case_on_newline
- toggle_bool
- trailing_closure
- unavailable_function
- unhandled_throwing_task
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- untyped_error_in_catch
- vertical_parameter_alignment_on_call
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- weak_delegate
- yoda_condition

identifier_name:
excluded: # excluded via string array
- id
- ID
7 changes: 3 additions & 4 deletions MiniSim/AccessibilityElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ class AccessibilityElement {
}

static func hasA11yAccess(prompt: Bool = true) -> Bool {
let checkOptPrompt = kAXTrustedCheckOptionPrompt.takeUnretainedValue() as NSString
let checkOptPrompt = kAXTrustedCheckOptionPrompt.takeUnretainedValue()
let options = [checkOptPrompt: prompt]
let accessEnabled = AXIsProcessTrustedWithOptions(options as CFDictionary?)
return accessEnabled
return AXIsProcessTrustedWithOptions(options as CFDictionary?)
}

static func allWindowsForPID(_ pid: pid_t) -> [AccessibilityElement] {
Expand All @@ -62,6 +61,6 @@ class AccessibilityElement {
return []
}

return windows.map({AccessibilityElement($0)})
return windows.map { AccessibilityElement($0) }
}
}
2 changes: 1 addition & 1 deletion MiniSim/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
return true
true
}
}
2 changes: 1 addition & 1 deletion MiniSim/AppleScript Commands/ExecuteCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by Oskar Kwasniewski on 15/08/2023.
//

import Foundation
import Cocoa
import Foundation

class ExecuteCommand: NSScriptCommand {
override func performDefaultImplementation() -> Any? {
Expand Down
2 changes: 1 addition & 1 deletion MiniSim/AppleScript Commands/GetCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by Oskar Kwasniewski on 09/07/2023.
//

import Foundation
import Cocoa
import Foundation

class GetCommands: NSScriptCommand {
override func performDefaultImplementation() -> Any? {
Expand Down
8 changes: 4 additions & 4 deletions MiniSim/AppleScript Commands/GetDevicesCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by Oskar Kwasniewski on 09/07/2023.
//

import Foundation
import Cocoa
import Foundation

class GetDevicesCommand: NSScriptCommand {
override func performDefaultImplementation() -> Any? {
Expand All @@ -19,12 +19,12 @@ class GetDevicesCommand: NSScriptCommand {
}

do {
if platform == .android {
switch platform {
case .android:
return try self.encode(DeviceService.getAndroidDevices())
} else {
case .ios:
return try self.encode(DeviceService.getIOSDevices())
}

} catch {
scriptErrorNumber = NSInternalScriptError
return nil
Expand Down
2 changes: 1 addition & 1 deletion MiniSim/AppleScript Commands/LaunchDeviceCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by Oskar Kwasniewski on 09/07/2023.
//

import Foundation
import Cocoa
import Foundation

class LaunchDeviceCommand: NSScriptCommand {
override func performDefaultImplementation() -> Any? {
Expand Down
2 changes: 1 addition & 1 deletion MiniSim/AppleScript Commands/NSScriptCommand+utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Created by Oskar Kwasniewski on 18/06/2023.
//

import Foundation
import Cocoa
import Foundation

extension NSScriptCommand {
func property(forKey key: String) -> Any? {
Expand Down
2 changes: 1 addition & 1 deletion MiniSim/Extensions/Bundle+appName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import Foundation

extension Bundle {
var appName: String? {
return object(forInfoDictionaryKey: "CFBundleDisplayName") as? String
object(forInfoDictionaryKey: "CFBundleDisplayName") as? String
}
}
3 changes: 1 addition & 2 deletions MiniSim/Extensions/Collection+get.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import Foundation

extension Collection {

/// Get at index object
///
/// - Parameter index: Index of object
/// - Returns: Element at index or nil
func get(at index: Index) -> Iterator.Element? {
return self.indices.contains(index) ? self[index] : nil
self.indices.contains(index) ? self[index] : nil
}
}
1 change: 0 additions & 1 deletion MiniSim/Extensions/NSMenuItem+ImageInit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extension NSMenuItem {
let imageName = self.getSystemImageFromName(name: title)
self.image = NSImage(systemSymbolName: imageName, accessibilityDescription: title)
}

}

self.tag = type.rawValue
Expand Down
10 changes: 5 additions & 5 deletions MiniSim/Extensions/NSNotificationName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import Foundation

extension NSNotification.Name {
static let menuWillOpen = NSNotification.Name("menuWillOpen")
static let menuDidClose = NSNotification.Name("menuDidClose")
static let deviceDeleted = NSNotification.Name("deviceDeleted")
static let commandDidSucceed = NSNotification.Name("commandDidSucceed")
extension Notification.Name {
static let menuWillOpen = Notification.Name("menuWillOpen")
static let menuDidClose = Notification.Name("menuDidClose")
static let deviceDeleted = Notification.Name("deviceDeleted")
static let commandDidSucceed = Notification.Name("commandDidSucceed")
}
10 changes: 6 additions & 4 deletions MiniSim/Extensions/String+match.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import Foundation

extension String {
func match(_ regex: String) -> [[String]] {
// swiftlint:disable:next legacy_objc_type
let nsString = self as NSString
let regexMatch = try? NSRegularExpression(pattern: regex, options: [])
let match = regexMatch?.matches(
in: self,
options: [],
range: NSRange(location: 0, length: nsString.length))
range: NSRange(location: 0, length: nsString.length)
)
.map { match in
(0..<match.numberOfRanges).map { idx in
match.range(at: idx).location == NSNotFound ? "" : nsString.substring(with: match.range(at: idx))
(0..<match.numberOfRanges).map { idx in
match.range(at: idx).location == NSNotFound ? "" : nsString.substring(with: match.range(at: idx))
}
}
}
return match ?? []
}
}
6 changes: 3 additions & 3 deletions MiniSim/Extensions/UserDefaults+Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

extension UserDefaults {
public struct Keys {
public enum Keys {
static let parameters = "parameters"
static let commands = "commands"
static let androidHome = "androidHome"
Expand All @@ -17,12 +17,12 @@ extension UserDefaults {
static let enableAndroidEmulators = "enableAndroidEmulators"
}

@objc dynamic public var androidHome: String? {
@objc public dynamic var androidHome: String? {
get { string(forKey: Keys.androidHome) }
set { set(newValue, forKey: Keys.androidHome) }
}

@objc dynamic public var isOnboardingFinished: Bool {
@objc public dynamic var isOnboardingFinished: Bool {
get { bool(forKey: Keys.isOnboardingFinished) }
set { set(newValue, forKey: Keys.isOnboardingFinished) }
}
Expand Down
30 changes: 16 additions & 14 deletions MiniSim/Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Menu: NSMenu {
assignKeyEquivalents()
}
willSet {
let deviceNames = Set(devices.map({ $0.displayName }))
let updatedDeviceNames = Set(newValue.map({ $0.displayName }))
let deviceNames = Set(devices.map { $0.displayName })
let updatedDeviceNames = Set(newValue.map { $0.displayName })
removeMenuItems(removedDevices: deviceNames.subtracting(updatedDeviceNames))
}
}
Expand Down Expand Up @@ -81,12 +81,12 @@ class Menu: NSMenu {
}

private func getDeviceByName(name: String) -> Device? {
return devices.first { $0.displayName == name }
devices.first { $0.displayName == name }
}

private func removeMenuItems(removedDevices: Set<String>) {
self.items
.filter({ removedDevices.contains($0.title) })
.filter { removedDevices.contains($0.title) }
.forEach(safeRemoveItem)
}

Expand Down Expand Up @@ -120,14 +120,14 @@ class Menu: NSMenu {
}

private func getKeyKequivalent(index: Int) -> String {
return Character(UnicodeScalar(0x0030+index)!).lowercased()
Character(UnicodeScalar(0x0030 + index)!).lowercased()
}

private func assignKeyEquivalents() {
let sections = DeviceListSection.allCases.map {$0.title}
let sections = DeviceListSection.allCases.map { $0.title }
let deviceItems = items.filter { !sections.contains($0.title) }
let iosDeviceNames = devices.filter({ $0.platform == Platform.ios }).map { $0.displayName }
let androidDeviceNames = devices.filter({ $0.platform == Platform.android }).map { $0.displayName }
let iosDeviceNames = devices.filter { $0.platform == Platform.ios }.map { $0.displayName }
let androidDeviceNames = devices.filter { $0.platform == Platform.android }.map { $0.displayName }

let iosDevices = deviceItems.filter { iosDeviceNames.contains($0.title) }
let androidDevices = deviceItems.filter { androidDeviceNames.contains($0.title) }
Expand Down Expand Up @@ -157,7 +157,7 @@ class Menu: NSMenu {

// MARK: Populate sections
private func populateDevices() {
let sortedDevices = devices.sorted(by: { $0.platform == .android && $1.platform == .ios })
let sortedDevices = devices.sorted { $0.platform == .android && $1.platform == .ios }
let platformSections: [DeviceListSection] = sections
for section in platformSections {
let devices = filter(devices: sortedDevices, for: section)
Expand Down Expand Up @@ -225,11 +225,13 @@ class Menu: NSMenu {
let actionsSubMenu = createActionsSubMenu(
for: platform.subMenuItems,
isDeviceBooted: device.booted,
callback: callback)
callback: callback
)
let customCommandSubMenu = createCustomCommandsMenu(
for: platform,
isDeviceBooted: device.booted,
callback: callback)
callback: callback
)
(actionsSubMenu + customCommandSubMenu).forEach { subMenu.addItem($0) }
return subMenu
}
Expand Down Expand Up @@ -275,16 +277,16 @@ class Menu: NSMenu {
}

private func safeInsertItem(_ item: NSMenuItem, at index: Int) {
guard !items.contains(where: {$0.title == item.title}), index <= items.count else {
guard !items.contains(where: { $0.title == item.title }),
index <= items.count else {
return
}

insertItem(item, at: index)
}

private func safeRemoveItem(_ item: NSMenuItem?) {
guard let item = item,
items.contains(item) else {
guard let item, items.contains(item) else {
return
}

Expand Down
2 changes: 1 addition & 1 deletion MiniSim/Model/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct Device: Hashable, Codable {
var name: String
var version: String?
var identifier: String?
var booted: Bool = false
var booted: Bool
var platform: Platform

var displayName: String {
Expand Down
2 changes: 1 addition & 1 deletion MiniSim/Model/Parameter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ struct Parameter: Identifiable, Hashable, Codable {
var id = UUID()
var title: String
var command: String
var enabled: Bool = true
var enabled = true
}
6 changes: 3 additions & 3 deletions MiniSim/Model/Variables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ enum Variables: String {
case xcrunPath = "$xcrun_path"

static var common: [Variables] {
return [deviceName]
[deviceName]
}

static var android: [Variables] {
return [androidHomePath, adbPath]
[androidHomePath, adbPath]
}

static var ios: [Variables] {
return [uuid, xcrunPath]
[uuid, xcrunPath]
}

var description: String {
Expand Down
Loading

0 comments on commit 98f585f

Please sign in to comment.