From 301a2fbeca2a4285335946c4a914b05f71cbb978 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 12 Oct 2019 15:48:28 +0200 Subject: [PATCH 01/15] builder/dockerfile/mockbackend_test.go: suppress SA9005 (staticcheck) ``` builder/dockerfile/mockbackend_test.go:107:21: SA9005: struct doesn't have any exported fields, nor custom marshaling (staticcheck) return json.Marshal(rawImage(*i)) ^ ``` Signed-off-by: Sebastiaan van Stijn --- builder/dockerfile/mockbackend_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/dockerfile/mockbackend_test.go b/builder/dockerfile/mockbackend_test.go index 06b3ffd6e0..81f74175a2 100644 --- a/builder/dockerfile/mockbackend_test.go +++ b/builder/dockerfile/mockbackend_test.go @@ -104,7 +104,7 @@ func (i *mockImage) OperatingSystem() string { func (i *mockImage) MarshalJSON() ([]byte, error) { type rawImage mockImage - return json.Marshal(rawImage(*i)) + return json.Marshal(rawImage(*i)) //nolint:staticcheck } type mockImageCache struct { From 94647b5d8609b28ba807ec41b3ed198838dcaecf Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 12 Oct 2019 16:07:00 +0200 Subject: [PATCH 02/15] graphdriver/aufs: SA4021: x = append(y) is equivalent to x = y (staticcheck) ``` daemon/graphdriver/aufs/aufs_test.go:746:8: SA4021: x = append(y) is equivalent to x = y (staticcheck) ids = append(ids[2:]) ^ ``` Also pre-allocating the ids slice while we're at it. Signed-off-by: Sebastiaan van Stijn --- daemon/graphdriver/aufs/aufs_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/daemon/graphdriver/aufs/aufs_test.go b/daemon/graphdriver/aufs/aufs_test.go index 0752c842b4..b5d952475f 100644 --- a/daemon/graphdriver/aufs/aufs_test.go +++ b/daemon/graphdriver/aufs/aufs_test.go @@ -729,9 +729,9 @@ func BenchmarkConcurrentAccess(b *testing.B) { numConcurrent := 256 // create a bunch of ids - var ids []string + ids := make([]string, numConcurrent) for i := 0; i < numConcurrent; i++ { - ids = append(ids, stringid.GenerateRandomID()) + ids[i] = stringid.GenerateRandomID() } if err := d.Create(ids[0], "", nil); err != nil { @@ -743,7 +743,7 @@ func BenchmarkConcurrentAccess(b *testing.B) { } parent := ids[1] - ids = append(ids[2:]) + ids = ids[2:] chErr := make(chan error, numConcurrent) var outerGroup sync.WaitGroup From ec1fd4b1b0401fad3d03654c16057712aff34e29 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 12 Oct 2019 16:09:10 +0200 Subject: [PATCH 03/15] distribution: SA4021: x = append(y) is equivalent to x = y (staticcheck) ``` distribution/push_v2_test.go:552:29: SA4021: x = append(y) is equivalent to x = y (staticcheck) return nil, errcode.Errors(append([]error{errcode.ErrorCodeUnauthorized.WithMessage("unauthorized")})) ^ ``` Signed-off-by: Sebastiaan van Stijn --- distribution/push_v2_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distribution/push_v2_test.go b/distribution/push_v2_test.go index 9bf3675ece..ca0db486f5 100644 --- a/distribution/push_v2_test.go +++ b/distribution/push_v2_test.go @@ -549,7 +549,7 @@ type mockBlobStoreWithCreate struct { } 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 { From 5f47cef514acba3d0fa0856064057d4c7f218c31 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 12 Oct 2019 16:52:08 +0200 Subject: [PATCH 04/15] fix nolint comments for SA1019: filters.ToParamWithVersion is deprecated The old nolint comment didn't seem to work anymore; ``` client/container_list.go:39:22: SA1019: filters.ToParamWithVersion is deprecated: do not use in any new code; use ToJSON instead (staticcheck) client/events.go:94:22: SA1019: filters.ToParamWithVersion is deprecated: do not use in any new code; use ToJSON instead (staticcheck) client/image_list.go:28:22: SA1019: filters.ToParamWithVersion is deprecated: do not use in any new code; use ToJSON instead (staticcheck) ``` Signed-off-by: Sebastiaan van Stijn --- client/container_list.go | 2 +- client/events.go | 2 +- client/hijack.go | 2 +- client/image_list.go | 2 +- client/network_list.go | 2 +- client/plugin_list.go | 2 +- client/volume_list.go | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/client/container_list.go b/client/container_list.go index c099d80e2a..a973de597f 100644 --- a/client/container_list.go +++ b/client/container_list.go @@ -35,7 +35,7 @@ func (cli *Client) ContainerList(ctx context.Context, options types.ContainerLis } 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) if err != nil { diff --git a/client/events.go b/client/events.go index f347cadf14..f0dc9d9e12 100644 --- a/client/events.go +++ b/client/events.go @@ -90,7 +90,7 @@ func buildEventsQueryParams(cliVersion string, options types.EventsOptions) (url } 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) if err != nil { return nil, err diff --git a/client/hijack.go b/client/hijack.go index 6f8205501f..e1dc49ef0f 100644 --- a/client/hijack.go +++ b/client/hijack.go @@ -88,7 +88,7 @@ func (cli *Client) setupHijackConn(ctx context.Context, req *http.Request, proto // Server hijacks the connection, error 'connection closed' expected 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 != nil { return nil, err diff --git a/client/image_list.go b/client/image_list.go index a5bc4b095f..a4d7505094 100644 --- a/client/image_list.go +++ b/client/image_list.go @@ -24,7 +24,7 @@ func (cli *Client) ImageList(ctx context.Context, options types.ImageListOptions } } if optionFilters.Len() > 0 { - //lint:ignore SA1019 for old code + //nolint:staticcheck // ignore SA1019 for old code filterJSON, err := filters.ToParamWithVersion(cli.version, optionFilters) if err != nil { return images, err diff --git a/client/network_list.go b/client/network_list.go index 8ca7eb6128..ed2acb5571 100644 --- a/client/network_list.go +++ b/client/network_list.go @@ -13,7 +13,7 @@ import ( func (cli *Client) NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) { query := url.Values{} 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) if err != nil { return nil, err diff --git a/client/plugin_list.go b/client/plugin_list.go index a51c930e6d..cf1935e2f5 100644 --- a/client/plugin_list.go +++ b/client/plugin_list.go @@ -15,7 +15,7 @@ func (cli *Client) PluginList(ctx context.Context, filter filters.Args) (types.P query := url.Values{} if filter.Len() > 0 { - //lint:ignore SA1019 for old code + //nolint:staticcheck // ignore SA1019 for old code filterJSON, err := filters.ToParamWithVersion(cli.version, filter) if err != nil { return plugins, err diff --git a/client/volume_list.go b/client/volume_list.go index d68fc2b986..942498dde2 100644 --- a/client/volume_list.go +++ b/client/volume_list.go @@ -15,7 +15,7 @@ func (cli *Client) VolumeList(ctx context.Context, filter filters.Args) (volumet query := url.Values{} if filter.Len() > 0 { - //lint:ignore SA1019 for old code + //nolint:staticcheck // ignore SA1019 for old code filterJSON, err := filters.ToParamWithVersion(cli.version, filter) if err != nil { return volumes, err From 1f7beb85949c4c31b3b5874510531021d5a2b45b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 12 Oct 2019 17:32:20 +0200 Subject: [PATCH 05/15] daemon/events/testutils: remove redundant variable Signed-off-by: Sebastiaan van Stijn --- daemon/events/testutils/testutils.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/daemon/events/testutils/testutils.go b/daemon/events/testutils/testutils.go index b6766adb90..c9ef45da2a 100644 --- a/daemon/events/testutils/testutils.go +++ b/daemon/events/testutils/testutils.go @@ -62,10 +62,9 @@ func Scan(text string) (*events.Message, error) { attrs[kv[0]] = kv[1] } - tu := time.Unix(t, tn) return &events.Message{ Time: t, - TimeNano: tu.UnixNano(), + TimeNano: time.Unix(t, tn).UnixNano(), Type: md["eventType"], Action: md["action"], Actor: events.Actor{ From 04fcb6cfbf0d3419891af82e26d963f22b248fa4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 12 Oct 2019 17:35:13 +0200 Subject: [PATCH 06/15] pkg/jsonmessage: fix SA1006: printf-style function with no arguments Also fixed some incorrectly formatted comments ``` pkg/jsonmessage/jsonmessage.go:180:20: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck) fmt.Fprintf(out, endl) ^ ``` Signed-off-by: Sebastiaan van Stijn --- pkg/jsonmessage/jsonmessage.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/jsonmessage/jsonmessage.go b/pkg/jsonmessage/jsonmessage.go index 6d66408984..814993ec36 100644 --- a/pkg/jsonmessage/jsonmessage.go +++ b/pkg/jsonmessage/jsonmessage.go @@ -139,13 +139,13 @@ type JSONMessage struct { Stream string `json:"stream,omitempty"` Status string `json:"status,omitempty"` Progress *JSONProgress `json:"progressDetail,omitempty"` - ProgressMessage string `json:"progress,omitempty"` //deprecated + ProgressMessage string `json:"progress,omitempty"` // deprecated ID string `json:"id,omitempty"` From string `json:"from,omitempty"` Time int64 `json:"time,omitempty"` TimeNano int64 `json:"timeNano,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 *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 { clearLine(out) endl = "\r" - fmt.Fprintf(out, endl) + fmt.Fprint(out, endl) } else if jm.Progress != nil && jm.Progress.String() != "" { //disable progressbar in non-terminal return nil } @@ -194,7 +194,7 @@ func (jm *JSONMessage) Display(out io.Writer, isTerminal bool) error { } if jm.Progress != nil && isTerminal { 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) } else if jm.Stream != "" { fmt.Fprintf(out, "%s%s", jm.Stream, endl) From cba180cac9de350dc5cf9ab9036401e6f44ff339 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 13 Oct 2019 22:07:35 +0200 Subject: [PATCH 07/15] graphdriver/btrfs: SA4003: no value of type uint64 is less than 0 (staticcheck) ``` daemon/graphdriver/btrfs/btrfs.go:609:5: SA4003: no value of type uint64 is less than 0 (staticcheck) if driver.options.size <= 0 { ^ ``` Signed-off-by: Sebastiaan van Stijn --- daemon/graphdriver/btrfs/btrfs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/graphdriver/btrfs/btrfs.go b/daemon/graphdriver/btrfs/btrfs.go index a20875eb91..ec963dcb7f 100644 --- a/daemon/graphdriver/btrfs/btrfs.go +++ b/daemon/graphdriver/btrfs/btrfs.go @@ -606,7 +606,7 @@ func (d *Driver) parseStorageOpt(storageOpt map[string]string, driver *Driver) e // Set btrfs storage size 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))) } if d.options.minSpace > 0 && driver.options.size < d.options.minSpace { From 6d9c219c549ba9e6b48e945dce3c9e4e64214850 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 13 Oct 2019 22:10:24 +0200 Subject: [PATCH 08/15] daemon: S1033: unnecessary guard around call to delete (gosimple) ``` daemon/container_operations.go:787:2: S1033: unnecessary guard around call to delete (gosimple) if _, ok := container.NetworkSettings.Networks[n.ID()]; ok { ^ ``` Signed-off-by: Sebastiaan van Stijn --- daemon/config/config.go | 4 +--- daemon/container_operations.go | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/daemon/config/config.go b/daemon/config/config.go index 0fbd81f021..b04d5bb961 100644 --- a/daemon/config/config.go +++ b/daemon/config/config.go @@ -493,9 +493,7 @@ func findConfigurationConflicts(config map[string]interface{}, flags *pflag.Flag if len(unknownKeys) > 0 { unknownNamedConflicts := func(f *pflag.Flag) { 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) diff --git a/daemon/container_operations.go b/daemon/container_operations.go index 205c090501..498a7fc8cb 100644 --- a/daemon/container_operations.go +++ b/daemon/container_operations.go @@ -784,9 +784,8 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName EndpointSettings: endpointConfig, 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 { return err From af3bbcc00ceb0197bd22c46666affcf1a9724479 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 14 Oct 2019 00:57:38 +0200 Subject: [PATCH 09/15] aufs: SA4011: did you mean to break out of the outer loop? (staticcheck) As caught by staticcheck (after disabling the default exclusion rules); Based on the comment, this break was indeed meant to break the loop and return the error. ``` daemon/graphdriver/aufs/mount.go:54:4: SA4011: ineffective break statement. Did you mean to break out of the outer loop? (staticcheck) break ^ ``` Signed-off-by: Sebastiaan van Stijn --- daemon/graphdriver/aufs/mount.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/graphdriver/aufs/mount.go b/daemon/graphdriver/aufs/mount.go index 83970d4dbe..3c5f70d644 100644 --- a/daemon/graphdriver/aufs/mount.go +++ b/daemon/graphdriver/aufs/mount.go @@ -51,7 +51,7 @@ func Unmount(target string) error { continue // try again default: // any other error is fatal - break + return err } } From 4840fd895328da757bd67b6be212f86cae8f93eb Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 14 Oct 2019 02:04:51 +0200 Subject: [PATCH 10/15] pkg/mount: SA4011: ineffective break statement (staticcheck) ``` pkg/mount/mountinfo_linux.go:93:5: SA4011: ineffective break statement. Did you mean to break out of the outer loop? (staticcheck) break ^ ``` Signed-off-by: Sebastiaan van Stijn --- pkg/mount/mountinfo_linux.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/mount/mountinfo_linux.go b/pkg/mount/mountinfo_linux.go index fe6e3ddba1..58ca61f3f7 100644 --- a/pkg/mount/mountinfo_linux.go +++ b/pkg/mount/mountinfo_linux.go @@ -90,7 +90,6 @@ func parseInfoFile(r io.Reader, filter FilterFunc) ([]*Info, error) { mount propagation flags in fields[6]. The correct behavior is to ignore any unknown optional fields. */ - break } } if i == numFields { From 47502344b9aab6919f0b426e037b68e899735abd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 14 Oct 2019 02:07:51 +0200 Subject: [PATCH 11/15] golangci-lint: update exclusion rules for todo's Signed-off-by: Sebastiaan van Stijn --- hack/validate/golangci-lint.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/hack/validate/golangci-lint.yml b/hack/validate/golangci-lint.yml index f3d0377495..b683229f83 100644 --- a/hack/validate/golangci-lint.yml +++ b/hack/validate/golangci-lint.yml @@ -40,10 +40,7 @@ issues: - errcheck - gosec - - text: "G201: SQL string formatting" - linters: - - gosec - - text: "G202: SQL string concatenation" + - text: "(G201|G202): SQL string (formatting|concatenation)" linters: - gosec # FIXME temporarily suppress these. See #39928 @@ -51,11 +48,7 @@ issues: linters: - staticcheck # FIXME temporarily suppress these. See #39924 - - text: "SA1019: h.Xattrs is deprecated: Use PAXRecords instead" - linters: - - staticcheck - # FIXME temporarily suppress these. See #39924 - - text: "SA1019: hdr.Xattrs is deprecated: Use PAXRecords instead" + - text: "SA1019: .*\\.Xattrs is deprecated: Use PAXRecords instead" linters: - staticcheck # FIXME temporarily suppress these. See #39926 @@ -66,3 +59,7 @@ issues: - text: "SA1019: httputil.ClientConn is deprecated" linters: - staticcheck + # FIXME temporarily suppress these (related to the ones above) + - text: "SA1019: httputil.ErrPersistEOF is deprecated" + linters: + - staticcheck From fe3c14d5ba35a5e41929d90f8fa6111a92d80d97 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 14 Oct 2019 02:11:40 +0200 Subject: [PATCH 12/15] golangci-lint: fix "golint" not ignoring generated files Signed-off-by: Sebastiaan van Stijn --- hack/validate/golangci-lint.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hack/validate/golangci-lint.yml b/hack/validate/golangci-lint.yml index b683229f83..b1dd1b69d9 100644 --- a/hack/validate/golangci-lint.yml +++ b/hack/validate/golangci-lint.yml @@ -22,12 +22,6 @@ linters: - bundles - docs - skip-files: - - ".*\\.pb\\.go" - - "dockerversion/version_autogen.go" - - "api/types/container/container_.*" - - "api/types/volume/volume_.*" - linters-settings: govet: check-shadowing: false @@ -40,6 +34,11 @@ issues: - errcheck - gosec + # 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: + - golint - text: "(G201|G202): SQL string (formatting|concatenation)" linters: - gosec From 086b4541cf9d27d9c2654f316a6f69b0d9caedd9 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 14 Oct 2019 02:13:32 +0200 Subject: [PATCH 13/15] golangci-lint: disable default exclusion rules The default exclusion rules were too permissive; disable them, but copy the relevant ones to the configuation. Signed-off-by: Sebastiaan van Stijn --- hack/validate/golangci-lint.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/hack/validate/golangci-lint.yml b/hack/validate/golangci-lint.yml index b1dd1b69d9..76a00cec99 100644 --- a/hack/validate/golangci-lint.yml +++ b/hack/validate/golangci-lint.yml @@ -27,7 +27,35 @@ linters-settings: check-shadowing: false issues: + # The default exclusion rules are a bit too permissive, so copying the relevant ones below + exclude-use-default: false + 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. - path: _test\.go linters: From a06d7f5a3e22f69ca9eccb56cf4e4fa53faa84ff Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 14 Oct 2019 02:15:48 +0200 Subject: [PATCH 14/15] golangci-lint: include all enabled linters in config This makes it clearer from the configuration what linters are enabled. Also disables the `gofmt` linter, because it's superseded by the `goimports` linter. Signed-off-by: Sebastiaan van Stijn --- hack/validate/golangci-lint.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hack/validate/golangci-lint.yml b/hack/validate/golangci-lint.yml index 76a00cec99..e547c09917 100644 --- a/hack/validate/golangci-lint.yml +++ b/hack/validate/golangci-lint.yml @@ -1,7 +1,6 @@ linters: enable: - deadcode - - gofmt - goimports - golint - gosec @@ -9,7 +8,12 @@ linters: - govet - ineffassign - misspell + - staticcheck + - structcheck + - typecheck - unconvert + - unused + - varcheck disable: - errcheck From 9cb9c6eba4f13b7aade4ed406a8990b41b1439b9 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 19 Sep 2019 17:59:26 +0200 Subject: [PATCH 15/15] bump golangci-lint v1.20.0 release notes: - v1.20.0: https://github.com/golangci/golangci-lint/releases/tag/v1.20.0 - Add WSL linter (#771) - Add gocognit linter (#756) - govet: add more analyzers - dramatically reduce memory usage - reduce 1.5x memory usage on large repos on repeated runs - Rename deadline option to timeout and mark deadline as deprecated - v1.19.1: https://github.com/golangci/golangci-lint/releases/tag/v1.19.1 - v1.19.0: https://github.com/golangci/golangci-lint/releases/tag/v1.19.0 - Add dogsled linter. - Add whitespace linter - Add Godox linter support - Various performance optimizations - v1.18.0: https://github.com/golangci/golangci-lint/releases/tag/v1.18.0 - Support go1.13 - Update format of junit xml output to mark failures as such - Speed up linting: use deduplicated packages - Add user supplied error messages in depguard issues - Add funlen linter Signed-off-by: Sebastiaan van Stijn --- hack/dockerfile/install/golangci_lint.installer | 12 ++++++++++-- hack/validate/golangci-lint | 7 ++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/hack/dockerfile/install/golangci_lint.installer b/hack/dockerfile/install/golangci_lint.installer index 198f8a76b2..26895bcefa 100755 --- a/hack/dockerfile/install/golangci_lint.installer +++ b/hack/dockerfile/install/golangci_lint.installer @@ -1,11 +1,19 @@ #!/bin/sh -: "${GOLANGCI_LINT_COMMIT=v1.17.1}" +: "${GOLANGCI_LINT_COMMIT=v1.20.0}" install_golangci_lint() { echo "Installing golangci-lint version ${GOLANGCI_LINT_COMMIT}" go get -d github.com/golangci/golangci-lint/cmd/golangci-lint cd "$GOPATH/src/github.com/golangci/golangci-lint/" || exit 1 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" } diff --git a/hack/validate/golangci-lint b/hack/validate/golangci-lint index 41750f6e26..02fcf50ff7 100755 --- a/hack/validate/golangci-lint +++ b/hack/validate/golangci-lint @@ -6,7 +6,7 @@ SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # CI platforms differ, so per-platform GOLANGCI_LINT_OPTS can be set # from a platform-specific Dockerfile, otherwise let's just set # (somewhat pessimistic) default of 10 minutes. -: ${GOLANGCI_LINT_OPTS=--deadline=20m} +: "${GOLANGCI_LINT_OPTS=--timeout=10m}" [ -n "${TESTDEBUG}" ] && set -x @@ -18,9 +18,10 @@ elif ${PKG_CONFIG} 'libsystemd-journal' 2> /dev/null ; then fi # 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} \ --print-resources-usage \ --build-tags="${DOCKER_BUILDTAGS}" \ --verbose \ - --config ${SCRIPTDIR}/golangci-lint.yml + --config "${SCRIPTDIR}/golangci-lint.yml"