Skip to content

Enable SwiftLint rule: return_value_from_void_function#25572

Closed
mokagio wants to merge 1 commit into
trunkfrom
mokagio/swiftlint-return-value-from-void-function
Closed

Enable SwiftLint rule: return_value_from_void_function#25572
mokagio wants to merge 1 commit into
trunkfrom
mokagio/swiftlint-return-value-from-void-function

Conversation

@mokagio
Copy link
Copy Markdown
Contributor

@mokagio mokagio commented May 20, 2026

Description

Enable the SwiftLint return_value_from_void_function rule and resolve all 129 existing violations across the codebase.

  • The rule disallows return <expr> inside a function whose return type is Void. The expression is usually a no-op call to another Void function; splitting it into two statements makes intent explicit and avoids the trap of accidentally returning a non-Void value from a Void function later.
  • SwiftLint auto-fixed 128 violations mechanically (each return foo() becomes foo() followed by return).
  • One manual fix in BlogListViewModel.refresh(): the early-out had return try await task.value; rewritten as two statements so the function no longer returns the value.
  • No agentic edits beyond that single split. Nothing left for human review.

Part of the Orchard SwiftLint rollout campaign.

Testing instructions

  • CI build + lint should pass.
  • Optional spot-check: open one of the touched files (e.g. PostEditor+Publish.swift) and confirm the guard !isUploadingMedia else { ... } blocks still behave the same — the only change is statement order on the early-out branch.

Adds the rule to `only_rules` in `.swiftlint.yml` and resolves all 129
existing violations: 128 via SwiftLint's auto-fix and one manual fix in
`BlogListViewModel.refresh()` (split `return try await task.value` into
two statements so the function no longer returns a value).

Part of the Orchard SwiftLint rollout campaign.
@mokagio mokagio requested a review from a team as a code owner May 20, 2026 22:02
Copilot AI review requested due to automatic review settings May 20, 2026 22:02
@mokagio mokagio self-assigned this May 20, 2026
@mokagio mokagio added this to the 26.9 milestone May 20, 2026
@dangermattic
Copy link
Copy Markdown
Collaborator

2 Warnings
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.
⚠️ This PR is assigned to the milestone 26.9. This milestone is due in less than 4 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.

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 return_value_from_void_function rule and updates the codebase to comply by removing return <expr> patterns inside Void functions (typically return someVoidCall()), replacing them with someVoidCall() followed by an explicit return.

Changes:

  • Enable return_value_from_void_function in SwiftLint configuration.
  • Mechanically rewrite return <void-expression> into two statements (<void-expression> then return) across app, modules, and tests.
  • Manually split the early-out in BlogListViewModel.refresh() so the Void function no longer “returns” the awaited value.

Reviewed changes

Copilot reviewed 70 out of 70 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
WordPress/WordPressShareExtension/Sources/Extensions/Tracks+ShareExtension.swift Replace return assertionFailure(...) with assertionFailure(...); return.
WordPress/Classes/ViewRelated/Tags/TagsService.swift Remove return <expr> from a Void async continuation call.
WordPress/Classes/ViewRelated/Stats/Subscribers/StatsSubscribersViewController.swift Split return wpAssertionFailure(...) guard early-outs.
WordPress/Classes/ViewRelated/Reader/Subscriptions/ReaderSubscriptionsViewModel.swift Split return await task.value into await task.value; return in a Void async function.
WordPress/Classes/ViewRelated/Reader/Detail/ReaderDetailViewController.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/ViewRelated/Reader/Detail/ReaderDetailCoordinator.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/ViewRelated/Reader/Comments/ReaderCommentsViewController.swift Split multiple return wpAssertionFailure(...) early-outs across methods.
WordPress/Classes/ViewRelated/Reader/Cards/ReaderRecommendedSitesCell.swift Split return wpAssertionFailure(...) guard early-outs in button handlers.
WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/ViewRelated/Post/Utils/PostNoticePublishSuccessView.swift Split return wpAssertionFailure(...) early-outs before presenting flows.
WordPress/Classes/ViewRelated/Post/Utils/PostNoticeNavigationCoordinator.swift Split return wpAssertionFailure(...) early-outs when presenter missing.
WordPress/Classes/ViewRelated/Post/PostSettings/Views/PostSettingsFeaturedImageRow.swift Split return wpAssertionFailure(...) guard early-outs in selection handling.
WordPress/Classes/ViewRelated/Post/PostSettings/Views/Excerpt/PostSettingsGenerateExcerptView.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/ViewRelated/Post/PostSettings/PostSettingsViewModel.swift Split return wpAssertionFailure(...) guard early-outs in navigation/setup paths.
WordPress/Classes/ViewRelated/Post/PostEditor+Publish.swift Split return displayMediaIsUploadingAlert() / return discardAndDismiss() guard early-outs.
WordPress/Classes/ViewRelated/Post/Controllers/PostListViewController.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/ViewRelated/Post/Controllers/AbstractPostListViewController.swift Split return wpAssertionFailure(...) and other return <expr> early-outs.
WordPress/Classes/ViewRelated/Media/SiteMedia/Controllers/SiteMediaCollectionViewController.swift Split return perform() to perform(); return.
WordPress/Classes/ViewRelated/Media/MediaPicker/Menu/MediaPickerMenu+ImagePlayground.swift Split return wpAssertionFailure(...) guard early-out for availability.
WordPress/Classes/ViewRelated/Media/Lightbox/LightboxImageScrollView.swift Split return centerImageView() into centerImageView(); return.
WordPress/Classes/ViewRelated/Me/Me Main/MeViewController.swift Remove return <expr> from async throwing continuations returning Void.
WordPress/Classes/ViewRelated/Gutenberg/Utils/GutenbergFilesAppMediaSource.swift Split return assertionFailure(...) guard early-out.
WordPress/Classes/ViewRelated/Gutenberg/Utils/GutenbergExternalMeidaPicker.swift Split return assertionFailure(...) guard early-out.
WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift Split return showUnsupportedBlockUnexpectedErrorAlert() into call + return.
WordPress/Classes/ViewRelated/Comments/Views/Detail/CommentContentTableViewCell.swift Split multiple return wpAssertionFailure(...) guard early-outs.
WordPress/Classes/ViewRelated/Comments/Views/Detail/CommentCellViewModel.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/ViewRelated/Comments/Controllers/Create/CommentCreateViewModel.swift Split return UserDefaults.standard.set(...) into call + return.
WordPress/Classes/ViewRelated/Comments/Controllers/CommentDetailViewController.swift Split return headerCell.configure(...) into call + return.
WordPress/Classes/ViewRelated/Blog/Subscribers/Details/SubscriberDetailsView.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/BlogListViewModel.swift Split return try await task.value into try await task.value; return in refresh().
WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/BlogListSiteView.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/ViewRelated/Blog/My Site/Header/HomeSiteHeaderViewController+SiteActions.swift Split return DDLogError(...) guard early-out.
WordPress/Classes/ViewRelated/Blog/BloggingReminders/BloggingRemindersFlowSettingsViewController.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/ViewRelated/Blog/Blog Details/BlogDetailsViewController+Swift.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/ViewRelated/Blog/Blog Dashboard/Cards/BlogDashboardPersonalizeCardCell.swift Split return DDLogError(...) guard early-out.
WordPress/Classes/Utility/WebViewController/WebKitViewController.swift Split return completion(...) into completion(...); return.
WordPress/Classes/Utility/WebViewController/CookieJar.swift Split return hasWordPressAuthCookie(...) and return completion() patterns.
WordPress/Classes/Utility/In-App Feedback/SubmitFeedbackViewController.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/System/WordPressAppDelegate.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/System/Root View/SplitViewRootPresenter.swift Split return wpAssertionFailure(...) in error path.
WordPress/Classes/System/Root View/RootViewPresenter.swift Split return showJetpackOverlayForDisabledEntryPoint() into call + return.
WordPress/Classes/System/Root View/ReaderPresenter.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/System/ReaderWindowManager.swift Split return wpAssertionFailure(...) guard early-out.
WordPress/Classes/Services/PostRepository.swift Split return wpAssertionFailure(...) early-outs in sync/patch paths.
WordPress/Classes/Services/PostCoordinator.swift Split several return worker.log(...) / return DDLogInfo(...) early-outs.
WordPress/Classes/Services/EditorSettingsService.swift Split return success() / return failure(error) into call + return.
WordPress/Classes/Apps/Reader/Home/ReaderHomeViewController.swift Split return wpAssertionFailure(...) guard early-out.
Tests/WordPressKitTests/WordPressKitTests/Tests/RemoteTestCase.swift Split return XCTFail(...) into XCTFail(...); return.
Tests/WordPressKitTests/WordPressKitTests/Tests/JetpackProxyServiceRemoteTests.swift Split return XCTFail() guard early-outs across tests.
Tests/WordPressAuthenticatorTests/SingIn/LoginViewControllerTests.swift Split return XCTFail(...) guard early-out.
Tests/WordPressAuthenticatorTests/SingIn/AppleAuthenticatorTests.swift Split return XCTFail(...) guard early-out.
Tests/WordPressAuthenticatorTests/GoogleSignIn/URL+GoogleSignInTests.swift Split return XCTFail(...) into XCTFail(...); return in helper asserts.
Tests/WordPressAuthenticatorTests/GoogleSignIn/NewGoogleAuthenticatorTests.swift Split return XCTFail(...) in error-case guards.
Tests/KeystoneTests/Tests/Services/PostCoordinatorTests.swift Split return XCTFail(...) and return try await ... into call/await + return.
Tests/KeystoneTests/Tests/Services/BlogServiceDeduplicationTests.swift Split return XCTFail(...) guard early-out.
Tests/KeystoneTests/Tests/Features/Dashboard/BlazeCampaignsStreamTests.swift Split return XCTFail(...) and return completion(.failure(...)) patterns.
Sources/WordPressData/Swift/PostMetadataContainer.swift Split return wpAssertionFailure(...) guard early-out.
Sources/WordPressData/Swift/ContextManager.swift Split return assertionFailure() guard early-out.
Sources/WordPressData/Swift/AbstractPost.swift Split return wpAssertionFailure(...) guard early-out.
Sources/WordPressAuthenticator/Helpers/UnifiedAuth/ViewRelated/VerifyEmail/VerifyEmailViewController.swift Split return super.styleBackground() into call + return.
Sources/WordPressAuthenticator/Helpers/UnifiedAuth/ViewRelated/SiteAddress/SiteCredentialsViewController.swift Split return validateFormAndLogin() into call + return.
Sources/WordPressAuthenticator/Helpers/UnifiedAuth/ViewRelated/SiteAddress/SiteAddressViewController.swift Split return displayError(...) into call + return.
Sources/WordPressAuthenticator/Helpers/UnifiedAuth/ViewRelated/Password/PasswordCoordinator.swift Split return WPLogError(...) guard early-out.
Sources/WordPressAuthenticator/Helpers/UnifiedAuth/ViewRelated/Login/MagicLinkRequestedViewController.swift Split return super.styleBackground() into call + return.
Sources/WordPressAuthenticator/Helpers/UnifiedAuth/ViewRelated/GetStarted/GetStartedViewController.swift Split return dividerStackView.isHidden = true into assignment + return.
Sources/WordPressAuthenticator/Helpers/UnifiedAuth/ViewRelated/2FA/TwoFAViewController.swift Split multiple return <expr> early-outs into call + return.
Sources/WordPressAuthenticator/Features/NUX/Button/NUXStackedButtonsViewController.swift Split return dividerStackView.isHidden = true into assignment + return.
Modules/Sources/UITestsFoundation/XCUIElement+TapUntil.swift Split return XCTFail(...) and return tapUntil(...) into call + return.
.swiftlint.yml Enable return_value_from_void_function in only_rules.
Comments suppressed due to low confidence (1)

Tests/WordPressAuthenticatorTests/GoogleSignIn/URL+GoogleSignInTests.swift:85

  • Grammar in the failure message: "Could not created" should be "Could not create".
    guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false) else {
        XCTFail(
            "Could not created `URLComponents` from given `URL` \(url).",
            file: file,
            line: line
        )
        return

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

guard configuration.enableManualSiteCredentialLogin else {
return validateFormAndLogin() // handles login with XMLRPC normally
validateFormAndLogin() // handles login with XMLRPC normally
return // handles login with XMLRPC normally
Comment on lines 324 to +326
guard let presentationDelegate else {
return wpAssertionFailure("presentationDelegate mising")
wpAssertionFailure("presentationDelegate mising")
return
Comment thread .swiftlint.yml
# Type annotations are redundant when the type can be inferred.
- redundant_type_annotation

# Returning a value from a function declared as returning Void is disallowed.
Comment on lines +50 to +55
XCTFail(
"Could not created `URLComponents` from given `URL` \(actual).",
file: file,
line: line
)
return
@wpmobilebot
Copy link
Copy Markdown
Contributor

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 Number32267
VersionPR #25572
Bundle IDorg.wordpress.alpha
Commit8404288
Installation URL4t56if9nn4vs0
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

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 Number32267
VersionPR #25572
Bundle IDcom.jetpack.alpha
Commit8404288
Installation URL7dd6c36fhipmg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@crazytonyli
Copy link
Copy Markdown
Contributor

I don't think we need to enforce this rule. I don't mind code like return wpAssertionFailure(...).

@mokagio
Copy link
Copy Markdown
Contributor Author

mokagio commented May 20, 2026

@crazytonyli sounds good. Closing.

@mokagio mokagio closed this May 20, 2026
@mokagio mokagio deleted the mokagio/swiftlint-return-value-from-void-function branch May 20, 2026 23:53
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