feat: add fail-now checker - #302
Open
mmorel-35 wants to merge 2 commits into
Open
Conversation
ccoVeille
suggested changes
Mar 18, 2026
mmorel-35
pushed a commit
to mmorel-35/testifylint
that referenced
this pull request
May 28, 2026
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
mmorel-35
force-pushed
the
issue-144
branch
2 times, most recently
from
July 10, 2026 10:46
b5176b7 to
5b9af9b
Compare
…replacements Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.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.
assert.Fail,assert.FailNow(and theirf/requirevariants) are thin wrappers over standardtesting.Tmethods. This checker detects their use and auto-fixes to the direct stdlib equivalents.Checker:
fail-nowttype)Fix mapping
assert.Fail(t, "msg")t.Error("msg")assert.Fail(t, "fail", "msg")t.Error("msg")assert.Fail(t, "fail", "fmt %s", arg)t.Errorf("fmt %s", arg)assert.Failf(t, "fail", "fmt %s", arg)t.Errorf("fmt %s", arg)assert.FailNow(t, "msg")t.Fatal("msg")assert.FailNow(t, "fail", "fmt %s", arg)t.Fatalf("fmt %s", arg)assert.FailNowf(t, "fail", "fmt %s", arg)t.Fatalf("fmt %s", arg)s.FailNow("msg")(suite receiver)s.T().Fatal("msg")When
msgAndArgsare present in non-fvariants,failureMessageis dropped andmsgAndArgsbecome the replacement arguments (matching testify's ownmessageFromMsgAndArgsconvention). Suite method calls are fixed viareceiver.T()when the receiver implementsTestifySuite.Fix safety constraints
ExprStmt/GoStmt/DeferStmt). In expression contexts (e.g._ = assert.Fail(...),if assert.Fail(...) {}), the diagnostic is reported but no fix is suggested, to avoid producing uncompilable code.targument having the target method (checked viatypes.LookupFieldOrMethod). Iftonly implementsassert.TestingT(which only requiresErrorf), the non-ffix is withheld.assertObj.Fail(...)whereassertObjis*assert.Assertions) are ignored entirely — no diagnostic is emitted since there is no accessibletesting.Tto suggest.Implementation
internal/checkers/fail_now.go— checker (implemented asAdvancedCheckerusinginsp.WithStackfor parent-node context) + fix logicinternal/checkers/checkers_registry.go— registered in the advanced-checker section, enabled by defaultinternal/testgen/gen_fail_now.go— test generator with errored + golden templates covering all arg variants, suite method calls, expression-context no-fix cases, and ignored assertion-object callsanalyzer/testdata/src/go-require-http-handlers/— updated test + golden to reflect thatassert.FailNowands.FailNowin HTTP handlers are now also fixed by this checkerCloses #144