Skip to content

Commit d6f2eab

Browse files
committed
Update SwiftLint and SwiftFormat to latest versions and tidy up code formatting
- Bring everything up to speed with Swift 5.9 and review all of the rules – some breaking ones have been fixed, some disabled ones aren't needed anymore. - Add IntelliJ `swift - list + format` shared configuration. - Add the swift-format configuration (the official one, not the good-old SwiftFormat) – the latest IntelliJ moving away from built-in formatting to this shitty alternative, but hopefully this will get reverted… 🤞
1 parent 13f4e98 commit d6f2eab

20 files changed

Lines changed: 96 additions & 69 deletions

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.swift-format

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"dotChainWrappingBehaviour": "preserve",
3+
"indentation": { "spaces": 4 },
4+
"indentSwitchCaseLabels": true,
5+
"insertSpaces": true,
6+
"lineLength": 1000,
7+
"maximumBlankLines": 2,
8+
"spacesBeforeEndOfLineComments": 1,
9+
"tabWidth": 4,
10+
"version": 1
11+
}

.swiftformat

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--swiftversion 5.9
2+
3+
## Configure rules:
4+
--closure-void preserve
5+
--else-position same-line
6+
--extension-acl on-declarations
7+
--guard-else same-line
8+
--import-grouping testable-first
9+
--linebreaks lf
10+
--semicolons inline
11+
--trim-whitespace always
12+
13+
### Disable unwanted rules:
14+
--disable andOperator
15+
--disable blankLinesAtStartOfScope
16+
--disable blankLinesBetweenScopes
17+
--disable consecutiveBlankLines
18+
--disable genericExtensions
19+
--disable hoistAwait
20+
--disable hoistPatternLet
21+
--disable hoistTry
22+
--disable indent
23+
--disable numberFormatting
24+
--disable opaqueGenericParameters
25+
--disable redundantFileprivate
26+
--disable redundantInternal
27+
--disable redundantSelf
28+
--disable redundantType
29+
--disable strongOutlets
30+
--disable todos
31+
--disable trailingClosures
32+
--disable unusedArguments
33+
--disable void
34+
--disable wrapArguments
35+
--disable wrapFunctionBodies
36+
--disable wrapLoopBodies
37+
--disable wrapMultilineStatementBraces
38+
--disable wrapPropertyBodies

.swiftlint.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,34 @@ analyzer_rules:
88
- explicit_self
99

1010
opt_in_rules:
11+
- explicit_acl
1112
- explicit_top_level_acl
1213
- modifier_order
14+
- pattern_matching_keywords
1315
- prefer_self_type_over_type_of_self
1416

1517
disabled_rules:
1618
- cyclomatic_complexity
17-
- discarded_notification_center_observer
18-
- duplicate_imports
1919
- file_length
2020
- force_cast
21-
- force_try
2221
- function_body_length
23-
- function_parameter_count
2422
- identifier_name
2523
- large_tuple
2624
- line_length
2725
- nesting
2826
- opening_brace
2927
- private_over_fileprivate
30-
- redundant_discardable_let
28+
- reduce_boolean
29+
- todo
3130
- type_body_length
32-
- type_name
33-
- unused_closure_parameter
34-
- unused_setter_value # https://github.com/realm/SwiftLint/issues/2585
35-
- weak_delegate
31+
- unneeded_override
3632

3733
trailing_comma:
3834
mandatory_comma: true
3935

36+
trailing_whitespace:
37+
ignores_comments: false
38+
4039
vertical_whitespace:
4140
max_empty_lines: 2
4241

Mintfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
realm/SwiftLint@0.62.1
2+
nicklockwood/SwiftFormat@0.59.1

Observatory.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
17FD06581333B3906BE6258A /* Test.Shortcut.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Test.Shortcut.swift; sourceTree = "<group>"; };
7373
17FD078E512F21A8ECE8F335 /* Test.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Test.swift; sourceTree = "<group>"; };
7474
17FD0872935075E62744FA2B /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; };
75+
17FD0873935075E62744FA2B /* .swift-format */ = {isa = PBXFileReference; lastKnownFileType = text; path = ".swift-format"; sourceTree = "<group>"; };
76+
17FD0874935075E62744FA2B /* .swiftformat */ = {isa = PBXFileReference; lastKnownFileType = file.swiftformat; path = .swiftformat; sourceTree = "<group>"; };
7577
17FD08D461EB26AE885B82AC /* Entrypoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Entrypoint.swift; sourceTree = "<group>"; };
7678
17FD08E9489864D454E503B4 /* Test.Observer.Event.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Test.Observer.Event.swift; sourceTree = "<group>"; };
7779
17FD0916F82FAC336830F9E0 /* Observer.Notification.Handler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Observer.Notification.Handler.swift; sourceTree = "<group>"; };
@@ -88,6 +90,7 @@
8890
17FD0F7C4A53D96FBDB8674E /* Observer.Hotkey.Handler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Observer.Hotkey.Handler.swift; sourceTree = "<group>"; };
8991
17FD0F994461E499BAC659EB /* Package.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
9092
17FD0FB54AAAEB24AB193225 /* Shortcut.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Shortcut.swift; sourceTree = "<group>"; };
93+
17FD0FB64AAAEB24AB193225 /* Mintfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Mintfile; sourceTree = "<group>"; };
9194
1968096E1E1189C984B6F696 /* Test.Keyboard.Modifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Test.Keyboard.Modifier.swift; sourceTree = "<group>"; };
9295
691492DAECCDA8F37886F020 /* framework.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = framework.plist; sourceTree = "<group>"; };
9396
692C0EE3AC3E3172836E1B96 /* application.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = application.plist; sourceTree = "<group>"; };
@@ -338,7 +341,10 @@
338341
E6D7642B1CDDBA100071CCB0 /* product */,
339342
17FD0BB4EDB0784084E6A631 /* source */,
340343
17FD0872935075E62744FA2B /* .gitignore */,
344+
17FD0873935075E62744FA2B /* .swift-format */,
345+
17FD0874935075E62744FA2B /* .swiftformat */,
341346
17FD094B1DAE4CF98579274D /* .swiftlint.yml */,
347+
17FD0FB64AAAEB24AB193225 /* Mintfile */,
342348
17FD0F994461E499BAC659EB /* Package.swift */,
343349
E690D12D267D1B0C002FD479 /* Package.resolved */,
344350
E690D12E267D1B14002FD479 /* LICENSE.md */,

Package.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// swift-tools-version: 5.7
1+
// swift-tools-version: 5.9
22
import PackageDescription
33

44
let package = Package(
55
name: "Observatory",
66
platforms: [
7-
.macOS(.v10_13)
7+
.macOS(.v10_15)
88
],
99
products: [
1010
.library(name: "Observatory", targets: ["Observatory"]),
@@ -17,14 +17,13 @@ let package = Package(
1717
.target(
1818
name: "Observatory",
1919
path: "source/Observatory",
20-
exclude: ["Test", "Testing"]
20+
exclude: ["Test", "Testing"],
2121
),
2222
.testTarget(
2323
name: "Observatory-Test",
2424
dependencies: ["Observatory", "Quick", "Nimble"],
2525
path: "source/Observatory",
26-
exclude: ["Keyboard", "Observer", "Shortcut"]
27-
// sources: ["Test", "Testing"] // Since tools 5.3 this alone doesn't work and produces a warning… no need for it really…
26+
exclude: ["Keyboard", "Observer", "Shortcut"],
2827
),
2928
],
3029
swiftLanguageVersions: [.v5]

source/Demo/Entrypoint.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import AppKit
22
import Observatory
33

4-
@NSApplicationMain public class AppDelegate: NSObject, NSApplicationDelegate {
5-
}
4+
@main public class AppDelegate: NSObject, NSApplicationDelegate {}
65

76
open class ViewController: NSViewController {
87
@IBOutlet private weak var buttonFoo: ShortcutRecorderButton!
@@ -26,7 +25,7 @@ open class ViewController: NSViewController {
2625
}
2726

2827
override open func viewDidAppear() {
29-
/// Reset first responder, do it asynchronously, because the window will modify it once presented.
28+
// Reset first responder, do it asynchronously, because the window will modify it once presented.
3029
DispatchQueue.main.async(execute: { self.view.window?.makeFirstResponder(nil) })
3130
}
3231

source/Observatory/Keyboard/Keyboard.Key.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ extension KeyboardKey.Layout {
260260

261261
/// Cache layout data by input source – this minimizes calls to Carbon's TIS, which are super-unstable and thread-unsafe…
262262
fileprivate static var cache: [Self: Data] = [:]
263-
private static func invalidateCaches() { Self.lock.withLock({ Self.cache = [:] }) }
263+
private static func invalidateCaches() { self.lock.withLock({ Self.cache = [:] }) }
264264

265265
/// Input source change observers.
266266
private static var observers: [NSObjectProtocol] = []

0 commit comments

Comments
 (0)