diff --git a/wsl.go b/wsl.go index 313b527..01cc9dc 100644 --- a/wsl.go +++ b/wsl.go @@ -845,8 +845,7 @@ func (p *Processor) findRHS(node ast.Node) []string { case *ast.BasicLit, *ast.SelectStmt, *ast.ChanType, *ast.LabeledStmt, *ast.DeclStmt, *ast.BranchStmt, *ast.TypeSpec, *ast.ArrayType, *ast.CaseClause, - *ast.CommClause, *ast.KeyValueExpr, *ast.MapType, - *ast.FuncLit: + *ast.CommClause, *ast.MapType, *ast.FuncLit: // Nothing to add to RHS case *ast.Ident: return []string{t.Name} @@ -905,6 +904,9 @@ func (p *Processor) findRHS(node ast.Node) []string { rhs = append(rhs, p.findRHS(t.X)...) rhs = append(rhs, p.findRHS(t.Low)...) rhs = append(rhs, p.findRHS(t.High)...) + case *ast.KeyValueExpr: + rhs = p.findRHS(t.Key) + rhs = append(rhs, p.findRHS(t.Value)...) default: if x, ok := maybeX(t); ok { return p.findRHS(x) diff --git a/wsl_test.go b/wsl_test.go index 3dd30e9..717a8c4 100644 --- a/wsl_test.go +++ b/wsl_test.go @@ -1921,6 +1921,20 @@ func TestWithConfig(t *testing.T) { reasonShortDeclNotExclusive, }, }, + { + description: "key value pairs can use variables", + code: []byte(`package main + + func main() { + // Network constants + someData := GetSomeData() + log.WithFields(log.Fields{ + "data1": someData.One, + "data2": someData.Two, + "data3": someData.Three, + }).Debug("Loaded Network Constants") + }`), + }, } for _, tc := range cases {