Skip to content

Commit

Permalink
fixed linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
droot committed Feb 11, 2025
1 parent 3be1230 commit 43e027a
Show file tree
Hide file tree
Showing 40 changed files with 175 additions and 185 deletions.
8 changes: 2 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

run:
deadline: 5m
skip-dirs:
thirdparty/

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
- errcheck
Expand All @@ -33,19 +29,19 @@ linters:
- misspell
- nakedret
- staticcheck
- structcheck
- stylecheck
- revive
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace

issues:
exclude:
- Using the variable on range scope `tc` in function literal
exclude-dirs:
- thirdparty/

linters-settings:
dupl:
Expand Down
2 changes: 1 addition & 1 deletion commands/alpha/alphacmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GetCommand(ctx context.Context, _, version string) *cobra.Command {
Use: "alpha",
Short: alphadocs.AlphaShort,
Long: alphadocs.AlphaLong,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
h, err := cmd.Flags().GetBool("help")
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion commands/alpha/license/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewCommand(ctx context.Context, _ string) *cobra.Command {
Use: "license",
Short: "[Alpha] " + licensedocs.LicenseShort,
Long: "[Alpha] " + licensedocs.LicenseShort + "\n" + licensedocs.LicenseLong,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
h, err := cmd.Flags().GetBool("help")
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion commands/alpha/rollouts/rolloutscmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewCommand(ctx context.Context, version string) *cobra.Command {
Use: "rollouts",
Short: "rollouts",
Long: "rollouts",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
h, err := cmd.Flags().GetBool("help")
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion commands/fn/doc/cmdfndoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewRunner(ctx context.Context, parent string) *Runner {
}
r.Command = c
c.Flags().StringVarP(&r.Image, "image", "i", "", "kpt function image name")
_ = r.Command.RegisterFlagCompletionFunc("image", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
_ = r.Command.RegisterFlagCompletionFunc("image", func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return cmdutil.SuggestFunctions(cmd), cobra.ShellCompDirectiveDefault
})
cmdutil.FixDocs("kpt", parent, c)
Expand Down
2 changes: 1 addition & 1 deletion commands/fn/fncmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GetCommand(ctx context.Context, name string) *cobra.Command {
Short: fndocs.FnShort,
Long: fndocs.FnLong,
Aliases: []string{"functions"},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
h, err := cmd.Flags().GetBool("help")
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion commands/fn/render/cmdrender.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewRunner(ctx context.Context, parent string) *Runner {

c.Flags().Var(&r.RunnerOptions.ImagePullPolicy, "image-pull-policy",
"pull image before running the container "+r.RunnerOptions.ImagePullPolicy.HelpAllowedValues())
_ = c.RegisterFlagCompletionFunc("image-pull-policy", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
_ = c.RegisterFlagCompletionFunc("image-pull-policy", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return r.RunnerOptions.ImagePullPolicy.AllStrings(), cobra.ShellCompDirectiveDefault
})

Expand Down
2 changes: 1 addition & 1 deletion commands/fn/render/cmdrender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ func TestCmd_flagAndArgParsing_Symlink(t *testing.T) {
}

// NoOpRunE is a noop function to replace the run function of a command. Useful for testing argument parsing.
var NoOpRunE = func(cmd *cobra.Command, args []string) error { return nil }
var NoOpRunE = func(_ *cobra.Command, _ []string) error { return nil }
2 changes: 1 addition & 1 deletion commands/live/migrate/migratecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func NewRunner(
Short: livedocs.MigrateShort,
Long: livedocs.MigrateShort + "\n" + livedocs.MigrateLong,
Example: livedocs.MigrateExamples,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
if len(args) == 0 {
// default to current working directory
args = append(args, ".")
Expand Down
4 changes: 2 additions & 2 deletions commands/live/migrate/migratecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestKptMigrate_migrateKptfileToRG(t *testing.T) {
migrateRunner := NewRunner(ctx, tf, cmLoader, ioStreams)
migrateRunner.dryRun = tc.dryRun
migrateRunner.rgFile = tc.rgFilename
migrateRunner.cmInvClientFunc = func(factory util.Factory) (inventory.Client, error) {
migrateRunner.cmInvClientFunc = func(_ util.Factory) (inventory.Client, error) {
return inventory.NewFakeClient([]object.ObjMetadata{}), nil
}
err = migrateRunner.migrateKptfileToRG([]string{dir})
Expand Down Expand Up @@ -242,7 +242,7 @@ func TestKptMigrate_retrieveConfigMapInv(t *testing.T) {
// Create MigrateRunner and call "retrieveConfigMapInv"
cmLoader := manifestreader.NewManifestLoader(tf)
migrateRunner := NewRunner(ctx, tf, cmLoader, ioStreams)
migrateRunner.cmInvClientFunc = func(factory util.Factory) (inventory.Client, error) {
migrateRunner.cmInvClientFunc = func(_ util.Factory) (inventory.Client, error) {
return inventory.NewFakeClient([]object.ObjMetadata{}), nil
}
actual, err := migrateRunner.retrieveConfigMapInv(strings.NewReader(tc.configMap), []string{"-"})
Expand Down
2 changes: 1 addition & 1 deletion commands/live/status/cmdstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ foo/deployment.apps/default/foo is InProgress: inProgress
invFactory := inventory.FakeClientFactory(tc.inventory)
loader := NewFakeLoader(ctx, tf, tc.inventory)
runner := NewRunner(ctx, tf, invFactory, loader)
runner.PollerFactoryFunc = func(c cmdutil.Factory) (poller.Poller, error) {
runner.PollerFactoryFunc = func(_ cmdutil.Factory) (poller.Poller, error) {
return &fakePoller{tc.events}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion commands/pkg/diff/cmddiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ func TestCmd_flagAndArgParsing_Symlink(t *testing.T) {
assert.Equal(t, filepath.Join(cwd, "path", "to", "pkg", "dir"), r.Path)
}

var NoOpRunE = func(cmd *cobra.Command, args []string) error { return nil }
var NoOpRunE = func(_ *cobra.Command, _ []string) error { return nil }
2 changes: 1 addition & 1 deletion commands/pkg/get/cmdget.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewRunner(ctx context.Context, parent string) *Runner {
strings.Join(kptfilev1.UpdateStrategiesAsStrings(), ","))
c.Flags().BoolVar(&r.isDeploymentInstance, "for-deployment", false,
"(Experimental) indicates if this package will be deployed to a cluster.")
_ = c.RegisterFlagCompletionFunc("strategy", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
_ = c.RegisterFlagCompletionFunc("strategy", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return kptfilev1.UpdateStrategiesAsStrings(), cobra.ShellCompDirectiveDefault
})
return r
Expand Down
14 changes: 8 additions & 6 deletions commands/pkg/get/cmdget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// revive:disable:unused-parameter

package get_test

import (
Expand Down Expand Up @@ -169,7 +171,7 @@ func TestCmd_fail(t *testing.T) {
}

// NoOpRunE is a noop function to replace the run function of a command. Useful for testing argument parsing.
var NoOpRunE = func(cmd *cobra.Command, args []string) error { return nil }
var NoOpRunE = func(_ *cobra.Command, _ []string) error { return nil }

// NoOpFailRunE causes the test to fail if run is called. Useful for validating run isn't called for
// errors.
Expand Down Expand Up @@ -205,26 +207,26 @@ func TestCmd_Execute_flagAndArgParsing(t *testing.T) {
validations func(repo, dir string, r *get.Runner, err error)
}{
"must have at least 1 arg": {
argsFunc: func(repo, _ string) []string {
argsFunc: func(_, _ string) []string {
return []string{}
},
runE: failRun,
validations: func(_, _ string, r *get.Runner, err error) {
validations: func(_, _ string, _ *get.Runner, err error) {
assert.EqualError(t, err, "requires at least 1 arg(s), only received 0")
},
},
"must provide unambiguous repo, dir and version": {
argsFunc: func(repo, _ string) []string {
argsFunc: func(_, _ string) []string {
return []string{"foo", "bar", "baz"}
},
runE: failRun,
validations: func(_, _ string, r *get.Runner, err error) {
validations: func(_, _ string, _ *get.Runner, err error) {
assert.Error(t, err)
assert.Contains(t, err.Error(), "ambiguous repo/dir@version specify '.git' in argument")
},
},
"repo arg is split up correctly into ref and repo": {
argsFunc: func(repo, _ string) []string {
argsFunc: func(_, _ string) []string {
return []string{"something://foo.git/@master", "./"}
},
runE: NoOpRunE,
Expand Down
2 changes: 1 addition & 1 deletion commands/pkg/pkgcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GetCommand(ctx context.Context, name string) *cobra.Command {
Short: pkgdocs.PkgShort,
Long: pkgdocs.PkgLong,
Aliases: []string{"package"},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
h, err := cmd.Flags().GetBool("help")
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion commands/pkg/update/cmdupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewRunner(ctx context.Context, parent string) *Runner {
"the update strategy that will be used when updating the package. This will change "+
"the default strategy for the package -- must be one of: "+
strings.Join(kptfilev1.UpdateStrategiesAsStrings(), ","))
_ = c.RegisterFlagCompletionFunc("strategy", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
_ = c.RegisterFlagCompletionFunc("strategy", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return kptfilev1.UpdateStrategiesAsStrings(), cobra.ShellCompDirectiveDefault
})
cmdutil.FixDocs("kpt", parent, c)
Expand Down
4 changes: 2 additions & 2 deletions commands/pkg/update/cmdupdate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func TestCmd_onlyVersionAsInput(t *testing.T) {
}

// NoOpRunE is a noop function to replace the run function of a command. Useful for testing argument parsing.
var NoOpRunE = func(cmd *cobra.Command, args []string) error { return nil }
var NoOpRunE = func(_ *cobra.Command, _ []string) error { return nil }

// NoOpFailRunE causes the test to fail if run is called. Useful for validating run isn't called for
// errors.
Expand Down Expand Up @@ -429,7 +429,7 @@ func TestCmd_path(t *testing.T) {
defer testutil.Chdir(t, test.currentWD)()

r := update.NewRunner(fake.CtxWithDefaultPrinter(), "kpt")
r.Command.RunE = func(cmd *cobra.Command, args []string) error {
r.Command.RunE = func(_ *cobra.Command, _ []string) error {
if !assert.Equal(t, test.expectedFullPackagePath, r.Update.Pkg.UniquePath.String()) {
t.FailNow()
}
Expand Down
4 changes: 2 additions & 2 deletions internal/alpha/printers/table/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func getProgress(resInfo *resourceInfo) (string, string, error) {

color, setColor := printcommon.ColorForStatus(rs.Status)
if setColor {
s = printcommon.SprintfWithColor(color, s)
s = printcommon.SprintfWithColor(color, "%s", s)
}

text = s
Expand Down Expand Up @@ -295,7 +295,7 @@ func getConditions(rs *pollingevent.ResourceStatus) []string {
}
}

s := printcommon.SprintfWithColor(color, text)
s := printcommon.SprintfWithColor(color, "%s", text)
conditionStrings = append(conditionStrings, s)
}
return conditionStrings
Expand Down
2 changes: 1 addition & 1 deletion internal/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func E(args ...interface{}) error {
case error:
e.Err = a
case string:
e.Err = fmt.Errorf(a)
e.Err = fmt.Errorf("%s", a)
default:
panic(fmt.Errorf("unknown type %T for value %v in call to error.E", a, a))
}
Expand Down
2 changes: 1 addition & 1 deletion internal/fnruntime/imagepullpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (e *ImagePullPolicy) Set(v string) error {
return nil
}
}
return fmt.Errorf("must must be one of " + strings.Join(e.AllStrings(), ", "))
return fmt.Errorf("must be one of: %s", strings.Join(e.AllStrings(), ", "))
}

func (e *ImagePullPolicy) AllStrings() []string {
Expand Down
8 changes: 4 additions & 4 deletions internal/fnruntime/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func presentIn(targetNode *yaml.RNode, input []*yaml.RNode) bool {
return false
}

// SetResourceIds adds kpt-resource-id annotation to each input resource
func SetResourceIds(input []*yaml.RNode) error {
// SetResourceIDs adds kpt-resource-id annotation to each input resource
func SetResourceIDs(input []*yaml.RNode) error {
id := 0
for i := range input {
idStr := fmt.Sprintf("%v", id)
Expand All @@ -124,8 +124,8 @@ func SetResourceIds(input []*yaml.RNode) error {
return nil
}

// DeleteResourceIds removes the kpt-resource-id annotation from all resources
func DeleteResourceIds(input []*yaml.RNode) error {
// DeleteResourceIDs removes the kpt-resource-id annotation from all resources
func DeleteResourceIDs(input []*yaml.RNode) error {
for i := range input {
err := input[i].PipeE(yaml.ClearAnnotation(ResourceIDAnnotation))
if err != nil {
Expand Down
Loading

0 comments on commit 43e027a

Please sign in to comment.