From 1d7e6a3ca81beab666c8166ff9bb7887c9a075fa Mon Sep 17 00:00:00 2001 From: Tanmay Chaudhry Date: Tue, 28 Jun 2022 10:55:13 +0530 Subject: [PATCH 1/2] Ignore/Fix all remaining staticcheck errors Signed-off-by: Tanmay Chaudhry --- pkg/cnab/cnab-to-oci/registry.go | 2 +- pkg/cnab/provider/runtime.go | 3 ++- pkg/config/loader.go | 2 +- pkg/plugins/pluggable/loader.go | 2 +- pkg/porter/helpers.go | 1 - pkg/porter/lifecycle_test.go | 7 +++++-- pkg/porter/parameters.go | 1 + pkg/porter/stamp.go | 2 +- pkg/porter/upgrade.go | 1 + pkg/runtime/runtime-manifest.go | 1 + pkg/runtime/runtime-manifest_test.go | 2 +- pkg/secrets/plugins/filesystem/store.go | 2 +- pkg/storage/installation_store_test.go | 2 ++ pkg/storage/migrations/manager.go | 1 + pkg/storage/parameter_store_test.go | 4 ++-- pkg/storage/plugins/mongodb/mongodb.go | 1 - pkg/test/logger.go | 1 + staticcheck.conf | 4 ++++ tests/tester/helpers.go | 1 + 19 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 staticcheck.conf diff --git a/pkg/cnab/cnab-to-oci/registry.go b/pkg/cnab/cnab-to-oci/registry.go index b25f7bce5..d15e97bc8 100644 --- a/pkg/cnab/cnab-to-oci/registry.go +++ b/pkg/cnab/cnab-to-oci/registry.go @@ -17,8 +17,8 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/pkg/jsonmessage" - "github.com/docker/docker/pkg/term" "github.com/google/go-containerregistry/pkg/crane" + "github.com/moby/term" "github.com/opencontainers/go-digest" ) diff --git a/pkg/cnab/provider/runtime.go b/pkg/cnab/provider/runtime.go index e26a5f993..5e8557c71 100644 --- a/pkg/cnab/provider/runtime.go +++ b/pkg/cnab/provider/runtime.go @@ -13,7 +13,8 @@ var _ CNABProvider = &Runtime{} type Runtime struct { *config.Config - credentials storage.CredentialSetProvider + credentials storage.CredentialSetProvider + //lint:ignore U1000 unused at the moment, will be used in the future parameters storage.ParameterSetProvider secrets secrets.Store installations storage.InstallationProvider diff --git a/pkg/config/loader.go b/pkg/config/loader.go index 90200713e..c0eb045bd 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -48,7 +48,7 @@ func LoadFromViper(viperCfg func(v *viper.Viper)) DataStoreLoaderFunc { return func(ctx context.Context, cfg *Config, templateData map[string]interface{}) error { home, _ := cfg.GetHomeDir() - ctx, log := tracing.StartSpanWithName(ctx, "LoadFromViper", attribute.String("porter.PORTER_HOME", home)) + _, log := tracing.StartSpanWithName(ctx, "LoadFromViper", attribute.String("porter.PORTER_HOME", home)) defer log.EndSpan() v := viper.New() diff --git a/pkg/plugins/pluggable/loader.go b/pkg/plugins/pluggable/loader.go index 5d5950d60..6032102f8 100644 --- a/pkg/plugins/pluggable/loader.go +++ b/pkg/plugins/pluggable/loader.go @@ -88,7 +88,7 @@ func (l *PluginLoader) Load(ctx context.Context, pluginType PluginTypeConfig) (* // selectPlugin picks the plugin to use and loads its configuration. func (l *PluginLoader) selectPlugin(ctx context.Context, cfg PluginTypeConfig) error { - ctx, span := tracing.StartSpan(ctx) + _, span := tracing.StartSpan(ctx) defer span.EndSpan() l.selectedPluginKey = nil diff --git a/pkg/porter/helpers.go b/pkg/porter/helpers.go index f97cb4425..ec1a9af19 100644 --- a/pkg/porter/helpers.go +++ b/pkg/porter/helpers.go @@ -235,7 +235,6 @@ func (p *TestPorter) CompareGoldenFile(goldenFile string, got string) { // CreateInstallation saves an installation record into claim store and store // sensitive parameters into secret store. func (p *TestPorter) SanitizeParameters(raw []secrets.Strategy, recordID string, bun cnab.ExtendedBundle) []secrets.Strategy { - strategies := make([]secrets.Strategy, 0, len(raw)) strategies, err := p.Sanitizer.CleanParameters(context.Background(), raw, bun, recordID) require.NoError(p.T(), err) diff --git a/pkg/porter/lifecycle_test.go b/pkg/porter/lifecycle_test.go index c763d3e97..3207a6ee2 100644 --- a/pkg/porter/lifecycle_test.go +++ b/pkg/porter/lifecycle_test.go @@ -14,8 +14,11 @@ import ( ) var ( - kahn1dot0Hash = "887e7e65e39277f8744bd00278760b06" - kahn1dot01 = cnab.MustParseOCIReference("deislabs/kubekahn:1.0") + //lint:ignore U1000 ignore unused variables + kahn1dot0Hash = "887e7e65e39277f8744bd00278760b06" + //lint:ignore U1000 ignore unused variables + kahn1dot01 = cnab.MustParseOCIReference("deislabs/kubekahn:1.0") + //lint:ignore U1000 ignore unused variables kahnlatestHash = "fd4bbe38665531d10bb653140842a370" kahnlatest = cnab.MustParseOCIReference("deislabs/kubekahn:latest") ) diff --git a/pkg/porter/parameters.go b/pkg/porter/parameters.go index c3309f529..c8d3d77c2 100644 --- a/pkg/porter/parameters.go +++ b/pkg/porter/parameters.go @@ -397,6 +397,7 @@ func (p *Porter) loadParameterSets(ctx context.Context, bun cnab.ExtendedBundle, return resolvedParameters, nil } +//lint:ignore U1000 Ignore unused function func (p *Porter) loadParameterFromFile(path string) (storage.ParameterSet, error) { var cs storage.ParameterSet err := encoding.UnmarshalFile(p.FileSystem, path, &cs) diff --git a/pkg/porter/stamp.go b/pkg/porter/stamp.go index 6017695c1..527a85d8b 100644 --- a/pkg/porter/stamp.go +++ b/pkg/porter/stamp.go @@ -82,7 +82,7 @@ func (p *Porter) IsBundleUpToDate(ctx context.Context, opts bundleFileOptions) ( if !isImageCached { if p.Debug { - fmt.Fprintln(p.Err, errors.New(fmt.Sprintf("Invocation image %s doesn't exist in the local image cache, will need to build first", invocationImage.Image))) + fmt.Fprintln(p.Err, fmt.Errorf("Invocation image %s doesn't exist in the local image cache, will need to build first", invocationImage.Image)) } return false, nil } diff --git a/pkg/porter/upgrade.go b/pkg/porter/upgrade.go index b4f977458..2e97e2ccf 100644 --- a/pkg/porter/upgrade.go +++ b/pkg/porter/upgrade.go @@ -35,6 +35,7 @@ func (o UpgradeOptions) Validate(ctx context.Context, args []string, p *Porter) if err != nil { return errors.New("invalid bundle version --version. Must be a semantic version, for example 1.2.3") } + //lint:ignore SA4005 the bundle options are validated below, so ignore ineffective assignment warning o.Version = v.String() } diff --git a/pkg/runtime/runtime-manifest.go b/pkg/runtime/runtime-manifest.go index 9b7649e52..82830aa97 100644 --- a/pkg/runtime/runtime-manifest.go +++ b/pkg/runtime/runtime-manifest.go @@ -216,6 +216,7 @@ func (m *RuntimeManifest) ApplyStepOutputs(assignments map[string]string) error type StepOutput struct { // The final value of the output returned by the mixin after executing + //lint:ignore U1000 ignore unused warning value string Name string `yaml:"name"` diff --git a/pkg/runtime/runtime-manifest_test.go b/pkg/runtime/runtime-manifest_test.go index 57f30357c..4b8aa0639 100644 --- a/pkg/runtime/runtime-manifest_test.go +++ b/pkg/runtime/runtime-manifest_test.go @@ -409,7 +409,7 @@ func TestResolveInMainDict(t *testing.T) { t.Logf("install data %v", installStep.Data) exec := installStep.Data["exec"].(map[string]interface{}) assert.NotNil(t, exec) - command := exec["command"].(interface{}) + command := exec["command"] assert.NotNil(t, command) cmdVal, ok := command.(string) assert.True(t, ok) diff --git a/pkg/secrets/plugins/filesystem/store.go b/pkg/secrets/plugins/filesystem/store.go index a6cfb5709..61b361c45 100644 --- a/pkg/secrets/plugins/filesystem/store.go +++ b/pkg/secrets/plugins/filesystem/store.go @@ -48,7 +48,7 @@ func (s *Store) Connect(ctx context.Context) error { return nil } - ctx, log := tracing.StartSpan(ctx) + _, log := tracing.StartSpan(ctx) defer log.EndSpan() if _, err := s.SetSecretDir(); err != nil { diff --git a/pkg/storage/installation_store_test.go b/pkg/storage/installation_store_test.go index 58b4c8f88..26124e2f2 100644 --- a/pkg/storage/installation_store_test.go +++ b/pkg/storage/installation_store_test.go @@ -15,12 +15,14 @@ import ( var _ InstallationProvider = InstallationStore{} +//lint:ignore U1000 ignore unused warning var b64encode = func(src []byte) ([]byte, error) { dst := make([]byte, base64.StdEncoding.EncodedLen(len(src))) base64.StdEncoding.Encode(dst, src) return dst, nil } +//lint:ignore U1000 ignore unused warning var b64decode = func(src []byte) ([]byte, error) { dst := make([]byte, base64.StdEncoding.DecodedLen(len(src))) n, err := base64.StdEncoding.Decode(dst, src) diff --git a/pkg/storage/migrations/manager.go b/pkg/storage/migrations/manager.go index c87fc0368..dfe6d62f3 100644 --- a/pkg/storage/migrations/manager.go +++ b/pkg/storage/migrations/manager.go @@ -369,6 +369,7 @@ func (m *Manager) migrateParameters(w io.Writer) error { } // getSchemaVersion attempts to read the schemaVersion stamped on a document. +//lint:ignore U1000 ignore unused function warning func getSchemaVersion(data []byte) string { var peek struct { SchemaVersion schema.Version `json:"schemaVersion"` diff --git a/pkg/storage/parameter_store_test.go b/pkg/storage/parameter_store_test.go index 055390a64..d91f39084 100644 --- a/pkg/storage/parameter_store_test.go +++ b/pkg/storage/parameter_store_test.go @@ -83,10 +83,10 @@ func TestParameterStore_CRUD(t *testing.T) { require.NoError(t, err) require.Empty(t, params, "List should return no entries") - pset, err = paramStore.GetParameterSet(ctx, "", myParamSet.Name) + _, err = paramStore.GetParameterSet(ctx, "", myParamSet.Name) require.ErrorIs(t, err, ErrNotFound{}) - pset, err = paramStore.GetParameterSet(ctx, "", myParamSet2.Name) + _, err = paramStore.GetParameterSet(ctx, "", myParamSet2.Name) require.ErrorIs(t, err, ErrNotFound{}) } diff --git a/pkg/storage/plugins/mongodb/mongodb.go b/pkg/storage/plugins/mongodb/mongodb.go index 441ed0ddb..5f0700fbe 100644 --- a/pkg/storage/plugins/mongodb/mongodb.go +++ b/pkg/storage/plugins/mongodb/mongodb.go @@ -145,7 +145,6 @@ func (s *Store) EnsureIndex(ctx context.Context, opts plugins.EnsureIndexOptions Options: options.Index(), } model.Options.SetUnique(index.Unique) - model.Options.SetBackground(true) c, ok := indices[index.Collection] if !ok { diff --git a/pkg/test/logger.go b/pkg/test/logger.go index b394f8633..0908f4377 100644 --- a/pkg/test/logger.go +++ b/pkg/test/logger.go @@ -9,6 +9,7 @@ type Logger struct { func (l Logger) Write(p []byte) (n int, err error) { defer func() { + //lint:ignore SA9003 ignore empty branch if err := recover(); err != nil { // ignore logs written after the test is complete, don't panic } diff --git a/staticcheck.conf b/staticcheck.conf new file mode 100644 index 000000000..6ce9676c0 --- /dev/null +++ b/staticcheck.conf @@ -0,0 +1,4 @@ +# Default Config +checks = ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023", "-ST1005"] +initialisms = ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS"] +http_status_code_whitelist = ["200", "400", "404", "500"] \ No newline at end of file diff --git a/tests/tester/helpers.go b/tests/tester/helpers.go index 6b264dc36..af1203f46 100644 --- a/tests/tester/helpers.go +++ b/tests/tester/helpers.go @@ -15,6 +15,7 @@ import ( "github.com/stretchr/testify/require" ) +//lint:ignore U1000 ignore unused var var testBundleBuilt = false // PrepareTestBundle ensures that the mybuns test bundle has been built. From e14b409c4d879295874eb8975ba04bf4c5f37ce2 Mon Sep 17 00:00:00 2001 From: Tanmay Chaudhry Date: Wed, 29 Jun 2022 10:43:41 +0530 Subject: [PATCH 2/2] ignore unused context vars, remove unused functionality Signed-off-by: Tanmay Chaudhry --- pkg/config/loader.go | 3 ++- pkg/plugins/pluggable/loader.go | 3 ++- pkg/porter/lifecycle_integration_test.go | 4 ++++ pkg/porter/lifecycle_test.go | 8 +------- pkg/porter/parameters.go | 11 ----------- pkg/secrets/plugins/filesystem/store.go | 3 ++- pkg/storage/installation_store_test.go | 15 --------------- staticcheck.conf | 2 +- tests/tester/helpers.go | 3 --- 9 files changed, 12 insertions(+), 40 deletions(-) diff --git a/pkg/config/loader.go b/pkg/config/loader.go index c0eb045bd..958c6e19b 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -48,7 +48,8 @@ func LoadFromViper(viperCfg func(v *viper.Viper)) DataStoreLoaderFunc { return func(ctx context.Context, cfg *Config, templateData map[string]interface{}) error { home, _ := cfg.GetHomeDir() - _, log := tracing.StartSpanWithName(ctx, "LoadFromViper", attribute.String("porter.PORTER_HOME", home)) + //lint:ignore SA4006 ignore unused context for now + ctx, log := tracing.StartSpanWithName(ctx, "LoadFromViper", attribute.String("porter.PORTER_HOME", home)) defer log.EndSpan() v := viper.New() diff --git a/pkg/plugins/pluggable/loader.go b/pkg/plugins/pluggable/loader.go index 6032102f8..29a4b04ed 100644 --- a/pkg/plugins/pluggable/loader.go +++ b/pkg/plugins/pluggable/loader.go @@ -88,7 +88,8 @@ func (l *PluginLoader) Load(ctx context.Context, pluginType PluginTypeConfig) (* // selectPlugin picks the plugin to use and loads its configuration. func (l *PluginLoader) selectPlugin(ctx context.Context, cfg PluginTypeConfig) error { - _, span := tracing.StartSpan(ctx) + //lint:ignore SA4006 ignore unused ctx for now. + ctx, span := tracing.StartSpan(ctx) defer span.EndSpan() l.selectedPluginKey = nil diff --git a/pkg/porter/lifecycle_integration_test.go b/pkg/porter/lifecycle_integration_test.go index 2a3a91e32..b6ceb8c1b 100644 --- a/pkg/porter/lifecycle_integration_test.go +++ b/pkg/porter/lifecycle_integration_test.go @@ -15,6 +15,10 @@ import ( "github.com/stretchr/testify/require" ) +var ( + kahnlatestHash = "fd4bbe38665531d10bb653140842a370" +) + func TestResolveBundleReference(t *testing.T) { t.Parallel() t.Run("current bundle source", func(t *testing.T) { diff --git a/pkg/porter/lifecycle_test.go b/pkg/porter/lifecycle_test.go index 3207a6ee2..8610d348d 100644 --- a/pkg/porter/lifecycle_test.go +++ b/pkg/porter/lifecycle_test.go @@ -14,13 +14,7 @@ import ( ) var ( - //lint:ignore U1000 ignore unused variables - kahn1dot0Hash = "887e7e65e39277f8744bd00278760b06" - //lint:ignore U1000 ignore unused variables - kahn1dot01 = cnab.MustParseOCIReference("deislabs/kubekahn:1.0") - //lint:ignore U1000 ignore unused variables - kahnlatestHash = "fd4bbe38665531d10bb653140842a370" - kahnlatest = cnab.MustParseOCIReference("deislabs/kubekahn:latest") + kahnlatest = cnab.MustParseOCIReference("deislabs/kubekahn:latest") ) func TestInstallFromTagIgnoresCurrentBundle(t *testing.T) { diff --git a/pkg/porter/parameters.go b/pkg/porter/parameters.go index c8d3d77c2..efd6789c6 100644 --- a/pkg/porter/parameters.go +++ b/pkg/porter/parameters.go @@ -397,17 +397,6 @@ func (p *Porter) loadParameterSets(ctx context.Context, bun cnab.ExtendedBundle, return resolvedParameters, nil } -//lint:ignore U1000 Ignore unused function -func (p *Porter) loadParameterFromFile(path string) (storage.ParameterSet, error) { - var cs storage.ParameterSet - err := encoding.UnmarshalFile(p.FileSystem, path, &cs) - if err != nil { - return cs, fmt.Errorf("error loading parameter set in %s: %w", path, err) - } - - return cs, nil -} - type DisplayValue struct { Name string `json:"name" yaml:"name"` Type string `json:"type" yaml:"type"` diff --git a/pkg/secrets/plugins/filesystem/store.go b/pkg/secrets/plugins/filesystem/store.go index 61b361c45..4acda29eb 100644 --- a/pkg/secrets/plugins/filesystem/store.go +++ b/pkg/secrets/plugins/filesystem/store.go @@ -48,7 +48,8 @@ func (s *Store) Connect(ctx context.Context) error { return nil } - _, log := tracing.StartSpan(ctx) + //lint:ignore SA4006 ignore unused ctx for now + ctx, log := tracing.StartSpan(ctx) defer log.EndSpan() if _, err := s.SetSecretDir(); err != nil { diff --git a/pkg/storage/installation_store_test.go b/pkg/storage/installation_store_test.go index 26124e2f2..0caa2306c 100644 --- a/pkg/storage/installation_store_test.go +++ b/pkg/storage/installation_store_test.go @@ -2,7 +2,6 @@ package storage import ( "context" - "encoding/base64" "testing" "get.porter.sh/porter/pkg/cnab" @@ -15,20 +14,6 @@ import ( var _ InstallationProvider = InstallationStore{} -//lint:ignore U1000 ignore unused warning -var b64encode = func(src []byte) ([]byte, error) { - dst := make([]byte, base64.StdEncoding.EncodedLen(len(src))) - base64.StdEncoding.Encode(dst, src) - return dst, nil -} - -//lint:ignore U1000 ignore unused warning -var b64decode = func(src []byte) ([]byte, error) { - dst := make([]byte, base64.StdEncoding.DecodedLen(len(src))) - n, err := base64.StdEncoding.Decode(dst, src) - return dst[:n], err -} - var exampleBundle = bundle.Bundle{ SchemaVersion: "schemaVersion", Name: "mybun", diff --git a/staticcheck.conf b/staticcheck.conf index 6ce9676c0..c03047de4 100644 --- a/staticcheck.conf +++ b/staticcheck.conf @@ -1,4 +1,4 @@ # Default Config checks = ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023", "-ST1005"] initialisms = ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS"] -http_status_code_whitelist = ["200", "400", "404", "500"] \ No newline at end of file +http_status_code_whitelist = ["200", "400", "404", "500"] diff --git a/tests/tester/helpers.go b/tests/tester/helpers.go index af1203f46..8b8e36fc8 100644 --- a/tests/tester/helpers.go +++ b/tests/tester/helpers.go @@ -15,9 +15,6 @@ import ( "github.com/stretchr/testify/require" ) -//lint:ignore U1000 ignore unused var -var testBundleBuilt = false - // PrepareTestBundle ensures that the mybuns test bundle has been built. func (t Tester) PrepareTestBundle() { // These are environment variables referenced by the mybuns credential set