aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/golang/lint/golint/golint.go
diff options
context:
space:
mode:
authorJoe Richey joerichey@google.com <joerichey@google.com>2018-08-30 02:24:33 -0700
committerJoe Richey joerichey@google.com <joerichey@google.com>2018-08-30 02:24:33 -0700
commit630c8d1d002286cc26bafec78a7f120b5c0e78af (patch)
tree5d453c5b099a2881c74ac49922eb968e235bedfd /vendor/github.com/golang/lint/golint/golint.go
parentb7f5b0ab3c9b1af9397c557e410473119399f8b6 (diff)
Update dependancies to lastest version
Diffstat (limited to 'vendor/github.com/golang/lint/golint/golint.go')
-rw-r--r--vendor/github.com/golang/lint/golint/golint.go162
1 files changed, 0 insertions, 162 deletions
diff --git a/vendor/github.com/golang/lint/golint/golint.go b/vendor/github.com/golang/lint/golint/golint.go
deleted file mode 100644
index 0088274..0000000
--- a/vendor/github.com/golang/lint/golint/golint.go
+++ /dev/null
@@ -1,162 +0,0 @@
-// 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.
-
-// golint lints the Go source files named on its command line.
-package main
-
-import (
- "flag"
- "fmt"
- "go/build"
- "io/ioutil"
- "os"
- "path/filepath"
- "strings"
-
- "github.com/golang/lint"
-)
-
-var (
- minConfidence = flag.Float64("min_confidence", 0.8, "minimum confidence of a problem to print it")
- setExitStatus = flag.Bool("set_exit_status", false, "set exit status to 1 if any issues are found")
- suggestions int
-)
-
-func usage() {
- fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
- fmt.Fprintf(os.Stderr, "\tgolint [flags] # runs on package in current directory\n")
- fmt.Fprintf(os.Stderr, "\tgolint [flags] [packages]\n")
- fmt.Fprintf(os.Stderr, "\tgolint [flags] [directories] # where a '/...' suffix includes all sub-directories\n")
- fmt.Fprintf(os.Stderr, "\tgolint [flags] [files] # all must belong to a single package\n")
- fmt.Fprintf(os.Stderr, "Flags:\n")
- flag.PrintDefaults()
-}
-
-func main() {
- flag.Usage = usage
- flag.Parse()
-
- if flag.NArg() == 0 {
- lintDir(".")
- } else {
- // dirsRun, filesRun, and pkgsRun indicate whether golint is applied to
- // directory, file or package targets. The distinction affects which
- // checks are run. It is no valid to mix target types.
- var dirsRun, filesRun, pkgsRun int
- var args []string
- for _, arg := range flag.Args() {
- if trimmedArg := strings.TrimSuffix(arg, "/..."); trimmedArg != arg && isDir(trimmedArg) {
- dirsRun = 1
- for _, dirname := range allPackagesInFS(arg) {
- if strings.Contains(dirname[len(trimmedArg):], "/vendor/") {
- continue
- }
- args = append(args, dirname)
- }
- } else if isDir(arg) {
- dirsRun = 1
- args = append(args, arg)
- } else if exists(arg) {
- filesRun = 1
- args = append(args, arg)
- } else {
- pkgsRun = 1
- args = append(args, arg)
- }
- }
-
- if dirsRun+filesRun+pkgsRun != 1 {
- usage()
- os.Exit(2)
- }
- switch {
- case dirsRun == 1:
- for _, dir := range args {
- lintDir(dir)
- }
- case filesRun == 1:
- lintFiles(args...)
- case pkgsRun == 1:
- for _, pkg := range importPaths(args) {
- lintPackage(pkg)
- }
- }
- }
-
- if *setExitStatus && suggestions > 0 {
- fmt.Fprintf(os.Stderr, "Found %d lint suggestions; failing.\n", suggestions)
- os.Exit(1)
- }
-}
-
-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(lint.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)
- suggestions++
- }
- }
-}
-
-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
- 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)
- }
- }
- // TODO(dsymonds): Do foo_test too (pkg.XTestGoFiles)
-
- lintFiles(files...)
-}