}
os.Exit(exitCode)
}
- if doPackage(".", flag.Args(), nil) == nil {
+ if doPackage(flag.Args(), nil) == nil {
warnf("no files checked")
}
os.Exit(exitCode)
names = append(names, pkg.TestGoFiles...) // These are also in the "foo" package.
names = append(names, pkg.SFiles...)
prefixDirectory(directory, names)
- basePkg := doPackage(directory, names, nil)
+ basePkg := doPackage(names, nil)
// Is there also a "foo_test" package? If so, do that one as well.
if len(pkg.XTestGoFiles) > 0 {
names = pkg.XTestGoFiles
prefixDirectory(directory, names)
- doPackage(directory, names, basePkg)
+ doPackage(names, basePkg)
}
}
// doPackage analyzes the single package constructed from the named files.
// It returns the parsed Package or nil if none of the files have been checked.
-func doPackage(directory string, names []string, basePkg *Package) *Package {
+func doPackage(names []string, basePkg *Package) *Package {
var files []*File
var astFiles []*ast.File
fs := token.NewFileSet()
maxArgNum := firstArg
for i, w := 0, 0; i < len(format); i += w {
w = 1
- if format[i] == '%' {
- state := f.parsePrintfVerb(call, name, format[i:], firstArg, argNum)
- if state == nil {
- return
- }
- w = len(state.format)
- if !f.okPrintfArg(call, state) { // One error per format is enough.
- return
- }
- if len(state.argNums) > 0 {
- // Continue with the next sequential argument.
- argNum = state.argNums[len(state.argNums)-1] + 1
- }
- for _, n := range state.argNums {
- if n >= maxArgNum {
- maxArgNum = n + 1
- }
+ if format[i] != '%' {
+ continue
+ }
+ state := f.parsePrintfVerb(call, name, format[i:], firstArg, argNum)
+ if state == nil {
+ return
+ }
+ w = len(state.format)
+ if !f.okPrintfArg(call, state) { // One error per format is enough.
+ return
+ }
+ if len(state.argNums) > 0 {
+ // Continue with the next sequential argument.
+ argNum = state.argNums[len(state.argNums)-1] + 1
+ }
+ for _, n := range state.argNums {
+ if n >= maxArgNum {
+ maxArgNum = n + 1
}
}
}
nargs := len(state.argNums)
for i := 0; i < nargs-trueArgs; i++ {
argNum := state.argNums[i]
- if !f.argCanBeChecked(call, i, true, state) {
+ if !f.argCanBeChecked(call, i, state) {
return
}
arg := call.Args[argNum]
return true
}
argNum := state.argNums[len(state.argNums)-1]
- if !f.argCanBeChecked(call, len(state.argNums)-1, false, state) {
+ if !f.argCanBeChecked(call, len(state.argNums)-1, state) {
return false
}
arg := call.Args[argNum]
// argCanBeChecked reports whether the specified argument is statically present;
// it may be beyond the list of arguments or in a terminal slice... argument, which
// means we can't see it.
-func (f *File) argCanBeChecked(call *ast.CallExpr, formatArg int, isStar bool, state *formatState) bool {
+func (f *File) argCanBeChecked(call *ast.CallExpr, formatArg int, state *formatState) bool {
argNum := state.argNums[formatArg]
if argNum < 0 {
// Shouldn't happen, so catch it with prejudice.