Skip to content

Commit af12a22

Browse files
authored
Ignore/Fix all remaining staticcheck errors (getporter#2201)
* 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]>
1 parent 33bed82 commit af12a22

20 files changed

+23
-37
lines changed

pkg/cnab/cnab-to-oci/registry.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import (
1717
"github.com/docker/docker/api/types"
1818
"github.com/docker/docker/api/types/filters"
1919
"github.com/docker/docker/pkg/jsonmessage"
20-
"github.com/docker/docker/pkg/term"
2120
"github.com/google/go-containerregistry/pkg/crane"
21+
"github.com/moby/term"
2222
"github.com/opencontainers/go-digest"
2323
)
2424

pkg/cnab/provider/runtime.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ var _ CNABProvider = &Runtime{}
1313

1414
type Runtime struct {
1515
*config.Config
16-
credentials storage.CredentialSetProvider
16+
credentials storage.CredentialSetProvider
17+
//lint:ignore U1000 unused at the moment, will be used in the future
1718
parameters storage.ParameterSetProvider
1819
secrets secrets.Store
1920
installations storage.InstallationProvider

pkg/config/loader.go

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func LoadFromViper(viperCfg func(v *viper.Viper)) DataStoreLoaderFunc {
4848
return func(ctx context.Context, cfg *Config, templateData map[string]interface{}) error {
4949
home, _ := cfg.GetHomeDir()
5050

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

pkg/plugins/pluggable/loader.go

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func (l *PluginLoader) Load(ctx context.Context, pluginType PluginTypeConfig) (*
8888

8989
// selectPlugin picks the plugin to use and loads its configuration.
9090
func (l *PluginLoader) selectPlugin(ctx context.Context, cfg PluginTypeConfig) error {
91+
//lint:ignore SA4006 ignore unused ctx for now.
9192
ctx, span := tracing.StartSpan(ctx)
9293
defer span.EndSpan()
9394

pkg/porter/helpers.go

-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ func (p *TestPorter) CompareGoldenFile(goldenFile string, got string) {
235235
// CreateInstallation saves an installation record into claim store and store
236236
// sensitive parameters into secret store.
237237
func (p *TestPorter) SanitizeParameters(raw []secrets.Strategy, recordID string, bun cnab.ExtendedBundle) []secrets.Strategy {
238-
strategies := make([]secrets.Strategy, 0, len(raw))
239238
strategies, err := p.Sanitizer.CleanParameters(context.Background(), raw, bun, recordID)
240239
require.NoError(p.T(), err)
241240

pkg/porter/lifecycle_integration_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import (
1515
"github.com/stretchr/testify/require"
1616
)
1717

18+
var (
19+
kahnlatestHash = "fd4bbe38665531d10bb653140842a370"
20+
)
21+
1822
func TestResolveBundleReference(t *testing.T) {
1923
t.Parallel()
2024
t.Run("current bundle source", func(t *testing.T) {

pkg/porter/lifecycle_test.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ import (
1414
)
1515

1616
var (
17-
kahn1dot0Hash = "887e7e65e39277f8744bd00278760b06"
18-
kahn1dot01 = cnab.MustParseOCIReference("deislabs/kubekahn:1.0")
19-
kahnlatestHash = "fd4bbe38665531d10bb653140842a370"
20-
kahnlatest = cnab.MustParseOCIReference("deislabs/kubekahn:latest")
17+
kahnlatest = cnab.MustParseOCIReference("deislabs/kubekahn:latest")
2118
)
2219

2320
func TestInstallFromTagIgnoresCurrentBundle(t *testing.T) {

pkg/porter/parameters.go

-10
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,6 @@ func (p *Porter) loadParameterSets(ctx context.Context, bun cnab.ExtendedBundle,
397397
return resolvedParameters, nil
398398
}
399399

400-
func (p *Porter) loadParameterFromFile(path string) (storage.ParameterSet, error) {
401-
var cs storage.ParameterSet
402-
err := encoding.UnmarshalFile(p.FileSystem, path, &cs)
403-
if err != nil {
404-
return cs, fmt.Errorf("error loading parameter set in %s: %w", path, err)
405-
}
406-
407-
return cs, nil
408-
}
409-
410400
type DisplayValue struct {
411401
Name string `json:"name" yaml:"name"`
412402
Type string `json:"type" yaml:"type"`

pkg/porter/stamp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (p *Porter) IsBundleUpToDate(ctx context.Context, opts bundleFileOptions) (
8282

8383
if !isImageCached {
8484
if p.Debug {
85-
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)))
85+
fmt.Fprintln(p.Err, fmt.Errorf("Invocation image %s doesn't exist in the local image cache, will need to build first", invocationImage.Image))
8686
}
8787
return false, nil
8888
}

pkg/porter/upgrade.go

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (o UpgradeOptions) Validate(ctx context.Context, args []string, p *Porter)
3535
if err != nil {
3636
return errors.New("invalid bundle version --version. Must be a semantic version, for example 1.2.3")
3737
}
38+
//lint:ignore SA4005 the bundle options are validated below, so ignore ineffective assignment warning
3839
o.Version = v.String()
3940
}
4041

pkg/runtime/runtime-manifest.go

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ func (m *RuntimeManifest) ApplyStepOutputs(assignments map[string]string) error
216216

217217
type StepOutput struct {
218218
// The final value of the output returned by the mixin after executing
219+
//lint:ignore U1000 ignore unused warning
219220
value string
220221

221222
Name string `yaml:"name"`

pkg/runtime/runtime-manifest_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ func TestResolveInMainDict(t *testing.T) {
409409
t.Logf("install data %v", installStep.Data)
410410
exec := installStep.Data["exec"].(map[string]interface{})
411411
assert.NotNil(t, exec)
412-
command := exec["command"].(interface{})
412+
command := exec["command"]
413413
assert.NotNil(t, command)
414414
cmdVal, ok := command.(string)
415415
assert.True(t, ok)

pkg/secrets/plugins/filesystem/store.go

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func (s *Store) Connect(ctx context.Context) error {
4848
return nil
4949
}
5050

51+
//lint:ignore SA4006 ignore unused ctx for now
5152
ctx, log := tracing.StartSpan(ctx)
5253
defer log.EndSpan()
5354

pkg/storage/installation_store_test.go

-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package storage
22

33
import (
44
"context"
5-
"encoding/base64"
65
"testing"
76

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

1615
var _ InstallationProvider = InstallationStore{}
1716

18-
var b64encode = func(src []byte) ([]byte, error) {
19-
dst := make([]byte, base64.StdEncoding.EncodedLen(len(src)))
20-
base64.StdEncoding.Encode(dst, src)
21-
return dst, nil
22-
}
23-
24-
var b64decode = func(src []byte) ([]byte, error) {
25-
dst := make([]byte, base64.StdEncoding.DecodedLen(len(src)))
26-
n, err := base64.StdEncoding.Decode(dst, src)
27-
return dst[:n], err
28-
}
29-
3017
var exampleBundle = bundle.Bundle{
3118
SchemaVersion: "schemaVersion",
3219
Name: "mybun",

pkg/storage/migrations/manager.go

+1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ func (m *Manager) migrateParameters(w io.Writer) error {
369369
}
370370

371371
// getSchemaVersion attempts to read the schemaVersion stamped on a document.
372+
//lint:ignore U1000 ignore unused function warning
372373
func getSchemaVersion(data []byte) string {
373374
var peek struct {
374375
SchemaVersion schema.Version `json:"schemaVersion"`

pkg/storage/parameter_store_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ func TestParameterStore_CRUD(t *testing.T) {
8383
require.NoError(t, err)
8484
require.Empty(t, params, "List should return no entries")
8585

86-
pset, err = paramStore.GetParameterSet(ctx, "", myParamSet.Name)
86+
_, err = paramStore.GetParameterSet(ctx, "", myParamSet.Name)
8787
require.ErrorIs(t, err, ErrNotFound{})
8888

89-
pset, err = paramStore.GetParameterSet(ctx, "", myParamSet2.Name)
89+
_, err = paramStore.GetParameterSet(ctx, "", myParamSet2.Name)
9090
require.ErrorIs(t, err, ErrNotFound{})
9191
}
9292

pkg/storage/plugins/mongodb/mongodb.go

-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ func (s *Store) EnsureIndex(ctx context.Context, opts plugins.EnsureIndexOptions
145145
Options: options.Index(),
146146
}
147147
model.Options.SetUnique(index.Unique)
148-
model.Options.SetBackground(true)
149148

150149
c, ok := indices[index.Collection]
151150
if !ok {

pkg/test/logger.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type Logger struct {
99

1010
func (l Logger) Write(p []byte) (n int, err error) {
1111
defer func() {
12+
//lint:ignore SA9003 ignore empty branch
1213
if err := recover(); err != nil {
1314
// ignore logs written after the test is complete, don't panic
1415
}

staticcheck.conf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Default Config
2+
checks = ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023", "-ST1005"]
3+
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"]
4+
http_status_code_whitelist = ["200", "400", "404", "500"]

tests/tester/helpers.go

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515
"github.com/stretchr/testify/require"
1616
)
1717

18-
var testBundleBuilt = false
19-
2018
// PrepareTestBundle ensures that the mybuns test bundle has been built.
2119
func (t Tester) PrepareTestBundle() {
2220
// These are environment variables referenced by the mybuns credential set

0 commit comments

Comments
 (0)