fix: don't touch AST

This commit is contained in:
Gabriel Augendre 2024-03-27 19:57:23 +01:00
parent 75b2beb848
commit e294cd822f

View file

@ -3,7 +3,6 @@ package analyzer
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt"
"go/ast" "go/ast"
"go/printer" "go/printer"
"go/token" "go/token"
@ -54,15 +53,20 @@ func run(pass *analysis.Pass) (interface{}, error) {
break break
} }
assignStmt.Tok = token.DEFINE suggestedStmt := ast.AssignStmt{
suggested := render(pass.Fset, assignStmt) Lhs: assignStmt.Lhs,
TokPos: assignStmt.TokPos,
Tok: token.DEFINE,
Rhs: assignStmt.Rhs,
}
suggested := render(pass.Fset, &suggestedStmt)
pass.Report(analysis.Diagnostic{ pass.Report(analysis.Diagnostic{
Pos: assignStmt.Pos(), Pos: assignStmt.Pos(),
Message: "context not shadowed in loop", Message: "context not shadowed in loop",
SuggestedFixes: []analysis.SuggestedFix{ SuggestedFixes: []analysis.SuggestedFix{
{ {
Message: fmt.Sprintf("replace `=` with `:=`"), Message: "replace `=` with `:=`",
TextEdits: []analysis.TextEdit{ TextEdits: []analysis.TextEdit{
{ {
Pos: assignStmt.Pos(), Pos: assignStmt.Pos(),