Skip to content

Commit 19834b6

Browse files
committed
build(deps): bump github.com/Antonboom/testifylint from 1.3.1 to 1.4.0
1 parent 02740ea commit 19834b6

9 files changed

+111
-13
lines changed

.golangci.next.reference.yml

+15-1
Original file line numberDiff line numberDiff line change
@@ -2192,13 +2192,16 @@ linters-settings:
21922192
- error-nil
21932193
- expected-actual
21942194
- float-compare
2195+
- formatter
21952196
- go-require
21962197
- len
21972198
- negative-positive
21982199
- nil-compare
21992200
- require-error
2201+
- suite-broken-parallel
22002202
- suite-dont-use-pkg
22012203
- suite-extra-assert-call
2204+
- suite-subtest-run
22022205
- suite-thelper
22032206
- useless-assert
22042207

@@ -2208,7 +2211,8 @@ linters-settings:
22082211
# Enable checkers by name
22092212
# (in addition to default
22102213
# blank-import, bool-compare, compares, empty, error-is-as, error-nil, expected-actual, go-require, float-compare,
2211-
# len, negative-positive, nil-compare, require-error, suite-dont-use-pkg, suite-extra-assert-call, useless-assert
2214+
# formatter, len, negative-positive, nil-compare, require-error, suite-broken-parallel, suite-dont-use-pkg,
2215+
# suite-extra-assert-call, suite-subtest-run, useless-assert
22122216
# ).
22132217
enable:
22142218
- blank-import
@@ -2219,13 +2223,16 @@ linters-settings:
22192223
- error-nil
22202224
- expected-actual
22212225
- float-compare
2226+
- formatter
22222227
- go-require
22232228
- len
22242229
- negative-positive
22252230
- nil-compare
22262231
- require-error
2232+
- suite-broken-parallel
22272233
- suite-dont-use-pkg
22282234
- suite-extra-assert-call
2235+
- suite-subtest-run
22292236
- suite-thelper
22302237
- useless-assert
22312238

@@ -2237,6 +2244,13 @@ linters-settings:
22372244
# Regexp for expected variable name.
22382245
# Default: (^(exp(ected)?|want(ed)?)([A-Z]\w*)?$)|(^(\w*[a-z])?(Exp(ected)?|Want(ed)?)$)
22392246
pattern: ^expected
2247+
formatter:
2248+
# To enable go vet's printf checks.
2249+
# Default: true
2250+
check-format-string: false
2251+
# To require f-assertions if format string is used.
2252+
# Default: false
2253+
require-f-funcs: true
22402254
go-require:
22412255
# To ignore HTTP handlers (like http.HandlerFunc).
22422256
# Default: false

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/Abirdcfly/dupword v0.0.14
1010
github.com/Antonboom/errname v0.1.13
1111
github.com/Antonboom/nilnil v0.1.9
12-
github.com/Antonboom/testifylint v1.3.1
12+
github.com/Antonboom/testifylint v1.4.0
1313
github.com/BurntSushi/toml v1.4.0
1414
github.com/Crocmagnon/fatcontext v0.2.2
1515
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24

go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsonschema/golangci.next.jsonschema.json

+25
Original file line numberDiff line numberDiff line change
@@ -2886,13 +2886,16 @@
28862886
"error-nil",
28872887
"expected-actual",
28882888
"float-compare",
2889+
"formatter",
28892890
"go-require",
28902891
"len",
28912892
"negative-positive",
28922893
"nil-compare",
28932894
"require-error",
2895+
"suite-broken-parallel",
28942896
"suite-dont-use-pkg",
28952897
"suite-extra-assert-call",
2898+
"suite-subtest-run",
28962899
"suite-thelper",
28972900
"useless-assert"
28982901
]
@@ -2906,13 +2909,16 @@
29062909
"error-nil",
29072910
"expected-actual",
29082911
"float-compare",
2912+
"float-compare",
29092913
"go-require",
29102914
"len",
29112915
"negative-positive",
29122916
"nil-compare",
29132917
"require-error",
2918+
"suite-broken-parallel",
29142919
"suite-dont-use-pkg",
29152920
"suite-extra-assert-call",
2921+
"suite-subtest-run",
29162922
"useless-assert"
29172923
]
29182924
},
@@ -2929,13 +2935,16 @@
29292935
"error-nil",
29302936
"expected-actual",
29312937
"float-compare",
2938+
"formatter",
29322939
"go-require",
29332940
"len",
29342941
"negative-positive",
29352942
"nil-compare",
29362943
"require-error",
2944+
"suite-broken-parallel",
29372945
"suite-dont-use-pkg",
29382946
"suite-extra-assert-call",
2947+
"suite-subtest-run",
29392948
"suite-thelper",
29402949
"useless-assert"
29412950
],
@@ -2966,6 +2975,22 @@
29662975
}
29672976
}
29682977
},
2978+
"formatter": {
2979+
"type": "object",
2980+
"additionalProperties": false,
2981+
"properties": {
2982+
"check-format-string": {
2983+
"description": "To enable go vet's printf checks.",
2984+
"type": "boolean",
2985+
"default": true
2986+
},
2987+
"require-f-funcs": {
2988+
"description": "To require f-assertions if format string is used.",
2989+
"type": "boolean",
2990+
"default": false
2991+
}
2992+
}
2993+
},
29692994
"go-require": {
29702995
"type": "object",
29712996
"additionalProperties": false,

pkg/config/linters_settings.go

+5
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,11 @@ type TestifylintSettings struct {
879879
ExpVarPattern string `mapstructure:"pattern"`
880880
} `mapstructure:"expected-actual"`
881881

882+
Formatter struct {
883+
CheckFormatString *bool `mapstructure:"check-format-string"`
884+
RequireFFuncs bool `mapstructure:"require-f-funcs"`
885+
} `mapstructure:"formatter"`
886+
882887
GoRequire struct {
883888
IgnoreHTTPHandlers bool `mapstructure:"ignore-http-handlers"`
884889
} `mapstructure:"go-require"`

pkg/golinters/testifylint/testdata/testifylint.go

+32-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package testdata
33

44
import (
5+
"fmt"
56
"io"
67
"testing"
78

@@ -21,15 +22,15 @@ func TestTestifylint(t *testing.T) {
2122
err error
2223
)
2324

24-
assert.Equal(t, predicate, true) // want "bool-compare: use assert\\.True"
25-
assert.Equal(t, Bool(predicate), false) // want "bool-compare: use assert\\.False"
26-
assert.True(t, resultInt == 1) // want "compares: use assert\\.Equal"
27-
assert.Equal(t, len(arr), 0) // want "empty: use assert\\.Empty"
28-
assert.Error(t, err, io.EOF) // want "error-is-as: invalid usage of assert\\.Error, use assert\\.ErrorIs instead"
29-
assert.Nil(t, err) // want "error-nil: use assert\\.NoError"
30-
assert.Equal(t, resultInt, 42) // want "expected-actual: need to reverse actual and expected values"
31-
assert.Equal(t, resultFloat, 42.42) // want "float-compare: use assert\\.InEpsilon \\(or InDelta\\)"
32-
assert.Equal(t, len(arr), 10) // want "len: use assert\\.Len"
25+
assert.Equal(t, predicate, true) // want "bool-compare: use assert\\.True"
26+
assert.Equal(t, Bool(predicate), false) // want "bool-compare: use assert\\.False"
27+
assert.True(t, resultInt == 1) // want "compares: use assert\\.Equal"
28+
assert.Equal(t, len(arr), 0) // want "empty: use assert\\.Empty"
29+
assert.Error(t, err, io.EOF) // want "error-is-as: invalid usage of assert\\.Error, use assert\\.ErrorIs instead"
30+
assert.Nil(t, err) // want "error-nil: use assert\\.NoError"
31+
assert.Equal(t, resultInt, 42) // want "expected-actual: need to reverse actual and expected values"
32+
assert.Equal(t, resultFloat, 42.42) // want "float-compare: use assert\\.InEpsilon \\(or InDelta\\)"
33+
assert.Equal(t, len(arr), 10) // want "len: use assert\\.Len"
3334

3435
assert.True(t, predicate)
3536
assert.Equal(t, resultInt, 1) // want "expected-actual: need to reverse actual and expected values"
@@ -48,6 +49,9 @@ func TestTestifylint(t *testing.T) {
4849
assert.Equal(t, predicate, true, "message %d", 42) // want "bool-compare: use assert\\.True"
4950
assert.Equalf(t, predicate, true, "message") // want "bool-compare: use assert\\.Truef"
5051
assert.Equalf(t, predicate, true, "message %d", 42) // want "bool-compare: use assert\\.Truef"
52+
53+
assert.Equal(t, 1, 2, fmt.Sprintf("msg")) // want "formatter: remove unnecessary fmt\\.Sprintf"
54+
assert.Equalf(t, 1, 2, "msg with arg", "arg") // want "formatter: assert\\.Equalf call has arguments but no formatting directives"
5155
})
5256

5357
assert.Equal(t, arr, nil) // want "nil-compare: use assert\\.Nil"
@@ -72,3 +76,22 @@ func (s *SuiteExample) TestAll() {
7276
var b bool
7377
s.Assert().True(b) // want "suite-extra-assert-call: need to simplify the assertion to s\\.True"
7478
}
79+
80+
func (s *SuiteExample) TestOne() {
81+
s.T().Parallel() // want "suite-broken-parallel: testify v1 does not support suite's parallel tests and subtests"
82+
83+
s.T().Run("subtest", func(t *testing.T) { // want "suite-subtest-run: use s\\.Run to run subtest"
84+
t.Parallel() // want "suite-broken-parallel: testify v1 does not support suite's parallel tests and subtests"
85+
86+
assert.Equal(s.T(), 1, 2) // want "suite-dont-use-pkg: use s\\.Equal"
87+
s.Equal(1, 2)
88+
})
89+
90+
s.Run("subtest", func() {
91+
s.T().Parallel() // want "suite-broken-parallel: testify v1 does not support suite's parallel tests and subtests"
92+
s.Equal(1, 2)
93+
})
94+
95+
var b bool
96+
s.Assert().True(b) // want "suite-extra-assert-call: need to simplify the assertion to s\\.True"
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//golangcitest:args -Etestifylint
2+
//golangcitest:config_path testdata/testifylint_formatter_only.yml
3+
package testdata
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestTestifylint(t *testing.T) {
13+
var err error
14+
var args []any
15+
assert.Error(t, err, "Parse(%v) should fail.", args) // want "formatter: use assert\\.Errorf$"
16+
17+
assert.Equal(t, 1, 2, fmt.Sprintf("msg")) // want "formatter: remove unnecessary fmt\\.Sprintf and use assert\\.Equalf"
18+
assert.DirExistsf(t, "", "msg with arg", 42)
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
linters-settings:
2+
testifylint:
3+
disable-all: true
4+
enable:
5+
- formatter
6+
formatter:
7+
check-format-string: false
8+
require-f-funcs: true

pkg/golinters/testifylint/testifylint.go

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func New(settings *config.TestifylintSettings) *goanalysis.Linter {
1818
"disable-all": settings.DisableAll,
1919

2020
"bool-compare.ignore-custom-types": settings.BoolCompare.IgnoreCustomTypes,
21+
"formatter.require-f-funcs": settings.Formatter.RequireFFuncs,
2122
"go-require.ignore-http-handlers": settings.GoRequire.IgnoreHTTPHandlers,
2223
}
2324
if len(settings.EnabledCheckers) > 0 {
@@ -27,6 +28,9 @@ func New(settings *config.TestifylintSettings) *goanalysis.Linter {
2728
cfg[a.Name]["disable"] = settings.DisabledCheckers
2829
}
2930

31+
if b := settings.Formatter.CheckFormatString; b != nil {
32+
cfg[a.Name]["formatter.check-format-string"] = *b
33+
}
3034
if p := settings.ExpectedActual.ExpVarPattern; p != "" {
3135
cfg[a.Name]["expected-actual.pattern"] = p
3236
}

0 commit comments

Comments
 (0)