-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: address TODOs across codebase in gomock and mockgen packages #238
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request upgrades the Go ecosystem and refines various functions throughout the codebase. The Go version has been bumped from 1.22 to 1.23.0 with an added toolchain specification, and dependency versions have been updated in several go.mod files. Function logic has been enhanced across multiple components: improved argument and error handling in the DoAndReturn method, refined error messaging and embedded method filtering in the parser, and better type parsing for named structures, unsafe pointers, and aliases. Minor formatting updates and test modifications further standardize the code style and test expectations. Changes
Sequence Diagram(s)sequenceDiagram
participant D as DoAndReturn
participant F as Function f
participant A as Action Handler
D->>D: Verify if parameter f is a function
alt f is not a function
D->>A: Register a panic action with an error message
else f is a function
D->>D: Compute expected argument count
D->>F: Invoke f with truncated argument list if needed
end
sequenceDiagram
participant P as fileParser
participant I as EmbeddedInterface
participant C as Caller
P->>I: Iterate over embedded methods
alt Method is shadowed
P->>P: Exclude the method from results
else Method is not shadowed
P->>P: Include the method in the result list
end
P->>C: Return the filtered method list
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
mockgen/package_mode.go (1)
316-320
: Special case handling for testThis code specifically enforces a name change for a test case. While it addresses a particular test scenario, it introduces a hard-coded special case.
Consider making this more general or documenting why this special case is necessary, as hard-coded test-specific logic might be confusing to future maintainers.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
go.sum
is excluded by!**/*.sum
📒 Files selected for processing (11)
go.mod
(1 hunks)gomock/call.go
(2 hunks)mockgen/gob_test.go
(1 hunks)mockgen/internal/tests/alias/interfaces.go
(2 hunks)mockgen/internal/tests/alias/subpkg/interfaces.go
(1 hunks)mockgen/internal/tests/generics/go.mod
(1 hunks)mockgen/internal/tests/typed/go.mod
(1 hunks)mockgen/model/model.go
(1 hunks)mockgen/package_mode.go
(2 hunks)mockgen/parse.go
(2 hunks)sample/user_test.go
(2 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
mockgen/internal/tests/alias/interfaces.go (1)
mockgen/internal/tests/alias/subpkg/interfaces.go (1) (1)
Quxer
(3-5)
gomock/call.go (2)
mockgen/internal/tests/typed_inorder/mock.go (6) (6)
c
(63-66)c
(69-72)c
(75-78)c
(101-104)c
(107-110)c
(113-116)mockgen/internal/tests/typed/source/mock_external_test.go (7) (7)
c
(66-69)c
(72-75)c
(78-81)c
(104-107)c
(110-113)c
(116-119)c
(142-145)
🔇 Additional comments (20)
mockgen/internal/tests/alias/subpkg/interfaces.go (1)
7-9
: Formatting Improvement: Spacing in Interface Declaration
The change frominterface{
tointerface {
improves readability and follows standard Go formatting conventions. No functionality is affected.mockgen/gob_test.go (1)
17-20
: Enhanced Argument Formatting for Package Parsing
The adjustments in the arguments of theparser.parsePackage
call improve the consistency of formatting. The removal of extraneous spaces in the package name and interface array comments clarifies intent without changing functionality.🧰 Tools
🪛 golangci-lint (1.64.8)
17-17: ineffectual assignment to err
(ineffassign)
mockgen/internal/tests/typed/go.mod (1)
3-5
: Go Version and Toolchain Update
Updating the Go version from1.22
to1.23.0
and adding the toolchain versiongo1.23.7
ensures a modern build environment and consistency across modules.mockgen/internal/tests/alias/interfaces.go (5)
5-7
: Comment Block Formatting – Case 1
Reformatting the comment for Case 1 to include a leading empty comment and proper indentation increases clarity. This is purely cosmetic and does not affect functionality.
14-15
: Comment Formatting – Case 3
The adjusted comment block (lines 14-15) for Case 3 now clearly states that the interface both accepts alias parameters and returns alias results. This minor reformatting aids in readability.
22-24
: Comment Formatting – Case 5
The updated comments in Case 5 (lines 22-24) improve the explanation regarding the underlying type usage. The changes are purely stylistic.
29-31
: Comment Formatting – Case 6
The restructured comment block for Case 6 now clearly indicates that the alias defined in this package should be used for types from another package. This enhances clarity with no functional impact.
34-36
: Comment Formatting – Case 7
The revised comments for Case 7 (lines 34-36) now better document that the generated methods should expose only the alias for an unexported type. This ensures the intended abstraction is maintained.mockgen/internal/tests/generics/go.mod (1)
3-5
: Go Version and Toolchain Consistency
As with other modules, updating the Go version to1.23.0
and adding the toolchain specificationgo1.23.7
brings consistency and ensures compatibility with the tools used across this repository.mockgen/model/model.go (2)
499-505
: Improved struct type handlingThis change correctly handles non-empty structs with names by creating a NamedType, fixing a previously unimplemented case in the type conversion system. This enhancement enables better support for struct types in the generated mocks.
506-507
: Added support for unsafe.PointerGood addition of support for unsafe.Pointer type, which properly maps to the predeclared "unsafe.Pointer" type. This addresses a TODO in the codebase and completes the type system's coverage.
go.mod (1)
9-10
:❓ Verification inconclusive
Updated dependencies
Dependencies have been upgraded to newer versions. These updates align with the Go version upgrade and should provide newer features and bug fixes.
Also applies to: 17-17
🌐 Web query:
Are there any breaking changes between golang.org/x/tools v0.22.0 and v0.31.0?
💡 Result:
Between golang.org/x/tools v0.22.0 and v0.31.0, there are several notable changes that may introduce breaking behavior:
Configuration Breaking Changes
- Removed
hoverKind=structured
: The experimentalStructured
hoverKind value was deprecated and removed in later releases, affecting clients relying on JSON-formatted hover responses [1].- Replaced
gc_details
code lens: Thegc_details
code lens was deleted and replaced with atoggleCompilerOptDetails
code action, requiring clients to adopt new interactions [1].API and Behavior Changes
- Modernize analyzer updates: The new
modernize
analyzer introduced code modernization hints. While these are optional (can be disabled via"analyses": { "modernize": false }
), their introduction changed default diagnostic behavior [1].- Refactoring improvements:
- New
Extract declarations to new file
action with stricter declaration selection logic [1]Extract constant
vsExtract variable
logic altered for constant expressions [1]Dependency Requirements
- Minimum Go version: Version v0.29.0 and later require Go 1.24+ due to new tool management features (
go get -tool
syntax) [4], while earlier versions worked with Go 1.16-1.23 [2][6][10].Package Changes
- Semantic token handling: The
noSemanticString
andnoSemanticTokenNumber
options were replaced with granularsemanticTokenTypes
configuration [1]:"semanticTokenTypes": {"string": false, "number": false}- Version comparison logic: The
golang.org/x/tools/internal/versions
package added stricter validation requiring valid "go"-prefixed version strings in Compare() [2].Security Updates
- Indirect dependencies like
golang.org/x/net
received security patches that could affect integration points [10][16].Projects upgrading should test these areas:
- Editor configuration (hover/code lens features)
- Go version compatibility
- Static analysis workflows using modernize hints
- Semantic token rendering configurations
- Dependency chains using x/tools' internal packages
While no API breakages are explicitly documented, the cumulative effect of configuration changes and dependency requirements creates significant upgrade friction requiring careful validation[1][2][4][10].
Citations:
- 1: https://github.com/golang/tools/releases
- 2: https://pkg.go.dev/golang.org/x/tools/internal/versions
- 3: https://sdk.operatorframework.io/docs/upgrading-sdk-version/version-upgrade-guide/
- 4: https://blog.howardjohn.info/posts/go-tools-command/
- 5: https://go.dev/blog/v2-go-modules
- 6: https://groups.google.com/g/golang-codereviews/c/WCqyxXdKMPk
- 7: https://dev.golang.org/release
- 8: https://pkg.go.dev/golang.org/x/tools/go/analysis
- 9: https://go.dev/doc/devel/release
- 10: https://cert-manager.io/docs/releases/release-notes/release-notes-1.14/
- 11: https://build.golang.org/log/e9a6b0e69b5f0838bceb3e4dd2320230e98741f8
- 12: https://github.com/open-telemetry/opentelemetry-go/releases
- 13: https://pkg.go.dev/golang.org/x/tools
- 14: https://github.com/dkorunic/axfr2hosts/releases
- 15: https://cloud.google.com/release-notes
- 16: https://lists.sr.ht/~rjarry/aerc-devel/patches/56633
- 17: https://www.freshports.org/devel/go-tools/
- 18: https://github.com/open-telemetry/opentelemetry-go-contrib/releases
- 19: x/vuln/cmd/govulncheck: outdated go version requirements in doc.go golang/go#68256
- 20: https://deps.dev/go/golang.org%2Fx%2Fnet/v0.0.0-20180811021610-c39426892332/compare
Attention: Verify Breaking Changes Introduced by Dependency Updates
The dependency update in go.mod (lines 9‑10 and 17) now upgrades to:
golang.org/x/mod v0.24.0 golang.org/x/tools v0.31.0
While these upgrades align with the Go version bump and offer new features and bug fixes, note that the update of golang.org/x/tools from earlier versions (e.g. v0.22.0) introduces several changes that might be breaking, including:
- Configuration changes: Removal of
hoverKind=structured
may affect clients relying on structured JSON hover responses.- Code lens modifications: The
gc_details
code lens has been replaced by the newtoggleCompilerOptDetails
action, which may require updates in client integrations.- Static analysis and refactoring adjustments: Changes in modernize analyzer defaults and refactoring actions could alter diagnostic behavior.
- Dependency prerequisites: Versions v0.29.0 and later require Go 1.24+, so ensure our Go environment satisfies this requirement.
Please verify that these changes do not adversely impact our usage, particularly for hover, code lens functionality, and static analysis workflows.
mockgen/package_mode.go (1)
303-306
: Better handling for basic type aliasesGood enhancement to handle type aliases referring to basic types. This implementation returns the underlying basic type name rather than treating it as a named type, which improves code consistency and correctness.
gomock/call.go (3)
115-125
: Improved error handling for non-function argumentsExcellent improvement to detect invalid inputs early during mock setup rather than at execution time. The panic is now deferred to the action execution with a clear error message about the type mismatch.
130-141
: Better validation of function argument countsEnhanced validation for the number of arguments in the DoAndReturn function. The error messages are now more descriptive, and the check happens during setup rather than execution, preventing confusing runtime errors.
142-158
: Fixed argument count handlingThis change properly handles cases where the calling code provides more arguments than the function expects by truncating the argument list. This prevents index out of range errors that could occur when calling the function with the wrong number of arguments.
sample/user_test.go (2)
164-167
: Change aligns with DoAndReturn type validation enhancementThe function signature has been updated to return
[3]int
instead of no return value. This change intentionally creates a return type mismatch to test the enhanced type validation inDoAndReturn
, which matches the PR objective of implementing type checking with error messages during mock setup.
179-181
: Appropriate test case for return type validationThis second test function now returns
[3]int
with values (instead of a boolean), which correctly provides a test case for the enhanced type checking. The test functions in both run cases are now consistently returning the same type but with different values.mockgen/parse.go (2)
173-194
: Improved error handling and formattingThe error reporting has been enhanced with several important improvements:
- Added nil check for fileSet before attempting to use it
- Added validation for position validity with ps.IsValid()
- Improved filename handling with proper escaping of special characters (particularly % signs)
- Formatted error messages consistently with location information
These changes align with the PR objective to enhance error reporting in the fileParser.
475-491
: Proper implementation of interface shadowing rulesThis change implements the method shadowing rules for embedded interfaces, removing a TODO item from the codebase. The implementation correctly:
- Creates a new slice to hold non-shadowed methods
- Checks each method from the embedded interface against existing methods in the embedding interface
- Only includes methods that aren't shadowed by the embedding interface
This implementation resolves the interface shadowing issue mentioned in the PR objectives.
Address TODOs across codebase in gomock and mockgen
This PR implements several TODO items in the codebase to improve robustness and error handling.
Changes Made
DoAndReturn Type Checking
Type Handling Improvements in mockgen
Interface Shadowing Implementation
Error Reporting Enhancement
Test Plan
Related Issues
N/A - These were TODO items in the codebase
Summary by CodeRabbit