Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftLint integration #90

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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
- empty_collection_literal
- empty_count
- empty_string
- enum_case_associated_values_count
- expiring_todo
- explicit_init
- fallthrough
- fatal_error_message
- file_name_no_space
- first_where
- flatmap_over_map_reduce
# - force_unwrapping # nice to have
okwasniewski marked this conversation as resolved.
Show resolved Hide resolved
- 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_magic_numbers # nice to have
- nslocalizedstring_key
- 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
34 changes: 28 additions & 6 deletions MiniSim.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
objects = {

/* Begin PBXBuildFile section */
52B363EA2AEC0D3D006F515C /* ParametersTableViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B363E92AEC0D3D006F515C /* ParametersTableViewModel.swift */; };
52B363EC2AEC10A3006F515C /* ParametersTableForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B363EB2AEC10A3006F515C /* ParametersTableForm.swift */; };
52B363EE2AEC10B3006F515C /* ParametersTableFormViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B363ED2AEC10B3006F515C /* ParametersTableFormViewModel.swift */; };
4AFACC742AD730BE00EC369F /* SubMenuItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AFACC732AD730BE00EC369F /* SubMenuItem.swift */; };
4AFACC762AD73D7900EC369F /* NSMenuItem+ConvenienceInit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AFACC752AD73D7900EC369F /* NSMenuItem+ConvenienceInit.swift */; };
4AFACC782AD74E9000EC369F /* DeviceListSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AFACC772AD74E9000EC369F /* DeviceListSection.swift */; };
52B363EA2AEC0D3D006F515C /* ParametersTableViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B363E92AEC0D3D006F515C /* ParametersTableViewModel.swift */; };
52B363EC2AEC10A3006F515C /* ParametersTableForm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B363EB2AEC10A3006F515C /* ParametersTableForm.swift */; };
52B363EE2AEC10B3006F515C /* ParametersTableFormViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52B363ED2AEC10B3006F515C /* ParametersTableFormViewModel.swift */; };
76059BF52AD4361C0008D38B /* SetupPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76059BF42AD4361C0008D38B /* SetupPreferences.swift */; };
76059BF72AD449DC0008D38B /* OnboardingHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76059BF62AD449DC0008D38B /* OnboardingHeader.swift */; };
76059BF92AD558C30008D38B /* SetupItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76059BF82AD558C30008D38B /* SetupItemView.swift */; };
Expand Down Expand Up @@ -83,12 +83,12 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
52B363E92AEC0D3D006F515C /* ParametersTableViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParametersTableViewModel.swift; sourceTree = "<group>"; };
52B363EB2AEC10A3006F515C /* ParametersTableForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParametersTableForm.swift; sourceTree = "<group>"; };
52B363ED2AEC10B3006F515C /* ParametersTableFormViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParametersTableFormViewModel.swift; sourceTree = "<group>"; };
4AFACC732AD730BE00EC369F /* SubMenuItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubMenuItem.swift; sourceTree = "<group>"; };
4AFACC752AD73D7900EC369F /* NSMenuItem+ConvenienceInit.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSMenuItem+ConvenienceInit.swift"; sourceTree = "<group>"; };
4AFACC772AD74E9000EC369F /* DeviceListSection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceListSection.swift; sourceTree = "<group>"; };
52B363E92AEC0D3D006F515C /* ParametersTableViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParametersTableViewModel.swift; sourceTree = "<group>"; };
52B363EB2AEC10A3006F515C /* ParametersTableForm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParametersTableForm.swift; sourceTree = "<group>"; };
52B363ED2AEC10B3006F515C /* ParametersTableFormViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParametersTableFormViewModel.swift; sourceTree = "<group>"; };
76059BF42AD4361C0008D38B /* SetupPreferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetupPreferences.swift; sourceTree = "<group>"; };
76059BF62AD449DC0008D38B /* OnboardingHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingHeader.swift; sourceTree = "<group>"; };
76059BF82AD558C30008D38B /* SetupItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SetupItemView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -374,6 +374,7 @@
buildRules = (
);
dependencies = (
4A78928A2AF1A9A3004D3FC8 /* PBXTargetDependency */,
);
name = MiniSim;
packageProductDependencies = (
Expand Down Expand Up @@ -421,6 +422,7 @@
768F8EC629954C8A00DFBCDB /* XCRemoteSwiftPackageReference "Sparkle" */,
76AC9AF72A0EB50800864A8B /* XCRemoteSwiftPackageReference "SymbolPicker" */,
763EEB112A26896B008428F1 /* XCRemoteSwiftPackageReference "CodeEditor" */,
4A7892862AF1A767004D3FC8 /* XCRemoteSwiftPackageReference "SwiftLint" */,
);
productRefGroup = 766BD2312981628A0042261B /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -539,6 +541,13 @@
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
4A78928A2AF1A9A3004D3FC8 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
productRef = 4A7892892AF1A9A3004D3FC8 /* SwiftLintPlugin */;
};
/* End PBXTargetDependency section */

/* Begin XCBuildConfiguration section */
766BD23D2981628C0042261B /* Debug */ = {
isa = XCBuildConfiguration;
Expand Down Expand Up @@ -754,6 +763,14 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
4A7892862AF1A767004D3FC8 /* XCRemoteSwiftPackageReference "SwiftLint" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "git@github.com:realm/SwiftLint.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.53.0;
};
};
7630B25F29853EF400D8B57D /* XCRemoteSwiftPackageReference "Preferences" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/sindresorhus/Preferences";
Expand Down Expand Up @@ -813,6 +830,11 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
4A7892892AF1A9A3004D3FC8 /* SwiftLintPlugin */ = {
isa = XCSwiftPackageProductDependency;
package = 4A7892862AF1A767004D3FC8 /* XCRemoteSwiftPackageReference "SwiftLint" */;
productName = "plugin:SwiftLintPlugin";
};
7630B26029853EF400D8B57D /* Preferences */ = {
isa = XCSwiftPackageProductDependency;
package = 7630B25F29853EF400D8B57D /* XCRemoteSwiftPackageReference "Preferences" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
"version" : "1.2.2"
}
},
{
"identity" : "collectionconcurrencykit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/JohnSundell/CollectionConcurrencyKit.git",
"state" : {
"revision" : "b4f23e24b5a1bff301efc5e70871083ca029ff95",
"version" : "0.2.0"
}
},
{
"identity" : "cryptoswift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/krzyzanowskim/CryptoSwift.git",
"state" : {
"revision" : "32f641cf24fc7abc1c591a2025e9f2f572648b0f",
"version" : "1.7.2"
}
},
{
"identity" : "highlightr",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -54,6 +72,15 @@
"version" : "2.3.0"
}
},
{
"identity" : "sourcekitten",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/SourceKitten.git",
"state" : {
"revision" : "b6dc09ee51dfb0c66e042d2328c017483a1a5d56",
"version" : "0.34.1"
}
},
{
"identity" : "sparkle",
"kind" : "remoteSourceControl",
Expand All @@ -63,6 +90,51 @@
"version" : "2.3.1"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531",
"version" : "1.2.3"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "74203046135342e4a4a627476dd6caf8b28fe11b",
"version" : "509.0.0"
}
},
{
"identity" : "swiftlint",
"kind" : "remoteSourceControl",
"location" : "git@github.com:realm/SwiftLint.git",
"state" : {
"revision" : "6d2e58271ebc14c37bf76d7c9f4082cc15bad718",
"version" : "0.53.0"
}
},
{
"identity" : "swiftytexttable",
"kind" : "remoteSourceControl",
"location" : "https://github.com/scottrhoyt/SwiftyTextTable.git",
"state" : {
"revision" : "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3",
"version" : "0.9.0"
}
},
{
"identity" : "swxmlhash",
"kind" : "remoteSourceControl",
"location" : "https://github.com/drmohundro/SWXMLHash.git",
"state" : {
"revision" : "a853604c9e9a83ad9954c7e3d2a565273982471f",
"version" : "7.0.2"
}
},
{
"identity" : "symbolpicker",
"kind" : "remoteSourceControl",
Expand All @@ -71,6 +143,15 @@
"revision" : "1e81757fc81fdee86f48d101eab0d0f8e9e0ec3d",
"version" : "1.4.2"
}
},
{
"identity" : "yams",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/Yams.git",
"state" : {
"revision" : "0d9ee7ea8c4ebd4a489ad7a73d5c6cad55d6fed3",
"version" : "5.0.6"
}
}
],
"version" : 2
Expand Down
29 changes: 14 additions & 15 deletions MiniSim/AccessibilityElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ import ShellOut

class AccessibilityElement {
private let underlyingElement: AXUIElement

required init(_ axUIElement: AXUIElement) {
self.underlyingElement = axUIElement
}

@discardableResult func performAction(key: String) -> AXError {
AXUIElementPerformAction(underlyingElement, key as CFString)
}

func attribute<T>(key: NSAccessibility.Attribute, type: T.Type) -> T? {
var value: AnyObject?
let result = AXUIElementCopyAttributeValue(underlyingElement, key as CFString, &value)

guard
result == .success,
let typedValue = value as? T
else {
return nil
}

return typedValue
}

func setAttribute(key: String, value: CFTypeRef) {
AXUIElementSetAttributeValue(underlyingElement, key as CFString, value);
AXUIElementSetAttributeValue(underlyingElement, key as CFString, value)
}

static func forceFocus(pid: pid_t) {
DispatchQueue.global(qos: .userInitiated).async {
let script = """
Expand All @@ -47,21 +47,20 @@ class AccessibilityElement {
_ = try? shellOut(to: script)
}
}

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] {
let app = AccessibilityElement(AXUIElementCreateApplication(pid))
let windows = app.attribute(key: .windows, type: [AXUIElement].self)
guard let windows else {
return []
}
return windows.map({AccessibilityElement($0)})

return windows.map { AccessibilityElement($0) }
}
}
8 changes: 4 additions & 4 deletions MiniSim/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import KeyboardShortcuts

class AppDelegate: NSObject, NSApplicationDelegate {
private var miniSim: MiniSim!

func applicationDidFinishLaunching(_ aNotification: Notification) {
miniSim = MiniSim()

KeyboardShortcuts.onKeyUp(for: .toggleMiniSim) {
self.miniSim.open()
}
}

func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
return true
true
}
}
Loading