Skip to content

Commit fb8ecdb

Browse files
kultiashanbrown
authored andcommitted
bump thelper linter version to v0.3.0 (golangci#1696)
1 parent 384cfd3 commit fb8ecdb

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

.golangci.example.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ linters-settings:
298298
# specify an error message to output when a blacklisted package is used
299299
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
300300
ifshort:
301-
# Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax.
301+
# Maximum length of variable declaration measured in number of lines, after which linter won't suggest using short syntax.
302302
# Has higher priority than max-decl-chars.
303303
max-decl-lines: 1
304304
# 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:
364364
first: true
365365
name: true
366366
begin: true
367+
tb:
368+
first: true
369+
name: true
370+
begin: true
367371
unparam:
368372
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
369373
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
github.com/jgautheron/goconst v0.0.0-20201117150253-ccae5bf973f3
3333
github.com/jingyugao/rowserrcheck v0.0.0-20210130005344-c6a0c12dd98d
3434
github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3
35-
github.com/kulti/thelper v0.2.1
35+
github.com/kulti/thelper v0.3.0
3636
github.com/kunwardeep/paralleltest v1.0.2
3737
github.com/kyoh86/exportloopref v0.1.8
3838
github.com/maratori/testpackage v1.0.1

go.sum

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

pkg/config/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ type ThelperSettings struct {
408408
Name bool `mapstructure:"name"`
409409
Begin bool `mapstructure:"begin"`
410410
} `mapstructure:"benchmark"`
411+
TB struct {
412+
First bool `mapstructure:"first"`
413+
Name bool `mapstructure:"name"`
414+
Begin bool `mapstructure:"begin"`
415+
} `mapstructure:"tb"`
411416
}
412417

413418
type IfshortSettings struct {

pkg/golinters/thelper.go

+10
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ func NewThelper(cfg *config.ThelperSettings) *goanalysis.Linter {
3737
opts = append(opts, "b_first")
3838
}
3939

40+
if cfg.TB.Name {
41+
opts = append(opts, "tb_name")
42+
}
43+
if cfg.TB.Begin {
44+
opts = append(opts, "tb_begin")
45+
}
46+
if cfg.TB.First {
47+
opts = append(opts, "tb_first")
48+
}
49+
4050
cfgMap[a.Name] = map[string]interface{}{
4151
"checks": strings.Join(opts, ","),
4252
}

test/testdata/thelper.go

+13
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,19 @@ func bhelperWithIncorrectName(o *testing.B) { // ERROR `parameter \*testing.B sh
2929
o.Helper()
3030
}
3131

32+
func tbhelperWithHelperAfterAssignment(tb testing.TB) { // ERROR "test helper function should start from tb.Helper()"
33+
_ = 0
34+
tb.Helper()
35+
}
36+
37+
func tbhelperWithNotFirst(s string, tb testing.TB, i int) { // ERROR `parameter testing.TB should be the first`
38+
tb.Helper()
39+
}
40+
41+
func tbhelperWithIncorrectName(o testing.TB) { // ERROR `parameter testing.TB should have name tb`
42+
o.Helper()
43+
}
44+
3245
func TestSubtestShouldNotBeChecked(t *testing.T) {
3346
testCases := []struct {
3447
desc string

0 commit comments

Comments
 (0)