Skip to content

Commit 24952da

Browse files
committed
fixed linter warnings
1 parent 3be1230 commit 24952da

40 files changed

+171
-173
lines changed

.golangci.yml

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22

33
run:
44
deadline: 5m
5-
skip-dirs:
6-
thirdparty/
75

86
linters:
97
# please, do not use `enable-all`: it's deprecated and will be removed soon.
108
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
119
disable-all: true
1210
enable:
1311
- bodyclose
14-
- deadcode
15-
- depguard
1612
- dogsled
1713
- dupl
1814
- errcheck
@@ -33,19 +29,19 @@ linters:
3329
- misspell
3430
- nakedret
3531
- staticcheck
36-
- structcheck
3732
- stylecheck
3833
- revive
3934
- typecheck
4035
- unconvert
4136
- unparam
4237
- unused
43-
- varcheck
4438
- whitespace
4539

4640
issues:
4741
exclude:
4842
- Using the variable on range scope `tc` in function literal
43+
exclude-dirs:
44+
- thirdparty/
4945

5046
linters-settings:
5147
dupl:

commands/alpha/alphacmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func GetCommand(ctx context.Context, _, version string) *cobra.Command {
3232
Use: "alpha",
3333
Short: alphadocs.AlphaShort,
3434
Long: alphadocs.AlphaLong,
35-
RunE: func(cmd *cobra.Command, args []string) error {
35+
RunE: func(cmd *cobra.Command, _ []string) error {
3636
h, err := cmd.Flags().GetBool("help")
3737
if err != nil {
3838
return err

commands/alpha/license/command.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewCommand(ctx context.Context, _ string) *cobra.Command {
2727
Use: "license",
2828
Short: "[Alpha] " + licensedocs.LicenseShort,
2929
Long: "[Alpha] " + licensedocs.LicenseShort + "\n" + licensedocs.LicenseLong,
30-
RunE: func(cmd *cobra.Command, args []string) error {
30+
RunE: func(cmd *cobra.Command, _ []string) error {
3131
h, err := cmd.Flags().GetBool("help")
3232
if err != nil {
3333
return err

commands/alpha/rollouts/rolloutscmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewCommand(ctx context.Context, version string) *cobra.Command {
2929
Use: "rollouts",
3030
Short: "rollouts",
3131
Long: "rollouts",
32-
RunE: func(cmd *cobra.Command, args []string) error {
32+
RunE: func(cmd *cobra.Command, _ []string) error {
3333
h, err := cmd.Flags().GetBool("help")
3434
if err != nil {
3535
return err

commands/fn/doc/cmdfndoc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func NewRunner(ctx context.Context, parent string) *Runner {
4343
}
4444
r.Command = c
4545
c.Flags().StringVarP(&r.Image, "image", "i", "", "kpt function image name")
46-
_ = r.Command.RegisterFlagCompletionFunc("image", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
46+
_ = r.Command.RegisterFlagCompletionFunc("image", func(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
4747
return cmdutil.SuggestFunctions(cmd), cobra.ShellCompDirectiveDefault
4848
})
4949
cmdutil.FixDocs("kpt", parent, c)

commands/fn/fncmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func GetCommand(ctx context.Context, name string) *cobra.Command {
3232
Short: fndocs.FnShort,
3333
Long: fndocs.FnLong,
3434
Aliases: []string{"functions"},
35-
RunE: func(cmd *cobra.Command, args []string) error {
35+
RunE: func(cmd *cobra.Command, _ []string) error {
3636
h, err := cmd.Flags().GetBool("help")
3737
if err != nil {
3838
return err

commands/fn/render/cmdrender.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func NewRunner(ctx context.Context, parent string) *Runner {
5353

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

commands/fn/render/cmdrender_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ func TestCmd_flagAndArgParsing_Symlink(t *testing.T) {
4444
}
4545

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

commands/live/migrate/migratecmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func NewRunner(
8686
Short: livedocs.MigrateShort,
8787
Long: livedocs.MigrateShort + "\n" + livedocs.MigrateLong,
8888
Example: livedocs.MigrateExamples,
89-
RunE: func(cmd *cobra.Command, args []string) error {
89+
RunE: func(_ *cobra.Command, args []string) error {
9090
if len(args) == 0 {
9191
// default to current working directory
9292
args = append(args, ".")

commands/live/migrate/migratecmd_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func TestKptMigrate_migrateKptfileToRG(t *testing.T) {
168168
migrateRunner := NewRunner(ctx, tf, cmLoader, ioStreams)
169169
migrateRunner.dryRun = tc.dryRun
170170
migrateRunner.rgFile = tc.rgFilename
171-
migrateRunner.cmInvClientFunc = func(factory util.Factory) (inventory.Client, error) {
171+
migrateRunner.cmInvClientFunc = func(_ util.Factory) (inventory.Client, error) {
172172
return inventory.NewFakeClient([]object.ObjMetadata{}), nil
173173
}
174174
err = migrateRunner.migrateKptfileToRG([]string{dir})
@@ -242,7 +242,7 @@ func TestKptMigrate_retrieveConfigMapInv(t *testing.T) {
242242
// Create MigrateRunner and call "retrieveConfigMapInv"
243243
cmLoader := manifestreader.NewManifestLoader(tf)
244244
migrateRunner := NewRunner(ctx, tf, cmLoader, ioStreams)
245-
migrateRunner.cmInvClientFunc = func(factory util.Factory) (inventory.Client, error) {
245+
migrateRunner.cmInvClientFunc = func(_ util.Factory) (inventory.Client, error) {
246246
return inventory.NewFakeClient([]object.ObjMetadata{}), nil
247247
}
248248
actual, err := migrateRunner.retrieveConfigMapInv(strings.NewReader(tc.configMap), []string{"-"})

commands/live/status/cmdstatus_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ foo/deployment.apps/default/foo is InProgress: inProgress
265265
invFactory := inventory.FakeClientFactory(tc.inventory)
266266
loader := NewFakeLoader(ctx, tf, tc.inventory)
267267
runner := NewRunner(ctx, tf, invFactory, loader)
268-
runner.PollerFactoryFunc = func(c cmdutil.Factory) (poller.Poller, error) {
268+
runner.PollerFactoryFunc = func(_ cmdutil.Factory) (poller.Poller, error) {
269269
return &fakePoller{tc.events}, nil
270270
}
271271

commands/pkg/diff/cmddiff_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@ func TestCmd_flagAndArgParsing_Symlink(t *testing.T) {
9191
assert.Equal(t, filepath.Join(cwd, "path", "to", "pkg", "dir"), r.Path)
9292
}
9393

94-
var NoOpRunE = func(cmd *cobra.Command, args []string) error { return nil }
94+
var NoOpRunE = func(_ *cobra.Command, _ []string) error { return nil }

commands/pkg/get/cmdget.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func NewRunner(ctx context.Context, parent string) *Runner {
5555
strings.Join(kptfilev1.UpdateStrategiesAsStrings(), ","))
5656
c.Flags().BoolVar(&r.isDeploymentInstance, "for-deployment", false,
5757
"(Experimental) indicates if this package will be deployed to a cluster.")
58-
_ = c.RegisterFlagCompletionFunc("strategy", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
58+
_ = c.RegisterFlagCompletionFunc("strategy", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
5959
return kptfilev1.UpdateStrategiesAsStrings(), cobra.ShellCompDirectiveDefault
6060
})
6161
return r

commands/pkg/get/cmdget_test.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// revive:disable:unused-parameter
16+
1517
package get_test
1618

1719
import (
@@ -169,7 +171,7 @@ func TestCmd_fail(t *testing.T) {
169171
}
170172

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

174176
// NoOpFailRunE causes the test to fail if run is called. Useful for validating run isn't called for
175177
// errors.
@@ -205,26 +207,26 @@ func TestCmd_Execute_flagAndArgParsing(t *testing.T) {
205207
validations func(repo, dir string, r *get.Runner, err error)
206208
}{
207209
"must have at least 1 arg": {
208-
argsFunc: func(repo, _ string) []string {
210+
argsFunc: func(_, _ string) []string {
209211
return []string{}
210212
},
211213
runE: failRun,
212-
validations: func(_, _ string, r *get.Runner, err error) {
214+
validations: func(_, _ string, _ *get.Runner, err error) {
213215
assert.EqualError(t, err, "requires at least 1 arg(s), only received 0")
214216
},
215217
},
216218
"must provide unambiguous repo, dir and version": {
217-
argsFunc: func(repo, _ string) []string {
219+
argsFunc: func(_, _ string) []string {
218220
return []string{"foo", "bar", "baz"}
219221
},
220222
runE: failRun,
221-
validations: func(_, _ string, r *get.Runner, err error) {
223+
validations: func(_, _ string, _ *get.Runner, err error) {
222224
assert.Error(t, err)
223225
assert.Contains(t, err.Error(), "ambiguous repo/dir@version specify '.git' in argument")
224226
},
225227
},
226228
"repo arg is split up correctly into ref and repo": {
227-
argsFunc: func(repo, _ string) []string {
229+
argsFunc: func(_, _ string) []string {
228230
return []string{"something://foo.git/@master", "./"}
229231
},
230232
runE: NoOpRunE,

commands/pkg/pkgcmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func GetCommand(ctx context.Context, name string) *cobra.Command {
3232
Short: pkgdocs.PkgShort,
3333
Long: pkgdocs.PkgLong,
3434
Aliases: []string{"package"},
35-
RunE: func(cmd *cobra.Command, args []string) error {
35+
RunE: func(cmd *cobra.Command, _ []string) error {
3636
h, err := cmd.Flags().GetBool("help")
3737
if err != nil {
3838
return err

commands/pkg/update/cmdupdate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func NewRunner(ctx context.Context, parent string) *Runner {
5454
"the update strategy that will be used when updating the package. This will change "+
5555
"the default strategy for the package -- must be one of: "+
5656
strings.Join(kptfilev1.UpdateStrategiesAsStrings(), ","))
57-
_ = c.RegisterFlagCompletionFunc("strategy", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
57+
_ = c.RegisterFlagCompletionFunc("strategy", func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
5858
return kptfilev1.UpdateStrategiesAsStrings(), cobra.ShellCompDirectiveDefault
5959
})
6060
cmdutil.FixDocs("kpt", parent, c)

commands/pkg/update/cmdupdate_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func TestCmd_onlyVersionAsInput(t *testing.T) {
278278
}
279279

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

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

431431
r := update.NewRunner(fake.CtxWithDefaultPrinter(), "kpt")
432-
r.Command.RunE = func(cmd *cobra.Command, args []string) error {
432+
r.Command.RunE = func(_ *cobra.Command, _ []string) error {
433433
if !assert.Equal(t, test.expectedFullPackagePath, r.Update.Pkg.UniquePath.String()) {
434434
t.FailNow()
435435
}

internal/alpha/printers/table/printer.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func getProgress(resInfo *resourceInfo) (string, string, error) {
212212

213213
color, setColor := printcommon.ColorForStatus(rs.Status)
214214
if setColor {
215-
s = printcommon.SprintfWithColor(color, s)
215+
s = printcommon.SprintfWithColor(color, "%s", s)
216216
}
217217

218218
text = s
@@ -295,7 +295,7 @@ func getConditions(rs *pollingevent.ResourceStatus) []string {
295295
}
296296
}
297297

298-
s := printcommon.SprintfWithColor(color, text)
298+
s := printcommon.SprintfWithColor(color, "%s", text)
299299
conditionStrings = append(conditionStrings, s)
300300
}
301301
return conditionStrings

internal/errors/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func E(args ...interface{}) error {
192192
case error:
193193
e.Err = a
194194
case string:
195-
e.Err = fmt.Errorf(a)
195+
e.Err = fmt.Errorf("%s", a)
196196
default:
197197
panic(fmt.Errorf("unknown type %T for value %v in call to error.E", a, a))
198198
}

internal/fnruntime/imagepullpolicy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (e *ImagePullPolicy) Set(v string) error {
5353
return nil
5454
}
5555
}
56-
return fmt.Errorf("must must be one of " + strings.Join(e.AllStrings(), ", "))
56+
return fmt.Errorf("must be one of: %s", strings.Join(e.AllStrings(), ", "))
5757
}
5858

5959
func (e *ImagePullPolicy) AllStrings() []string {

internal/fnruntime/utils.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ func presentIn(targetNode *yaml.RNode, input []*yaml.RNode) bool {
110110
return false
111111
}
112112

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

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

0 commit comments

Comments
 (0)