Skip to content
Myr

refactor: apply golangci-lint autofixes, work around false positives

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Ville Skyttä · committed by Marc Khouzam · parent 75790e4 · Browse files · 6 files+18 added−19 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+18 added−19 removed

  • other:+18 added−19 removed

6 files+18 added−19 removed

modified:doc/man_docs.go+2 added-2 removed
210 unmodified lines
211 manPreamble(buf, header, cmd, dashCommandName)212 manPrintOptions(buf, cmd)213 if len(cmd.Example) > 0 {214 buf.WriteString("# EXAMPLE\n")215 buf.WriteString(fmt.Sprintf("```\n%s\n```\n", cmd.Example))215 fmt.Fprintf(buf, "```\n%s\n```\n", cmd.Example)216 }217 if hasSeeAlso(cmd) {218 buf.WriteString("# SEE ALSO\n")219 seealsos := make([]string, 0)
19 unmodified lines
239 }240 buf.WriteString(strings.Join(seealsos, ", ") + "\n")241 }242 if !cmd.DisableAutoGenTag {243 buf.WriteString(fmt.Sprintf("# HISTORY\n%s Auto generated by spf13/cobra\n", header.Date.Format("2-Jan-2006")))243 fmt.Fprintf(buf, "# HISTORY\n%s Auto generated by spf13/cobra\n", header.Date.Format("2-Jan-2006"))244 }245 return buf.Bytes()246}
modified:doc/md_docs.go+4 added-4 removed
67 unmodified lines
68 buf.WriteString(cmd.Long + "\n\n")69 }7071 if cmd.Runnable() {72 buf.WriteString(fmt.Sprintf("```\n%s\n```\n\n", cmd.UseLine()))72 fmt.Fprintf(buf, "```\n%s\n```\n\n", cmd.UseLine())73 }7475 if len(cmd.Example) > 0 {76 buf.WriteString("### Examples\n\n")77 buf.WriteString(fmt.Sprintf("```\n%s\n```\n\n", cmd.Example))77 fmt.Fprintf(buf, "```\n%s\n```\n\n", cmd.Example)78 }7980 if err := printOptions(buf, cmd, name); err != nil {81 return err
4 unmodified lines
86 parent := cmd.Parent()87 pname := parent.CommandPath()88 link := pname + markdownExtension89 link = strings.ReplaceAll(link, " ", "_")90 buf.WriteString(fmt.Sprintf("* [%s](%s)\t - %s\n", pname, linkHandler(link), parent.Short))90 fmt.Fprintf(buf, "* [%s](%s)\t - %s\n", pname, linkHandler(link), parent.Short)91 cmd.VisitParents(func(c *cobra.Command) {92 if c.DisableAutoGenTag {93 cmd.DisableAutoGenTag = c.DisableAutoGenTag94 }
9 unmodified lines
104 }105 cname := name + " " + child.Name()106 link := cname + markdownExtension107 link = strings.ReplaceAll(link, " ", "_")108 buf.WriteString(fmt.Sprintf("* [%s](%s)\t - %s\n", cname, linkHandler(link), child.Short))108 fmt.Fprintf(buf, "* [%s](%s)\t - %s\n", cname, linkHandler(link), child.Short)109 }110 buf.WriteString("\n")111 }112 if !cmd.DisableAutoGenTag {
46 unmodified lines
modified:doc/rest_docs.go+4 added-4 removed
80 unmodified lines
81 buf.WriteString("~~~~~~~~\n\n")82 buf.WriteString("\n" + long + "\n\n")8384 if cmd.Runnable() {85 buf.WriteString(fmt.Sprintf("::\n\n %s\n\n", cmd.UseLine()))85 fmt.Fprintf(buf, "::\n\n %s\n\n", cmd.UseLine())86 }8788 if len(cmd.Example) > 0 {89 buf.WriteString("Examples\n")90 buf.WriteString("~~~~~~~~\n\n")91 buf.WriteString(fmt.Sprintf("::\n\n%s\n\n", indentString(cmd.Example, " ")))91 fmt.Fprintf(buf, "::\n\n%s\n\n", indentString(cmd.Example, " "))92 }9394 if err := printOptionsReST(buf, cmd, name); err != nil {95 return err
4 unmodified lines
100 if cmd.HasParent() {101 parent := cmd.Parent()102 pname := parent.CommandPath()103 ref = strings.ReplaceAll(pname, " ", "_")104 buf.WriteString(fmt.Sprintf("* %s \t - %s\n", linkHandler(pname, ref), parent.Short))104 fmt.Fprintf(buf, "* %s \t - %s\n", linkHandler(pname, ref), parent.Short)105 cmd.VisitParents(func(c *cobra.Command) {106 if c.DisableAutoGenTag {107 cmd.DisableAutoGenTag = c.DisableAutoGenTag108 }
8 unmodified lines
117 continue118 }119 cname := name + " " + child.Name()120 ref = strings.ReplaceAll(cname, " ", "_")121 buf.WriteString(fmt.Sprintf("* %s \t - %s\n", linkHandler(cname, ref), child.Short))121 fmt.Fprintf(buf, "* %s \t - %s\n", linkHandler(cname, ref), child.Short)122 }123 buf.WriteString("\n")124 }125 if !cmd.DisableAutoGenTag {
61 unmodified lines
modified:doc/yaml_docs.go+1 added-1 removed
151 unmodified lines
152 flags.VisitAll(func(flag *pflag.Flag) {153 // Todo, when we mark a shorthand is deprecated, but specify an empty message.154 // The flag.ShorthandDeprecated is empty as the shorthand is deprecated.155 // Using len(flag.ShorthandDeprecated) > 0 can't handle this, others are ok.156 if !(len(flag.ShorthandDeprecated) > 0) && len(flag.Shorthand) > 0 {156 if len(flag.ShorthandDeprecated) == 0 && len(flag.Shorthand) > 0 {157 opt := cmdOption{158 flag.Name,159 flag.Shorthand,160 flag.DefValue,
15 unmodified lines
modified:completions_test.go+5 added-6 removed
2897 unmodified lines
2898 t.Run("format with []string", func(t *testing.T) {2899 var userComp func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective)29002901 // check against new signature2902 var _ CompletionFunc = userComp2902 var _ CompletionFunc = userComp //nolint:staticcheck // LHS type is needed for this use case29032904 // check Command accepts2905 cmd := Command{2906 ValidArgsFunction: userComp,
5 unmodified lines
2912 t.Run("format with []Completion", func(t *testing.T) {2913 var userComp func(cmd *Command, args []string, toComplete string) ([]Completion, ShellCompDirective)29142915 // check against new signature2916 var _ CompletionFunc = userComp29172916 var _ CompletionFunc = userComp //nolint:staticcheck // LHS type is needed for this use case2917 // check Command accepts2918 cmd := Command{2919 ValidArgsFunction: userComp,2920 }
4 unmodified lines
2925 t.Run("format with CompletionFunc", func(t *testing.T) {2926 var userComp CompletionFunc29272928 // check helper against old signature2930 var _ func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) = userComp2931 var _ func(cmd *Command, args []string, toComplete string) ([]Completion, ShellCompDirective) = userComp2929 var _ func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) = userComp //nolint:staticcheck // LHS type is needed for this use case2930 var _ func(cmd *Command, args []string, toComplete string) ([]Completion, ShellCompDirective) = userComp //nolint:staticcheck // LHS type is needed for this use case29312932 // check Command accepts2933 cmd := Command{2934 ValidArgsFunction: userComp,
30 unmodified lines
29652966 var userComp UserCompletionTypeAliasHelper29672968 // Here we are validating the existing type validates the CompletionFunc type2970 var _ CompletionFunc = userComp2969 var _ CompletionFunc = userComp //nolint:staticcheck // LHS type is needed for this use case29702971 cmd := Command{2972 ValidArgsFunction: userComp,2973 }
1044 unmodified lines
modified:completions.go+2 added-2 removed
373 unmodified lines
374 }375 // Error while attempting to parse flags376 if flagErr != nil {377 // If error type is flagCompError and we don't want flagCompletion we should ignore the error378 if _, ok := flagErr.(*flagCompError); !(ok && !flagCompletion) {378 if _, ok := flagErr.(*flagCompError); !ok || flagCompletion {379 return finalCmd, []Completion{}, ShellCompDirectiveDefault, flagErr380 }381 }382
389 unmodified lines
772 // We also create the 'completion' command if the user is triggering773 // shell completion for it (prog __complete completion '')774 subCmd, cmdArgs, err := c.Find(args)775 if err != nil || subCmd.Name() != compCmdName &&776 !(subCmd.Name() == ShellCompRequestCmd && len(cmdArgs) > 1 && cmdArgs[0] == compCmdName) {776 (subCmd.Name() != ShellCompRequestCmd || len(cmdArgs) <= 1 || cmdArgs[0] != compCmdName) {777 // The completion command is not being called or being completed so we remove it.778 c.RemoveCommand(completionCmd)779 return780 }
225 unmodified lines