1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 11:48:53 +00:00

update go-bindata to v3.1.3

This brings the version of go-bindata in sync between the local version
and the version in the Docker container.  And also updates to the
latest version which has proper module versioning.
This commit is contained in:
Paul Gier 2020-03-31 10:50:46 -05:00
parent 462fa77fff
commit 75e13bcd15
51 changed files with 3595 additions and 34 deletions

View file

@ -260,7 +260,7 @@ $(FIRST_GOPATH)/bin/$(1):
endef
$(GO_BINDATA_BINARY):
@go install -mod=vendor github.com/go-bindata/go-bindata/go-bindata
@go install -mod=vendor github.com/go-bindata/go-bindata/v3/go-bindata
$(foreach binary,$(K8S_GEN_BINARIES),$(eval $(call _K8S_GEN_VAR_TARGET_,$(binary))))

2
go.mod
View file

@ -9,7 +9,7 @@ require (
github.com/coreos/bbolt v1.3.1-coreos.6 // indirect
github.com/coreos/etcd v3.3.15+incompatible // indirect
github.com/ghodss/yaml v1.0.0
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/go-bindata/go-bindata/v3 v3.1.3
github.com/go-kit/kit v0.9.0
github.com/go-openapi/swag v0.19.5
github.com/gogo/protobuf v1.3.1

7
go.sum
View file

@ -170,6 +170,8 @@ github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/go-bindata/go-bindata/v3 v3.1.3 h1:F0nVttLC3ws0ojc7p60veTurcOm//D4QBODNM7EGrCI=
github.com/go-bindata/go-bindata/v3 v3.1.3/go.mod h1:1/zrpXsLD8YDIbhZRqXzm1Ghc7NhEvIN9+Z6R5/xH4I=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-kit/kit v0.8.0 h1:Wz+5lgoB0kkuqLEc6NVmwRknTKP6dTGbSqvhZtBI/j0=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
@ -391,6 +393,7 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/errcheck v1.2.0 h1:reN85Pxc5larApoH1keMBiu2GWtPqXQ1nc9gx+jOU+E=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
@ -676,6 +679,8 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE=
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
@ -811,6 +816,8 @@ golang.org/x/tools v0.0.0-20191111182352-50fa39b762bc/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2 h1:EtTFh6h4SAKemS+CURDMTDIANuduG5zKEXShyy18bGA=
golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f h1:kDxGY2VmgABOe55qheT/TFqUMtcTHnomIPS1iv3G4Ms=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0=
gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=

View file

@ -5,6 +5,7 @@ ENV JSONNET_VERSION v0.15.0
ENV PROMTOOL_VERSION b90be6f32a33c03163d700e1452b54454ddce0ec
ENV GOLANGCILINT_VERSION v1.23.6
ENV JB_VERSION v0.3.1
ENV GO_BINDATA_VERSION v3.1.3
RUN apt-get update -y && apt-get install -y g++ make git && \
rm -rf /var/lib/apt/lists/*
@ -20,7 +21,7 @@ RUN GO111MODULE=on go get github.com/golangci/golangci-lint/cmd/golangci-lint@${
RUN GO111MODULE=on go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@${JB_VERSION}
RUN go get github.com/brancz/gojsontoyaml
RUN go get github.com/campoy/embedmd
RUN go get -u github.com/jteeuwen/go-bindata/...
RUN GO111MODULE=on go get github.com/go-bindata/go-bindata/v3/go-bindata@${GO_BINDATA_VERSION}
# Add po-lint
WORKDIR /go/src/github.com/coreos/prometheus-operator

View file

@ -21,7 +21,7 @@ package tools
import (
_ "github.com/brancz/gojsontoyaml"
_ "github.com/campoy/embedmd"
_ "github.com/go-bindata/go-bindata/go-bindata"
_ "github.com/go-bindata/go-bindata/v3/go-bindata"
_ "github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb"
_ "k8s.io/code-generator/cmd/client-gen"
_ "k8s.io/code-generator/cmd/informer-gen"

13
vendor/github.com/go-bindata/go-bindata/v3/.drone.yml generated vendored Normal file
View file

@ -0,0 +1,13 @@
kind: pipeline
name: default
workspace:
base: /go
path: github.com/go-bindata/go-bindata
steps:
- name: build
image: golang:1.12
commands:
- go get -u honnef.co/go/tools/cmd/staticcheck
- staticcheck ./...
- make

View file

@ -1,5 +1,5 @@
## bindata
[![Build Status](https://cloud.drone.io/api/badges/go-bindata/go-bindata/status.svg)](https://cloud.drone.io/go-bindata/go-bindata)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-bindata/bindata)](https://goreportcard.com/report/github.com/go-bindata/bindata)
This package converts any file into managable Go source code. Useful for
@ -58,12 +58,14 @@ To ignore files, pass in regexes using -ignore, for example:
To access asset data, we use the `Asset(string) ([]byte, error)` function which
is included in the generated output.
data, err := Asset("pub/style/foo.css")
if err != nil {
// Asset was not found.
}
```go
data, err := Asset("pub/style/foo.css")
if err != nil {
// Asset was not found.
}
// use asset data
// use asset data
```
### Debug vs Release builds
@ -92,7 +94,7 @@ It will now embed the latest version of the assets.
Using the `-nomemcopy` flag, will alter the way the output file is generated.
It will employ a hack that allows us to read the file data directly from
the compiled program's `.rodata` section. This ensures that when we call
the compiled program's `.rodata` section. This ensures that when we
call our generated function, we omit unnecessary memcopies.
The downside of this, is that it requires dependencies on the `reflect` and

View file

@ -163,20 +163,21 @@ func NewConfig() *Config {
// Part of which means checking if certain file/directory paths exist.
func (c *Config) validate() error {
if len(c.Package) == 0 {
return fmt.Errorf("Missing package name")
return fmt.Errorf("missing package name")
}
for _, input := range c.Input {
_, err := os.Lstat(input.Path)
if err != nil {
return fmt.Errorf("Failed to stat input path '%s': %v", input.Path, err)
return fmt.Errorf("failed to stat input path '%s': %v", input.Path, err)
}
}
if len(c.Output) == 0 {
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("Unable to determine current working directory.")
return fmt.Errorf("unable to determine current working directory")
}
c.Output = filepath.Join(cwd, "bindata.go")
@ -185,7 +186,7 @@ func (c *Config) validate() error {
stat, err := os.Lstat(c.Output)
if err != nil {
if !os.IsNotExist(err) {
return fmt.Errorf("Output path: %v", err)
return fmt.Errorf("output path: %v", err)
}
// File does not exist. This is fine, just make
@ -195,13 +196,13 @@ func (c *Config) validate() error {
err = os.MkdirAll(dir, 0744)
if err != nil {
return fmt.Errorf("Create output directory: %v", err)
return fmt.Errorf("create output directory: %v", err)
}
}
}
if stat != nil && stat.IsDir() {
return fmt.Errorf("Output path is a directory.")
return fmt.Errorf("output path is a directory")
}
return nil

View file

@ -50,7 +50,7 @@ func Translate(c *Config) error {
defer bfd.Flush()
// Write the header. This makes e.g. Github ignore diffs in generated files.
if _, err = fmt.Fprintf(bfd, "// Code generated for package %s by go-bindata DO NOT EDIT. (@generated)\n", c.Package); err != nil {
if _, err = fmt.Fprintf(bfd, "// Code generated by go-bindata. (@generated) DO NOT EDIT.\n\n //Package %s generated by go-bindata.", c.Package); err != nil {
return err
}
if _, err = fmt.Fprint(bfd, "// sources:\n"); err != nil {
@ -208,7 +208,7 @@ func findFiles(dir, prefix string, recursive bool, toc *[]Asset, ignore []*regex
// This shouldn't happen.
if len(asset.Name) == 0 {
return fmt.Errorf("Invalid file: %v", asset.Path)
return fmt.Errorf("invalid file: %v", asset.Path)
}
asset.Func = safeFunctionName(asset.Name, knownFuncs)

View file

@ -52,7 +52,8 @@ func writeDebugHeader(w io.Writer, c *Config) error {
"io/ioutil"
"os"
"path/filepath"
"strings"`
"strings"
"time"`
}
_, err := fmt.Fprintf(w, `%s
@ -72,6 +73,43 @@ type asset struct {
info os.FileInfo
}
type bindataFileInfo struct {
name string
size int64
mode os.FileMode
modTime time.Time
}
// Name return file name
func (fi bindataFileInfo) Name() string {
return fi.name
}
// Size return file size
func (fi bindataFileInfo) Size() int64 {
return fi.size
}
// Mode return file mode
func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
// ModTime return file modify time
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
// IsDir return file whether a directory
func (fi bindataFileInfo) IsDir() bool {
return fi.mode&os.ModeDir != 0
}
// Sys return file is sys mode
func (fi bindataFileInfo) Sys() interface{} {
return nil
}
`, header)
return err
}

View file

@ -3,7 +3,7 @@
// http://creativecommons.org/publicdomain/zero/1.0/
/*
bindata converts any file into managable Go source code. Useful for
bindata converts any file into manageable Go source code. Useful for
embedding binary data into a go program. The file data is optionally gzip
compressed before being converted to a raw byte slice.
@ -97,7 +97,7 @@ Path prefix stripping
The keys used in the `_bindata` map are the same as the input file name
passed to `go-bindata`. This includes the path. In most cases, this is not
desireable, as it puts potentially sensitive information in your code base.
desirable, as it puts potentially sensitive information in your code base.
For this purpose, the tool supplies another command line flag `-prefix`.
This accepts a portion of a path name, which should be stripped off from
the map keys and function names.

View file

@ -12,7 +12,7 @@ import (
"regexp"
"strings"
"github.com/go-bindata/go-bindata"
"github.com/go-bindata/go-bindata/v3"
)
func main() {

View file

@ -23,7 +23,7 @@ var AppVersionRev string
func Version() string {
if len(AppVersionRev) == 0 {
AppVersionRev = "2"
AppVersionRev = "3"
}
return fmt.Sprintf("%s %d.%d.%s (Go runtime %s).\nCopyright (c) 2010-2013, Jim Teeuwen.",

8
vendor/github.com/go-bindata/go-bindata/v3/go.mod generated vendored Normal file
View file

@ -0,0 +1,8 @@
module github.com/go-bindata/go-bindata/v3
go 1.12
require (
github.com/kisielk/errcheck v1.2.0
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f
)

13
vendor/github.com/go-bindata/go-bindata/v3/go.sum generated vendored Normal file
View file

@ -0,0 +1,13 @@
github.com/kisielk/errcheck v1.2.0 h1:reN85Pxc5larApoH1keMBiu2GWtPqXQ1nc9gx+jOU+E=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f h1:J5lckAjkw6qYlOZNj90mLYNTEKDvWeuc1yieZ8qUzUE=
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f h1:kDxGY2VmgABOe55qheT/TFqUMtcTHnomIPS1iv3G4Ms=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View file

@ -136,7 +136,7 @@ func header_compressed_nomemcopy(w io.Writer, c *Config) error {
func bindataRead(data, name string) ([]byte, error) {
gz, err := gzip.NewReader(strings.NewReader(data))
if err != nil {
return nil, fmt.Errorf("Read %%q: %%v", name, err)
return nil, fmt.Errorf("read %%q: %%v", name, err)
}
var buf bytes.Buffer
@ -144,7 +144,7 @@ func bindataRead(data, name string) ([]byte, error) {
clErr := gz.Close()
if err != nil {
return nil, fmt.Errorf("Read %%q: %%v", name, err)
return nil, fmt.Errorf("read %%q: %%v", name, err)
}
if clErr != nil {
return nil, err
@ -191,7 +191,7 @@ func header_compressed_memcopy(w io.Writer, c *Config) error {
func bindataRead(data []byte, name string) ([]byte, error) {
gz, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil {
return nil, fmt.Errorf("Read %%q: %%v", name, err)
return nil, fmt.Errorf("read %%q: %%v", name, err)
}
var buf bytes.Buffer
@ -199,7 +199,7 @@ func bindataRead(data []byte, name string) ([]byte, error) {
clErr := gz.Close()
if err != nil {
return nil, fmt.Errorf("Read %%q: %%v", name, err)
return nil, fmt.Errorf("read %%q: %%v", name, err)
}
if clErr != nil {
return nil, err
@ -314,7 +314,7 @@ func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
// Mode return file modify time
// ModTime return file modify time
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}

8
vendor/github.com/go-bindata/go-bindata/v3/tools.go generated vendored Normal file
View file

@ -0,0 +1,8 @@
// +build tools
package tools
import (
_ "github.com/kisielk/errcheck"
_ "golang.org/x/lint/golint"
)

11
vendor/github.com/kisielk/errcheck/.travis.yml generated vendored Normal file
View file

@ -0,0 +1,11 @@
language: go
sudo: false
matrix:
include:
- go: "1.9"
- go: "1.10"
- go: "tip"
script:
- go test -race ./...

22
vendor/github.com/kisielk/errcheck/LICENSE generated vendored Normal file
View file

@ -0,0 +1,22 @@
Copyright (c) 2013 Kamil Kisiel
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:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
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.

123
vendor/github.com/kisielk/errcheck/README.md generated vendored Normal file
View file

@ -0,0 +1,123 @@
# errcheck
errcheck is a program for checking for unchecked errors in go programs.
[![Build Status](https://travis-ci.org/kisielk/errcheck.png?branch=master)](https://travis-ci.org/kisielk/errcheck)
## Install
go get -u github.com/kisielk/errcheck
errcheck requires Go 1.9 or newer and depends on the package go/packages from the golang.org/x/tools repository.
## Use
For basic usage, just give the package path of interest as the first argument:
errcheck github.com/kisielk/errcheck/testdata
To check all packages beneath the current directory:
errcheck ./...
Or check all packages in your $GOPATH and $GOROOT:
errcheck all
errcheck also recognizes the following command-line options:
The `-tags` flag takes a space-separated list of build tags, just like `go
build`. If you are using any custom build tags in your code base, you may need
to specify the relevant tags here.
The `-asserts` flag enables checking for ignored type assertion results. It
takes no arguments.
The `-blank` flag enables checking for assignments of errors to the
blank identifier. It takes no arguments.
## Excluding functions
Use the `-exclude` flag to specify a path to a file containing a list of functions to
be excluded.
errcheck -exclude errcheck_excludes.txt path/to/package
The file should contain one function signature per line. The format for function signatures is
`package.FunctionName` while for methods it's `(package.Receiver).MethodName` for value receivers
and `(*package.Receiver).MethodName` for pointer receivers. If the function name is followed by string of form `(TYPE)`, then
the the function call is excluded only if the type of the first argument is `TYPE`. It also accepts a special suffix
`(os.Stdout)` and `(os.Stderr)`, which excludes the function only when the first argument is a literal `os.Stdout` or `os.Stderr`.
An example of an exclude file is:
io/ioutil.ReadFile
io.Copy(*bytes.Buffer)
io.Copy(os.Stdout)
(*net/http.Client).Do
The exclude list is combined with an internal list for functions in the Go standard library that
have an error return type but are documented to never return an error.
### The deprecated method
The `-ignore` flag takes a comma-separated list of pairs of the form package:regex.
For each package, the regex describes which functions to ignore within that package.
The package may be omitted to have the regex apply to all packages.
For example, you may wish to ignore common operations like Read and Write:
errcheck -ignore '[rR]ead|[wW]rite' path/to/package
or you may wish to ignore common functions like the `print` variants in `fmt`:
errcheck -ignore 'fmt:[FS]?[Pp]rint*' path/to/package
The `-ignorepkg` flag takes a comma-separated list of package import paths
to ignore:
errcheck -ignorepkg 'fmt,encoding/binary' path/to/package
Note that this is equivalent to:
errcheck -ignore 'fmt:.*,encoding/binary:.*' path/to/package
If a regex is provided for a package `pkg` via `-ignore`, and `pkg` also appears
in the list of packages passed to `-ignorepkg`, the latter takes precedence;
that is, all functions within `pkg` will be ignored.
Note that by default the `fmt` package is ignored entirely, unless a regex is
specified for it. To disable this, specify a regex that matches nothing:
errcheck -ignore 'fmt:a^' path/to/package
The `-ignoretests` flag disables checking of `_test.go` files. It takes
no arguments.
## Cgo
Currently errcheck is unable to check packages that import "C" due to limitations in the importer when used with versions earlier than Go 1.11.
However, you can use errcheck on packages that depend on those which use cgo. In order for this to work you need to go install the cgo dependencies before running errcheck on the dependent packages.
See https://github.com/kisielk/errcheck/issues/16 for more details.
## Exit Codes
errcheck returns 1 if any problems were found in the checked files.
It returns 2 if there were any other failures.
# Editor Integration
## Emacs
[go-errcheck.el](https://github.com/dominikh/go-errcheck.el)
integrates errcheck with Emacs by providing a `go-errcheck` command
and customizable variables to automatically pass flags to errcheck.
## Vim
[vim-go](https://github.com/fatih/vim-go) can run errcheck via both its `:GoErrCheck`
and `:GoMetaLinter` commands.

3
vendor/github.com/kisielk/errcheck/go.mod generated vendored Normal file
View file

@ -0,0 +1,3 @@
module github.com/kisielk/errcheck
require golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563

4
vendor/github.com/kisielk/errcheck/go.sum generated vendored Normal file
View file

@ -0,0 +1,4 @@
golang.org/x/tools v0.0.0-20180803180156-3c07937fe18c h1:Z6Xcg33osoOLCiz/EFPHedK6zJ9nl1KK4WH/LlykMxs=
golang.org/x/tools v0.0.0-20180803180156-3c07937fe18c/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563 h1:NIou6eNFigscvKJmsbyez16S2cIS6idossORlFtSt2E=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

View file

@ -0,0 +1,144 @@
package errcheck
import (
"fmt"
"go/types"
)
// walkThroughEmbeddedInterfaces returns a slice of Interfaces that
// we need to walk through in order to reach the actual definition,
// in an Interface, of the method selected by the given selection.
//
// false will be returned in the second return value if:
// - the right side of the selection is not a function
// - the actual definition of the function is not in an Interface
//
// The returned slice will contain all the interface types that need
// to be walked through to reach the actual definition.
//
// For example, say we have:
//
// type Inner interface {Method()}
// type Middle interface {Inner}
// type Outer interface {Middle}
// type T struct {Outer}
// type U struct {T}
// type V struct {U}
//
// And then the selector:
//
// V.Method
//
// We'll return [Outer, Middle, Inner] by first walking through the embedded structs
// until we reach the Outer interface, then descending through the embedded interfaces
// until we find the one that actually explicitly defines Method.
func walkThroughEmbeddedInterfaces(sel *types.Selection) ([]types.Type, bool) {
fn, ok := sel.Obj().(*types.Func)
if !ok {
return nil, false
}
// Start off at the receiver.
currentT := sel.Recv()
// First, we can walk through any Struct fields provided
// by the selection Index() method. We ignore the last
// index because it would give the method itself.
indexes := sel.Index()
for _, fieldIndex := range indexes[:len(indexes)-1] {
currentT = getTypeAtFieldIndex(currentT, fieldIndex)
}
// Now currentT is either a type implementing the actual function,
// an Invalid type (if the receiver is a package), or an interface.
//
// If it's not an Interface, then we're done, as this function
// only cares about Interface-defined functions.
//
// If it is an Interface, we potentially need to continue digging until
// we find the Interface that actually explicitly defines the function.
interfaceT, ok := maybeUnname(currentT).(*types.Interface)
if !ok {
return nil, false
}
// The first interface we pass through is this one we've found. We return the possibly
// wrapping types.Named because it is more useful to work with for callers.
result := []types.Type{currentT}
// If this interface itself explicitly defines the given method
// then we're done digging.
for !explicitlyDefinesMethod(interfaceT, fn) {
// Otherwise, we find which of the embedded interfaces _does_
// define the method, add it to our list, and loop.
namedInterfaceT, ok := getEmbeddedInterfaceDefiningMethod(interfaceT, fn)
if !ok {
// This should be impossible as long as we type-checked: either the
// interface or one of its embedded ones must implement the method...
panic(fmt.Sprintf("either %v or one of its embedded interfaces must implement %v", currentT, fn))
}
result = append(result, namedInterfaceT)
interfaceT = namedInterfaceT.Underlying().(*types.Interface)
}
return result, true
}
func getTypeAtFieldIndex(startingAt types.Type, fieldIndex int) types.Type {
t := maybeUnname(maybeDereference(startingAt))
s, ok := t.(*types.Struct)
if !ok {
panic(fmt.Sprintf("cannot get Field of a type that is not a struct, got a %T", t))
}
return s.Field(fieldIndex).Type()
}
// getEmbeddedInterfaceDefiningMethod searches through any embedded interfaces of the
// passed interface searching for one that defines the given function. If found, the
// types.Named wrapping that interface will be returned along with true in the second value.
//
// If no such embedded interface is found, nil and false are returned.
func getEmbeddedInterfaceDefiningMethod(interfaceT *types.Interface, fn *types.Func) (*types.Named, bool) {
for i := 0; i < interfaceT.NumEmbeddeds(); i++ {
embedded := interfaceT.Embedded(i)
if definesMethod(embedded.Underlying().(*types.Interface), fn) {
return embedded, true
}
}
return nil, false
}
func explicitlyDefinesMethod(interfaceT *types.Interface, fn *types.Func) bool {
for i := 0; i < interfaceT.NumExplicitMethods(); i++ {
if interfaceT.ExplicitMethod(i) == fn {
return true
}
}
return false
}
func definesMethod(interfaceT *types.Interface, fn *types.Func) bool {
for i := 0; i < interfaceT.NumMethods(); i++ {
if interfaceT.Method(i) == fn {
return true
}
}
return false
}
func maybeDereference(t types.Type) types.Type {
p, ok := t.(*types.Pointer)
if ok {
return p.Elem()
}
return t
}
func maybeUnname(t types.Type) types.Type {
n, ok := t.(*types.Named)
if ok {
return n.Underlying()
}
return t
}

View file

@ -0,0 +1,639 @@
// Package errcheck is the library used to implement the errcheck command-line tool.
//
// Note: The API of this package has not been finalized and may change at any point.
package errcheck
import (
"bufio"
"errors"
"fmt"
"go/ast"
"go/token"
"go/types"
"os"
"regexp"
"sort"
"strings"
"sync"
"golang.org/x/tools/go/packages"
)
var errorType *types.Interface
func init() {
errorType = types.Universe.Lookup("error").Type().Underlying().(*types.Interface)
}
var (
// ErrNoGoFiles is returned when CheckPackage is run on a package with no Go source files
ErrNoGoFiles = errors.New("package contains no go source files")
)
// UncheckedError indicates the position of an unchecked error return.
type UncheckedError struct {
Pos token.Position
Line string
FuncName string
}
// UncheckedErrors is returned from the CheckPackage function if the package contains
// any unchecked errors.
// Errors should be appended using the Append method, which is safe to use concurrently.
type UncheckedErrors struct {
mu sync.Mutex
// Errors is a list of all the unchecked errors in the package.
// Printing an error reports its position within the file and the contents of the line.
Errors []UncheckedError
}
func (e *UncheckedErrors) Append(errors ...UncheckedError) {
e.mu.Lock()
defer e.mu.Unlock()
e.Errors = append(e.Errors, errors...)
}
func (e *UncheckedErrors) Error() string {
return fmt.Sprintf("%d unchecked errors", len(e.Errors))
}
// Len is the number of elements in the collection.
func (e *UncheckedErrors) Len() int { return len(e.Errors) }
// Swap swaps the elements with indexes i and j.
func (e *UncheckedErrors) Swap(i, j int) { e.Errors[i], e.Errors[j] = e.Errors[j], e.Errors[i] }
type byName struct{ *UncheckedErrors }
// Less reports whether the element with index i should sort before the element with index j.
func (e byName) Less(i, j int) bool {
ei, ej := e.Errors[i], e.Errors[j]
pi, pj := ei.Pos, ej.Pos
if pi.Filename != pj.Filename {
return pi.Filename < pj.Filename
}
if pi.Line != pj.Line {
return pi.Line < pj.Line
}
if pi.Column != pj.Column {
return pi.Column < pj.Column
}
return ei.Line < ej.Line
}
type Checker struct {
// ignore is a map of package names to regular expressions. Identifiers from a package are
// checked against its regular expressions and if any of the expressions match the call
// is not checked.
Ignore map[string]*regexp.Regexp
// If blank is true then assignments to the blank identifier are also considered to be
// ignored errors.
Blank bool
// If asserts is true then ignored type assertion results are also checked
Asserts bool
// build tags
Tags []string
Verbose bool
// If true, checking of _test.go files is disabled
WithoutTests bool
// If true, checking of files with generated code is disabled
WithoutGeneratedCode bool
exclude map[string]bool
}
func NewChecker() *Checker {
c := Checker{}
c.SetExclude(map[string]bool{})
return &c
}
func (c *Checker) SetExclude(l map[string]bool) {
c.exclude = map[string]bool{}
// Default exclude for stdlib functions
for _, exc := range []string{
// bytes
"(*bytes.Buffer).Write",
"(*bytes.Buffer).WriteByte",
"(*bytes.Buffer).WriteRune",
"(*bytes.Buffer).WriteString",
// fmt
"fmt.Errorf",
"fmt.Print",
"fmt.Printf",
"fmt.Println",
"fmt.Fprint(*bytes.Buffer)",
"fmt.Fprintf(*bytes.Buffer)",
"fmt.Fprintln(*bytes.Buffer)",
"fmt.Fprint(*strings.Builder)",
"fmt.Fprintf(*strings.Builder)",
"fmt.Fprintln(*strings.Builder)",
"fmt.Fprint(os.Stderr)",
"fmt.Fprintf(os.Stderr)",
"fmt.Fprintln(os.Stderr)",
// math/rand
"math/rand.Read",
"(*math/rand.Rand).Read",
// strings
"(*strings.Builder).Write",
"(*strings.Builder).WriteByte",
"(*strings.Builder).WriteRune",
"(*strings.Builder).WriteString",
// hash
"(hash.Hash).Write",
} {
c.exclude[exc] = true
}
for k := range l {
c.exclude[k] = true
}
}
func (c *Checker) logf(msg string, args ...interface{}) {
if c.Verbose {
fmt.Fprintf(os.Stderr, msg+"\n", args...)
}
}
// loadPackages is used for testing.
var loadPackages = func(cfg *packages.Config, paths ...string) ([]*packages.Package, error) {
return packages.Load(cfg, paths...)
}
func (c *Checker) load(paths ...string) ([]*packages.Package, error) {
cfg := &packages.Config{
Mode: packages.LoadAllSyntax,
Tests: !c.WithoutTests,
BuildFlags: []string{fmt.Sprintf("-tags=%s", strings.Join(c.Tags, " "))},
}
return loadPackages(cfg, paths...)
}
var generatedCodeRegexp = regexp.MustCompile("^// Code generated .* DO NOT EDIT\\.$")
func (c *Checker) shouldSkipFile(file *ast.File) bool {
if !c.WithoutGeneratedCode {
return false
}
for _, cg := range file.Comments {
for _, comment := range cg.List {
if generatedCodeRegexp.MatchString(comment.Text) {
return true
}
}
}
return false
}
// CheckPackages checks packages for errors.
func (c *Checker) CheckPackages(paths ...string) error {
pkgs, err := c.load(paths...)
if err != nil {
return err
}
// Check for errors in the initial packages.
for _, pkg := range pkgs {
if len(pkg.Errors) > 0 {
return fmt.Errorf("errors while loading package %s: %v", pkg.ID, pkg.Errors)
}
}
var wg sync.WaitGroup
u := &UncheckedErrors{}
for _, pkg := range pkgs {
wg.Add(1)
go func(pkg *packages.Package) {
defer wg.Done()
c.logf("Checking %s", pkg.Types.Path())
v := &visitor{
pkg: pkg,
ignore: c.Ignore,
blank: c.Blank,
asserts: c.Asserts,
lines: make(map[string][]string),
exclude: c.exclude,
errors: []UncheckedError{},
}
for _, astFile := range v.pkg.Syntax {
if c.shouldSkipFile(astFile) {
continue
}
ast.Walk(v, astFile)
}
u.Append(v.errors...)
}(pkg)
}
wg.Wait()
if u.Len() > 0 {
// Sort unchecked errors and remove duplicates. Duplicates may occur when a file
// containing an unchecked error belongs to > 1 package.
sort.Sort(byName{u})
uniq := u.Errors[:0] // compact in-place
for i, err := range u.Errors {
if i == 0 || err != u.Errors[i-1] {
uniq = append(uniq, err)
}
}
u.Errors = uniq
return u
}
return nil
}
// visitor implements the errcheck algorithm
type visitor struct {
pkg *packages.Package
ignore map[string]*regexp.Regexp
blank bool
asserts bool
lines map[string][]string
exclude map[string]bool
errors []UncheckedError
}
// selectorAndFunc tries to get the selector and function from call expression.
// For example, given the call expression representing "a.b()", the selector
// is "a.b" and the function is "b" itself.
//
// The final return value will be true if it is able to do extract a selector
// from the call and look up the function object it refers to.
//
// If the call does not include a selector (like if it is a plain "f()" function call)
// then the final return value will be false.
func (v *visitor) selectorAndFunc(call *ast.CallExpr) (*ast.SelectorExpr, *types.Func, bool) {
sel, ok := call.Fun.(*ast.SelectorExpr)
if !ok {
return nil, nil, false
}
fn, ok := v.pkg.TypesInfo.ObjectOf(sel.Sel).(*types.Func)
if !ok {
// Shouldn't happen, but be paranoid
return nil, nil, false
}
return sel, fn, true
}
// fullName will return a package / receiver-type qualified name for a called function
// if the function is the result of a selector. Otherwise it will return
// the empty string.
//
// The name is fully qualified by the import path, possible type,
// function/method name and pointer receiver.
//
// For example,
// - for "fmt.Printf(...)" it will return "fmt.Printf"
// - for "base64.StdEncoding.Decode(...)" it will return "(*encoding/base64.Encoding).Decode"
// - for "myFunc()" it will return ""
func (v *visitor) fullName(call *ast.CallExpr) string {
_, fn, ok := v.selectorAndFunc(call)
if !ok {
return ""
}
// TODO(dh): vendored packages will have /vendor/ in their name,
// thus not matching vendored standard library packages. If we
// want to support vendored stdlib packages, we need to implement
// FullName with our own logic.
return fn.FullName()
}
// namesForExcludeCheck will return a list of fully-qualified function names
// from a function call that can be used to check against the exclusion list.
//
// If a function call is against a local function (like "myFunc()") then no
// names are returned. If the function is package-qualified (like "fmt.Printf()")
// then just that function's fullName is returned.
//
// Otherwise, we walk through all the potentially embeddded interfaces of the receiver
// the collect a list of type-qualified function names that we will check.
func (v *visitor) namesForExcludeCheck(call *ast.CallExpr) []string {
sel, fn, ok := v.selectorAndFunc(call)
if !ok {
return nil
}
name := v.fullName(call)
if name == "" {
return nil
}
// This will be missing for functions without a receiver (like fmt.Printf),
// so just fall back to the the function's fullName in that case.
selection, ok := v.pkg.TypesInfo.Selections[sel]
if !ok {
return []string{name}
}
// This will return with ok false if the function isn't defined
// on an interface, so just fall back to the fullName.
ts, ok := walkThroughEmbeddedInterfaces(selection)
if !ok {
return []string{name}
}
result := make([]string, len(ts))
for i, t := range ts {
// Like in fullName, vendored packages will have /vendor/ in their name,
// thus not matching vendored standard library packages. If we
// want to support vendored stdlib packages, we need to implement
// additional logic here.
result[i] = fmt.Sprintf("(%s).%s", t.String(), fn.Name())
}
return result
}
// isBufferType checks if the expression type is a known in-memory buffer type.
func (v *visitor) argName(expr ast.Expr) string {
// Special-case literal "os.Stdout" and "os.Stderr"
if sel, ok := expr.(*ast.SelectorExpr); ok {
if obj := v.pkg.TypesInfo.ObjectOf(sel.Sel); obj != nil {
vr, ok := obj.(*types.Var)
if ok && vr.Pkg() != nil && vr.Pkg().Name() == "os" && (vr.Name() == "Stderr" || vr.Name() == "Stdout") {
return "os." + vr.Name()
}
}
}
t := v.pkg.TypesInfo.TypeOf(expr)
if t == nil {
return ""
}
return t.String()
}
func (v *visitor) excludeCall(call *ast.CallExpr) bool {
var arg0 string
if len(call.Args) > 0 {
arg0 = v.argName(call.Args[0])
}
for _, name := range v.namesForExcludeCheck(call) {
if v.exclude[name] {
return true
}
if arg0 != "" && v.exclude[name+"("+arg0+")"] {
return true
}
}
return false
}
func (v *visitor) ignoreCall(call *ast.CallExpr) bool {
if v.excludeCall(call) {
return true
}
// Try to get an identifier.
// Currently only supports simple expressions:
// 1. f()
// 2. x.y.f()
var id *ast.Ident
switch exp := call.Fun.(type) {
case (*ast.Ident):
id = exp
case (*ast.SelectorExpr):
id = exp.Sel
default:
// eg: *ast.SliceExpr, *ast.IndexExpr
}
if id == nil {
return false
}
// If we got an identifier for the function, see if it is ignored
if re, ok := v.ignore[""]; ok && re.MatchString(id.Name) {
return true
}
if obj := v.pkg.TypesInfo.Uses[id]; obj != nil {
if pkg := obj.Pkg(); pkg != nil {
if re, ok := v.ignore[pkg.Path()]; ok {
return re.MatchString(id.Name)
}
// if current package being considered is vendored, check to see if it should be ignored based
// on the unvendored path.
if nonVendoredPkg, ok := nonVendoredPkgPath(pkg.Path()); ok {
if re, ok := v.ignore[nonVendoredPkg]; ok {
return re.MatchString(id.Name)
}
}
}
}
return false
}
// nonVendoredPkgPath returns the unvendored version of the provided package path (or returns the provided path if it
// does not represent a vendored path). The second return value is true if the provided package was vendored, false
// otherwise.
func nonVendoredPkgPath(pkgPath string) (string, bool) {
lastVendorIndex := strings.LastIndex(pkgPath, "/vendor/")
if lastVendorIndex == -1 {
return pkgPath, false
}
return pkgPath[lastVendorIndex+len("/vendor/"):], true
}
// errorsByArg returns a slice s such that
// len(s) == number of return types of call
// s[i] == true iff return type at position i from left is an error type
func (v *visitor) errorsByArg(call *ast.CallExpr) []bool {
switch t := v.pkg.TypesInfo.Types[call].Type.(type) {
case *types.Named:
// Single return
return []bool{isErrorType(t)}
case *types.Pointer:
// Single return via pointer
return []bool{isErrorType(t)}
case *types.Tuple:
// Multiple returns
s := make([]bool, t.Len())
for i := 0; i < t.Len(); i++ {
switch et := t.At(i).Type().(type) {
case *types.Named:
// Single return
s[i] = isErrorType(et)
case *types.Pointer:
// Single return via pointer
s[i] = isErrorType(et)
default:
s[i] = false
}
}
return s
}
return []bool{false}
}
func (v *visitor) callReturnsError(call *ast.CallExpr) bool {
if v.isRecover(call) {
return true
}
for _, isError := range v.errorsByArg(call) {
if isError {
return true
}
}
return false
}
// isRecover returns true if the given CallExpr is a call to the built-in recover() function.
func (v *visitor) isRecover(call *ast.CallExpr) bool {
if fun, ok := call.Fun.(*ast.Ident); ok {
if _, ok := v.pkg.TypesInfo.Uses[fun].(*types.Builtin); ok {
return fun.Name == "recover"
}
}
return false
}
func (v *visitor) addErrorAtPosition(position token.Pos, call *ast.CallExpr) {
pos := v.pkg.Fset.Position(position)
lines, ok := v.lines[pos.Filename]
if !ok {
lines = readfile(pos.Filename)
v.lines[pos.Filename] = lines
}
line := "??"
if pos.Line-1 < len(lines) {
line = strings.TrimSpace(lines[pos.Line-1])
}
var name string
if call != nil {
name = v.fullName(call)
}
v.errors = append(v.errors, UncheckedError{pos, line, name})
}
func readfile(filename string) []string {
var f, err = os.Open(filename)
if err != nil {
return nil
}
var lines []string
var scanner = bufio.NewScanner(f)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
return lines
}
func (v *visitor) Visit(node ast.Node) ast.Visitor {
switch stmt := node.(type) {
case *ast.ExprStmt:
if call, ok := stmt.X.(*ast.CallExpr); ok {
if !v.ignoreCall(call) && v.callReturnsError(call) {
v.addErrorAtPosition(call.Lparen, call)
}
}
case *ast.GoStmt:
if !v.ignoreCall(stmt.Call) && v.callReturnsError(stmt.Call) {
v.addErrorAtPosition(stmt.Call.Lparen, stmt.Call)
}
case *ast.DeferStmt:
if !v.ignoreCall(stmt.Call) && v.callReturnsError(stmt.Call) {
v.addErrorAtPosition(stmt.Call.Lparen, stmt.Call)
}
case *ast.AssignStmt:
if len(stmt.Rhs) == 1 {
// single value on rhs; check against lhs identifiers
if call, ok := stmt.Rhs[0].(*ast.CallExpr); ok {
if !v.blank {
break
}
if v.ignoreCall(call) {
break
}
isError := v.errorsByArg(call)
for i := 0; i < len(stmt.Lhs); i++ {
if id, ok := stmt.Lhs[i].(*ast.Ident); ok {
// We shortcut calls to recover() because errorsByArg can't
// check its return types for errors since it returns interface{}.
if id.Name == "_" && (v.isRecover(call) || isError[i]) {
v.addErrorAtPosition(id.NamePos, call)
}
}
}
} else if assert, ok := stmt.Rhs[0].(*ast.TypeAssertExpr); ok {
if !v.asserts {
break
}
if assert.Type == nil {
// type switch
break
}
if len(stmt.Lhs) < 2 {
// assertion result not read
v.addErrorAtPosition(stmt.Rhs[0].Pos(), nil)
} else if id, ok := stmt.Lhs[1].(*ast.Ident); ok && v.blank && id.Name == "_" {
// assertion result ignored
v.addErrorAtPosition(id.NamePos, nil)
}
}
} else {
// multiple value on rhs; in this case a call can't return
// multiple values. Assume len(stmt.Lhs) == len(stmt.Rhs)
for i := 0; i < len(stmt.Lhs); i++ {
if id, ok := stmt.Lhs[i].(*ast.Ident); ok {
if call, ok := stmt.Rhs[i].(*ast.CallExpr); ok {
if !v.blank {
continue
}
if v.ignoreCall(call) {
continue
}
if id.Name == "_" && v.callReturnsError(call) {
v.addErrorAtPosition(id.NamePos, call)
}
} else if assert, ok := stmt.Rhs[i].(*ast.TypeAssertExpr); ok {
if !v.asserts {
continue
}
if assert.Type == nil {
// Shouldn't happen anyway, no multi assignment in type switches
continue
}
v.addErrorAtPosition(id.NamePos, nil)
}
}
}
}
default:
}
return v
}
func isErrorType(t types.Type) bool {
return types.Implements(t, errorType)
}

194
vendor/github.com/kisielk/errcheck/main.go generated vendored Normal file
View file

@ -0,0 +1,194 @@
package main
import (
"bufio"
"flag"
"fmt"
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"github.com/kisielk/errcheck/internal/errcheck"
)
const (
exitCodeOk int = iota
exitUncheckedError
exitFatalError
)
var abspath bool
type ignoreFlag map[string]*regexp.Regexp
func (f ignoreFlag) String() string {
pairs := make([]string, 0, len(f))
for pkg, re := range f {
prefix := ""
if pkg != "" {
prefix = pkg + ":"
}
pairs = append(pairs, prefix+re.String())
}
return fmt.Sprintf("%q", strings.Join(pairs, ","))
}
func (f ignoreFlag) Set(s string) error {
if s == "" {
return nil
}
for _, pair := range strings.Split(s, ",") {
colonIndex := strings.Index(pair, ":")
var pkg, re string
if colonIndex == -1 {
pkg = ""
re = pair
} else {
pkg = pair[:colonIndex]
re = pair[colonIndex+1:]
}
regex, err := regexp.Compile(re)
if err != nil {
return err
}
f[pkg] = regex
}
return nil
}
type tagsFlag []string
func (f *tagsFlag) String() string {
return fmt.Sprintf("%q", strings.Join(*f, " "))
}
func (f *tagsFlag) Set(s string) error {
if s == "" {
return nil
}
tags := strings.Split(s, " ")
if tags == nil {
return nil
}
for _, tag := range tags {
if tag != "" {
*f = append(*f, tag)
}
}
return nil
}
var dotStar = regexp.MustCompile(".*")
func reportUncheckedErrors(e *errcheck.UncheckedErrors, verbose bool) {
wd, err := os.Getwd()
if err != nil {
wd = ""
}
for _, uncheckedError := range e.Errors {
pos := uncheckedError.Pos.String()
if !abspath {
newPos, err := filepath.Rel(wd, pos)
if err == nil {
pos = newPos
}
}
if verbose && uncheckedError.FuncName != "" {
fmt.Printf("%s:\t%s\t%s\n", pos, uncheckedError.FuncName, uncheckedError.Line)
} else {
fmt.Printf("%s:\t%s\n", pos, uncheckedError.Line)
}
}
}
func mainCmd(args []string) int {
runtime.GOMAXPROCS(runtime.NumCPU())
checker := errcheck.NewChecker()
paths, err := parseFlags(checker, args)
if err != exitCodeOk {
return err
}
if err := checker.CheckPackages(paths...); err != nil {
if e, ok := err.(*errcheck.UncheckedErrors); ok {
reportUncheckedErrors(e, checker.Verbose)
return exitUncheckedError
} else if err == errcheck.ErrNoGoFiles {
fmt.Fprintln(os.Stderr, err)
return exitCodeOk
}
fmt.Fprintf(os.Stderr, "error: failed to check packages: %s\n", err)
return exitFatalError
}
return exitCodeOk
}
func parseFlags(checker *errcheck.Checker, args []string) ([]string, int) {
flags := flag.NewFlagSet(args[0], flag.ContinueOnError)
flags.BoolVar(&checker.Blank, "blank", false, "if true, check for errors assigned to blank identifier")
flags.BoolVar(&checker.Asserts, "asserts", false, "if true, check for ignored type assertion results")
flags.BoolVar(&checker.WithoutTests, "ignoretests", false, "if true, checking of _test.go files is disabled")
flags.BoolVar(&checker.WithoutGeneratedCode, "ignoregenerated", false, "if true, checking of files with generated code is disabled")
flags.BoolVar(&checker.Verbose, "verbose", false, "produce more verbose logging")
flags.BoolVar(&abspath, "abspath", false, "print absolute paths to files")
tags := tagsFlag{}
flags.Var(&tags, "tags", "space-separated list of build tags to include")
ignorePkg := flags.String("ignorepkg", "", "comma-separated list of package paths to ignore")
ignore := ignoreFlag(map[string]*regexp.Regexp{})
flags.Var(ignore, "ignore", "[deprecated] comma-separated list of pairs of the form pkg:regex\n"+
" the regex is used to ignore names within pkg.")
var excludeFile string
flags.StringVar(&excludeFile, "exclude", "", "Path to a file containing a list of functions to exclude from checking")
if err := flags.Parse(args[1:]); err != nil {
return nil, exitFatalError
}
if excludeFile != "" {
exclude := make(map[string]bool)
fh, err := os.Open(excludeFile)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not read exclude file: %s\n", err)
return nil, exitFatalError
}
scanner := bufio.NewScanner(fh)
for scanner.Scan() {
name := scanner.Text()
exclude[name] = true
if checker.Verbose {
fmt.Printf("Excluding %s\n", name)
}
}
if err := scanner.Err(); err != nil {
fmt.Fprintf(os.Stderr, "Could not read exclude file: %s\n", err)
return nil, exitFatalError
}
checker.SetExclude(exclude)
}
checker.Tags = tags
for _, pkg := range strings.Split(*ignorePkg, ",") {
if pkg != "" {
ignore[pkg] = dotStar
}
}
checker.Ignore = ignore
paths := flags.Args()
if len(paths) == 0 {
paths = []string{"."}
}
return paths, exitCodeOk
}
func main() {
os.Exit(mainCmd(os.Args))
}

19
vendor/golang.org/x/lint/.travis.yml generated vendored Normal file
View file

@ -0,0 +1,19 @@
sudo: false
language: go
go:
- 1.10.x
- 1.11.x
- master
go_import_path: golang.org/x/lint
install:
- go get -t -v ./...
script:
- go test -v -race ./...
matrix:
allow_failures:
- go: master
fast_finish: true

15
vendor/golang.org/x/lint/CONTRIBUTING.md generated vendored Normal file
View file

@ -0,0 +1,15 @@
# Contributing to Golint
## Before filing an issue:
### Are you having trouble building golint?
Check you have the latest version of its dependencies. Run
```
go get -u golang.org/x/lint/golint
```
If you still have problems, consider searching for existing issues before filing a new issue.
## Before sending a pull request:
Have you understood the purpose of golint? Make sure to carefully read `README`.

27
vendor/golang.org/x/lint/LICENSE generated vendored Normal file
View file

@ -0,0 +1,27 @@
Copyright (c) 2013 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* 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.
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.

88
vendor/golang.org/x/lint/README.md generated vendored Normal file
View file

@ -0,0 +1,88 @@
Golint is a linter for Go source code.
[![Build Status](https://travis-ci.org/golang/lint.svg?branch=master)](https://travis-ci.org/golang/lint)
## Installation
Golint requires a
[supported release of Go](https://golang.org/doc/devel/release.html#policy).
go get -u golang.org/x/lint/golint
To find out where `golint` was installed you can run `go list -f {{.Target}} golang.org/x/lint/golint`. For `golint` to be used globally add that directory to the `$PATH` environment setting.
## Usage
Invoke `golint` with one or more filenames, directories, or packages named
by its import path. Golint uses the same
[import path syntax](https://golang.org/cmd/go/#hdr-Import_path_syntax) as
the `go` command and therefore
also supports relative import paths like `./...`. Additionally the `...`
wildcard can be used as suffix on relative and absolute file paths to recurse
into them.
The output of this tool is a list of suggestions in Vim quickfix format,
which is accepted by lots of different editors.
## Purpose
Golint differs from gofmt. Gofmt reformats Go source code, whereas
golint prints out style mistakes.
Golint differs from govet. Govet is concerned with correctness, whereas
golint is concerned with coding style. Golint is in use at Google, and it
seeks to match the accepted style of the open source Go project.
The suggestions made by golint are exactly that: suggestions.
Golint is not perfect, and has both false positives and false negatives.
Do not treat its output as a gold standard. We will not be adding pragmas
or other knobs to suppress specific warnings, so do not expect or require
code to be completely "lint-free".
In short, this tool is not, and will never be, trustworthy enough for its
suggestions to be enforced automatically, for example as part of a build process.
Golint makes suggestions for many of the mechanically checkable items listed in
[Effective Go](https://golang.org/doc/effective_go.html) and the
[CodeReviewComments wiki page](https://golang.org/wiki/CodeReviewComments).
## Scope
Golint is meant to carry out the stylistic conventions put forth in
[Effective Go](https://golang.org/doc/effective_go.html) and
[CodeReviewComments](https://golang.org/wiki/CodeReviewComments).
Changes that are not aligned with those documents will not be considered.
## Contributions
Contributions to this project are welcome provided they are [in scope](#scope),
though please send mail before starting work on anything major.
Contributors retain their copyright, so we need you to fill out
[a short form](https://developers.google.com/open-source/cla/individual)
before we can accept your contribution.
## Vim
Add this to your ~/.vimrc:
set rtp+=$GOPATH/src/golang.org/x/lint/misc/vim
If you have multiple entries in your GOPATH, replace `$GOPATH` with the right value.
Running `:Lint` will run golint on the current file and populate the quickfix list.
Optionally, add this to your `~/.vimrc` to automatically run `golint` on `:w`
autocmd BufWritePost,FileWritePost *.go execute 'Lint' | cwindow
## Emacs
Add this to your `.emacs` file:
(add-to-list 'load-path (concat (getenv "GOPATH") "/src/golang.org/x/lint/misc/emacs/"))
(require 'golint)
If you have multiple entries in your GOPATH, replace `$GOPATH` with the right value.
Running M-x golint will run golint on the current file.
For more usage, see [Compilation-Mode](http://www.gnu.org/software/emacs/manual/html_node/emacs/Compilation-Mode.html).

5
vendor/golang.org/x/lint/go.mod generated vendored Normal file
View file

@ -0,0 +1,5 @@
module golang.org/x/lint
go 1.11
require golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f

8
vendor/golang.org/x/lint/go.sum generated vendored Normal file
View file

@ -0,0 +1,8 @@
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f h1:kDxGY2VmgABOe55qheT/TFqUMtcTHnomIPS1iv3G4Ms=
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

159
vendor/golang.org/x/lint/golint/golint.go generated vendored Normal file
View file

@ -0,0 +1,159 @@
// 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"
"golang.org/x/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 strings.HasSuffix(arg, "/...") && isDir(arg[:len(arg)-len("/...")]) {
dirsRun = 1
for _, dirname := range allPackagesInFS(arg) {
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...)
}

309
vendor/golang.org/x/lint/golint/import.go generated vendored Normal file
View file

@ -0,0 +1,309 @@
package main
/*
This file holds a direct copy of the import path matching code of
https://github.com/golang/go/blob/master/src/cmd/go/main.go. It can be
replaced when https://golang.org/issue/8768 is resolved.
It has been updated to follow upstream changes in a few ways.
*/
import (
"fmt"
"go/build"
"log"
"os"
"path"
"path/filepath"
"regexp"
"runtime"
"strings"
)
var (
buildContext = build.Default
goroot = filepath.Clean(runtime.GOROOT())
gorootSrc = filepath.Join(goroot, "src")
)
// importPathsNoDotExpansion returns the import paths to use for the given
// command line, but it does no ... expansion.
func importPathsNoDotExpansion(args []string) []string {
if len(args) == 0 {
return []string{"."}
}
var out []string
for _, a := range args {
// Arguments are supposed to be import paths, but
// as a courtesy to Windows developers, rewrite \ to /
// in command-line arguments. Handles .\... and so on.
if filepath.Separator == '\\' {
a = strings.Replace(a, `\`, `/`, -1)
}
// Put argument in canonical form, but preserve leading ./.
if strings.HasPrefix(a, "./") {
a = "./" + path.Clean(a)
if a == "./." {
a = "."
}
} else {
a = path.Clean(a)
}
if a == "all" || a == "std" {
out = append(out, allPackages(a)...)
continue
}
out = append(out, a)
}
return out
}
// importPaths returns the import paths to use for the given command line.
func importPaths(args []string) []string {
args = importPathsNoDotExpansion(args)
var out []string
for _, a := range args {
if strings.Contains(a, "...") {
if build.IsLocalImport(a) {
out = append(out, allPackagesInFS(a)...)
} else {
out = append(out, allPackages(a)...)
}
continue
}
out = append(out, a)
}
return out
}
// matchPattern(pattern)(name) reports whether
// name matches pattern. Pattern is a limited glob
// pattern in which '...' means 'any string' and there
// is no other special syntax.
func matchPattern(pattern string) func(name string) bool {
re := regexp.QuoteMeta(pattern)
re = strings.Replace(re, `\.\.\.`, `.*`, -1)
// Special case: foo/... matches foo too.
if strings.HasSuffix(re, `/.*`) {
re = re[:len(re)-len(`/.*`)] + `(/.*)?`
}
reg := regexp.MustCompile(`^` + re + `$`)
return func(name string) bool {
return reg.MatchString(name)
}
}
// hasPathPrefix reports whether the path s begins with the
// elements in prefix.
func hasPathPrefix(s, prefix string) bool {
switch {
default:
return false
case len(s) == len(prefix):
return s == prefix
case len(s) > len(prefix):
if prefix != "" && prefix[len(prefix)-1] == '/' {
return strings.HasPrefix(s, prefix)
}
return s[len(prefix)] == '/' && s[:len(prefix)] == prefix
}
}
// treeCanMatchPattern(pattern)(name) reports whether
// name or children of name can possibly match pattern.
// Pattern is the same limited glob accepted by matchPattern.
func treeCanMatchPattern(pattern string) func(name string) bool {
wildCard := false
if i := strings.Index(pattern, "..."); i >= 0 {
wildCard = true
pattern = pattern[:i]
}
return func(name string) bool {
return len(name) <= len(pattern) && hasPathPrefix(pattern, name) ||
wildCard && strings.HasPrefix(name, pattern)
}
}
// allPackages returns all the packages that can be found
// under the $GOPATH directories and $GOROOT matching pattern.
// The pattern is either "all" (all packages), "std" (standard packages)
// or a path including "...".
func allPackages(pattern string) []string {
pkgs := matchPackages(pattern)
if len(pkgs) == 0 {
fmt.Fprintf(os.Stderr, "warning: %q matched no packages\n", pattern)
}
return pkgs
}
func matchPackages(pattern string) []string {
match := func(string) bool { return true }
treeCanMatch := func(string) bool { return true }
if pattern != "all" && pattern != "std" {
match = matchPattern(pattern)
treeCanMatch = treeCanMatchPattern(pattern)
}
have := map[string]bool{
"builtin": true, // ignore pseudo-package that exists only for documentation
}
if !buildContext.CgoEnabled {
have["runtime/cgo"] = true // ignore during walk
}
var pkgs []string
// Commands
cmd := filepath.Join(goroot, "src/cmd") + string(filepath.Separator)
filepath.Walk(cmd, func(path string, fi os.FileInfo, err error) error {
if err != nil || !fi.IsDir() || path == cmd {
return nil
}
name := path[len(cmd):]
if !treeCanMatch(name) {
return filepath.SkipDir
}
// Commands are all in cmd/, not in subdirectories.
if strings.Contains(name, string(filepath.Separator)) {
return filepath.SkipDir
}
// We use, e.g., cmd/gofmt as the pseudo import path for gofmt.
name = "cmd/" + name
if have[name] {
return nil
}
have[name] = true
if !match(name) {
return nil
}
_, err = buildContext.ImportDir(path, 0)
if err != nil {
if _, noGo := err.(*build.NoGoError); !noGo {
log.Print(err)
}
return nil
}
pkgs = append(pkgs, name)
return nil
})
for _, src := range buildContext.SrcDirs() {
if (pattern == "std" || pattern == "cmd") && src != gorootSrc {
continue
}
src = filepath.Clean(src) + string(filepath.Separator)
root := src
if pattern == "cmd" {
root += "cmd" + string(filepath.Separator)
}
filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
if err != nil || !fi.IsDir() || path == src {
return nil
}
// Avoid .foo, _foo, and testdata directory trees.
_, elem := filepath.Split(path)
if strings.HasPrefix(elem, ".") || strings.HasPrefix(elem, "_") || elem == "testdata" {
return filepath.SkipDir
}
name := filepath.ToSlash(path[len(src):])
if pattern == "std" && (strings.Contains(name, ".") || name == "cmd") {
// The name "std" is only the standard library.
// If the name is cmd, it's the root of the command tree.
return filepath.SkipDir
}
if !treeCanMatch(name) {
return filepath.SkipDir
}
if have[name] {
return nil
}
have[name] = true
if !match(name) {
return nil
}
_, err = buildContext.ImportDir(path, 0)
if err != nil {
if _, noGo := err.(*build.NoGoError); noGo {
return nil
}
}
pkgs = append(pkgs, name)
return nil
})
}
return pkgs
}
// allPackagesInFS is like allPackages but is passed a pattern
// beginning ./ or ../, meaning it should scan the tree rooted
// at the given directory. There are ... in the pattern too.
func allPackagesInFS(pattern string) []string {
pkgs := matchPackagesInFS(pattern)
if len(pkgs) == 0 {
fmt.Fprintf(os.Stderr, "warning: %q matched no packages\n", pattern)
}
return pkgs
}
func matchPackagesInFS(pattern string) []string {
// Find directory to begin the scan.
// Could be smarter but this one optimization
// is enough for now, since ... is usually at the
// end of a path.
i := strings.Index(pattern, "...")
dir, _ := path.Split(pattern[:i])
// pattern begins with ./ or ../.
// path.Clean will discard the ./ but not the ../.
// We need to preserve the ./ for pattern matching
// and in the returned import paths.
prefix := ""
if strings.HasPrefix(pattern, "./") {
prefix = "./"
}
match := matchPattern(pattern)
var pkgs []string
filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error {
if err != nil || !fi.IsDir() {
return nil
}
if path == dir {
// filepath.Walk starts at dir and recurses. For the recursive case,
// the path is the result of filepath.Join, which calls filepath.Clean.
// The initial case is not Cleaned, though, so we do this explicitly.
//
// This converts a path like "./io/" to "io". Without this step, running
// "cd $GOROOT/src/pkg; go list ./io/..." would incorrectly skip the io
// package, because prepending the prefix "./" to the unclean path would
// result in "././io", and match("././io") returns false.
path = filepath.Clean(path)
}
// Avoid .foo, _foo, and testdata directory trees, but do not avoid "." or "..".
_, elem := filepath.Split(path)
dot := strings.HasPrefix(elem, ".") && elem != "." && elem != ".."
if dot || strings.HasPrefix(elem, "_") || elem == "testdata" {
return filepath.SkipDir
}
name := prefix + filepath.ToSlash(path)
if !match(name) {
return nil
}
if _, err = build.ImportDir(path, 0); err != nil {
if _, noGo := err.(*build.NoGoError); !noGo {
log.Print(err)
}
return nil
}
pkgs = append(pkgs, name)
return nil
})
return pkgs
}

13
vendor/golang.org/x/lint/golint/importcomment.go generated vendored Normal file
View file

@ -0,0 +1,13 @@
// Copyright (c) 2018 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.
// +build go1.12
// Require use of the correct import path only for Go 1.12+ users, so
// any breakages coincide with people updating their CI configs or
// whatnot.
package main // import "golang.org/x/lint/golint"

1614
vendor/golang.org/x/lint/lint.go generated vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,57 @@
// Copyright 2019 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.
package packages
import (
"fmt"
"strings"
)
var allModes = []LoadMode{
NeedName,
NeedFiles,
NeedCompiledGoFiles,
NeedImports,
NeedDeps,
NeedExportsFile,
NeedTypes,
NeedSyntax,
NeedTypesInfo,
NeedTypesSizes,
}
var modeStrings = []string{
"NeedName",
"NeedFiles",
"NeedCompiledGoFiles",
"NeedImports",
"NeedDeps",
"NeedExportsFile",
"NeedTypes",
"NeedSyntax",
"NeedTypesInfo",
"NeedTypesSizes",
}
func (mod LoadMode) String() string {
m := mod
if m == 0 {
return fmt.Sprintf("LoadMode(0)")
}
var out []string
for i, x := range allModes {
if x > m {
break
}
if (m & x) != 0 {
out = append(out, modeStrings[i])
m = m ^ x
}
}
if m != 0 {
out = append(out, "Unknown")
}
return fmt.Sprintf("LoadMode(%s)", strings.Join(out, "|"))
}

View file

@ -64,7 +64,7 @@ func (r Range) Span() (Span, error) {
if f == nil {
return Span{}, fmt.Errorf("file not found in FileSet")
}
s := Span{v: span{URI: FileURI(f.Name())}}
s := Span{}
var err error
s.v.Start.Offset, err = offset(f, r.Start)
if err != nil {
@ -76,6 +76,16 @@ func (r Range) Span() (Span, error) {
return Span{}, err
}
}
// In the presence of line directives, a single File can have sections from
// multiple file names.
filename := f.Position(r.Start).Filename
if r.End.IsValid() {
if endFilename := f.Position(r.End).Filename; filename != endFilename {
return Span{}, fmt.Errorf("span begins in file %q but ends in %q", filename, endFilename)
}
}
s.v.URI = FileURI(filename)
s.v.Start.clean()
s.v.End.clean()
s.v.clean()

14
vendor/modules.txt vendored
View file

@ -28,9 +28,9 @@ github.com/fatih/color
github.com/fsnotify/fsnotify
# github.com/ghodss/yaml v1.0.0
github.com/ghodss/yaml
# github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/go-bindata/go-bindata
github.com/go-bindata/go-bindata/go-bindata
# github.com/go-bindata/go-bindata/v3 v3.1.3
github.com/go-bindata/go-bindata/v3
github.com/go-bindata/go-bindata/v3/go-bindata
# github.com/go-kit/kit v0.9.0
github.com/go-kit/kit/log
github.com/go-kit/kit/log/level
@ -82,6 +82,9 @@ github.com/jsonnet-bundler/jsonnet-bundler/spec/v0
github.com/jsonnet-bundler/jsonnet-bundler/spec/v1
github.com/jsonnet-bundler/jsonnet-bundler/spec/v1/deps
github.com/jsonnet-bundler/jsonnet-bundler/tool/rewrite
# github.com/kisielk/errcheck v1.2.0
github.com/kisielk/errcheck
github.com/kisielk/errcheck/internal/errcheck
# github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515
github.com/kr/logfmt
# github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348
@ -167,6 +170,9 @@ github.com/thanos-io/thanos/pkg/reloader
github.com/thanos-io/thanos/pkg/runutil
# golang.org/x/crypto v0.0.0-20191112222119-e1110fd1c708
golang.org/x/crypto/ssh/terminal
# golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f
golang.org/x/lint
golang.org/x/lint/golint
# golang.org/x/net v0.0.0-20191112182307-2180aed22343
golang.org/x/net/context
golang.org/x/net/context/ctxhttp
@ -189,7 +195,7 @@ golang.org/x/text/unicode/bidi
golang.org/x/text/unicode/norm
# golang.org/x/time v0.0.0-20191024005414-555d28b269f0
golang.org/x/time/rate
# golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2
# golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f
golang.org/x/tools/go/ast/astutil
golang.org/x/tools/go/gcexportdata
golang.org/x/tools/go/internal/gcimporter