Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new customlint analyzer to detect testing.T/testing.B/testing.TB variables being captured and used inside Cleanup closures (which can break because the test has already finished), and updates the one affected test case accordingly.
Changes:
- Register a new
cleanupanalyzer in thecustomlintplugin. - Implement the analyzer to report identifier uses of captured
testingvariables withinCleanupfunction literals. - Add analyzer testdata + golden output, and adjust an LSP completion test to avoid capturing
tin a cleanup closure.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
internal/lsp/server_completion_test.go |
Updates cleanup usage to avoid closing over t. |
_tools/customlint/plugin.go |
Registers the new cleanup analyzer in the plugin. |
_tools/customlint/cleanup.go |
Implements the cleanup analyzer logic. |
_tools/customlint/testdata/cleanup/cleanup.go |
Adds test cases that should/shouldn’t be flagged by the new analyzer. |
_tools/customlint/testdata/cleanup/cleanup.go.golden |
Adds expected diagnostics output for the new analyzer. |
| DefaultLibraryPath: bundled.LibPath(), | ||
| }, onServerRequest) | ||
| t.Cleanup(func() { assert.NilError(t, closeClient()) }) | ||
| t.Cleanup(func() { _ = closeClient() }) |
There was a problem hiding this comment.
closeClient() returns an error when the LSP server goroutines fail to shut down cleanly; ignoring it here can let test failures slip by silently. Consider handling the error without referencing t (e.g., fail-fast via panic or other non-testing.T reporting mechanism) so cleanup issues still cause the test to fail while satisfying the new lint rule.
| t.Cleanup(func() { _ = closeClient() }) | |
| t.Cleanup(func() { | |
| if err := closeClient(); err != nil { | |
| panic(err) | |
| } | |
| }) |
If
tis used in a cleanup, things break because the test has already ended. Add a lint rule to detect this and fix the one case.