Skip to content

Commit 4200194

Browse files
authored
build(deps): bump github.com/Antonboom/testifylint from 0.2.3 to 1.0.1 (#4186)
1 parent 2640ed7 commit 4200194

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
@@ -1944,29 +1944,61 @@ linters-settings:
19441944
all: false
19451945

19461946
testifylint:
1947-
# Enable all checkers.
1947+
# Enable all checkers (https://github.com/Antonboom/testifylint#checkers).
19481948
# Default: false
19491949
enable-all: true
1950-
# Enable specific checkers.
1951-
# https://github.com/Antonboom/testifylint#checkers
1952-
# 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"]
1950+
# Disable checkers by name
1951+
# (in addition to default
1952+
# suite-thelper
1953+
# ).
1954+
disable:
1955+
- bool-compare
1956+
- compares
1957+
- empty
1958+
- error-is-as
1959+
- error-nil
1960+
- expected-actual
1961+
- go-require
1962+
- float-compare
1963+
- len
1964+
- nil-compare
1965+
- require-error
1966+
- suite-dont-use-pkg
1967+
- suite-extra-assert-call
1968+
- suite-thelper
1969+
1970+
# Disable all checkers (https://github.com/Antonboom/testifylint#checkers).
1971+
# Default: false
1972+
disable-all: true
1973+
# Enable checkers by name
1974+
# (in addition to default
1975+
# bool-compare, compares, empty, error-is-as, error-nil, expected-actual, go-require, float-compare, len,
1976+
# nil-compare, require-error, suite-dont-use-pkg, suite-extra-assert-call
1977+
# ).
19531978
enable:
19541979
- bool-compare
19551980
- compares
19561981
- empty
19571982
- error-is-as
19581983
- error-nil
19591984
- expected-actual
1985+
- go-require
19601986
- float-compare
19611987
- len
1988+
- nil-compare
19621989
- require-error
19631990
- suite-dont-use-pkg
19641991
- suite-extra-assert-call
19651992
- suite-thelper
1993+
19661994
expected-actual:
19671995
# Regexp for expected variable name.
19681996
# Default: (^(exp(ected)?|want(ed)?)([A-Z]\w*)?$)|(^(\w*[a-z])?(Exp(ected)?|Want(ed)?)$)
19691997
pattern: ^expected
1998+
require-error:
1999+
# Regexp for assertions to analyze. If defined then only matched assertions will be reported.
2000+
# Default: ""
2001+
fn-pattern: ^(Errorf?|NoErrorf?)$
19702002
suite-extra-assert-call:
19712003
# To require or remove extra Assert() call?
19722004
# 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
@@ -784,13 +784,19 @@ type TagliatelleSettings struct {
784784
}
785785

786786
type TestifylintSettings struct {
787-
EnableAll bool `mapstructure:"enable-all"`
788-
EnabledCheckers []string `mapstructure:"enable"`
787+
EnableAll bool `mapstructure:"enable-all"`
788+
DisableAll bool `mapstructure:"disable-all"`
789+
EnabledCheckers []string `mapstructure:"enable"`
790+
DisabledCheckers []string `mapstructure:"disable"`
789791

790792
ExpectedActual struct {
791793
ExpVarPattern string `mapstructure:"pattern"`
792794
} `mapstructure:"expected-actual"`
793795

796+
RequireError struct {
797+
FnPattern string `mapstructure:"fn-pattern"`
798+
} `mapstructure:"require-error"`
799+
794800
SuiteExtraAssertCall struct {
795801
Mode string `mapstructure:"mode"`
796802
} `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)