diff --git a/src/cmd/vet/main.go b/src/cmd/vet/main.go index 4f3cca8f6dd765a8fcbf2ee86a6282e137c9d1df..81063856dd1f7cff06bfae8ea898c375aba31662 100644 --- a/src/cmd/vet/main.go +++ b/src/cmd/vet/main.go @@ -440,14 +440,22 @@ func (f *File) loc(pos token.Pos) string { return fmt.Sprintf("%s:%d", posn.Filename, posn.Line) } +// locPrefix returns a formatted representation of the position for use as a line prefix. +func (f *File) locPrefix(pos token.Pos) string { + if pos == token.NoPos { + return "" + } + return fmt.Sprintf("%s: ", f.loc(pos)) +} + // Warn reports an error but does not set the exit code. func (f *File) Warn(pos token.Pos, args ...interface{}) { - fmt.Fprintf(os.Stderr, "%s: %s", f.loc(pos), fmt.Sprintln(args...)) + fmt.Fprintf(os.Stderr, "%s%s", f.locPrefix(pos), fmt.Sprintln(args...)) } // Warnf reports a formatted error but does not set the exit code. func (f *File) Warnf(pos token.Pos, format string, args ...interface{}) { - fmt.Fprintf(os.Stderr, "%s: %s\n", f.loc(pos), fmt.Sprintf(format, args...)) + fmt.Fprintf(os.Stderr, "%s%s\n", f.locPrefix(pos), fmt.Sprintf(format, args...)) } // walkFile walks the file's tree.