Fix mock generation for default-valued parameters with underscore labels#209
Merged
Fix mock generation for default-valued parameters with underscore labels#209
Conversation
When an init parameter uses `_` as the inner label (e.g., `isLoggingEnabled _: Bool = false`), mock generation was using `_` as the parameter name, producing invalid code like `_: @autoclosure @escaping () -> Bool = false` and `let _ = _()`. Now uses the outer label when the inner label is `_`, matching the call-site convention. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #209 +/- ##
=======================================
Coverage 99.92% 99.92%
=======================================
Files 40 40
Lines 5354 5357 +3
=======================================
+ Hits 5350 5353 +3
Misses 4 4
🚀 New features to boost your workflow:
|
dfed
commented
Apr 4, 2026
- Split test into two (child mock + root mock) per one-assertion-per-test rule - Use if/else instead of bare if with early return per code style rules - SwiftFormat cleanup Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…label Instead of trying to generate mock parameters for default-valued init arguments whose call-site label is `_`, skip them entirely — `_` is not a valid parameter name. The init default value applies silently. For `outer _: Type = default` (inner label is `_` but outer label is usable), use `argument.label` (the outer label) as the mock parameter name. Removes the now-unnecessary `mockPropertyLabel` computed property. The simpler `argument.label` handles all cases since `_`-labeled params are filtered out before they reach parameter naming. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dfed
added a commit
that referenced
this pull request
Apr 4, 2026
- Merge main (underscore-label mock tests from PR #209) - Add comprehensive scanner tests for generateMock detection - Update mock generation manual example to match doc style - Use DEBUG in mockConditionalCompilation example Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_(e.g.,_ flag: Bool = falseor_: Bool = false) are now skipped in mock generation —_cannot be used as a parameter name, so the init's default value applies silently._as the inner label (e.g.,isLoggingEnabled _: Bool = false), the outer label is used as the mock parameter name viaargument.label.Manual.mdto describe this behavior.Test plan
mock_usesOuterLabelForChildMock_whenDefaultValuedParameterHasUnderscoreInnerLabelmock_usesOuterLabelForRootMock_whenDefaultValuedParameterHasUnderscoreInnerLabelmock_doesNotBubbleDefaultValuedParameter_whenOuterLabelIsUnderscoremock_doesNotBubbleDefaultValuedParameterForChildMock_whenOuterLabelIsUnderscoremock_doesNotBubbleDefaultValuedParameter_whenOnlyLabelIsUnderscoremock_doesNotBubbleDefaultValuedParameterForChildMock_whenOnlyLabelIsUnderscore🤖 Generated with Claude Code