Permalink
Browse files

Switch to using honnef.co/go/lint

  • Loading branch information...
1 parent a33a8d4 commit fc501be92c4a32446cf2429d0ff2d29fcdbfe661 @dominikh committed Apr 4, 2016
Showing with 89 additions and 1,314 deletions.
  1. +17 −24 LICENSE
  2. +2 −120 cmd/gosimple/gosimple.go
  3. +0 −302 cmd/gosimple/import.go
  4. +67 −609 lint.go
  5. +0 −17 lint16.go
  6. +3 −242 lint_test.go
View
@@ -1,27 +1,20 @@
-Copyright (c) 2013 The Go Authors. All rights reserved.
+Copyright (c) 2016 Dominik Honnef
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
- * Redistributions of source code must retain the above copyright
-notice, this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above
-copyright notice, this list of conditions and the following disclaimer
-in the documentation and/or other materials provided with the
-distribution.
- * Neither the name of Google Inc. nor the names of its
-contributors may be used to endorse or promote products derived from
-this software without specific prior written permission.
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,130 +1,12 @@
-// Copyright (c) 2013 The Go Authors. All rights reserved.
-//
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file or at
-// https://developers.google.com/open-source/licenses/bsd.
-
// gosimple lints the Go source files named on its command line.
package main // import "honnef.co/go/simple/cmd/gosimple"
-
import (
- "flag"
- "fmt"
- "go/build"
- "io/ioutil"
"os"
- "path/filepath"
- "strings"
+ "honnef.co/go/lint/lintutil"
"honnef.co/go/simple"
)
-var minConfidence = flag.Float64("min_confidence", 0.8, "minimum confidence of a problem to print it")
-
-func usage() {
- fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
- fmt.Fprintf(os.Stderr, "\tgosimple [flags] # runs on package in current directory\n")
- fmt.Fprintf(os.Stderr, "\tgosimple [flags] package\n")
- fmt.Fprintf(os.Stderr, "\tgosimple [flags] directory\n")
- fmt.Fprintf(os.Stderr, "\tgosimple [flags] files... # must be a single package\n")
- fmt.Fprintf(os.Stderr, "Flags:\n")
- flag.PrintDefaults()
-}
-
func main() {
- flag.Usage = usage
- flag.Parse()
-
- switch flag.NArg() {
- case 0:
- lintDir(".")
- case 1:
- arg := flag.Arg(0)
- if strings.HasSuffix(arg, "/...") && isDir(arg[:len(arg)-4]) {
- for _, dirname := range allPackagesInFS(arg) {
- lintDir(dirname)
- }
- } else if isDir(arg) {
- lintDir(arg)
- } else if exists(arg) {
- lintFiles(arg)
- } else {
- for _, pkgname := range importPaths([]string{arg}) {
- lintPackage(pkgname)
- }
- }
- default:
- lintFiles(flag.Args()...)
- }
-}
-
-func isDir(filename string) bool {
- fi, err := os.Stat(filename)
- return err == nil && fi.IsDir()
-}
-
-func exists(filename string) bool {
- _, err := os.Stat(filename)
- return err == nil
-}
-
-func lintFiles(filenames ...string) {
- files := make(map[string][]byte)
- for _, filename := range filenames {
- src, err := ioutil.ReadFile(filename)
- if err != nil {
- fmt.Fprintln(os.Stderr, err)
- continue
- }
- files[filename] = src
- }
-
- l := new(simple.Linter)
- ps, err := l.LintFiles(files)
- if err != nil {
- fmt.Fprintf(os.Stderr, "%v\n", err)
- return
- }
- for _, p := range ps {
- if p.Confidence >= *minConfidence {
- fmt.Printf("%v: %s\n", p.Position, p.Text)
- }
- }
-}
-
-func lintDir(dirname string) {
- pkg, err := build.ImportDir(dirname, 0)
- lintImportedPackage(pkg, err)
-}
-
-func lintPackage(pkgname string) {
- pkg, err := build.Import(pkgname, ".", 0)
- lintImportedPackage(pkg, err)
-}
-
-func lintImportedPackage(pkg *build.Package, err error) {
- if err != nil {
- if _, nogo := err.(*build.NoGoError); nogo {
- // Don't complain if the failure is due to no Go source files.
- return
- }
- fmt.Fprintln(os.Stderr, err)
- return
- }
-
- var files []string
- xtest := pkg.XTestGoFiles
- files = append(files, pkg.GoFiles...)
- files = append(files, pkg.CgoFiles...)
- files = append(files, pkg.TestGoFiles...)
- if pkg.Dir != "." {
- for i, f := range files {
- files[i] = filepath.Join(pkg.Dir, f)
- }
- for i, f := range xtest {
- xtest[i] = filepath.Join(pkg.Dir, f)
- }
- }
- lintFiles(xtest...)
- lintFiles(files...)
+ lintutil.ProcessArgs("gosimple", simple.Funcs, os.Args[1:])
}
Oops, something went wrong.

0 comments on commit fc501be

Please sign in to comment.