Skip to content

Commit

Permalink
Ignore/Fix all remaining staticcheck errors (getporter#2201)
Browse files Browse the repository at this point in the history
* Ignore/Fix all remaining staticcheck errors

Signed-off-by: Tanmay Chaudhry <[email protected]>

* ignore unused context vars, remove unused functionality

Signed-off-by: Tanmay Chaudhry <[email protected]>
  • Loading branch information
tchaudhry91 authored Jun 29, 2022
1 parent 33bed82 commit af12a22
Show file tree
Hide file tree
Showing 20 changed files with 23 additions and 37 deletions.
2 changes: 1 addition & 1 deletion pkg/cnab/cnab-to-oci/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/cnab/provider/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +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()

//lint:ignore SA4006 ignore unused context for now
ctx, log := tracing.StartSpanWithName(ctx, "LoadFromViper", attribute.String("porter.PORTER_HOME", home))
defer log.EndSpan()

Expand Down
1 change: 1 addition & 0 deletions pkg/plugins/pluggable/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +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 {
//lint:ignore SA4006 ignore unused ctx for now.
ctx, span := tracing.StartSpan(ctx)
defer span.EndSpan()

Expand Down
1 change: 0 additions & 1 deletion pkg/porter/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions pkg/porter/lifecycle_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions pkg/porter/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import (
)

var (
kahn1dot0Hash = "887e7e65e39277f8744bd00278760b06"
kahn1dot01 = cnab.MustParseOCIReference("deislabs/kubekahn:1.0")
kahnlatestHash = "fd4bbe38665531d10bb653140842a370"
kahnlatest = cnab.MustParseOCIReference("deislabs/kubekahn:latest")
kahnlatest = cnab.MustParseOCIReference("deislabs/kubekahn:latest")
)

func TestInstallFromTagIgnoresCurrentBundle(t *testing.T) {
Expand Down
10 changes: 0 additions & 10 deletions pkg/porter/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,16 +397,6 @@ func (p *Porter) loadParameterSets(ctx context.Context, bun cnab.ExtendedBundle,
return resolvedParameters, nil
}

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"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/porter/stamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/porter/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
1 change: 1 addition & 0 deletions pkg/runtime/runtime-manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/runtime-manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/secrets/plugins/filesystem/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (s *Store) Connect(ctx context.Context) error {
return nil
}

//lint:ignore SA4006 ignore unused ctx for now
ctx, log := tracing.StartSpan(ctx)
defer log.EndSpan()

Expand Down
13 changes: 0 additions & 13 deletions pkg/storage/installation_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package storage

import (
"context"
"encoding/base64"
"testing"

"get.porter.sh/porter/pkg/cnab"
Expand All @@ -15,18 +14,6 @@ import (

var _ InstallationProvider = InstallationStore{}

var b64encode = func(src []byte) ([]byte, error) {
dst := make([]byte, base64.StdEncoding.EncodedLen(len(src)))
base64.StdEncoding.Encode(dst, src)
return dst, nil
}

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",
Expand Down
1 change: 1 addition & 0 deletions pkg/storage/migrations/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/parameter_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
}

Expand Down
1 change: 0 additions & 1 deletion pkg/storage/plugins/mongodb/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/test/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions staticcheck.conf
Original file line number Diff line number Diff line change
@@ -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"]
2 changes: 0 additions & 2 deletions tests/tester/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"github.com/stretchr/testify/require"
)

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
Expand Down

0 comments on commit af12a22

Please sign in to comment.