Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore/Fix all remaining staticcheck errors #2201

Merged
merged 2 commits into from
Jun 29, 2022

Conversation

tchaudhry91
Copy link
Member

@tchaudhry91 tchaudhry91 commented Jun 28, 2022

What does this change

This adds configuration to staticcheck to:

  • Completely ignore ST1005 (Error capitalization and punctuation). All other check ignores are per default staticcheck conf.
  • Ignore unused vars (U1000) and code in a few ambiguous places via inline directives. These can be refactored with time.
  • Removes some unused vars (like ctx etc)
  • Removed model.Options.SetBackground(true) for mongo/options. This is deprecated and no longer needed. The default mechanism does not block anymore (https://www.mongodb.com/community/forums/t/after-4-2-background-createindexes/15136)

What issue does it fix

Closes #2081

Notes for the reviewer

@carolynvs Please take a look at the //lint:ignore values. Maybe we can trim some of that already. Rest is self explanatory.

Checklist

  • Did you write tests?
  • Did you write documentation?
  • Did you change porter.yaml or a storage document record? Update the corresponding schema file.
  • If this is your first pull request, please add your name to the bottom of our Contributors list. Thank you for making Porter better! 🙇‍♀️

Reviewer Checklist

  • Comment with /azp run test-porter-release if a magefile or build script was modified
  • Comment with /azp run porter-integration if it's a non-trivial PR

@@ -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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to not change this here because setting the ctx variable is important. Even if ctx isn't used after this point, if we add a line in the future that uses ctx, with this change they will accidentally use the old ctx instead of the new scoped context.

I see more changes like this below and really all of those changes need to be reverted for the same reason.

Copy link
Member Author

@tchaudhry91 tchaudhry91 Jun 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I'll revert it and add the //lint:ignore .

kahn1dot0Hash = "887e7e65e39277f8744bd00278760b06"
kahn1dot01 = cnab.MustParseOCIReference("deislabs/kubekahn:1.0")
//lint:ignore U1000 ignore unused variables
kahn1dot0Hash = "887e7e65e39277f8744bd00278760b06"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can be removed if they really aren't used. We have lots of tests elsewhere that vet the ParseOCIReference logic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently one of these is used (but in a different file), the linter still complaints. To fix it, I have moved it to the file where it's used.

@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality has been deprecated and can be removed.

@@ -15,12 +15,14 @@ import (

var _ InstallationProvider = InstallationStore{}

//lint:ignore U1000 ignore unused warning
var b64encode = func(src []byte) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This functionality has been deprecated in the most recent version of the storage protocol and can be removed.

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, this can be removed.

pkg/storage/plugins/mongodb/mongodb.go Show resolved Hide resolved
@@ -15,6 +15,7 @@ import (
"github.com/stretchr/testify/require"
)

//lint:ignore U1000 ignore unused var
var testBundleBuilt = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed

@tchaudhry91 tchaudhry91 requested a review from VinozzZ as a code owner June 29, 2022 05:13
@tchaudhry91 tchaudhry91 requested a review from carolynvs June 29, 2022 05:15
@tchaudhry91
Copy link
Member Author

Made changes as requested.

Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Phew, it took a lot to clean up all the errors! Thank you for doing this. 💯

@carolynvs carolynvs merged commit af12a22 into getporter:release/v1 Jun 29, 2022
@carolynvs carolynvs self-assigned this Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resolve lint and vet errors
2 participants