build(deps): bump github.com/Antonboom/testifylint from 0.2.3 to 1.0.1 (#4186)

This commit is contained in:
Anton Telyshev 2023-11-05 15:09:28 +02:00 committed by GitHub
parent 2640ed7c96
commit 42001943c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 150 additions and 15 deletions

View File

@ -1944,12 +1944,37 @@ linters-settings:
all: false
testifylint:
# Enable all checkers.
# Enable all checkers (https://github.com/Antonboom/testifylint#checkers).
# Default: false
enable-all: true
# Enable specific checkers.
# https://github.com/Antonboom/testifylint#checkers
# 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"]
# Disable checkers by name
# (in addition to default
# suite-thelper
# ).
disable:
- bool-compare
- compares
- empty
- error-is-as
- error-nil
- expected-actual
- go-require
- float-compare
- len
- nil-compare
- require-error
- suite-dont-use-pkg
- suite-extra-assert-call
- suite-thelper
# Disable all checkers (https://github.com/Antonboom/testifylint#checkers).
# Default: false
disable-all: true
# Enable checkers by name
# (in addition to default
# bool-compare, compares, empty, error-is-as, error-nil, expected-actual, go-require, float-compare, len,
# nil-compare, require-error, suite-dont-use-pkg, suite-extra-assert-call
# ).
enable:
- bool-compare
- compares
@ -1957,16 +1982,23 @@ linters-settings:
- error-is-as
- error-nil
- expected-actual
- go-require
- float-compare
- len
- nil-compare
- require-error
- suite-dont-use-pkg
- suite-extra-assert-call
- suite-thelper
expected-actual:
# Regexp for expected variable name.
# Default: (^(exp(ected)?|want(ed)?)([A-Z]\w*)?$)|(^(\w*[a-z])?(Exp(ected)?|Want(ed)?)$)
pattern: ^expected
require-error:
# Regexp for assertions to analyze. If defined then only matched assertions will be reported.
# Default: ""
fn-pattern: ^(Errorf?|NoErrorf?)$
suite-extra-assert-call:
# To require or remove extra Assert() call?
# Default: remove

6
go.mod
View File

@ -9,7 +9,7 @@ require (
github.com/Abirdcfly/dupword v0.0.13
github.com/Antonboom/errname v0.1.12
github.com/Antonboom/nilnil v0.1.7
github.com/Antonboom/testifylint v0.2.3
github.com/Antonboom/testifylint v1.0.1
github.com/BurntSushi/toml v1.3.2
github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24
github.com/GaijinEntertainment/go-exhaustruct/v3 v3.1.0
@ -191,9 +191,9 @@ require (
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20230307190834-24139beb5833 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect

11
go.sum generated
View File

@ -48,8 +48,8 @@ github.com/Antonboom/errname v0.1.12 h1:oh9ak2zUtsLp5oaEd/erjB4GPu9w19NyoIskZClD
github.com/Antonboom/errname v0.1.12/go.mod h1:bK7todrzvlaZoQagP1orKzWXv59X/x0W0Io2XT1Ssro=
github.com/Antonboom/nilnil v0.1.7 h1:ofgL+BA7vlA1K2wNQOsHzLJ2Pw5B5DpWRLdDAVvvTow=
github.com/Antonboom/nilnil v0.1.7/go.mod h1:TP+ScQWVEq0eSIxqU8CbdT5DFWoHp0MbP+KMUO1BKYQ=
github.com/Antonboom/testifylint v0.2.3 h1:MFq9zyL+rIVpsvLX4vDPLojgN7qODzWsrnftNX2Qh60=
github.com/Antonboom/testifylint v0.2.3/go.mod h1:IYaXaOX9NbfAyO+Y04nfjGI8wDemC1rUyM/cYolz018=
github.com/Antonboom/testifylint v1.0.1 h1:O+omzFmvgxAVYKUuMYQYwFxY6lpySeZ1nxQ62Xonw64=
github.com/Antonboom/testifylint v1.0.1/go.mod h1:tGEV9t6Th7DHXFVjd8oyLOBbIxXzs4CMEIAkbQ2RuC8=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
@ -664,8 +664,8 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91
golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI=
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@ -797,8 +797,9 @@ golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

View File

@ -784,13 +784,19 @@ type TagliatelleSettings struct {
}
type TestifylintSettings struct {
EnableAll bool `mapstructure:"enable-all"`
EnabledCheckers []string `mapstructure:"enable"`
EnableAll bool `mapstructure:"enable-all"`
DisableAll bool `mapstructure:"disable-all"`
EnabledCheckers []string `mapstructure:"enable"`
DisabledCheckers []string `mapstructure:"disable"`
ExpectedActual struct {
ExpVarPattern string `mapstructure:"pattern"`
} `mapstructure:"expected-actual"`
RequireError struct {
FnPattern string `mapstructure:"fn-pattern"`
} `mapstructure:"require-error"`
SuiteExtraAssertCall struct {
Mode string `mapstructure:"mode"`
} `mapstructure:"suite-extra-assert-call"`

View File

@ -14,14 +14,22 @@ func NewTestifylint(settings *config.TestifylintSettings) *goanalysis.Linter {
cfg := make(map[string]map[string]any)
if settings != nil {
cfg[a.Name] = map[string]any{
"enable-all": settings.EnableAll,
"enable-all": settings.EnableAll,
"disable-all": settings.DisableAll,
}
if len(settings.EnabledCheckers) > 0 {
cfg[a.Name]["enable"] = settings.EnabledCheckers
}
if len(settings.DisabledCheckers) > 0 {
cfg[a.Name]["disable"] = settings.DisabledCheckers
}
if p := settings.ExpectedActual.ExpVarPattern; p != "" {
cfg[a.Name]["expected-actual.pattern"] = p
}
if p := settings.RequireError.FnPattern; p != "" {
cfg[a.Name]["require-error.fn-pattern"] = p
}
if m := settings.SuiteExtraAssertCall.Mode; m != "" {
cfg[a.Name]["suite-extra-assert-call.mode"] = m
}

6
test/testdata/configs/testifylint.yml vendored Normal file
View File

@ -0,0 +1,6 @@
linters-settings:
testifylint:
disable-all: true
enable: require-error
require-error:
fn-pattern: ^NoError$

View File

@ -46,6 +46,15 @@ func TestTestifylint(t *testing.T) {
assert.Equalf(t, predicate, true, "message") // want "bool-compare: use assert\\.Truef"
assert.Equalf(t, predicate, true, "message %d", 42) // want "bool-compare: use assert\\.Truef"
})
assert.Equal(t, arr, nil) // want "nil-compare: use assert\\.Nil"
assert.Nil(t, arr)
go func() {
if assert.Error(t, err) {
require.ErrorIs(t, err, io.EOF) // want "go-require: require must only be used in the goroutine running the test function"
}
}()
}
type SuiteExample struct {

73
test/testdata/testifylint_config.go vendored Normal file
View File

@ -0,0 +1,73 @@
//golangcitest:args -Etestifylint
//golangcitest:config_path testdata/configs/testifylint.yml
package testdata
import (
"io"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
func TestTestifylint(t *testing.T) {
var (
predicate bool
resultInt int
resultFloat float64
arr []string
err error
)
assert.Equal(t, predicate, true)
assert.True(t, resultInt == 1)
assert.Equal(t, len(arr), 0)
assert.Error(t, err, io.EOF)
assert.Nil(t, err)
assert.Equal(t, resultInt, 42)
assert.Equal(t, resultFloat, 42.42)
assert.Equal(t, len(arr), 10)
assert.True(t, predicate)
assert.Equal(t, resultInt, 1)
assert.Empty(t, arr)
assert.ErrorIs(t, err, io.EOF)
assert.NoError(t, err) // want "require-error: for error assertions use require"
assert.Equal(t, 42, resultInt)
assert.NoErrorf(t, err, "boom!")
assert.InEpsilon(t, 42.42, resultFloat, 0.0001)
assert.Len(t, arr, 10)
require.ErrorIs(t, err, io.EOF)
require.NoError(t, err)
t.Run("formatted", func(t *testing.T) {
assert.Equal(t, predicate, true, "message")
assert.Equal(t, predicate, true, "message %d", 42)
assert.Equalf(t, predicate, true, "message")
assert.Equalf(t, predicate, true, "message %d", 42)
})
assert.Equal(t, arr, nil)
assert.Nil(t, arr)
go func() {
if assert.Error(t, err) {
require.ErrorIs(t, err, io.EOF)
}
}()
}
type SuiteExample struct {
suite.Suite
}
func TestSuiteExample(t *testing.T) {
suite.Run(t, new(SuiteExample))
}
func (s *SuiteExample) TestAll() {
var b bool
s.Assert().True(b)
}