LEFT | RIGHT |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Vet is a simple checker for static errors in Go source code. | 5 // Vet is a simple checker for static errors in Go source code. |
6 // See doc.go for more information. | 6 // See doc.go for more information. |
7 package main | 7 package main |
8 | 8 |
9 import ( | 9 import ( |
10 "bytes" | 10 "bytes" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 return err | 234 return err |
235 } | 235 } |
236 // One package per directory. Ignore the files themselves. | 236 // One package per directory. Ignore the files themselves. |
237 if !f.IsDir() { | 237 if !f.IsDir() { |
238 return nil | 238 return nil |
239 } | 239 } |
240 doPackageDir(path) | 240 doPackageDir(path) |
241 return nil | 241 return nil |
242 } | 242 } |
243 | 243 |
| 244 func (pkg *Package) hasFileWithSuffix(suffix string) bool { |
| 245 for _, f := range pkg.files { |
| 246 if strings.HasSuffix(f.name, suffix) { |
| 247 return true |
| 248 } |
| 249 } |
| 250 return false |
| 251 } |
| 252 |
244 // walkDir recursively walks the tree looking for Go packages. | 253 // walkDir recursively walks the tree looking for Go packages. |
245 func walkDir(root string) { | 254 func walkDir(root string) { |
246 filepath.Walk(root, visit) | 255 filepath.Walk(root, visit) |
247 } | 256 } |
248 | 257 |
249 // errorf formats the error to standard error, adding program | 258 // errorf formats the error to standard error, adding program |
250 // identification and a newline, and exits. | 259 // identification and a newline, and exits. |
251 func errorf(format string, args ...interface{}) { | 260 func errorf(format string, args ...interface{}) { |
252 fmt.Fprintf(os.Stderr, "vet: "+format+"\n", args...) | 261 fmt.Fprintf(os.Stderr, "vet: "+format+"\n", args...) |
253 os.Exit(2) | 262 os.Exit(2) |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 func (f *File) walkRangeStmt(n *ast.RangeStmt) { | 406 func (f *File) walkRangeStmt(n *ast.RangeStmt) { |
398 checkRangeLoop(f, n) | 407 checkRangeLoop(f, n) |
399 } | 408 } |
400 | 409 |
401 // gofmt returns a string representation of the expression. | 410 // gofmt returns a string representation of the expression. |
402 func (f *File) gofmt(x ast.Expr) string { | 411 func (f *File) gofmt(x ast.Expr) string { |
403 f.b.Reset() | 412 f.b.Reset() |
404 printer.Fprint(&f.b, f.fset, x) | 413 printer.Fprint(&f.b, f.fset, x) |
405 return f.b.String() | 414 return f.b.String() |
406 } | 415 } |
LEFT | RIGHT |