bump thelper linter version to v0.3.0 (#1696)

This commit is contained in:
Aleksey Bakin 2021-02-07 20:28:04 +03:00 committed by GitHub
parent aafdee85d2
commit cc152be1a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 4 deletions

View File

@ -298,7 +298,7 @@ linters-settings:
# specify an error message to output when a blacklisted package is used
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
ifshort:
# Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax.
# Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax.
# Has higher priority than max-decl-chars.
max-decl-lines: 1
# Maximum length of variable declaration measured in number of characters, after which linter won't suggest using short syntax.
@ -364,6 +364,10 @@ linters-settings:
first: true
name: true
begin: true
tb:
first: true
name: true
begin: true
unparam:
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:

2
go.mod
View File

@ -32,7 +32,7 @@ require (
github.com/jgautheron/goconst v0.0.0-20201117150253-ccae5bf973f3
github.com/jingyugao/rowserrcheck v0.0.0-20210130005344-c6a0c12dd98d
github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3
github.com/kulti/thelper v0.2.1
github.com/kulti/thelper v0.3.0
github.com/kunwardeep/paralleltest v1.0.2
github.com/kyoh86/exportloopref v0.1.8
github.com/maratori/testpackage v1.0.1

4
go.sum generated
View File

@ -230,8 +230,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kulti/thelper v0.2.1 h1:H4rSHiB3ALx//SXr+k9OPqKoOw2cAZpIQwVNH1RL5T4=
github.com/kulti/thelper v0.2.1/go.mod h1:vMu2Cizjy/grP+jmsvOFDx1kYP6+PD1lqg4Yu5exl2U=
github.com/kulti/thelper v0.3.0 h1:+HU/TdIp88Bd34Rclhf2TbZZz8phIZQooC3uasqkznc=
github.com/kulti/thelper v0.3.0/go.mod h1:vMu2Cizjy/grP+jmsvOFDx1kYP6+PD1lqg4Yu5exl2U=
github.com/kunwardeep/paralleltest v1.0.2 h1:/jJRv0TiqPoEy/Y8dQxCFJhD56uS/pnvtatgTZBHokU=
github.com/kunwardeep/paralleltest v1.0.2/go.mod h1:ZPqNm1fVHPllh5LPVujzbVz1JN2GhLxSfY+oqUsvG30=
github.com/kyoh86/exportloopref v0.1.8 h1:5Ry/at+eFdkX9Vsdw3qU4YkvGtzuVfzT4X7S77LoN/M=

View File

@ -408,6 +408,11 @@ type ThelperSettings struct {
Name bool `mapstructure:"name"`
Begin bool `mapstructure:"begin"`
} `mapstructure:"benchmark"`
TB struct {
First bool `mapstructure:"first"`
Name bool `mapstructure:"name"`
Begin bool `mapstructure:"begin"`
} `mapstructure:"tb"`
}
type IfshortSettings struct {

View File

@ -37,6 +37,16 @@ func NewThelper(cfg *config.ThelperSettings) *goanalysis.Linter {
opts = append(opts, "b_first")
}
if cfg.TB.Name {
opts = append(opts, "tb_name")
}
if cfg.TB.Begin {
opts = append(opts, "tb_begin")
}
if cfg.TB.First {
opts = append(opts, "tb_first")
}
cfgMap[a.Name] = map[string]interface{}{
"checks": strings.Join(opts, ","),
}

View File

@ -29,6 +29,19 @@ func bhelperWithIncorrectName(o *testing.B) { // ERROR `parameter \*testing.B sh
o.Helper()
}
func tbhelperWithHelperAfterAssignment(tb testing.TB) { // ERROR "test helper function should start from tb.Helper()"
_ = 0
tb.Helper()
}
func tbhelperWithNotFirst(s string, tb testing.TB, i int) { // ERROR `parameter testing.TB should be the first`
tb.Helper()
}
func tbhelperWithIncorrectName(o testing.TB) { // ERROR `parameter testing.TB should have name tb`
o.Helper()
}
func TestSubtestShouldNotBeChecked(t *testing.T) {
testCases := []struct {
desc string