Skip to content

bump thelper linter version to v0.3.0 #1696

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
Feb 7, 2021
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
6 changes: 5 additions & 1 deletion .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum

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

5 changes: 5 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions pkg/golinters/thelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ","),
}
Expand Down
13 changes: 13 additions & 0 deletions test/testdata/thelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down