Skip to content

Re-enable SwiftLint/SwiftFormat and clean up all reported violations - #1341

Merged
timbms merged 2 commits into
openhab:developfrom
timbms:fix/swiftlint-shorthand-operators
Sep 18, 2026
Merged

timbms merged 2 commits into
openhab:developfrom
timbms:fix/swiftlint-shorthand-operators

Conversation

@timbms

@timbms timbms commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

⚠️ Big diff — please read before reviewing

This PR touches 62 files to bring the codebase into compliance after re-enabling the SwiftLint/SwiftFormat build-phase plugin (BuildTools). Most of the diff is mechanical (formatting, indentation, rule-driven refactors) and should carry no functional change. Two spots are real bug fixes, called out explicitly below — please give those extra scrutiny.

Given the size, a smoke test of notification handling and the home-avatar picker is more valuable than a full line-by-line read of every formatting hunk.

Real behavior change (but only in test set)

NotificationCenterDelegateImpl.swift — userNotificationCenter(_:didReceive:) was missing async, so it never actually matched UNUserNotificationCenterDelegate's compiler-bridged requirement for didReceiveNotificationResponse:withCompletionHandler:. This means tapping a notification to open the app was silently not invoking this handler at all. Verified against the SDK header (withCompletionHandler:(void(^)(void)) → bridges to async with no return value) and fixed. Worth a manual notification-tap test.

  • Two XCTestCase.tearDown() overrides (MainUILayoutUITests, ToastUITests) mutated a @MainActor-isolated property from a nonisolated context (the synchronous tearDown() override doesn't inherit the class's @MainActor isolation). Switched to the async throws override, matching the pattern already used for setUp().

Mechanical cleanup

  • Split oversized types/files (type_body_length, file_length) into same-file extensions or new files — e.g. OpenHABWebViewModel's large injected-JS string constants moved to a new OpenHABWebViewInjectedJS.swift, with no behavior change.
  • Replaced large tuples (large_tuple) with small named structs in HomeAvatarView and AvatarColorPairTests.
  • Migrated HomeAvatarView's icon representation from raw SF Symbol name strings to SFSafeSymbols' SFSymbol type for compile-time safety at call sites. AvatarMode's persisted storage in OpenHABCore intentionally stays a plain String — the mapping happens at the app-target boundary (AvatarImageHelper), so persistence format is unchanged.
  • Renamed a couple of files to satisfy file_name (e.g. AppLifecycle.swiftNSNotification.Name.swift, matching the type it actually declares).
  • Long tail of rule-specific fixes: shorthand_operator, for_where, statement_position, unavailable_condition, multiple_closures_with_trailing_closure, async_without_await (with scoped swiftlint:disable where the rule is a false positive against a protocol-required signature), orphaned_doc_comment, closure_end_indentation (plus a scoped swiftformat:disable indent where SwiftFormat has a known --ifdef no-indent + closure indentation quirk).

Test plan

  • xcodebuild build for the openHAB scheme succeeds clean
  • xcodebuild build-for-testing succeeds (compiles all test targets, including UI tests)
  • Full OpenHABCoreTests + openHABTestsSwift suites pass
  • Manual smoke test: tap a push notification while the app is backgrounded and confirm it navigates correctly
  • Manual smoke test: home avatar icon picker (add/edit a home's icon) still renders and saves correctly

Comment generated with help of Claude Code](https://claude.com/claude-code)

timbms and others added 2 commits September 17, 2026 22:53
Re-enables the SwiftLint/SwiftFormat build-phase plugin (BuildTools) and
brings the whole codebase into compliance with its ruleset. This is a wide,
mostly mechanical diff — read the PR description before merging.

Highlights:
- Fix real bugs surfaced by the cleanup, not just style: NotificationCenterDelegateImpl's
  didReceive(response:) was missing `async`, so it silently never matched
  UNUserNotificationCenterDelegate's bridged requirement (notification-tap handling was
  dead code); two XCTestCase tearDown() overrides mutated a @mainactor property from a
  nonisolated context and now use the async override.
- Split oversized types/files (type_body_length, file_length) into same-file extensions
  or new files (e.g. OpenHABWebViewModel's injected JS moved to
  OpenHABWebViewInjectedJS.swift) without changing behavior.
- Replace large tuples with small named structs (HomeAvatarView, AvatarColorPairTests).
- Migrate HomeAvatarView's icon representation from raw SF Symbol name strings to
  SFSafeSymbols' SFSymbol type; AvatarMode's persisted storage stays String at the
  OpenHABCore boundary.
- Rename files to satisfy file_name (NSNotification.Name.swift).
- Assorted rule fixes: shorthand_operator, for_where, statement_position,
  unavailable_condition, multiple_closures_with_trailing_closure, async_without_await,
  orphaned_doc_comment, closure_end_indentation.

Verified: full `xcodebuild build` succeeds; OpenHABCoreTests and openHABTestsSwift
(including UI-test-target compilation) all pass. No intended functional changes other
than the two bug fixes called out above.

Signed-off-by: Tim Mueller-Seydlitz <timbms@gmail.com>
@timbms

timbms commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

@digitaldan @DigiH @TAKeanice I have reenabled swiftlint and swiftformat. All resulting errors and warnings are addressed. It would be great to push it asap unless you are working offsite on potentially conflicting contributions

@timbms
timbms merged commit c205652 into openhab:develop Sep 18, 2026
2 checks passed
Comment thread BuildTools/.swiftlint.yml
max_length:
warning: 90
error: 1000
excluded:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many exclusions make the rule ineffective. If it's superfluous we should deactivate it completely.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or set the min length to 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants