Skip to content

Enable SwiftLint rule: explicit_init#25573

Merged
mokagio merged 2 commits into
trunkfrom
mokagio/swiftlint-explicit-init
May 21, 2026
Merged

Enable SwiftLint rule: explicit_init#25573
mokagio merged 2 commits into
trunkfrom
mokagio/swiftlint-explicit-init

Conversation

@mokagio
Copy link
Copy Markdown
Contributor

@mokagio mokagio commented May 21, 2026

Description

Enables the explicit_init SwiftLint rule, which discourages writing Type.init(...) when Type(...) is sufficient (the contextual init is enough).

  • Auto-fixed: 36 violations across 36 files via bundle exec rake lintfix.
  • Agentic fixes: none.
  • Left for human review: none.

Part of the Orchard SwiftLint rollout campaign.

Testing instructions

CI: build + tests should remain green. The autofix is purely syntactic — it only removes the .init token between a type and its argument list.

Part of the Orchard SwiftLint rollout campaign.

The rule discourages explicitly calling `.init(...)` when the type is
known, preferring `Type(...)` over `Type.init(...)`.

`rake lintfix` auto-fixed 36 files; no manual fixes were needed.

---

Generated with the help of Claude Code, https://claude.com/claude-code

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 21, 2026 00:26
@mokagio mokagio self-assigned this May 21, 2026
@mokagio mokagio added this to the 27.0 milestone May 21, 2026
@dangermattic
Copy link
Copy Markdown
Collaborator

1 Warning
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.

Generated by 🚫 Danger

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Enables SwiftLint’s explicit_init opt-in rule and applies automated fixes across the iOS app, modules, and test targets to remove redundant .init calls (e.g., Type.init(...)Type(...)) in preparation for the broader SwiftLint rollout.

Changes:

  • Enabled explicit_init in .swiftlint.yml under only_rules.
  • Auto-fixed existing explicit_init violations across app/module source and test files.
  • Normalized initializer call sites for UIKit/Foundation/CoreData/SwiftUI types and project-specific models.

Reviewed changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
WordPress/Classes/ViewRelated/Views/BadgeLabel.swift Removes redundant .init from UIEdgeInsets construction.
WordPress/Classes/ViewRelated/Support/SupportTableViewControllerConfiguration.swift Uses Self() instead of Self.init() for configuration creation.
WordPress/Classes/ViewRelated/Support/SupportTableViewController.swift Replaces UINavigationController.init(...) with shorthand init.
WordPress/Classes/ViewRelated/Stats/StatsLikesListViewController.swift Simplifies EmptyStateView initialization passed into UIHostingView.
WordPress/Classes/ViewRelated/Stats/Shared Views/Stats Detail/SiteStatsInsightsDetailsTableViewController.swift Uses shorthand UINavigationController(...) init.
WordPress/Classes/ViewRelated/Stats/Shared Views/Stats Detail/SiteStatsDetailTableViewController.swift Uses shorthand UINavigationController(...) init.
WordPress/Classes/ViewRelated/Stats/Shared Views/Post Stats/PostStatsTableViewController.swift Uses shorthand UINavigationController(...) init.
WordPress/Classes/ViewRelated/Stats/Period Stats/SiteStatsPeriodViewModel.swift Removes .init from StatsTotalRowData construction in mapping.
WordPress/Classes/ViewRelated/Stats/Period Stats/SiteStatsPeriodTableViewController.swift Uses shorthand UINavigationController(...) init.
WordPress/Classes/ViewRelated/Stats/Insights/StatsMostPopularTimeInsightsCell.swift Uses shorthand Calendar(identifier:) init.
WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsViewModel.swift Removes .init from StatsTwoColumnRowData constructions.
WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsTableViewController.swift Uses shorthand UINavigationController(...) init.
WordPress/Classes/ViewRelated/Stats/Helpers/StatsDataHelper.swift Removes .init from StatsTotalRowData construction.
WordPress/Classes/ViewRelated/Reader/Theme/ReaderDisplaySettingViewController.swift Removes .init from DSButtonStyle construction.
WordPress/Classes/ViewRelated/Reader/Detail/Views/ReaderDetailLikesListController.swift Simplifies EmptyStateView initialization passed into UIHostingView.
WordPress/Classes/ViewRelated/Reader/Detail/Views/ReaderDetailCommentsHeader.swift Removes redundant .init calls for presenter and UIImage(systemName:).
WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCellViewModel.swift Removes .init from ReaderPost Core Data entity initialization.
WordPress/Classes/ViewRelated/Notifications/Views/CommentLargeButton.swift Removes .init from UIEdgeInsets passed into pinEdges.
WordPress/Classes/ViewRelated/Jetpack/Login/JetpackConnectionViewModel.swift Uses Self(...) instead of Self.init(...) for slug wrappers.
WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainDetails/ViewController/RegisterDomainDetailsViewController.swift Removes .init from NSAttributedString creation.
WordPress/Classes/ViewRelated/Aztec/ViewControllers/UnknownEditorViewController.swift Removes .init from UIEdgeInsets constant.
WordPress/Classes/Utility/Spotlight/SearchManager.swift Uses shorthand EditPostViewController(post:) init.
WordPress/Classes/Utility/Sharing/ShareNoticeNavigationCoordinator.swift Uses shorthand EditPostViewController(post:) init.
WordPress/Classes/Utility/BuildInformation/RemoteConfigParameter.swift Uses shorthand LosslessStringConvertible init T(...).
WordPress/Classes/Utility/BackgroundTasks/WeeklyRoundupBackgroundTask.swift Removes .init from TimeInterval(-1) usage.
WordPress/Classes/Services/AccountSettingsService.swift Removes .init from AccountSettings(managed:) creation.
WordPress/Classes/Models/Blog/BlogSettings+DateAndTimeFormat.swift Uses shorthand Calendar(identifier:) init.
Tests/WordPressKitTests/WordPressKitTests/Tests/IPLocationRemoteTests.swift Uses shorthand URLSession(configuration:) init.
Tests/WordPressKitTests/CoreAPITests/WordPressComRestApiTests.swift Removes .init from HTTPStubsResponse(error:) creation.
Tests/KeystoneTests/Tests/Features/Stats/StatsMockDataLoader.swift Uses shorthand JSONObject(fromFileNamed:) initializer call.
Tests/KeystoneTests/Tests/Features/Domains/AllDomainsListItemViewModelTests.swift Uses shorthand Date(timeIntervalSinceNow:) init.
Tests/KeystoneTests/Helpers/NSManagedObject+Fixture.swift Uses shorthand Core Data Self(context:) init.
Tests/KeystoneTests/Helpers/ModelTestHelper.swift Uses shorthand Core Data Blog(context:) / WPAccount(context:) init.
Modules/Tests/WordPressSharedTests/WPUserAgentTests.swift Uses shorthand String(format:...) init.
Modules/Sources/WordPressKitModels/RemoteVideoPressVideo.swift Removes .init from VideoPressPrivacySetting(rawValue:).
Modules/Sources/WordPressKitModels/RemoteUser+Likes.swift Uses shorthand RemoteLikeUserPreferredBlog(dictionary:) init.
.swiftlint.yml Enables explicit_init rule in the opt-in only_rules list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread WordPress/Classes/Utility/BackgroundTasks/WeeklyRoundupBackgroundTask.swift Outdated
@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented May 21, 2026

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number32272
VersionPR #25573
Bundle IDorg.wordpress.alpha
Commitd575c75
Installation URL4vo0q5s6fm0n8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented May 21, 2026

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number32272
VersionPR #25573
Bundle IDcom.jetpack.alpha
Commitd575c75
Installation URL1mndp1g162sp0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@mokagio mokagio enabled auto-merge May 21, 2026 05:57
@mokagio mokagio requested a review from crazytonyli May 21, 2026 05:58
@mokagio mokagio added this pull request to the merge queue May 21, 2026
Merged via the queue into trunk with commit 206ee4a May 21, 2026
24 checks passed
@mokagio mokagio deleted the mokagio/swiftlint-explicit-init branch May 21, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants