Skip to content
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

Add *ast.KeyValueExpr as a source for RHS varaibles #108

Merged
merged 1 commit into from
Jun 17, 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: 4 additions & 2 deletions wsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions wsl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,19 @@ func TestWithConfig(t *testing.T) {
reasonShortDeclNotExclusive,
},
},
{
description: "key value pairs can use variables",
code: []byte(`package main

func main() {
someData := GetSomeData()
log.WithFields(log.Fields{
"data1": someData.One,
"data2": someData.Two,
"data3": someData.Three,
}).Debug("Got some data")
}`),
},
}

for _, tc := range cases {
Expand Down