From 2e20eadb1c0a6668853e4b3ad3e139beeb1daf6a Mon Sep 17 00:00:00 2001 From: Eric Chlebek Date: Mon, 7 Feb 2022 18:06:07 -0800 Subject: [PATCH] Add staticcheck github action (#4489) * Add staticcheck github action Signed-off-by: Eric Chlebek * Tweak Signed-off-by: Eric Chlebek * add staticcheck.conf, remove golangci-lint Signed-off-by: Justin Kolberg * remove duplicate imports Signed-off-by: Justin Kolberg * add staticcheck & fix failing checks Signed-off-by: Justin Kolberg Co-authored-by: Justin Kolberg --- .github/workflows/golangci-lint.yml | 89 ---------------------- .github/workflows/static-check.yml | 25 ++++++ .golangci.yml | 4 - agent/statsd.go | 7 +- agent/statsd_server_solaris.go | 5 +- backend/apid/graphql/check.go | 5 +- backend/apid/graphql/entity_test.go | 3 +- backend/apid/graphql/filter/filter.go | 16 ++-- backend/apid/graphql/filter/filter_test.go | 2 +- backend/apid/graphql/mutator_test.go | 3 +- backend/cmd/init.go | 1 + backend/keepalived/keepalived_test.go | 3 +- backend/pipeline/filter/legacy.go | 8 +- backend/pipeline/mutator/javascript.go | 6 +- backend/store/etag.go | 2 - backend/store/etcd/namespace_store.go | 23 +++--- cli/client/authentication.go | 4 + cli/cmdmanager/manager.go | 2 +- cli/commands/hook/interactive.go | 1 + cli/commands/hooks/ensure_configured.go | 2 + cli/commands/user/create.go | 1 + staticcheck.conf | 46 +++++++++++ util/environment/environment.go | 8 +- 23 files changed, 123 insertions(+), 143 deletions(-) delete mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .github/workflows/static-check.yml delete mode 100644 .golangci.yml create mode 100644 staticcheck.conf diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index cc371070e0..0000000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,89 +0,0 @@ -name: golangci-lint - -on: - push: - tags: - - 'v*' - branches: - - main - pull_request: - branches: - - '**' - -env: - GO_VERSION: 1.17.6 - GOLANGCI_LINT_VERSION: v1.42.1 - -jobs: - lint: - name: lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: "${{ env.GO_VERSION }}" - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: "${{ env.GOLANGCI_LINT_VERSION }}" - args: --timeout=5m - lint-api-core-v2-mod: - name: lint-api-core-v2-mod - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: "${{ env.GO_VERSION }}" - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: "${{ env.GOLANGCI_LINT_VERSION }}" - working-directory: api/core/v2 - args: --timeout=5m - lint-api-core-v3-mod: - name: lint-api-core-v3-mod - runs-on: ubuntu-latest - env: - GOSUMDB: off - GOPROXY: direct - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: "${{ env.GO_VERSION }}" - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: "${{ env.GOLANGCI_LINT_VERSION }}" - working-directory: api/core/v3 - args: --timeout=5m - lint-backend-store-v2-mod: - name: lint-backend-store-v2-mod - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: "${{ env.GO_VERSION }}" - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: "${{ env.GOLANGCI_LINT_VERSION }}" - working-directory: backend/store/v2 - args: --timeout=5m - lint-types-mod: - name: lint-types-mod - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-go@v2 - with: - go-version: "${{ env.GO_VERSION }}" - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 - with: - version: "${{ env.GOLANGCI_LINT_VERSION }}" - working-directory: types - args: --timeout=5m diff --git a/.github/workflows/static-check.yml b/.github/workflows/static-check.yml new file mode 100644 index 0000000000..824e246e0a --- /dev/null +++ b/.github/workflows/static-check.yml @@ -0,0 +1,25 @@ +name: static-check + +on: + push: + tags: + - 'v*' + branches: + - main + pull_request: + branches: + - '*' + +jobs: + staticcheck: + name: staticcheck (project) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + with: + fetch-depth: 1 + - uses: dominikh/staticcheck-action@v1.0.0 + with: + version: "2021.1.1" +env: + GO_VERSION: 1.17.1 diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index 3245445787..0000000000 --- a/.golangci.yml +++ /dev/null @@ -1,4 +0,0 @@ -run: - timeout: 5m - build-tags: - - integration diff --git a/agent/statsd.go b/agent/statsd.go index c0c811043e..b4050fb36a 100644 --- a/agent/statsd.go +++ b/agent/statsd.go @@ -5,8 +5,11 @@ import ( "errors" ) -// StatsdUnsupported is returned when statsd can't be supported on the platform. -var StatsdUnsupported = errors.New("statsd not supported on this platform") +// ErrStatsdUnsupported is returned when statsd can't be supported on the platform. +var ErrStatsdUnsupported = errors.New("statsd not supported on this platform") + +// DEPRECATED: use ErrStatsdUnsupported +var StatsdUnsupported = ErrStatsdUnsupported // StatsdServer is the interface the agent requires to run a statsd server. type StatsdServer interface { diff --git a/agent/statsd_server_solaris.go b/agent/statsd_server_solaris.go index 186874f2c8..dce5d422e0 100644 --- a/agent/statsd_server_solaris.go +++ b/agent/statsd_server_solaris.go @@ -11,11 +11,10 @@ func GetMetricsAddr(s StatsdServer) string { // statsdServer is a no-op statsd server for solaris support. // the gostatsd package requires a library that can't be built on solaris. -type statsdServer struct { -} +type statsdServer struct{} func (s statsdServer) Run(context.Context) error { - return StatsdUnsupported + return ErrStatsdUnsupported } func NewStatsdServer(*Agent) statsdServer { diff --git a/backend/apid/graphql/check.go b/backend/apid/graphql/check.go index 8b748f50dc..4d039e6caa 100644 --- a/backend/apid/graphql/check.go +++ b/backend/apid/graphql/check.go @@ -5,7 +5,6 @@ import ( "github.com/graphql-go/graphql" corev2 "github.com/sensu/sensu-go/api/core/v2" - v2 "github.com/sensu/sensu-go/api/core/v2" "github.com/sensu/sensu-go/backend/apid/graphql/globalid" "github.com/sensu/sensu-go/backend/apid/graphql/schema" "github.com/sensu/sensu-go/types" @@ -91,7 +90,7 @@ func checkIsSilencedBy(check interface { // ToJSON implements response to request for 'toJSON' field. func (r *checkCfgImpl) ToJSON(p graphql.ResolveParams) (interface{}, error) { - return types.WrapResource(p.Source.(v2.Resource)), nil + return types.WrapResource(p.Source.(corev2.Resource)), nil } // RuntimeAssets implements response to request for 'runtimeAssets' field. @@ -226,7 +225,7 @@ func (r *checkImpl) RuntimeAssets(p graphql.ResolveParams) (interface{}, error) // ToJSON implements response to request for 'toJSON' field. func (r *checkImpl) ToJSON(p graphql.ResolveParams) (interface{}, error) { - return types.WrapResource(p.Source.(v2.Resource)), nil + return types.WrapResource(p.Source.(corev2.Resource)), nil } // diff --git a/backend/apid/graphql/entity_test.go b/backend/apid/graphql/entity_test.go index bd1c757489..e912107283 100644 --- a/backend/apid/graphql/entity_test.go +++ b/backend/apid/graphql/entity_test.go @@ -7,7 +7,6 @@ import ( "time" corev2 "github.com/sensu/sensu-go/api/core/v2" - v2 "github.com/sensu/sensu-go/api/core/v2" "github.com/sensu/sensu-go/backend/apid/graphql/schema" "github.com/sensu/sensu-go/graphql" "github.com/stretchr/testify/assert" @@ -22,7 +21,7 @@ func TestEntityTypeMetadataField(t *testing.T) { res, err := impl.Metadata(graphql.ResolveParams{Source: src, Context: context.Background()}) require.NoError(t, err) assert.NotEmpty(t, res) - assert.IsType(t, v2.ObjectMeta{}, res) + assert.IsType(t, corev2.ObjectMeta{}, res) } func TestEntityTypeRelatedField(t *testing.T) { diff --git a/backend/apid/graphql/filter/filter.go b/backend/apid/graphql/filter/filter.go index a23d3ccfd6..f7303a14c4 100644 --- a/backend/apid/graphql/filter/filter.go +++ b/backend/apid/graphql/filter/filter.go @@ -8,11 +8,15 @@ import ( ) var ( - // KeylessStatementErr statement is missing a key - KeylessStatementErr = errors.New("filters must have the format KEY:VAL") + // ErrKeylessStatement is returned when a statement is missing a key + ErrKeylessStatement = errors.New("filters must have the format KEY:VAL") + // DEPRECATED: use ErrKeylessStatement + KeylessStatementErr = ErrKeylessStatement - // FilterNotFoundErr could not match a filter for the given key - FilterNotFoundErr = errors.New("no filter could be matched with the given statement") + // ErrFilterNotFound is returned when a filter is not found for a given key + ErrFilterNotFound = errors.New("no filter could be matched with the given statement") + // DEPRECATED: use ErrFilterNotFound + FilterNotFoundErr = ErrFilterNotFound ) // Match a given resource @@ -35,12 +39,12 @@ func Compile(statements []string, filters map[string]Filter, fieldsFn FieldsFunc for _, s := range statements { ss := strings.SplitN(s, statementSeparator, 2) if len(ss) != 2 { - return nil, KeylessStatementErr + return nil, ErrKeylessStatement } k, v := ss[0], ss[1] f, ok := filters[k] if !ok { - return nil, FilterNotFoundErr + return nil, ErrFilterNotFound } matcher, err := f(v, fieldsFn) if err != nil { diff --git a/backend/apid/graphql/filter/filter_test.go b/backend/apid/graphql/filter/filter_test.go index 44deb97a72..a61112a47c 100644 --- a/backend/apid/graphql/filter/filter_test.go +++ b/backend/apid/graphql/filter/filter_test.go @@ -21,7 +21,7 @@ func TestCompile(t *testing.T) { // statement doesn't match a filter m, err = Compile([]string{"unknown:test"}, filters, nil) - require.Error(t, err, KeylessStatementErr) + require.Error(t, err, ErrKeylessStatement) assert.Nil(t, m) // statement is not valid diff --git a/backend/apid/graphql/mutator_test.go b/backend/apid/graphql/mutator_test.go index d5ca15333a..78105ecca4 100644 --- a/backend/apid/graphql/mutator_test.go +++ b/backend/apid/graphql/mutator_test.go @@ -5,14 +5,13 @@ import ( "testing" corev2 "github.com/sensu/sensu-go/api/core/v2" - v2 "github.com/sensu/sensu-go/api/core/v2" "github.com/sensu/sensu-go/graphql" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestMutatorTypeToJSONField(t *testing.T) { - src := v2.FixtureMutator("name") + src := corev2.FixtureMutator("name") imp := &mutatorImpl{} res, err := imp.ToJSON(graphql.ResolveParams{Source: src, Context: context.Background()}) diff --git a/backend/cmd/init.go b/backend/cmd/init.go index 1cbf4a4147..666d4c7d47 100644 --- a/backend/cmd/init.go +++ b/backend/cmd/init.go @@ -175,6 +175,7 @@ func InitCommand() *cobra.Command { return err } if opts.AdminPassword != opts.AdminPasswordConfirmation { + //lint:ignore ST1005 this error is written to stdout/stderr return errors.New("Password confirmation doesn't match the password") } initConfig.SeedConfig.AdminUsername = opts.AdminUsername diff --git a/backend/keepalived/keepalived_test.go b/backend/keepalived/keepalived_test.go index 9ca8f5c9e7..981e5a9a65 100644 --- a/backend/keepalived/keepalived_test.go +++ b/backend/keepalived/keepalived_test.go @@ -10,7 +10,6 @@ import ( "github.com/sensu/sensu-go/backend/liveness" "github.com/sensu/sensu-go/backend/messaging" stor "github.com/sensu/sensu-go/backend/store" - storev2 "github.com/sensu/sensu-go/backend/store/v2" storv2 "github.com/sensu/sensu-go/backend/store/v2" "github.com/sensu/sensu-go/backend/store/v2/storetest" "github.com/sensu/sensu-go/backend/store/v2/wrap" @@ -429,7 +428,7 @@ func TestDeadCallbackNoEvent(t *testing.T) { t.Fatal(err) } - wrapper, err := storev2.WrapResource( + wrapper, err := storv2.WrapResource( corev3.FixtureEntityConfig("entity1"), []wrap.Option{wrap.CompressNone, wrap.EncodeJSON}...) require.NoError(t, err) diff --git a/backend/pipeline/filter/legacy.go b/backend/pipeline/filter/legacy.go index 1ecdf58b99..7d411ce47e 100644 --- a/backend/pipeline/filter/legacy.go +++ b/backend/pipeline/filter/legacy.go @@ -28,7 +28,7 @@ var ( "not_silenced", } - getFilterErr = errors.New("could not retrieve filter") + errCouldNotRetrieveFilter = errors.New("could not retrieve filter") // PipelineFilterFuncs gets patched by enterprise sensu-go PipelineFilterFuncs map[string]interface{} @@ -77,12 +77,12 @@ func (l *LegacyAdapter) Filter(ctx context.Context, ref *corev2.ResourceReferenc filter, err := l.Store.GetEventFilterByName(tctx, ref.Name) cancel() if err != nil { - logger.WithFields(fields).WithError(err).Warning(getFilterErr.Error()) + logger.WithFields(fields).WithError(err).Warning(errCouldNotRetrieveFilter.Error()) return false, err } if filter == nil { - logger.WithFields(fields).WithError(err).Warning(getFilterErr.Error()) - return false, fmt.Errorf(getFilterErr.Error()) + logger.WithFields(fields).WithError(err).Warning(errCouldNotRetrieveFilter.Error()) + return false, fmt.Errorf(errCouldNotRetrieveFilter.Error()) } // Execute the filter, evaluating each of its diff --git a/backend/pipeline/mutator/javascript.go b/backend/pipeline/mutator/javascript.go index 220ce3a40f..f0127ec7ab 100644 --- a/backend/pipeline/mutator/javascript.go +++ b/backend/pipeline/mutator/javascript.go @@ -23,7 +23,7 @@ const ( ) var ( - halt = errors.New("halt") + errHalt = errors.New("halt") ) // JavascriptAdapter is a mutator adapter which mutates an event using @@ -146,7 +146,7 @@ func (m *MutatorExecutionEnvironment) Eval(ctx context.Context, expression strin } vm.Interrupt = make(chan func(), 1) defer func() { - if e := recover(); e != nil && e == halt { + if e := recover(); e != nil && e == errHalt { err = errors.New("mutator timeout reached, execution halted") } else if e != nil { panic(e) @@ -158,7 +158,7 @@ func (m *MutatorExecutionEnvironment) Eval(ctx context.Context, expression strin select { case <-time.After(m.Timeout): vm.Interrupt <- func() { - panic(halt) + panic(errHalt) } case <-done: } diff --git a/backend/store/etag.go b/backend/store/etag.go index 97fa7bc88b..5a76491e7d 100644 --- a/backend/store/etag.go +++ b/backend/store/etag.go @@ -104,8 +104,6 @@ func scanETag(header string) (string, string) { case c == 0x21 || c >= 0x23 && c <= 0x7E || c >= 0x80: case c == '"': return string(header[:i+1]), header[i+1:] - default: - break } } diff --git a/backend/store/etcd/namespace_store.go b/backend/store/etcd/namespace_store.go index d9ea50e97a..9a12000a09 100644 --- a/backend/store/etcd/namespace_store.go +++ b/backend/store/etcd/namespace_store.go @@ -9,8 +9,7 @@ import ( corev2 "github.com/sensu/sensu-go/api/core/v2" "github.com/sensu/sensu-go/backend/store" "github.com/sensu/sensu-go/backend/store/etcd/kvc" - "go.etcd.io/etcd/client/v3" - v3 "go.etcd.io/etcd/client/v3" + clientv3 "go.etcd.io/etcd/client/v3" ) const ( @@ -42,10 +41,10 @@ func (s *Store) CreateNamespace(ctx context.Context, namespace *corev2.Namespace res, err := s.client.Txn(ctx). If( // Ensure the namespace does not already exist - v3.Compare(v3.Version(namespaceKey), "=", 0)). + clientv3.Compare(clientv3.Version(namespaceKey), "=", 0)). Then( // Create it - v3.OpPut(namespaceKey, string(namespaceBytes)), + clientv3.OpPut(namespaceKey, string(namespaceBytes)), ).Commit() if err != nil { return &store.ErrInternal{Message: err.Error()} @@ -68,14 +67,14 @@ func (s *Store) DeleteNamespace(ctx context.Context, name string) error { err := kvc.Backoff(ctx).Retry(func(n int) (done bool, err error) { // Validate whether there are any resources referencing the namespace getresp, err = s.client.Txn(ctx).Then( - v3.OpGet(checkKeyBuilder.WithNamespace(name).Build(), v3.WithPrefix(), v3.WithCountOnly()), - v3.OpGet(entityConfigKeyBuilder.WithNamespace(name).Build(), v3.WithPrefix(), v3.WithCountOnly()), - v3.OpGet(assetKeyBuilder.WithNamespace(name).Build(), v3.WithPrefix(), v3.WithCountOnly()), - v3.OpGet(handlerKeyBuilder.WithNamespace(name).Build(), v3.WithPrefix(), v3.WithCountOnly()), - v3.OpGet(mutatorKeyBuilder.WithNamespace(name).Build(), v3.WithPrefix(), v3.WithCountOnly()), - v3.OpGet(eventFilterKeyBuilder.WithNamespace(name).Build(), v3.WithPrefix(), v3.WithCountOnly()), - v3.OpGet(hookKeyBuilder.WithNamespace(name).Build(), v3.WithPrefix(), v3.WithCountOnly()), - v3.OpGet(silencedKeyBuilder.WithNamespace(name).Build(), v3.WithPrefix(), v3.WithCountOnly()), + clientv3.OpGet(checkKeyBuilder.WithNamespace(name).Build(), clientv3.WithPrefix(), clientv3.WithCountOnly()), + clientv3.OpGet(entityConfigKeyBuilder.WithNamespace(name).Build(), clientv3.WithPrefix(), clientv3.WithCountOnly()), + clientv3.OpGet(assetKeyBuilder.WithNamespace(name).Build(), clientv3.WithPrefix(), clientv3.WithCountOnly()), + clientv3.OpGet(handlerKeyBuilder.WithNamespace(name).Build(), clientv3.WithPrefix(), clientv3.WithCountOnly()), + clientv3.OpGet(mutatorKeyBuilder.WithNamespace(name).Build(), clientv3.WithPrefix(), clientv3.WithCountOnly()), + clientv3.OpGet(eventFilterKeyBuilder.WithNamespace(name).Build(), clientv3.WithPrefix(), clientv3.WithCountOnly()), + clientv3.OpGet(hookKeyBuilder.WithNamespace(name).Build(), clientv3.WithPrefix(), clientv3.WithCountOnly()), + clientv3.OpGet(silencedKeyBuilder.WithNamespace(name).Build(), clientv3.WithPrefix(), clientv3.WithCountOnly()), ).Commit() return kvc.RetryRequest(n, err) }) diff --git a/cli/client/authentication.go b/cli/client/authentication.go index 0cfb31d740..8b0917588c 100644 --- a/cli/client/authentication.go +++ b/cli/client/authentication.go @@ -46,6 +46,7 @@ func (client *RestClient) TestCreds(userid, password string) error { if res.StatusCode() == 401 { return errors.New(string(res.Body())) } else if res.StatusCode() >= 400 { + //lint:ignore ST1005 this error is written to stdout/stderr return errors.New("Received an unexpected response from the API") } @@ -63,6 +64,7 @@ func (client *RestClient) Logout(token string) error { } if res.StatusCode() >= 400 { + //lint:ignore ST1005 this error is written to stdout/stderr return fmt.Errorf("The server returned the error: %d %s", res.StatusCode(), res.String(), @@ -112,6 +114,7 @@ func (client *RestClient) RefreshAccessToken(tokens *corev2.Tokens) (*corev2.Tok } if res.StatusCode() >= 400 { + //lint:ignore ST1005 this error is written to stdout/stderr return nil, fmt.Errorf("The server returned the error: %d %s", res.StatusCode(), res.String(), @@ -120,6 +123,7 @@ func (client *RestClient) RefreshAccessToken(tokens *corev2.Tokens) (*corev2.Tok tokens, ok := res.Result().(*corev2.Tokens) if !ok { + //lint:ignore ST1005 this error is written to stdout/stderr return nil, fmt.Errorf("Unable to unmarshal response from server") } diff --git a/cli/cmdmanager/manager.go b/cli/cmdmanager/manager.go index 9fcaa71aeb..49bd474b9e 100644 --- a/cli/cmdmanager/manager.go +++ b/cli/cmdmanager/manager.go @@ -170,7 +170,7 @@ func (m *CommandManager) InstallCommandFromBonsai(alias, bonsaiAssetName string) asset, ok := wrapper.Value.(*corev2.Asset) if !ok { - return fmt.Errorf("bonsai returned %s.%s, want core/v2.Asset!", wrapper.APIVersion, wrapper.Type) + return fmt.Errorf("bonsai returned %s.%s, want core/v2.Asset", wrapper.APIVersion, wrapper.Type) } asset.Namespace = sensuctlAssetNamespace diff --git a/cli/commands/hook/interactive.go b/cli/commands/hook/interactive.go index 9aff1032f7..1f1d811a93 100644 --- a/cli/commands/hook/interactive.go +++ b/cli/commands/hook/interactive.go @@ -102,6 +102,7 @@ func (opts *hookOpts) administerQuestionnaire(editing bool) error { }, Validate: func(val interface{}) error { if str, ok := val.(string); ok && str != "false" && str != "true" { + //lint:ignore ST1005 this error is written to stdout/stderr return fmt.Errorf("Please enter either true or false") } return nil diff --git a/cli/commands/hooks/ensure_configured.go b/cli/commands/hooks/ensure_configured.go index e2f2ed6dba..3459393a5d 100644 --- a/cli/commands/hooks/ensure_configured.go +++ b/cli/commands/hooks/ensure_configured.go @@ -39,6 +39,7 @@ func ConfigurationPresent(cmd *cobra.Command, cli *cli.SensuCli) error { tokens := cli.Config.Tokens() if cli.Config.APIUrl() == "" { + //lint:ignore ST1005 this error is written to stdout/stderr return fmt.Errorf( "No API URL is defined. You can either configure an API URL by running \"%s configure\" "+ "or by using the --api-url command line option", @@ -47,6 +48,7 @@ func ConfigurationPresent(cmd *cobra.Command, cli *cli.SensuCli) error { } if (tokens == nil || tokens.Access == "") && cli.Config.APIKey() == "" { + //lint:ignore ST1005 this error is written to stdout/stderr return fmt.Errorf( "Unable to locate credentials. You can either configure credentials by running \"%s configure\" "+ "or by using the --api-key command line option", diff --git a/cli/commands/user/create.go b/cli/commands/user/create.go index 7f6a4f3d8d..9a33064cb0 100644 --- a/cli/commands/user/create.go +++ b/cli/commands/user/create.go @@ -55,6 +55,7 @@ func CreateCommand(cli *cli.SensuCli) *cobra.Command { } if isInteractive && opts.Password != opts.PasswordConfirmation { + //lint:ignore ST1005 this error is written to stdout/stderr return errors.New("Password confirmation doesn't match the password") } user := opts.toUser() diff --git a/staticcheck.conf b/staticcheck.conf new file mode 100644 index 0000000000..fbdb5abe4b --- /dev/null +++ b/staticcheck.conf @@ -0,0 +1,46 @@ +checks = [ + # Enable all checks + "all", + + # Disable SA1019 + # Using a deprecated function, variable, constant or field. + # https://staticcheck.io/docs/checks#SA1019 + "-SA1019", + + # Disable ST1000 + # Incorrect or missing package comment. + # https://staticcheck.io/docs/checks#ST1000 + "-ST1000", + + # Disable ST1003 + # ST1003 - Poorly chosen identifier. + # https://staticcheck.io/docs/checks#ST1003 + "-ST1003", + + # Disable ST1016 + # Use consistent method receiver names. + # https://staticcheck.io/docs/checks#ST1016 + "-ST1016", + + # Disable ST1020 + # The documentation of an exported function should start with the + # function’s name. + # https://staticcheck.io/docs/checks#ST1020 + "-ST1020", + + # Disable ST1021 + # The documentation of an exported type should start with type’s name. + # https://staticcheck.io/docs/checks#ST1021 + "-ST1021", + + # Disable ST1022 + # The documentation of an exported variable or constant should start + # with variable’s name. + # https://staticcheck.io/docs/checks#ST1022 + "-ST1022", + + # Disable ST1023 + # Redundant type in variable declaration. + # https://staticcheck.io/docs/checks#ST1023 + "-ST1023", +] diff --git a/util/environment/environment.go b/util/environment/environment.go index 0722c0836a..1176e3d4aa 100644 --- a/util/environment/environment.go +++ b/util/environment/environment.go @@ -57,10 +57,7 @@ func toMap(s []string) map[string]string { switch len(split) { case 1: - if split[0] == v { - // There is no '=' in the input, consider it malformed - break - } else { + if split[0] != v { // We came across VAR=, which is equivalent to VAR="" m[split[0]] = "" } @@ -69,9 +66,6 @@ func toMap(s []string) map[string]string { key := coerceKey(split[0]) // A proper VAR=VALUE definiton m[key] = split[1] - default: - // Anything else is considered malformed and ignored - break } }