Skip to content

Commit

Permalink
allow underscore assignments in node containers
Browse files Browse the repository at this point in the history
  • Loading branch information
nunnatsa committed Mar 24, 2024
1 parent 97de4a9 commit 9724af7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion linter/ginkgo_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func checkAssignments(pass *analysis.Pass, list []ast.Stmt) bool {
case *ast.AssignStmt:
for i, val := range st.Rhs {
if _, isFunc := val.(*ast.FuncLit); !isFunc {
if id, isIdent := st.Lhs[i].(*ast.Ident); isIdent {
if id, isIdent := st.Lhs[i].(*ast.Ident); isIdent && id.Name != "_" {
reportNoFix(pass, id.Pos(), useBeforeEachTemplate, id.Name)
foundSomething = true
}
Expand Down
2 changes: 2 additions & 0 deletions testdata/src/a/vars-in-containers/all_containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ var _ = Describe("When's", func() {
shouldNotTriggerWarningEither = 2
)

_ = getValue()

When("test When", func() {
const shouldNotTriggerWarning = 3
const (
Expand Down
6 changes: 6 additions & 0 deletions testdata/src/a/vars-in-containers/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ type Human struct {
ID string `json:"id"`
}

func getValue() int {
return 42
}

var _ = Describe("vars in Describe", func() {
var a = 1 // want `use BeforeEach\(\) to assign variable a`
var (
Expand All @@ -27,6 +31,8 @@ var _ = Describe("vars in Describe", func() {
g, h, valid2 int
)

_ = getValue()

if b == "testing" {
d = b // want `use BeforeEach\(\) to assign variable d`
} else {
Expand Down

0 comments on commit 9724af7

Please sign in to comment.