]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: remove two unused parameters and simplify
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 6 Sep 2017 19:59:00 +0000 (21:59 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Thu, 7 Sep 2017 08:26:27 +0000 (08:26 +0000)
The isStar and directory function parameters have been unused ever since
they were introduced. Remove them.

While at it, apply some other minor simplifications, such as simplifying
a HasPrefix if and using an early continue to unindent many lines of
code.

Change-Id: I8d57353e9ec10cdb59c5388cf6152ce0ec17bdba
Reviewed-on: https://go-review.googlesource.com/62030
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Marvin Stenger <marvin.stenger94@gmail.com>
src/cmd/vet/buildtag.go
src/cmd/vet/main.go
src/cmd/vet/method.go
src/cmd/vet/print.go
src/cmd/vet/unused.go

index 5fa08b62d7eb22d6b6f0cd7a25d2387786d7c06f..80d8f819240c4eec9f1f816ae7b1515938509fc3 100644 (file)
@@ -69,9 +69,7 @@ func checkBuildTag(name string, data []byte) {
                                                setExit(1)
                                                break Args
                                        }
-                                       if strings.HasPrefix(elem, "!") {
-                                               elem = elem[1:]
-                                       }
+                                       elem = strings.TrimPrefix(elem, "!")
                                        for _, c := range elem {
                                                if !unicode.IsLetter(c) && !unicode.IsDigit(c) && c != '_' && c != '.' {
                                                        fmt.Fprintf(os.Stderr, "%s:%d: invalid non-alphanumeric build constraint: %s\n", name, i+1, arg)
index 34c5297b89f9e7faeef89a4291819b31d7c47fd5..ffe988b9fcef4cf28acf553858e20fb36201c51f 100644 (file)
@@ -250,7 +250,7 @@ func main() {
                }
                os.Exit(exitCode)
        }
-       if doPackage(".", flag.Args(), nil) == nil {
+       if doPackage(flag.Args(), nil) == nil {
                warnf("no files checked")
        }
        os.Exit(exitCode)
@@ -290,12 +290,12 @@ func doPackageDir(directory string) {
        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)
        }
 }
 
@@ -312,7 +312,7 @@ type Package struct {
 
 // 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()
index baefa554a404bd181dbf938cc153eef0925bdb3a..b13ce2fcb56cc0d5ea8a552c8dfe34e184eae2b8 100644 (file)
@@ -138,7 +138,7 @@ func typeFlatten(l []*ast.Field) []ast.Expr {
                        t = append(t, f.Type)
                        continue
                }
-               for _ = range f.Names {
+               for range f.Names {
                        t = append(t, f.Type)
                }
        }
index 9998ddae074aa7ff3663e273b397c86ed49e9127..dae307695b268f7a3f20418952d693feecfe33e1 100644 (file)
@@ -237,23 +237,24 @@ func (f *File) checkPrintf(call *ast.CallExpr, name string) {
        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
                        }
                }
        }
@@ -498,7 +499,7 @@ func (f *File) okPrintfArg(call *ast.CallExpr, state *formatState) (ok bool) {
        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]
@@ -511,7 +512,7 @@ func (f *File) okPrintfArg(call *ast.CallExpr, state *formatState) (ok bool) {
                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]
@@ -577,7 +578,7 @@ func (f *File) isFunctionValue(e ast.Expr) bool {
 // 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.
index df2317a4365f6eb7120af02fda61a342db4b9f87..02fcd841cd06db44eb25ae134c63107d45778820 100644 (file)
@@ -82,7 +82,7 @@ func checkUnusedResult(f *File, n ast.Node) {
                }
        } else if !ok {
                // package-qualified function (e.g. fmt.Errorf)
-               obj, _ := f.pkg.uses[selector.Sel]
+               obj := f.pkg.uses[selector.Sel]
                if obj, ok := obj.(*types.Func); ok {
                        qname := obj.Pkg().Path() + "." + obj.Name()
                        if unusedFuncs[qname] {