Skip to content

Commit 5ef0b18

Browse files
committed
Linting
1 parent 6398188 commit 5ef0b18

10 files changed

+395
-418
lines changed

sources/BridgingFunctions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension DataSizeable {
3030
value.data_size = Int32(MemoryLayout<Self>.size - offset)
3131
return value
3232
}
33-
33+
3434
mutating func setCString(_ swiftString: String, to keypath: WritableKeyPath<Self, UnsafePointer<CChar>?>) {
3535
swiftString.withCString { cStr in
3636
// Duplicate the string to create a persisting C string

sources/InputSource.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class SquirrelInstaller {
2626
}
2727
return inputSources
2828
}()
29-
29+
3030
func enabledModes() -> [InputMode] {
3131
var enabledModes = Set<InputMode>()
3232
for (mode, inputSource) in getInputSource(modes: InputMode.allCases) {
@@ -39,7 +39,7 @@ final class SquirrelInstaller {
3939
}
4040
return Array(enabledModes)
4141
}
42-
42+
4343
func register() {
4444
let enabledInputModes = enabledModes()
4545
if !enabledInputModes.isEmpty {
@@ -50,7 +50,7 @@ final class SquirrelInstaller {
5050
TISRegisterInputSource(SquirrelApp.appDir as CFURL)
5151
print("Registered input source from \(SquirrelApp.appDir)")
5252
}
53-
53+
5454
func enable(modes: [InputMode] = []) {
5555
let enabledInputModes = enabledModes()
5656
if !enabledInputModes.isEmpty && modes.isEmpty {
@@ -62,11 +62,11 @@ final class SquirrelInstaller {
6262
for (mode, inputSource) in getInputSource(modes: modesToEnable) {
6363
if let enabled = getBool(for: inputSource, key: kTISPropertyInputSourceIsEnabled), !enabled {
6464
let error = TISEnableInputSource(inputSource)
65-
print("Enable \(error == noErr ? "succeeds" : "fails") for input source: \(mode.rawValue)");
65+
print("Enable \(error == noErr ? "succeeds" : "fails") for input source: \(mode.rawValue)")
6666
}
6767
}
6868
}
69-
69+
7070
func select(mode: InputMode? = nil) {
7171
let enabledInputModes = enabledModes()
7272
let modeToSelect = mode ?? .primary
@@ -90,7 +90,7 @@ final class SquirrelInstaller {
9090
}
9191
}
9292
}
93-
93+
9494
func disable(modes: [InputMode] = []) {
9595
let modesToDisable = modes.isEmpty ? InputMode.allCases : modes
9696
for (mode, inputSource) in getInputSource(modes: modesToDisable) {
@@ -100,7 +100,7 @@ final class SquirrelInstaller {
100100
}
101101
}
102102
}
103-
103+
104104
private func getInputSource(modes: [InputMode]) -> [InputMode: TISInputSource] {
105105
var matchingSources = [InputMode: TISInputSource]()
106106
for mode in modes {
@@ -110,7 +110,7 @@ final class SquirrelInstaller {
110110
}
111111
return matchingSources
112112
}
113-
113+
114114
private func getBool(for inputSource: TISInputSource, key: CFString!) -> Bool? {
115115
let enabledRef = TISGetInputSourceProperty(inputSource, key)
116116
guard let enabled = unsafeBitCast(enabledRef, to: CFBoolean?.self) else { return nil }

sources/MacOSKeyCodes.swift

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Carbon
99
import AppKit
1010

1111
struct SquirrelKeycode {
12-
12+
1313
static func osxModifiersToRime(modifiers: NSEvent.ModifierFlags) -> UInt32 {
1414
var ret: UInt32 = 0
1515
if modifiers.contains(.capsLock) {
@@ -29,19 +29,19 @@ struct SquirrelKeycode {
2929
}
3030
return ret
3131
}
32-
32+
3333
static func osxKeycodeToRime(keycode: UInt16, keychar: Character?, shift: Bool, caps: Bool) -> UInt32 {
3434
if let code = keycodeMappings[Int(keycode)] {
3535
return UInt32(code)
3636
}
37-
37+
3838
if let keychar = keychar, keychar.isASCII, let codeValue = keychar.unicodeScalars.first?.value {
3939
// NOTE: IBus/Rime use different keycodes for uppercase/lowercase letters.
4040
if keychar.isLowercase && (shift || caps) {
4141
// lowercase -> Uppercase
4242
return keychar.uppercased().unicodeScalars.first!.value
4343
}
44-
44+
4545
switch codeValue {
4646
case 0x20...0x7e:
4747
return codeValue
@@ -57,11 +57,11 @@ struct SquirrelKeycode {
5757
break
5858
}
5959
}
60-
60+
6161
return UInt32(XK_VoidSymbol)
6262
}
63-
64-
private static let keycodeMappings: Dictionary<Int, Int32> = [
63+
64+
private static let keycodeMappings: [Int: Int32] = [
6565
// modifiers
6666
kVK_CapsLock: XK_Caps_Lock,
6767
kVK_Command: XK_Super_L, // XK_Meta_L?
@@ -73,7 +73,7 @@ struct SquirrelKeycode {
7373
kVK_RightOption: XK_Alt_R,
7474
kVK_Shift: XK_Shift_L,
7575
kVK_RightShift: XK_Shift_R,
76-
76+
7777
// special
7878
kVK_Delete: XK_BackSpace,
7979
kVK_Escape: XK_Escape,
@@ -82,7 +82,7 @@ struct SquirrelKeycode {
8282
kVK_Return: XK_Return,
8383
kVK_Space: XK_space,
8484
kVK_Tab: XK_Tab,
85-
85+
8686
// function
8787
kVK_F1: XK_F1,
8888
kVK_F2: XK_F2,
@@ -104,7 +104,7 @@ struct SquirrelKeycode {
104104
kVK_F18: XK_F18,
105105
kVK_F19: XK_F19,
106106
kVK_F20: XK_F20,
107-
107+
108108
// cursor
109109
kVK_UpArrow: XK_Up,
110110
kVK_DownArrow: XK_Down,
@@ -114,7 +114,7 @@ struct SquirrelKeycode {
114114
kVK_PageDown: XK_Page_Down,
115115
kVK_Home: XK_Home,
116116
kVK_End: XK_End,
117-
117+
118118
// keypad
119119
kVK_ANSI_Keypad0: XK_KP_0,
120120
kVK_ANSI_Keypad1: XK_KP_1,
@@ -134,13 +134,13 @@ struct SquirrelKeycode {
134134
kVK_ANSI_KeypadPlus: XK_KP_Add,
135135
kVK_ANSI_KeypadDivide: XK_KP_Divide,
136136
kVK_ANSI_KeypadEnter: XK_KP_Enter,
137-
137+
138138
// other
139139
kVK_ISO_Section: XK_section,
140140
kVK_JIS_Yen: XK_yen,
141141
kVK_JIS_Underscore: XK_underscore,
142142
kVK_JIS_KeypadComma: XK_comma,
143143
kVK_JIS_Eisu: XK_Eisu_Shift,
144-
kVK_JIS_Kana: XK_Kana_Shift,
144+
kVK_JIS_Kana: XK_Kana_Shift
145145
]
146146
}

sources/Main.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ struct SquirrelApp {
1818
static let appDir = "/Library/Input Library/Squirrel.app".withCString { dir in
1919
URL(fileURLWithFileSystemRepresentation: dir, isDirectory: false, relativeTo: nil)
2020
}
21-
21+
2222
static func main() {
2323
let rimeAPI: RimeApi_stdbool = rime_get_api_stdbool().pointee
24-
24+
2525
let handled = autoreleasepool {
2626
let installer = SquirrelInstaller()
2727
let args = CommandLine.arguments
@@ -67,7 +67,7 @@ struct SquirrelApp {
6767
return true
6868
case "--build":
6969
// Notification
70-
SquirrelApplicationDelegate.showMessage(msgText: NSLocalizedString("deploy_update", comment: ""), msgId: "deploy")
70+
SquirrelApplicationDelegate.showMessage(msgText: NSLocalizedString("deploy_update", comment: ""))
7171
// Build all schemas in current directory
7272
var builderTraits = RimeTraits.rimeStructInit()
7373
builderTraits.setCString("rime.squirrel-builder", to: \.app_name)
@@ -90,7 +90,7 @@ struct SquirrelApp {
9090
if handled {
9191
return
9292
}
93-
93+
9494
autoreleasepool {
9595
// find the bundle identifier and then initialize the input method server
9696
let main = Bundle.main
@@ -102,10 +102,10 @@ struct SquirrelApp {
102102
let delegate = SquirrelApplicationDelegate()
103103
app.delegate = delegate
104104
app.setActivationPolicy(.accessory)
105-
105+
106106
// opencc will be configured with relative dictionary paths
107107
FileManager.default.changeCurrentDirectoryPath(main.sharedSupportPath!)
108-
108+
109109
if NSApp.squirrelAppDelegate.problematicLaunchDetected() {
110110
print("Problematic launch detected!")
111111
let args = ["Problematic launch detected! Squirrel may be suffering a crash due to improper configuration. Revert previous modifications to see if the problem recurs."]
@@ -121,15 +121,15 @@ struct SquirrelApp {
121121
NSApp.squirrelAppDelegate.loadSettings()
122122
print("Squirrel reporting!")
123123
}
124-
124+
125125
// finally run everything
126126
app.run()
127127
print("Squirrel is quitting...")
128128
rimeAPI.finalize()
129129
}
130130
return
131131
}
132-
132+
133133
static let helpDoc = """
134134
Supported arguments:
135135
Perform actions:

0 commit comments

Comments
 (0)