]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: give warning for construct 'Println(os.Stderr, ...)'
authorShenghou Ma <minux.ma@gmail.com>
Tue, 14 Feb 2012 16:24:41 +0000 (11:24 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 14 Feb 2012 16:24:41 +0000 (11:24 -0500)
        also fixes this bug in net/http/httptest.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5654083

src/cmd/vet/print.go
src/pkg/net/http/httptest/server.go

index fe94137a7ee0a1116cd267bec54cfeef7c765403..e0717f8e8ef31a60a6f54e032d4110a9476735b6 100644 (file)
@@ -207,7 +207,18 @@ func (f *File) checkPrintfVerb(call *ast.CallExpr, verb rune, flags []byte) {
 // call.Args[skip] is the first argument to be printed.
 func (f *File) checkPrint(call *ast.CallExpr, name string, skip int) {
        isLn := strings.HasSuffix(name, "ln")
+       isF := strings.HasPrefix(name, "F")
        args := call.Args
+       // check for Println(os.Stderr, ...)
+       if skip == 0 && !isF && len(args) > 0 {
+               if sel, ok := args[0].(*ast.SelectorExpr); ok {
+                       if x, ok := sel.X.(*ast.Ident); ok {
+                               if x.Name == "os" && strings.HasPrefix(sel.Sel.Name, "Std") {
+                                       f.Warnf(call.Pos(), "first argument to %s is %s.%s", name, x.Name, sel.Sel.Name)
+                               }
+                       }
+               }
+       }
        if len(args) <= skip {
                if *verbose && !isLn {
                        f.Badf(call.Pos(), "no args in %s call", name)
index ace1bf382870d773835611be8c075b6b42a45b40..8d911f7575bfbfa0592bb54e9e4e3912b8a43ed7 100644 (file)
@@ -95,7 +95,7 @@ func (s *Server) Start() {
        s.URL = "http://" + s.Listener.Addr().String()
        go s.Config.Serve(s.Listener)
        if *serve != "" {
-               fmt.Println(os.Stderr, "httptest: serving on", s.URL)
+               fmt.Fprintln(os.Stderr, "httptest: serving on", s.URL)
                select {}
        }
 }