Skip to content

Commit

Permalink
Upgrade golangci version to v1.52.2 and fix lint errors
Browse files Browse the repository at this point in the history
This patch updgrade golangci version to v1.52.2
and replace deadcode with unused as it was deprecated
in the v1.49.0 and also fixes lint errors

Signed-off-by: Shiv Verma <[email protected]>
  • Loading branch information
pratap0007 authored and tekton-robot committed May 4, 2023
1 parent 008ddd5 commit b24e3b5
Show file tree
Hide file tree
Showing 32 changed files with 77 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ linters:
- gocritic
- revive
- misspell
- deadcode
- unused
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ M = $(shell printf "\033[34;1m🐱\033[0m")
TIMEOUT_UNIT = 5m
TIMEOUT_E2E = 20m

GOLANGCI_VERSION = v1.47.2
GOLANGCI_VERSION = v1.52.2

YAML_FILES := $(shell find . -type f -regex ".*y[a]ml" -print)

Expand Down
9 changes: 3 additions & 6 deletions cmd/docs/md_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/spf13/cobra"
)

func printOptions(buf *bytes.Buffer, cmd *cobra.Command, name string) error {
func printOptions(buf *bytes.Buffer, cmd *cobra.Command) error {
flags := cmd.NonInheritedFlags()
flags.SetOutput(buf)
if flags.HasAvailableFlags() {
Expand Down Expand Up @@ -80,7 +80,7 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
buf.WriteString(fmt.Sprintf("%s\n\n", cmd.Example))
}

if err := printOptions(buf, cmd, name); err != nil {
if err := printOptions(buf, cmd); err != nil {
return err
}
if hasSeeAlso(cmd) {
Expand Down Expand Up @@ -154,10 +154,7 @@ func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHa
if _, err := io.WriteString(f, filePrepender(filename)); err != nil {
return err
}
if err := GenMarkdownCustom(cmd, f, linkHandler); err != nil {
return err
}
return nil
return GenMarkdownCustom(cmd, f, linkHandler)
}

// Test to see if we have a reason to print See Also information in docs
Expand Down
7 changes: 1 addition & 6 deletions pkg/actions/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ func GetV1(gr schema.GroupVersionResource, c *cli.Clients, objname, ns string, o
if err != nil {
return err
}

if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredObj.UnstructuredContent(), obj); err != nil {
return err
}

return nil
return runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredObj.UnstructuredContent(), obj)
}

func GetUnstructured(gr schema.GroupVersionResource, c *cli.Clients, objname, ns string, op metav1.GetOptions) (*unstructured.Unstructured, error) {
Expand Down
5 changes: 1 addition & 4 deletions pkg/actions/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ func ListV1(gr schema.GroupVersionResource, c *cli.Clients, opts metav1.ListOpti
return err
}

if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredObj.UnstructuredContent(), obj); err != nil {
return err
}
return nil
return runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredObj.UnstructuredContent(), obj)
}

// list takes a partial resource and fetches a list of that resource's objects in the cluster using the dynamic client.
Expand Down
6 changes: 1 addition & 5 deletions pkg/actions/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,5 @@ func Patch(gr schema.GroupVersionResource, clients *cli.Clients, objName string,
return err
}

if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredObj.UnstructuredContent(), obj); err != nil {
return err
}

return nil
return runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredObj.UnstructuredContent(), obj)
}
8 changes: 4 additions & 4 deletions pkg/cmd/clustertask/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ func deleteClusterTasks(opts *options.DeleteOptions, s *cli.Stream, p cli.Params
if err != nil {
return err
}
d.Delete(s, cts)
d.Delete(cts)
case opts.DeleteRelated:
d.WithRelated("TaskRun", taskRunLister(cs, p), func(taskRunName string) error {
return actions.Delete(trGroupResource, cs.Dynamic, cs.Tekton.Discovery(), taskRunName, p.Namespace(), metav1.DeleteOptions{})
})
deletedClusterTaskNames := d.Delete(s, ctNames)
d.DeleteRelated(s, deletedClusterTaskNames)
deletedClusterTaskNames := d.Delete(ctNames)
d.DeleteRelated(deletedClusterTaskNames)
default:
d.Delete(s, ctNames)
d.Delete(ctNames)

}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/clustertriggerbinding/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func deleteClusterTriggerBindings(s *cli.Stream, p cli.Params, ctbNames []string
return err
}
}
d.Delete(s, ctbNames)
d.Delete(ctbNames)

if !deleteAll {
d.PrintSuccesses(s)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/eventlistener/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func deleteEventListeners(s *cli.Stream, p cli.Params, elNames []string, deleteA
return err
}
}
d.Delete(s, elNames)
d.Delete(elNames)

if !deleteAll {
d.PrintSuccesses(s)
Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/pipeline/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ func deletePipelines(opts *options.DeleteOptions, s *cli.Stream, p cli.Params, p
if err != nil {
return err
}
d.Delete(s, pNames)
d.Delete(pNames)
case opts.DeleteRelated:
d.WithRelated("PipelineRun", pipelineRunLister(cs, p.Namespace()), func(pipelineRunName string) error {
return actions.Delete(pipelinerunGroupResource, cs.Dynamic, cs.Tekton.Discovery(), pipelineRunName, p.Namespace(), metav1.DeleteOptions{})
})
deletedPipelineNames := d.Delete(s, pNames)
d.DeleteRelated(s, deletedPipelineNames)
deletedPipelineNames := d.Delete(pNames)
d.DeleteRelated(deletedPipelineNames)
default:
d.Delete(s, pNames)
d.Delete(pNames)
}
if !opts.DeleteAllNs {
d.PrintSuccesses(s)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func Command(p cli.Params) *cobra.Command {
logCommand(p),
startCommand(p),
exportCommand(p),
signCommand(p),
verifyCommand(p),
signCommand(),
verifyCommand(),
)
return cmd
}
2 changes: 1 addition & 1 deletion pkg/cmd/pipeline/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type signOptions struct {
targetFile string
}

func signCommand(p cli.Params) *cobra.Command {
func signCommand() *cobra.Command {
opts := &signOptions{}
f := cliopts.NewPrintFlags("trustedresources")
eg := `Sign a Pipeline pipeline.yaml:
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/pipeline/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type verifyOptions struct {
kmsKey string
}

func verifyCommand(p cli.Params) *cobra.Command {
func verifyCommand() *cobra.Command {
opts := &verifyOptions{}
f := cliopts.NewPrintFlags("trustedresources")
eg := `Verify a Pipeline signed.yaml:
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/pipelinerun/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ func deletePipelineRuns(s *cli.Stream, p cli.Params, prNames []string, opts *opt
}
numberOfDeletedPr = len(prtodelete)
numberOfKeptPr = len(prtokeep)
d.Delete(s, prtodelete)
d.Delete(prtodelete)
case opts.ParentResourceName == "":
d = deleter.New("PipelineRun", func(pipelineRunName string) error {
return actions.Delete(prGroupResource, cs.Dynamic, cs.Tekton.Discovery(), pipelineRunName, p.Namespace(), metav1.DeleteOptions{})
})
d.Delete(s, prNames)
d.Delete(prNames)
default:
d = deleter.New("Pipeline", func(_ string) error {
return errors.New("the Pipeline should not be deleted")
Expand All @@ -184,7 +184,7 @@ func deletePipelineRuns(s *cli.Stream, p cli.Params, prNames []string, opts *opt
fmt.Fprintf(s.Out, "There is/are only %d %s(s) associated for Pipeline: %s \n", len(prtokeep), opts.Resource, opts.ParentResourceName)
return nil
}
d.DeleteRelated(s, []string{opts.ParentResourceName})
d.DeleteRelated([]string{opts.ParentResourceName})
}

if !opts.DeleteAllNs {
Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/task/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ func deleteTask(opts *options.DeleteOptions, s *cli.Stream, p cli.Params, taskNa
if err != nil {
return err
}
d.Delete(s, taskNames)
d.Delete(taskNames)
case opts.DeleteRelated:
d.WithRelated("TaskRun", taskRunLister(cs, p.Namespace()), func(taskRunName string) error {
return actions.Delete(taskrunGroupResource, cs.Dynamic, cs.Tekton.Discovery(), taskRunName, p.Namespace(), metav1.DeleteOptions{})
})
deletedTaskNames := d.Delete(s, taskNames)
d.DeleteRelated(s, deletedTaskNames)
deletedTaskNames := d.Delete(taskNames)
d.DeleteRelated(deletedTaskNames)
default:
d.Delete(s, taskNames)
d.Delete(taskNames)
}
if !opts.DeleteAllNs {
d.PrintSuccesses(s)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/task/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type signOptions struct {
targetFile string
}

func signCommand(p cli.Params) *cobra.Command {
func signCommand() *cobra.Command {
opts := &signOptions{}
f := cliopts.NewPrintFlags("trustedresources")
eg := `Sign a Task task.yaml:
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func Command(p cli.Params) *cobra.Command {
logCommand(p),
startCommand(p),
createCommand(p),
signCommand(p),
verifyCommand(p),
signCommand(),
verifyCommand(),
)
return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/task/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type verifyOptions struct {
kmsKey string
}

func verifyCommand(p cli.Params) *cobra.Command {
func verifyCommand() *cobra.Command {
opts := &verifyOptions{}
f := cliopts.NewPrintFlags("trustedresources")
eg := `Verify a Task signed.yaml:
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/taskrun/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func deleteTaskRuns(s *cli.Stream, p cli.Params, trNames []string, opts *options
}
numberOfDeletedTr = len(trToDelete)
numberOfKeptTr = len(trToKeep)
d.Delete(s, trToDelete)
d.Delete(trToDelete)
case opts.ParentResourceName == "":
d = deleter.New("TaskRun", func(taskRunName string) error {
return actions.Delete(taskrunGroupResource, cs.Dynamic, cs.Tekton.Discovery(), taskRunName, p.Namespace(), metav1.DeleteOptions{})
Expand All @@ -196,7 +196,7 @@ func deleteTaskRuns(s *cli.Stream, p cli.Params, trNames []string, opts *options
}
processedTrNames = append(processedTrNames, tr.Name)
}
d.Delete(s, processedTrNames)
d.Delete(processedTrNames)
default:
d = deleter.New(opts.ParentResource, func(_ string) error {
err := fmt.Sprintf("the %s should not be deleted", opts.ParentResource)
Expand Down Expand Up @@ -227,7 +227,7 @@ func deleteTaskRuns(s *cli.Stream, p cli.Params, trNames []string, opts *options
fmt.Fprintf(s.Out, "There is/are only %d %s(s) associated for %s: %s \n", len(trToKeep), opts.Resource, opts.ParentResource, opts.ParentResourceName)
return nil
}
d.DeleteRelated(s, []string{opts.ParentResourceName})
d.DeleteRelated([]string{opts.ParentResourceName})
}

if !opts.DeleteAllNs {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/triggerbinding/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func deleteTriggerBindings(s *cli.Stream, p cli.Params, tbNames []string, delete
return err
}
}
d.Delete(s, tbNames)
d.Delete(tbNames)

if !deleteAll {
d.PrintSuccesses(s)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/triggertemplate/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func deleteTriggerTemplates(s *cli.Stream, p cli.Params, ttNames []string, delet
return err
}
}
d.Delete(s, ttNames)
d.Delete(ttNames)

if !deleteAll {
d.PrintSuccesses(s)
Expand Down
18 changes: 9 additions & 9 deletions pkg/deleter/deleter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func (d *Deleter) WithRelated(kind string, listFunc func(string) ([]string, erro
// the passed in streams struct and are also aggregated for later access
// with d.Errors(). The names of successfully deleted resources are
// returned.
func (d *Deleter) Delete(streams *cli.Stream, resourceNames []string) []string {
func (d *Deleter) Delete(resourceNames []string) []string {
for _, name := range resourceNames {
if err := d.delete(name); err != nil {
d.appendError(streams, fmt.Errorf("failed to delete %s %q: %s", d.kind, name, err))
d.appendError(fmt.Errorf("failed to delete %s %q: %s", d.kind, name, err))
} else {
d.successfulDeletes = append(d.successfulDeletes, name)
}
Expand All @@ -63,33 +63,33 @@ func (d *Deleter) Delete(streams *cli.Stream, resourceNames []string) []string {

// DeleteRelated performs the deletion of resources related to d's kind. Errors are
// aggregated and can be accessed with d.Errors().
func (d *Deleter) DeleteRelated(streams *cli.Stream, resourceNames []string) {
func (d *Deleter) DeleteRelated(resourceNames []string) {
if d.relatedKind != "" && d.listRelated != nil && d.deleteRelated != nil {
for _, name := range resourceNames {
d.deleteRelatedList(streams, name)
d.deleteRelatedList(name)
}
}
}

// deleteRelatedList gets the list of resources related to resourceName using the
// provided listFunc and then calls the deleteRelated func for each relation.
func (d *Deleter) deleteRelatedList(streams *cli.Stream, resourceName string) {
func (d *Deleter) deleteRelatedList(resourceName string) {
if related, err := d.listRelated(resourceName); err != nil {
err = fmt.Errorf("failed to list %ss: %s", strings.ToLower(d.relatedKind), err)
d.appendError(streams, err)
d.appendError(err)
} else {
if len(related) > 0 {
for _, subresource := range related {
if err := d.deleteRelated(subresource); err != nil {
err = fmt.Errorf("failed to delete %s %q: %s", d.relatedKind, subresource, err)
d.appendError(streams, err)
d.appendError(err)
} else {
d.successfulRelatedDeletes = append(d.successfulRelatedDeletes, subresource)
}
}
} else {
err = fmt.Errorf("no %ss associated with %s %q", d.relatedKind, d.kind, resourceName)
d.appendError(streams, err)
d.appendError(err)
}
}
}
Expand All @@ -106,7 +106,7 @@ func (d *Deleter) PrintSuccesses(streams *cli.Stream) {

// appendError adds that error to the list of accumulated errors that
// have occurred during execution.
func (d *Deleter) appendError(streams *cli.Stream, err error) {
func (d *Deleter) appendError(err error) {
d.errors = append(d.errors, err)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/deleter/deleter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestDelete(t *testing.T) {
stderr := &strings.Builder{}
streams := &cli.Stream{Out: stdout, Err: stderr}
d := New("FooBar", tc.deleteFunc)
d.Delete(streams, tc.names)
d.Delete(tc.names)
d.PrintSuccesses(streams)
if err := d.Errors(); err != nil {
if tc.expectedErr == "" {
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestDeleteRelated(t *testing.T) {
d := New("FooBar", successfulDeleteFunc())
if tc.relatedKind != "" {
d.WithRelated(tc.relatedKind, tc.listFunc, tc.deleteFunc)
d.DeleteRelated(streams, []string{"foo"})
d.DeleteRelated([]string{"foo"})
}
d.PrintSuccesses(streams)
if err := d.Errors(); err != nil {
Expand Down Expand Up @@ -121,8 +121,8 @@ func TestDeleteAndDeleteRelated(t *testing.T) {
streams := &cli.Stream{Out: stdout, Err: stderr}
d := New(tc.kind, tc.deleteFunc)
d.WithRelated(tc.relatedKind, tc.listRelatedFunc, tc.deleteRelatedFunc)
deletedNames := d.Delete(streams, tc.names)
d.DeleteRelated(streams, deletedNames)
deletedNames := d.Delete(tc.names)
d.DeleteRelated(deletedNames)
d.PrintSuccesses(streams)
if err := d.Errors(); err != nil {
if tc.expectedErr == "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/formatted/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ func BaseCompletion(target string, args []string) ([]string, cobra.ShellCompDire
}

// ParentCompletion do completion of command to the Parent
func ParentCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
func ParentCompletion(cmd *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective) {
return BaseCompletion(cmd.Parent().Name(), args)
}
Loading

0 comments on commit b24e3b5

Please sign in to comment.