Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1916,29 +1916,61 @@ 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
- 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

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
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,13 +764,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"`
Expand Down
10 changes: 9 additions & 1 deletion pkg/golinters/testifylint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions test/testdata/configs/testifylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
linters-settings:
testifylint:
disable-all: true
enable: require-error
require-error:
fn-pattern: ^NoError$
9 changes: 9 additions & 0 deletions test/testdata/testifylint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
73 changes: 73 additions & 0 deletions test/testdata/testifylint_config.go
Original file line number Diff line number Diff line change
@@ -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)
}