Skip to content

Drop unused arguments instead of underscoring them#344

Merged
leogdion merged 2 commits into
parent/342-beta1-followupsfrom
claude/investigate-unused-arguments-1V9JY
May 14, 2026
Merged

Drop unused arguments instead of underscoring them#344
leogdion merged 2 commits into
parent/342-beta1-followupsfrom
claude/investigate-unused-arguments-1V9JY

Conversation

@leogdion

@leogdion leogdion commented May 14, 2026

Copy link
Copy Markdown
Member

Periphery flagged several arguments as unused. Rather than silencing
them with _:, remove the arguments where the design allows.

  • RecordManaging.executeBatchOperations: drop recordType:. Each
    RecordOperation already carries its own recordType, so the
    separate parameter was redundant. Updates protocol, CloudKitService
    conformance, generic + record-collection extensions, and the
    in-tree mock. BushelCloud conformers (BushelCloudKitService,
    MockCloudKitService) are updated in lockstep; the s2s overload
    with classification: keeps recordType: because it logs the type.
  • ResponseConfig.successfulQuery / ResponseProvider.successfulQuery:
    drop the unused records: parameter; the canned body was always
    {"records": []}. The query-tests helper that forwarded it follows.
  • CurrentUserCommand.filterUserFields: delete the no-op helper that
    returned its input unchanged. Also delete the dead duplicate
    shouldIncludeField in the same file (the live copy lives in
    OutputFormatting+Records).

Summary by CodeRabbit

  • Bug Fixes
    • Fixed CurrentUserCommand to return complete user information instead of filtering fields, ensuring users see all available profile data.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b37d2c3e-07c3-4e11-8f6f-39c88c5ecbbc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR simplifies the executeBatchOperations API by removing an explicit recordType parameter and relying on each RecordOperation to carry its own record type. The change flows from protocol definition through all implementations, call sites, and tests. A separate, unrelated change removes user field filtering from the current user command output.

Changes

Batch Operations API Simplification

Layer / File(s) Summary
Protocol definition and primary service implementation
Sources/MistKit/Protocols/RecordManaging.swift, Sources/MistKit/Service/CloudKitService+RecordManaging.swift
The RecordManaging protocol's executeBatchOperations signature removes the recordType parameter. Documentation is updated to reflect that each RecordOperation already contains record type information. CloudKitService implementation follows the same signature change.
BushelCloud service adaptation
Examples/BushelCloud/Sources/BushelCloudKit/CloudKit/BushelCloudKitService.swift, Examples/BushelCloud/Tests/BushelCloudKitTests/Mocks/MockCloudKitService.swift
BushelCloudKitService adds a simplified overload that infers recordType from the first operation and delegates to the existing classification-based overload. MockCloudKitService iterates per-operation record types instead of using a batch-level parameter.
Extension call sites
Sources/MistKit/Extensions/RecordManaging+Generic.swift, Sources/MistKit/Extensions/RecordManaging+RecordCollection.swift
Calls to executeBatchOperations in generic sync and collection-based sync/delete operations remove the explicit recordType argument.
Test mock and helper updates
Tests/MistKitTests/Protocols/MockRecordManagingService.swift, Tests/MistKitTests/Mocks/ResponseConfig.swift, Tests/MistKitTests/Mocks/ResponseProvider.swift, Tests/MistKitTests/Service/CloudKitServiceQueryTests+Helpers.swift
Test mocks and response factories are updated to match the new signatures. successfulQuery factories become parameterless, and makeSuccessfulService is simplified.
Test execution updates
Examples/BushelCloud/Tests/BushelCloudKitTests/CloudKit/MockCloudKitServiceTests.swift, Examples/BushelCloud/Tests/BushelCloudKitTests/ErrorHandling/CloudKitErrorHandlingTests.swift
Unit and error-handling tests update all executeBatchOperations calls to remove the recordType argument across create, delete, batch, error, history, and storage operations.

User Command Output Simplification

Layer / File(s) Summary
Remove user field filtering from command output
Examples/MistDemo/Sources/MistDemo/Commands/CurrentUserCommand.swift
The CurrentUserCommand.execute() method no longer filters fetched user information by config.fields and instead outputs the full userInfo directly, while preserving error handling.

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 A hop and skip, the API's now slick—
No more recordType passed around the trick.
Each operation knows its own kind,
Simpler contracts we all find!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 44.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Drop unused arguments instead of underscoring them' accurately describes the main theme of this changeset, which removes unused function arguments across multiple files rather than replacing them with underscores.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/investigate-unused-arguments-1V9JY

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@leogdion leogdion changed the base branch from main to parent/342-beta1-followups May 14, 2026 17:19
@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 20.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.27%. Comparing base (2f1dd7f) to head (cbb7de4).
⚠️ Report is 1 commits behind head on parent/342-beta1-followups.

Files with missing lines Patch % Lines
...it/Protocols/RecordManaging+RecordCollection.swift 0.00% 2 Missing ⚠️
...rces/MistDemoKit/Commands/CurrentUserCommand.swift 0.00% 1 Missing ⚠️
...ce/Extensions/CloudKitService+RecordManaging.swift 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                      Coverage Diff                       @@
##           parent/342-beta1-followups     #344      +/-   ##
==============================================================
- Coverage                       71.34%   71.27%   -0.07%     
==============================================================
  Files                             553      552       -1     
  Lines                           15350    15330      -20     
==============================================================
- Hits                            10951    10927      -24     
- Misses                           4399     4403       +4     
Flag Coverage Δ
mistdemo-spm-macos 60.38% <0.00%> (+0.05%) ⬆️
mistdemo-swift-6.2-jammy ?
mistdemo-swift-6.2-noble ?
mistdemo-swift-6.3-jammy ?
mistdemo-swift-6.3-noble 60.37% <0.00%> (+0.05%) ⬆️
spm 55.27% <25.00%> (+0.11%) ⬆️
swift-6.1-jammy ?
swift-6.1-noble ?
swift-6.2-jammy ?
swift-6.2-noble ?
swift-6.3-jammy ?
swift-6.3-noble 55.33% <25.00%> (+0.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
Examples/MistDemo/Sources/MistDemo/Commands/CurrentUserCommand.swift (1)

47-48: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

--fields help text appears stale after removing field filtering.

execute() now always outputs full userInfo, but help still says --fields controls included fields. Please either remove/deprecate that option text here or wire config.fields into the new output path so CLI behavior matches docs.

Suggested doc fix (if option is intentionally removed)
-            --fields <fields>          Comma-separated list of fields to include
             --output-format <format>   Output format: json, table, csv, yaml

Also applies to: 63-64

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Examples/MistDemo/Sources/MistDemo/Commands/CurrentUserCommand.swift` around
lines 47 - 48, Help text for the --fields flag is stale because execute() always
prints full userInfo; either remove/deprecate the flag from the CLI metadata or
actually use config.fields when formatting output. Fix option by removing the
"--fields" entry from the option/help definition (and any associated parsing) or
implement wiring inside execute(): read config.fields (or the parsed fields
option) and filter the userInfo before passing it to the output formatter
(ensure the filtering logic uses the same field names as the help text). Update
or remove any mentions of "--fields" in the command's help strings so
documentation matches the runtime behavior.
🧹 Nitpick comments (1)
Sources/MistKit/Protocols/RecordManaging.swift (1)

47-49: ⚡ Quick win

Clarify batching responsibility in the protocol docs.

This comment currently implies executeBatchOperations itself enforces chunking. In this PR, concrete implementations (e.g., CloudKitService) delegate directly, and batching is done by extension call sites. Consider rewording to avoid implying automatic batching at this layer.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Sources/MistKit/Protocols/RecordManaging.swift` around lines 47 - 49, The doc
for executeBatchOperations misleadingly suggests the method enforces CloudKit's
200-ops chunking; update the documentation for executeBatchOperations (and
mention RecordOperation) to clarify that it accepts a batch of RecordOperation
but does not guarantee/request-level chunking—concrete implementations like
CloudKitService or their callers are responsible for splitting into
CloudKit-sized chunks; rephrase to state that batching/chunking is the
caller/implementation responsibility and that executeBatchOperations processes
the provided batch as-is.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@Examples/MistDemo/Sources/MistDemo/Commands/CurrentUserCommand.swift`:
- Around line 47-48: Help text for the --fields flag is stale because execute()
always prints full userInfo; either remove/deprecate the flag from the CLI
metadata or actually use config.fields when formatting output. Fix option by
removing the "--fields" entry from the option/help definition (and any
associated parsing) or implement wiring inside execute(): read config.fields (or
the parsed fields option) and filter the userInfo before passing it to the
output formatter (ensure the filtering logic uses the same field names as the
help text). Update or remove any mentions of "--fields" in the command's help
strings so documentation matches the runtime behavior.

---

Nitpick comments:
In `@Sources/MistKit/Protocols/RecordManaging.swift`:
- Around line 47-49: The doc for executeBatchOperations misleadingly suggests
the method enforces CloudKit's 200-ops chunking; update the documentation for
executeBatchOperations (and mention RecordOperation) to clarify that it accepts
a batch of RecordOperation but does not guarantee/request-level
chunking—concrete implementations like CloudKitService or their callers are
responsible for splitting into CloudKit-sized chunks; rephrase to state that
batching/chunking is the caller/implementation responsibility and that
executeBatchOperations processes the provided batch as-is.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5afd57c1-9d76-45e9-93e8-bdff3755bd26

📥 Commits

Reviewing files that changed from the base of the PR and between 38f0d77 and b3c9c25.

📒 Files selected for processing (13)
  • Examples/BushelCloud/Sources/BushelCloudKit/CloudKit/BushelCloudKitService.swift
  • Examples/BushelCloud/Tests/BushelCloudKitTests/CloudKit/MockCloudKitServiceTests.swift
  • Examples/BushelCloud/Tests/BushelCloudKitTests/ErrorHandling/CloudKitErrorHandlingTests.swift
  • Examples/BushelCloud/Tests/BushelCloudKitTests/Mocks/MockCloudKitService.swift
  • Examples/MistDemo/Sources/MistDemo/Commands/CurrentUserCommand.swift
  • Sources/MistKit/Extensions/RecordManaging+Generic.swift
  • Sources/MistKit/Extensions/RecordManaging+RecordCollection.swift
  • Sources/MistKit/Protocols/RecordManaging.swift
  • Sources/MistKit/Service/CloudKitService+RecordManaging.swift
  • Tests/MistKitTests/Mocks/ResponseConfig.swift
  • Tests/MistKitTests/Mocks/ResponseProvider.swift
  • Tests/MistKitTests/Protocols/MockRecordManagingService.swift
  • Tests/MistKitTests/Service/CloudKitServiceQueryTests+Helpers.swift

PR 343 silenced Periphery warnings by renaming unused parameters to `_:`.
Where the design allows, drop the arguments entirely rather than keep
them as dead placeholders.

- `RecordManaging.executeBatchOperations(_:recordType:)`
  -> `executeBatchOperations(_:)`. Each `RecordOperation` already carries
  its own `recordType`, so the separate parameter was redundant. Updates
  the protocol, `CloudKitService` conformance, generic + record-collection
  extensions, and the in-tree mock. BushelCloud conformers
  (`BushelCloudKitService`, `MockCloudKitService`) are updated in
  lockstep; the s2s overload with `classification:` keeps `recordType:`
  because it actually logs the type.
- `discoverAllUserIdentities`: delete the entire stubbed surface
  (`CloudKitService.discoverAllUserIdentities()`, the response-processor
  stub, and the `Operations.discoverAllUserIdentities.Input.Path`
  extension). The function was `@available(*, unavailable)` pending #28,
  which is unlikely to resolve. The generated OpenAPI client retains the
  endpoint and can be re-wrapped if the upstream behavior changes.
- `setupServerToServer(apiToken:keyID:...)` -> drop `apiToken:`.
  Server-to-server uses key signing, not an API token. The dispatcher in
  `AuthenticationHelper.setupAuthentication` is specialized so only the
  s2s branch omits the argument.
- `ResponseConfig.successfulQuery(records:)` /
  `ResponseProvider.successfulQuery(records:)` -> drop `records:`. The
  canned body was always `{"records": []}`. The query-tests helper that
  forwarded it (`makeSuccessfulService(records:)`) follows.
- `CurrentUserCommand.filterUserFields` -> delete. The helper returned
  its input unchanged; `UserInfo` is fetched and handed directly to
  `outputResult`.
@leogdion leogdion force-pushed the claude/investigate-unused-arguments-1V9JY branch from b3c9c25 to 338e6bb Compare May 14, 2026 17:30
@claude

claude Bot commented May 14, 2026

Copy link
Copy Markdown

Code Review

Overview: This PR removes a genuinely redundant recordType parameter from executeBatchOperations (since RecordOperation already carries it), eliminates dead code in CurrentUserCommand, and drops the unused records: param from test helpers. The changes are well-scoped and consistently applied across the call graph.


What is done well

  • Protocol simplification is correct. RecordOperation.recordType is the authoritative source; a separate batch-level recordType created a latent inconsistency risk if someone ever passed a mismatched type.
  • Dead-code removal in CurrentUserCommand is accurate. filterUserFields returned its input unchanged, and shouldIncludeField was a duplicate of the live copy in OutputFormatting+Records. Both deletions are safe.
  • ResponseConfig.successfulQuery(records:) fix is correct. The records: param was silently ignored (body was always an empty records array), so dropping it removes a misleading API.
  • All call sites updated consistently — protocol, implementations, mocks, tests, and examples are in sync.

Issues and Suggestions

1. Empty-array fallback in BushelCloudKitService is fragile

let recordType = operations.first?.recordType ?? ""

An empty operations array produces an empty recordType, which flows into the classification overload that logs it. Callers should not normally pass an empty batch, but the silent fallback produces confusing log output. Prefer an early guard:

guard !operations.isEmpty else { return }
let recordType = operations.first!.recordType

Or at minimum use ?? "unknown" so logs remain legible.

2. Missing newline at end of CurrentUserCommand.swift

The diff ends with "No newline at end of file". Minor but easy to fix.

3. New comment in BushelCloudKitService may be unnecessary

Per project conventions (CLAUDE.md: "Only add a comment when the WHY is non-obvious"), the new two-line comment largely explains the obvious. If it survives, the first sentence (why operations.first rather than nothing) earns its place; the second does not.

4. CurrentUserCommand silently ignores config.fields

Before this PR, filterUserFields was a no-op that still threaded config.fields through. After the PR, config.fields is no longer referenced in the execute flow at all — if a CLI caller passes --fields, it is silently ignored. If field filtering is intentionally out of scope, consider emitting a warning when config.fields is non-nil rather than a completely silent drop.


Summary

Overall this is a solid cleanup PR. The two main actionable items are the empty-array guard in BushelCloudKitService and the silent config.fields drop.

Area Status
API simplification Correct and clean
Dead code removal Accurate
Empty-batch fallback Use guard !operations.isEmpty else { return } instead of empty-string fallback
Missing EOF newline Minor fix needed
config.fields silently ignored Worth a warning or note
New comment Optional cleanup

@claude

claude Bot commented May 14, 2026

Copy link
Copy Markdown

Code Review — PR #344: Drop unused arguments instead of underscoring them

Overview

Clean-up PR that removes redundant parameters flagged by Periphery. Three distinct changes:

  1. Drop recordType: from RecordManaging.executeBatchOperations — each RecordOperation already carries its own type.
  2. Remove the @available(*, unavailable) stub for discoverAllUserIdentities() along with its path init and response-processor shim.
  3. Delete dead code: filterUserFields no-op in CurrentUserCommand, unused records: in ResponseConfig/ResponseProvider.successfulQuery, and unused apiToken _: in AuthenticationHelper.setupServerToServer.

The direction is correct throughout. Two items worth addressing before merge.


Issues

1. Empty-operations fallback in BushelCloudKitService (minor)

The new protocol-conforming implementation reads:

let recordType = operations.first?.recordType ?? ""

The empty-string fallback is harmless in practice (callers never pass an empty batch), but it silently passes "" as recordType to the classification overload that logs it. An explicit guard is clearer:

guard !operations.isEmpty else { return }
let recordType = operations[0].recordType

This makes an accidental empty-batch a loud no-op rather than a silent log anomaly.

2. CLAUDE.md is now stale

discoverAllUserIdentities() is removed entirely by this PR, but CLAUDE.md still references it in two places:

  • Line 172 (operations table): discoverAllUserIdentities() *(unavailable — pending #28)*
  • Line 188 (result types section): the bullet describing its return value

Both should be removed.


Minor Observations

  • PR description inconsistency: The description says "Also delete the dead duplicate shouldIncludeField in the same file" but that deletion does not appear in the CurrentUserCommand.swift diff. PR Resolve #342: v1.0.0-beta.1 follow-ups (#341 #327 #321 #317) + CI fixes #343 already removed it per that PR's description — worth updating the description to avoid confusion.

  • ResponseConfig.successfulQuery(records:) removal: Honest fix — the parameter was always ignored in favour of a hardcoded {"records": []} body. Clean no-behaviour-change removal.

  • discoverAllUserIdentities deletion scope: Removing the path init and #if swift(>=6.2) response-processor shim is the right call. Because the function was @available(*, unavailable), no external caller could have used it — not a breaking change. The openapi.yaml endpoint definition remains, so regenerating the client still produces Operations.discoverAllUserIdentities; only the hand-written wrappers are gone. If this endpoint stays deferred long-term, a brief comment or issue reference in openapi.yaml would help future contributors understand why there is no Swift surface for it.


Summary

Two actionable items before merge:

  1. Add a guard !operations.isEmpty else { return } guard in BushelCloudKitService.executeBatchOperations.
  2. Remove discoverAllUserIdentities references from CLAUDE.md lines 172 and 188.

Everything else looks good — the API simplification is correct, dead code is cleanly removed, and call-site updates are consistent across all conformers and tests.

Empty batches now early-return instead of forwarding an empty
recordType to the classification overload that logs it.
Addresses PR #344 review.
@leogdion leogdion merged commit ca993bc into parent/342-beta1-followups May 14, 2026
20 checks passed
@claude

claude Bot commented May 14, 2026

Copy link
Copy Markdown

Code Review for PR 344 - see inline notes below.

@claude

claude Bot commented May 14, 2026

Copy link
Copy Markdown

Code Review for PR 344: Drop unused arguments instead of underscoring them

Overview:
Clean-up that removes genuinely unused parameters across three independent areas. Overall the changes are correct and improve clarity.

Code Quality:

  • Protocol doc comment in RecordManaging.swift accurately explains why recordType: was removed.
  • Removing the @available(*, unavailable) stubs and Operations.discoverAllUserIdentities.Input.Path.swift is the right call.
  • successfulQuery simplification is a correctness fix: callers were passing records: dicts and silently getting back the hardcoded empty body.

Potential Issues:

  1. Silent early-return on empty operations in BushelCloudKitService
    The new guard on operations.first?.recordType returns silently when the array is empty. Almost certainly harmless, but undocumented. Adding a comment like '// Empty batch - nothing to do' on the guard would help future readers.

  2. Mixed-type batches (informational)
    The old signature made callers assert a single type per batch; the new signature leaves this implicit. In practice every call-site already groups by type before calling executeBatchOperations, so no real risk. A note in the protocol doc would help future implementors.

  3. config.fields may be orphaned in CurrentUserCommand
    The removed filterUserFields was the only consumer of config.fields here. Worth confirming that config.fields is threaded through to outputResult via OutputFormatting+Records. If not, --fields silently becomes a no-op for this command.

Breaking Change:
Removing recordType: from RecordManaging is source-breaking for external conformers. Acceptable in beta but should be in the changelog.

Test Coverage:
All mock conformers updated in the same PR. No new tests strictly required, but a test exercising the empty-operations guard in BushelCloudKitService would make the silent-return explicit.

Summary: Solid cleanup, net -140 lines. Actionable items: (1) document the empty-array early-return guard; (2) verify config.fields reaches outputResult in CurrentUserCommand; (3) note the protocol breaking change in release notes.

@leogdion leogdion deleted the claude/investigate-unused-arguments-1V9JY branch May 18, 2026 09:28
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