mirror of
https://github.com/golang/go
synced 2024-11-17 05:44:52 -07:00
cmd/fix: always format source file before fixing
This makes the changes to the file easier to explain. Not all the changes may come from the fixers directly, if the file is not gofmt-ed already. Change-Id: I81776da446a34a1239a3130317d2aae1437d61a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/240555 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
This commit is contained in:
parent
7b77ff4c88
commit
09833da6b4
@ -137,6 +137,21 @@ func processFile(filename string, useStdin bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Make sure file is in canonical format.
|
||||
// This "fmt" pseudo-fix cannot be disabled.
|
||||
newSrc, err := gofmtFile(file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !bytes.Equal(newSrc, src) {
|
||||
newFile, err := parser.ParseFile(fset, filename, newSrc, parserMode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
file = newFile
|
||||
fmt.Fprintf(&fixlog, " fmt")
|
||||
}
|
||||
|
||||
// Apply all fixes to file.
|
||||
newFile := file
|
||||
fixed := false
|
||||
@ -180,7 +195,7 @@ func processFile(filename string, useStdin bool) error {
|
||||
// output of the printer run on a standard AST generated by the parser,
|
||||
// but the source we generated inside the loop above is the
|
||||
// output of the printer run on a mangled AST generated by a fixer.
|
||||
newSrc, err := gofmtFile(newFile)
|
||||
newSrc, err = gofmtFile(newFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user