Skip to content

Commit 1046297

Browse files
committed
bump testifylint to stable version
1 parent 61f2ef3 commit 1046297

File tree

8 files changed

+150
-15
lines changed

8 files changed

+150
-15
lines changed

.golangci.reference.yml

+36-4
Original file line numberDiff line numberDiff line change
@@ -1916,29 +1916,61 @@ linters-settings:
19161916
all: false
19171917

19181918
testifylint:
1919-
# Enable all checkers.
1919+
# Enable all checkers (https://github.com/Antonboom/testifylint#checkers).
19201920
# Default: false
19211921
enable-all: true
1922-
# Enable specific checkers.
1923-
# https://github.com/Antonboom/testifylint#checkers
1924-
# Default: ["bool-compare", "compares", "empty", "error-is-as", "error-nil", "expected-actual", "float-compare", "len", "require-error", "suite-dont-use-pkg", "suite-extra-assert-call"]
1922+
# Disable checkers by name
1923+
# (in addition to default
1924+
# suite-thelper
1925+
# ).
1926+
disable:
1927+
- bool-compare
1928+
- compares
1929+
- empty
1930+
- error-is-as
1931+
- error-nil
1932+
- expected-actual
1933+
- go-require
1934+
- float-compare
1935+
- len
1936+
- nil-compare
1937+
- require-error
1938+
- suite-dont-use-pkg
1939+
- suite-extra-assert-call
1940+
- suite-thelper
1941+
1942+
# Disable all checkers (https://github.com/Antonboom/testifylint#checkers).
1943+
# Default: false
1944+
disable-all: true
1945+
# Enable checkers by name
1946+
# (in addition to default
1947+
# bool-compare, compares, empty, error-is-as, error-nil, expected-actual, go-require, float-compare, len,
1948+
# nil-compare, require-error, suite-dont-use-pkg, suite-extra-assert-call
1949+
# ).
19251950
enable:
19261951
- bool-compare
19271952
- compares
19281953
- empty
19291954
- error-is-as
19301955
- error-nil
19311956
- expected-actual
1957+
- go-require
19321958
- float-compare
19331959
- len
1960+
- nil-compare
19341961
- require-error
19351962
- suite-dont-use-pkg
19361963
- suite-extra-assert-call
19371964
- suite-thelper
1965+
19381966
expected-actual:
19391967
# Regexp for expected variable name.
19401968
# Default: (^(exp(ected)?|want(ed)?)([A-Z]\w*)?$)|(^(\w*[a-z])?(Exp(ected)?|Want(ed)?)$)
19411969
pattern: ^expected
1970+
require-error:
1971+
# Regexp for assertions to analyze. If defined then only matched assertions will be reported.
1972+
# Default: ""
1973+
fn-pattern: ^(Errorf?|NoErrorf?)$
19421974
suite-extra-assert-call:
19431975
# To require or remove extra Assert() call?
19441976
# Default: remove

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/Abirdcfly/dupword v0.0.13
1010
github.com/Antonboom/errname v0.1.12
1111
github.com/Antonboom/nilnil v0.1.7
12-
github.com/Antonboom/testifylint v0.2.3
12+
github.com/Antonboom/testifylint v1.0.1
1313
github.com/BurntSushi/toml v1.3.2
1414
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24
1515
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.1.0
@@ -191,9 +191,9 @@ require (
191191
go.uber.org/multierr v1.6.0 // indirect
192192
go.uber.org/zap v1.24.0 // indirect
193193
golang.org/x/exp/typeparams v0.0.0-20230307190834-24139beb5833 // indirect
194-
golang.org/x/mod v0.13.0 // indirect
194+
golang.org/x/mod v0.14.0 // indirect
195195
golang.org/x/sync v0.4.0 // indirect
196-
golang.org/x/sys v0.13.0 // indirect
196+
golang.org/x/sys v0.14.0 // indirect
197197
golang.org/x/text v0.13.0 // indirect
198198
google.golang.org/protobuf v1.28.0 // indirect
199199
gopkg.in/ini.v1 v1.67.0 // indirect

go.sum

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

pkg/config/linters_settings.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -764,13 +764,19 @@ type TagliatelleSettings struct {
764764
}
765765

766766
type TestifylintSettings struct {
767-
EnableAll bool `mapstructure:"enable-all"`
768-
EnabledCheckers []string `mapstructure:"enable"`
767+
EnableAll bool `mapstructure:"enable-all"`
768+
DisabledCheckers []string `mapstructure:"disable"`
769+
DisableAll bool `mapstructure:"disable-all"`
770+
EnabledCheckers []string `mapstructure:"enable"`
769771

770772
ExpectedActual struct {
771773
ExpVarPattern string `mapstructure:"pattern"`
772774
} `mapstructure:"expected-actual"`
773775

776+
RequireError struct {
777+
FnPattern string `mapstructure:"fn-pattern"`
778+
} `mapstructure:"require-error"`
779+
774780
SuiteExtraAssertCall struct {
775781
Mode string `mapstructure:"mode"`
776782
} `mapstructure:"suite-extra-assert-call"`

pkg/golinters/testifylint.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@ func NewTestifylint(settings *config.TestifylintSettings) *goanalysis.Linter {
1414
cfg := make(map[string]map[string]any)
1515
if settings != nil {
1616
cfg[a.Name] = map[string]any{
17-
"enable-all": settings.EnableAll,
17+
"enable-all": settings.EnableAll,
18+
"disable-all": settings.DisableAll,
1819
}
1920
if len(settings.EnabledCheckers) > 0 {
2021
cfg[a.Name]["enable"] = settings.EnabledCheckers
2122
}
23+
if len(settings.DisabledCheckers) > 0 {
24+
cfg[a.Name]["disable"] = settings.DisabledCheckers
25+
}
26+
2227
if p := settings.ExpectedActual.ExpVarPattern; p != "" {
2328
cfg[a.Name]["expected-actual.pattern"] = p
2429
}
30+
if p := settings.RequireError.FnPattern; p != "" {
31+
cfg[a.Name]["require-error.fn-pattern"] = p
32+
}
2533
if m := settings.SuiteExtraAssertCall.Mode; m != "" {
2634
cfg[a.Name]["suite-extra-assert-call.mode"] = m
2735
}

test/testdata/configs/testifylint.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
linters-settings:
2+
testifylint:
3+
disable-all: true
4+
enable: require-error
5+
require-error:
6+
fn-pattern: ^NoError$

test/testdata/testifylint.go

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ func TestTestifylint(t *testing.T) {
4646
assert.Equalf(t, predicate, true, "message") // want "bool-compare: use assert\\.Truef"
4747
assert.Equalf(t, predicate, true, "message %d", 42) // want "bool-compare: use assert\\.Truef"
4848
})
49+
50+
assert.Equal(t, arr, nil) // want "nil-compare: use assert\\.Nil"
51+
assert.Nil(t, arr)
52+
53+
go func() {
54+
if assert.Error(t, err) {
55+
require.ErrorIs(t, err, io.EOF) // want "go-require: require must only be used in the goroutine running the test function"
56+
}
57+
}()
4958
}
5059

5160
type SuiteExample struct {

test/testdata/testifylint_config.go

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//golangcitest:args -Etestifylint
2+
//golangcitest:config_path testdata/configs/testifylint.yml
3+
package testdata
4+
5+
import (
6+
"io"
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
"github.com/stretchr/testify/suite"
12+
)
13+
14+
func TestTestifylint(t *testing.T) {
15+
var (
16+
predicate bool
17+
resultInt int
18+
resultFloat float64
19+
arr []string
20+
err error
21+
)
22+
23+
assert.Equal(t, predicate, true)
24+
assert.True(t, resultInt == 1)
25+
assert.Equal(t, len(arr), 0)
26+
assert.Error(t, err, io.EOF)
27+
assert.Nil(t, err)
28+
assert.Equal(t, resultInt, 42)
29+
assert.Equal(t, resultFloat, 42.42)
30+
assert.Equal(t, len(arr), 10)
31+
32+
assert.True(t, predicate)
33+
assert.Equal(t, resultInt, 1)
34+
assert.Empty(t, arr)
35+
assert.ErrorIs(t, err, io.EOF)
36+
assert.NoError(t, err) // want "require-error: for error assertions use require"
37+
assert.Equal(t, 42, resultInt)
38+
assert.NoErrorf(t, err, "boom!")
39+
assert.InEpsilon(t, 42.42, resultFloat, 0.0001)
40+
assert.Len(t, arr, 10)
41+
42+
require.ErrorIs(t, err, io.EOF)
43+
require.NoError(t, err)
44+
45+
t.Run("formatted", func(t *testing.T) {
46+
assert.Equal(t, predicate, true, "message")
47+
assert.Equal(t, predicate, true, "message %d", 42)
48+
assert.Equalf(t, predicate, true, "message")
49+
assert.Equalf(t, predicate, true, "message %d", 42)
50+
})
51+
52+
assert.Equal(t, arr, nil)
53+
assert.Nil(t, arr)
54+
55+
go func() {
56+
if assert.Error(t, err) {
57+
require.ErrorIs(t, err, io.EOF)
58+
}
59+
}()
60+
}
61+
62+
type SuiteExample struct {
63+
suite.Suite
64+
}
65+
66+
func TestSuiteExample(t *testing.T) {
67+
suite.Run(t, new(SuiteExample))
68+
}
69+
70+
func (s *SuiteExample) TestAll() {
71+
var b bool
72+
s.Assert().True(b)
73+
}

0 commit comments

Comments
 (0)