1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #39964 from thaJeztah/bump_golangci_lint

bump golangci-lint v1.20.0
This commit is contained in:
Tibor Vass 2019-10-21 10:57:02 -07:00 committed by GitHub
commit c4cf72bad3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 79 additions and 47 deletions

View file

@ -104,7 +104,7 @@ func (i *mockImage) OperatingSystem() string {
func (i *mockImage) MarshalJSON() ([]byte, error) { func (i *mockImage) MarshalJSON() ([]byte, error) {
type rawImage mockImage type rawImage mockImage
return json.Marshal(rawImage(*i)) return json.Marshal(rawImage(*i)) //nolint:staticcheck
} }
type mockImageCache struct { type mockImageCache struct {

View file

@ -35,7 +35,7 @@ func (cli *Client) ContainerList(ctx context.Context, options types.ContainerLis
} }
if options.Filters.Len() > 0 { if options.Filters.Len() > 0 {
//lint:ignore SA1019 for old code //nolint:staticcheck // ignore SA1019 for old code
filterJSON, err := filters.ToParamWithVersion(cli.version, options.Filters) filterJSON, err := filters.ToParamWithVersion(cli.version, options.Filters)
if err != nil { if err != nil {

View file

@ -90,7 +90,7 @@ func buildEventsQueryParams(cliVersion string, options types.EventsOptions) (url
} }
if options.Filters.Len() > 0 { if options.Filters.Len() > 0 {
//lint:ignore SA1019 for old code //nolint:staticcheck // ignore SA1019 for old code
filterJSON, err := filters.ToParamWithVersion(cliVersion, options.Filters) filterJSON, err := filters.ToParamWithVersion(cliVersion, options.Filters)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -88,7 +88,7 @@ func (cli *Client) setupHijackConn(ctx context.Context, req *http.Request, proto
// Server hijacks the connection, error 'connection closed' expected // Server hijacks the connection, error 'connection closed' expected
resp, err := clientconn.Do(req) resp, err := clientconn.Do(req)
//lint:ignore SA1019 for connecting to old (pre go1.8) daemons //nolint:staticcheck // ignore SA1019 for connecting to old (pre go1.8) daemons
if err != httputil.ErrPersistEOF { if err != httputil.ErrPersistEOF {
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -24,7 +24,7 @@ func (cli *Client) ImageList(ctx context.Context, options types.ImageListOptions
} }
} }
if optionFilters.Len() > 0 { if optionFilters.Len() > 0 {
//lint:ignore SA1019 for old code //nolint:staticcheck // ignore SA1019 for old code
filterJSON, err := filters.ToParamWithVersion(cli.version, optionFilters) filterJSON, err := filters.ToParamWithVersion(cli.version, optionFilters)
if err != nil { if err != nil {
return images, err return images, err

View file

@ -13,7 +13,7 @@ import (
func (cli *Client) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) { func (cli *Client) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
query := url.Values{} query := url.Values{}
if options.Filters.Len() > 0 { if options.Filters.Len() > 0 {
//lint:ignore SA1019 for old code //nolint:staticcheck // ignore SA1019 for old code
filterJSON, err := filters.ToParamWithVersion(cli.version, options.Filters) filterJSON, err := filters.ToParamWithVersion(cli.version, options.Filters)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -15,7 +15,7 @@ func (cli *Client) PluginList(ctx context.Context, filter filters.Args) (types.P
query := url.Values{} query := url.Values{}
if filter.Len() > 0 { if filter.Len() > 0 {
//lint:ignore SA1019 for old code //nolint:staticcheck // ignore SA1019 for old code
filterJSON, err := filters.ToParamWithVersion(cli.version, filter) filterJSON, err := filters.ToParamWithVersion(cli.version, filter)
if err != nil { if err != nil {
return plugins, err return plugins, err

View file

@ -15,7 +15,7 @@ func (cli *Client) VolumeList(ctx context.Context, filter filters.Args) (volumet
query := url.Values{} query := url.Values{}
if filter.Len() > 0 { if filter.Len() > 0 {
//lint:ignore SA1019 for old code //nolint:staticcheck // ignore SA1019 for old code
filterJSON, err := filters.ToParamWithVersion(cli.version, filter) filterJSON, err := filters.ToParamWithVersion(cli.version, filter)
if err != nil { if err != nil {
return volumes, err return volumes, err

View file

@ -493,9 +493,7 @@ func findConfigurationConflicts(config map[string]interface{}, flags *pflag.Flag
if len(unknownKeys) > 0 { if len(unknownKeys) > 0 {
unknownNamedConflicts := func(f *pflag.Flag) { unknownNamedConflicts := func(f *pflag.Flag) {
if namedOption, ok := f.Value.(opts.NamedOption); ok { if namedOption, ok := f.Value.(opts.NamedOption); ok {
if _, valid := unknownKeys[namedOption.Name()]; valid { delete(unknownKeys, namedOption.Name())
delete(unknownKeys, namedOption.Name())
}
} }
} }
flags.VisitAll(unknownNamedConflicts) flags.VisitAll(unknownNamedConflicts)

View file

@ -784,9 +784,8 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName
EndpointSettings: endpointConfig, EndpointSettings: endpointConfig,
IPAMOperational: operIPAM, IPAMOperational: operIPAM,
} }
if _, ok := container.NetworkSettings.Networks[n.ID()]; ok {
delete(container.NetworkSettings.Networks, n.ID()) delete(container.NetworkSettings.Networks, n.ID())
}
if err := daemon.updateEndpointNetworkSettings(container, n, ep); err != nil { if err := daemon.updateEndpointNetworkSettings(container, n, ep); err != nil {
return err return err

View file

@ -62,10 +62,9 @@ func Scan(text string) (*events.Message, error) {
attrs[kv[0]] = kv[1] attrs[kv[0]] = kv[1]
} }
tu := time.Unix(t, tn)
return &events.Message{ return &events.Message{
Time: t, Time: t,
TimeNano: tu.UnixNano(), TimeNano: time.Unix(t, tn).UnixNano(),
Type: md["eventType"], Type: md["eventType"],
Action: md["action"], Action: md["action"],
Actor: events.Actor{ Actor: events.Actor{

View file

@ -729,9 +729,9 @@ func BenchmarkConcurrentAccess(b *testing.B) {
numConcurrent := 256 numConcurrent := 256
// create a bunch of ids // create a bunch of ids
var ids []string ids := make([]string, numConcurrent)
for i := 0; i < numConcurrent; i++ { for i := 0; i < numConcurrent; i++ {
ids = append(ids, stringid.GenerateRandomID()) ids[i] = stringid.GenerateRandomID()
} }
if err := d.Create(ids[0], "", nil); err != nil { if err := d.Create(ids[0], "", nil); err != nil {
@ -743,7 +743,7 @@ func BenchmarkConcurrentAccess(b *testing.B) {
} }
parent := ids[1] parent := ids[1]
ids = append(ids[2:]) ids = ids[2:]
chErr := make(chan error, numConcurrent) chErr := make(chan error, numConcurrent)
var outerGroup sync.WaitGroup var outerGroup sync.WaitGroup

View file

@ -51,7 +51,7 @@ func Unmount(target string) error {
continue // try again continue // try again
default: default:
// any other error is fatal // any other error is fatal
break return err
} }
} }

View file

@ -606,7 +606,7 @@ func (d *Driver) parseStorageOpt(storageOpt map[string]string, driver *Driver) e
// Set btrfs storage size // Set btrfs storage size
func (d *Driver) setStorageSize(dir string, driver *Driver) error { func (d *Driver) setStorageSize(dir string, driver *Driver) error {
if driver.options.size <= 0 { if driver.options.size == 0 {
return fmt.Errorf("btrfs: invalid storage size: %s", units.HumanSize(float64(driver.options.size))) return fmt.Errorf("btrfs: invalid storage size: %s", units.HumanSize(float64(driver.options.size)))
} }
if d.options.minSpace > 0 && driver.options.size < d.options.minSpace { if d.options.minSpace > 0 && driver.options.size < d.options.minSpace {

View file

@ -549,7 +549,7 @@ type mockBlobStoreWithCreate struct {
} }
func (blob *mockBlobStoreWithCreate) Create(ctx context.Context, options ...distribution.BlobCreateOption) (distribution.BlobWriter, error) { func (blob *mockBlobStoreWithCreate) Create(ctx context.Context, options ...distribution.BlobCreateOption) (distribution.BlobWriter, error) {
return nil, errcode.Errors(append([]error{errcode.ErrorCodeUnauthorized.WithMessage("unauthorized")})) return nil, errcode.Errors([]error{errcode.ErrorCodeUnauthorized.WithMessage("unauthorized")})
} }
type mockRepoWithBlob struct { type mockRepoWithBlob struct {

View file

@ -1,11 +1,19 @@
#!/bin/sh #!/bin/sh
: "${GOLANGCI_LINT_COMMIT=v1.17.1}" : "${GOLANGCI_LINT_COMMIT=v1.20.0}"
install_golangci_lint() { install_golangci_lint() {
echo "Installing golangci-lint version ${GOLANGCI_LINT_COMMIT}" echo "Installing golangci-lint version ${GOLANGCI_LINT_COMMIT}"
go get -d github.com/golangci/golangci-lint/cmd/golangci-lint go get -d github.com/golangci/golangci-lint/cmd/golangci-lint
cd "$GOPATH/src/github.com/golangci/golangci-lint/" || exit 1 cd "$GOPATH/src/github.com/golangci/golangci-lint/" || exit 1
git checkout -q "${GOLANGCI_LINT_COMMIT}" git checkout -q "${GOLANGCI_LINT_COMMIT}"
go build -buildmode=pie -o "${PREFIX}/golangci-lint" "github.com/golangci/golangci-lint/cmd/golangci-lint"
version="$(git describe --tags)"
commit="$(git rev-parse --short HEAD)"
commitDate="$(git show -s --format=%cd)"
go build \
-buildmode=pie \
-ldflags "-s -w -X \"main.version=${version}\" -X \"main.commit=${commit}\" -X \"main.date=${commitDate}\"" \
-o "${PREFIX}/golangci-lint" "github.com/golangci/golangci-lint/cmd/golangci-lint"
} }

View file

@ -6,7 +6,7 @@ SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# CI platforms differ, so per-platform GOLANGCI_LINT_OPTS can be set # CI platforms differ, so per-platform GOLANGCI_LINT_OPTS can be set
# from a platform-specific Dockerfile, otherwise let's just set # from a platform-specific Dockerfile, otherwise let's just set
# (somewhat pessimistic) default of 10 minutes. # (somewhat pessimistic) default of 10 minutes.
: ${GOLANGCI_LINT_OPTS=--deadline=20m} : "${GOLANGCI_LINT_OPTS=--timeout=10m}"
[ -n "${TESTDEBUG}" ] && set -x [ -n "${TESTDEBUG}" ] && set -x
@ -18,9 +18,10 @@ elif ${PKG_CONFIG} 'libsystemd-journal' 2> /dev/null ; then
fi fi
# TODO use --out-format=junit-xml and store artifacts # TODO use --out-format=junit-xml and store artifacts
GOGC=20 golangci-lint run \ # shellcheck disable=SC2086
GOGC=75 golangci-lint run \
${GOLANGCI_LINT_OPTS} \ ${GOLANGCI_LINT_OPTS} \
--print-resources-usage \ --print-resources-usage \
--build-tags="${DOCKER_BUILDTAGS}" \ --build-tags="${DOCKER_BUILDTAGS}" \
--verbose \ --verbose \
--config ${SCRIPTDIR}/golangci-lint.yml --config "${SCRIPTDIR}/golangci-lint.yml"

View file

@ -1,7 +1,6 @@
linters: linters:
enable: enable:
- deadcode - deadcode
- gofmt
- goimports - goimports
- golint - golint
- gosec - gosec
@ -9,7 +8,12 @@ linters:
- govet - govet
- ineffassign - ineffassign
- misspell - misspell
- staticcheck
- structcheck
- typecheck
- unconvert - unconvert
- unused
- varcheck
disable: disable:
- errcheck - errcheck
@ -22,28 +26,52 @@ linters:
- bundles - bundles
- docs - docs
skip-files:
- ".*\\.pb\\.go"
- "dockerversion/version_autogen.go"
- "api/types/container/container_.*"
- "api/types/volume/volume_.*"
linters-settings: linters-settings:
govet: govet:
check-shadowing: false check-shadowing: false
issues: issues:
# The default exclusion rules are a bit too permissive, so copying the relevant ones below
exclude-use-default: false
exclude-rules: exclude-rules:
# These are copied from the default exclude rules, except for "ineffective break statement"
# and GoDoc checks.
# https://github.com/golangci/golangci-lint/blob/0cc87df732aaf1d5ad9ce9ca538d38d916918b36/pkg/config/config.go#L36
- text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked"
linters:
- errcheck
- text: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this"
linters:
- golint
- text: "G103: Use of unsafe calls should be audited"
linters:
- gosec
- text: "G104: Errors unhandled"
linters:
- gosec
- text: "G204: Subprocess launch(ed with (variable|function call)|ing should be audited)"
linters:
- gosec
- text: "(G301|G302): (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)"
linters:
- gosec
- text: "G304: Potential file inclusion via variable"
linters:
- gosec
# Exclude some linters from running on tests files. # Exclude some linters from running on tests files.
- path: _test\.go - path: _test\.go
linters: linters:
- errcheck - errcheck
- gosec - gosec
- text: "G201: SQL string formatting" # Suppress golint complaining about generated types in api/types/
- text: "type name will be used as (container|volume)\\.(Container|Volume).* by other packages, and that stutters; consider calling this"
path: "api/types/(volume|container)/"
linters: linters:
- gosec - golint
- text: "G202: SQL string concatenation" - text: "(G201|G202): SQL string (formatting|concatenation)"
linters: linters:
- gosec - gosec
# FIXME temporarily suppress these. See #39928 # FIXME temporarily suppress these. See #39928
@ -51,11 +79,7 @@ issues:
linters: linters:
- staticcheck - staticcheck
# FIXME temporarily suppress these. See #39924 # FIXME temporarily suppress these. See #39924
- text: "SA1019: h.Xattrs is deprecated: Use PAXRecords instead" - text: "SA1019: .*\\.Xattrs is deprecated: Use PAXRecords instead"
linters:
- staticcheck
# FIXME temporarily suppress these. See #39924
- text: "SA1019: hdr.Xattrs is deprecated: Use PAXRecords instead"
linters: linters:
- staticcheck - staticcheck
# FIXME temporarily suppress these. See #39926 # FIXME temporarily suppress these. See #39926
@ -66,3 +90,7 @@ issues:
- text: "SA1019: httputil.ClientConn is deprecated" - text: "SA1019: httputil.ClientConn is deprecated"
linters: linters:
- staticcheck - staticcheck
# FIXME temporarily suppress these (related to the ones above)
- text: "SA1019: httputil.ErrPersistEOF is deprecated"
linters:
- staticcheck

View file

@ -139,13 +139,13 @@ type JSONMessage struct {
Stream string `json:"stream,omitempty"` Stream string `json:"stream,omitempty"`
Status string `json:"status,omitempty"` Status string `json:"status,omitempty"`
Progress *JSONProgress `json:"progressDetail,omitempty"` Progress *JSONProgress `json:"progressDetail,omitempty"`
ProgressMessage string `json:"progress,omitempty"` //deprecated ProgressMessage string `json:"progress,omitempty"` // deprecated
ID string `json:"id,omitempty"` ID string `json:"id,omitempty"`
From string `json:"from,omitempty"` From string `json:"from,omitempty"`
Time int64 `json:"time,omitempty"` Time int64 `json:"time,omitempty"`
TimeNano int64 `json:"timeNano,omitempty"` TimeNano int64 `json:"timeNano,omitempty"`
Error *JSONError `json:"errorDetail,omitempty"` Error *JSONError `json:"errorDetail,omitempty"`
ErrorMessage string `json:"error,omitempty"` //deprecated ErrorMessage string `json:"error,omitempty"` // deprecated
// Aux contains out-of-band data, such as digests for push signing and image id after building. // Aux contains out-of-band data, such as digests for push signing and image id after building.
Aux *json.RawMessage `json:"aux,omitempty"` Aux *json.RawMessage `json:"aux,omitempty"`
} }
@ -177,7 +177,7 @@ func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error {
if isTerminal && jm.Stream == "" && jm.Progress != nil { if isTerminal && jm.Stream == "" && jm.Progress != nil {
clearLine(out) clearLine(out)
endl = "\r" endl = "\r"
fmt.Fprintf(out, endl) fmt.Fprint(out, endl)
} else if jm.Progress != nil && jm.Progress.String() != "" { //disable progressbar in non-terminal } else if jm.Progress != nil && jm.Progress.String() != "" { //disable progressbar in non-terminal
return nil return nil
} }
@ -194,7 +194,7 @@ func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error {
} }
if jm.Progress != nil && isTerminal { if jm.Progress != nil && isTerminal {
fmt.Fprintf(out, "%s %s%s", jm.Status, jm.Progress.String(), endl) fmt.Fprintf(out, "%s %s%s", jm.Status, jm.Progress.String(), endl)
} else if jm.ProgressMessage != "" { //deprecated } else if jm.ProgressMessage != "" { // deprecated
fmt.Fprintf(out, "%s %s%s", jm.Status, jm.ProgressMessage, endl) fmt.Fprintf(out, "%s %s%s", jm.Status, jm.ProgressMessage, endl)
} else if jm.Stream != "" { } else if jm.Stream != "" {
fmt.Fprintf(out, "%s%s", jm.Stream, endl) fmt.Fprintf(out, "%s%s", jm.Stream, endl)

View file

@ -90,7 +90,6 @@ func parseInfoFile(r io.Reader, filter FilterFunc) ([]*Info, error) {
mount propagation flags in fields[6]. The correct mount propagation flags in fields[6]. The correct
behavior is to ignore any unknown optional fields. behavior is to ignore any unknown optional fields.
*/ */
break
} }
} }
if i == numFields { if i == numFields {