Add wrong-t checker for incorrect testing.T usage in testify assertions#304
Open
mmorel-35 wants to merge 2 commits into
Open
Add wrong-t checker for incorrect testing.T usage in testify assertions#304mmorel-35 wants to merge 2 commits into
wrong-t checker for incorrect testing.T usage in testify assertions#304mmorel-35 wants to merge 2 commits into
Conversation
…ions Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Copilot AI
added a commit
to mmorel-35/testifylint
that referenced
this pull request
May 28, 2026
…ssed to testify
mmorel-35
pushed a commit
to mmorel-35/testifylint
that referenced
this pull request
May 28, 2026
…ssed to testify
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.
Two related misuse patterns cause silent test failures or panics at runtime: passing
nil/freshly-created*testing.Tto package-level assertions, and using an*Assertionsobject bound to a parenttinside at.Runsubtest wheretis shadowed by a fresh child*testing.T.New checker:
wrong-t(enabled by default, no autofix)Case 1 — nil or fresh
*testing.Tas thetargumentDetected by inspecting the first parameter type of the called function's signature (
assert.TestingT/require.TestingT) and checking whether the supplied argument isnil, a composite literal oftesting.T, anew(testing.T)call, or a variable declared from one of those expressions.Case 2 —
*Assertionsobject created with outertused in a subtestDetected by collecting all
:=assignments fromassert.New/require.New, then for eacht.Runcallback (with a*testing.Tparameter) walking its direct body — stopping at nested function literals to avoid double-reporting — and flagging any receiver whose declaration precedes the callback.Files
internal/checkers/wrong_t.go— checker implementation (AdvancedChecker)internal/checkers/checkers_registry.go— registration (enabled by default)internal/checkers/checkers_registry_test.go,analyzer/checkers_factory_test.go— updated expected listsinternal/testgen/gen_wrong_t.go,internal/testgen/main.go— test-data generatoranalyzer/testdata/src/checkers-default/wrong-t/— generated test dataREADME.md— checker documentationCloses #255
Closes #197