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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 pkg, err := build.Default.ImportDir(directory, 0) | 152 pkg, err := build.Default.ImportDir(directory, 0) |
153 if err != nil { | 153 if err != nil { |
154 // If it's just that there are no go source files, that's fine. | 154 // If it's just that there are no go source files, that's fine. |
155 if _, nogo := err.(*build.NoGoError); nogo { | 155 if _, nogo := err.(*build.NoGoError); nogo { |
156 return | 156 return |
157 } | 157 } |
158 // Non-fatal: we are doing a recursive walk and there may be oth
er directories. | 158 // Non-fatal: we are doing a recursive walk and there may be oth
er directories. |
159 warnf("cannot process directory %s: %s", directory, err) | 159 warnf("cannot process directory %s: %s", directory, err) |
160 return | 160 return |
161 } | 161 } |
162 » names := append(pkg.GoFiles, pkg.CgoFiles...) | 162 » var names []string |
| 163 » names = append(names, pkg.CgoFiles...) |
163 names = append(names, pkg.TestGoFiles...) // These are also in the "foo"
package. | 164 names = append(names, pkg.TestGoFiles...) // These are also in the "foo"
package. |
164 prefixDirectory(directory, names) | 165 prefixDirectory(directory, names) |
165 doPackage(names) | 166 doPackage(names) |
166 // Is there also a "foo_test" package? If so, do that one as well. | 167 // Is there also a "foo_test" package? If so, do that one as well. |
167 if len(pkg.XTestGoFiles) > 0 { | 168 if len(pkg.XTestGoFiles) > 0 { |
168 names = pkg.XTestGoFiles | 169 names = pkg.XTestGoFiles |
169 prefixDirectory(directory, names) | 170 prefixDirectory(directory, names) |
170 doPackage(names) | 171 doPackage(names) |
171 } | 172 } |
172 } | 173 } |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 func (f *File) walkRangeStmt(n *ast.RangeStmt) { | 387 func (f *File) walkRangeStmt(n *ast.RangeStmt) { |
387 checkRangeLoop(f, n) | 388 checkRangeLoop(f, n) |
388 } | 389 } |
389 | 390 |
390 // goFmt returns a string representation of the expression | 391 // goFmt returns a string representation of the expression |
391 func (f *File) gofmt(x ast.Expr) string { | 392 func (f *File) gofmt(x ast.Expr) string { |
392 f.b.Reset() | 393 f.b.Reset() |
393 printer.Fprint(&f.b, f.fset, x) | 394 printer.Fprint(&f.b, f.fset, x) |
394 return f.b.String() | 395 return f.b.String() |
395 } | 396 } |
LEFT | RIGHT |