Skip to content

Commit

Permalink
feat: skip name and begin checks if name is
Browse files Browse the repository at this point in the history
  • Loading branch information
kulti committed Feb 6, 2021
1 parent 1c4fa19 commit 7415afb
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,17 @@ func checkFunc(pass *analysis.Pass, reports *reports, funcDecl funcDecl, opts ch
}
}

if opts.checkName {
if len(p.Names) > 0 && p.Names[0].Name != opts.varName {
reports.Reportf(funcDecl.Pos, "parameter %s should have name %s", opts.tbType, opts.varName)
if len(p.Names) > 0 && p.Names[0].Name != "_" {
if opts.checkName {
if p.Names[0].Name != opts.varName {
reports.Reportf(funcDecl.Pos, "parameter %s should have name %s", opts.tbType, opts.varName)
}
}
}

if opts.checkBegin {
if len(funcDecl.Body.List) == 0 || !isTHelperCall(pass, funcDecl.Body.List[0], opts.tbHelper) {
reports.Reportf(funcDecl.Pos, "test helper function should start from %s.Helper()", opts.varName)
if opts.checkBegin {
if len(funcDecl.Body.List) == 0 || !isTHelperCall(pass, funcDecl.Body.List[0], opts.tbHelper) {
reports.Reportf(funcDecl.Pos, "test helper function should start from %s.Helper()", opts.varName)
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/analyzer/testdata/src/b/b.go

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

3 changes: 3 additions & 0 deletions pkg/analyzer/testdata/src/b_begin/b.go

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

3 changes: 3 additions & 0 deletions pkg/analyzer/testdata/src/b_first/b.go

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

3 changes: 3 additions & 0 deletions pkg/analyzer/testdata/src/b_name/b.go

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

3 changes: 3 additions & 0 deletions pkg/analyzer/testdata/src/t/t.go

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

3 changes: 3 additions & 0 deletions pkg/analyzer/testdata/src/t_begin/t.go

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

3 changes: 3 additions & 0 deletions pkg/analyzer/testdata/src/t_first/t.go

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

3 changes: 3 additions & 0 deletions pkg/analyzer/testdata/src/t_name/t.go

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

3 changes: 3 additions & 0 deletions scripts/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func helperWithAnonymousHelper({{.Name}} *testing.{{.UName}}) {
func({{.Name}} *testing.{{.UName}}) {}({{.Name}}) {{if or (eq .Check "") (eq .Check "begin")}}// want "test helper function should start from {{.Name}}.Helper()"{{end}}
}
func helperWithNoName(_ *testing.{{.UName}}) {
}
func f() {}
`

Expand Down

0 comments on commit 7415afb

Please sign in to comment.