Add error-compare checker: detect err.Error() in assertions - #294
Open
mmorel-35 wants to merge 1 commit into
Open
Add error-compare checker: detect err.Error() in assertions#294mmorel-35 wants to merge 1 commit into
error-compare checker: detect err.Error() in assertions#294mmorel-35 wants to merge 1 commit into
Conversation
mmorel-35
force-pushed
the
error-compare
branch
from
March 13, 2026 19:25
684dd3d to
e1e0333
Compare
ccoVeille
approved these changes
Mar 14, 2026
mmorel-35
pushed a commit
to mmorel-35/testifylint
that referenced
this pull request
May 28, 2026
ccoVeille
approved these changes
May 29, 2026
ccoVeille
left a comment
Contributor
There was a problem hiding this comment.
Thank you for the fix of what I reported you
|
@Antonboom , some numbers Usages
I agree that I'd prefer EqualError or ErrorIs over ErrorContains, but for a large org, I'm okay allowing engineers to use ErrorContains. Regardless of preference the |
mmorel-35
force-pushed
the
error-compare
branch
from
August 7, 2026 11:38
5a52e9b to
57f370e
Compare
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
mmorel-35
force-pushed
the
error-compare
branch
from
August 7, 2026 11:42
57f370e to
58a872a
Compare
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.
Implements the
error-comparechecker (issue #47). Usingerr.Error()in testify assertions compares error string representations — fragile, ignores the error chain, and bypasses dedicated testify error APIs.Detected patterns
assert.Contains(t, err.Error(), "substr")assert.ErrorContains(t, err, "substr")assert.Contains(t, err.Error(), sentinel.Error())assert.ErrorIs(t, err, sentinel)assert.Equal(t, err.Error(), "msg")assert.EqualError(t, err, "msg")assert.Equal(t, "msg", err.Error())assert.EqualError(t, err, "msg")assert.Equal(t, err, sentinel)(both implement error)assert.ErrorIs(t, err, sentinel)assert.NotEqual(t, err, sentinel)(both implement error)assert.NotErrorIs(t, err, sentinel)All
f-suffixed variants are handled automatically.Implementation
helpers_error.go: AddedisErrErrorCall()(detectsx.Error()whereximplementserror) andimplementsErrorIface()(type-based, not restricted toerror-typed variables).error_compare.go: NewRegularCheckerhandlingContains,Equal, andNotEqualcases. Guards against overlap witherror-nilviaisNilcheck onEqual(t, err, nil). No autofix is provided for the two-errorEqual/NotEqualcases becauseErrorIs/NotErrorIsare not symmetric and argument order cannot be safely inferred from types alone.containsanderror-nil, enabled by default.ContainsandEqual(err.Error(), ...)cases are autofixed, whileEqual/NotEqualtwo-error cases remain unchanged in the golden output.Also reverts an unrelated change from a previous session that added a "redundant assertion" detection to
require-error.Closes #47