Skip to content

Commit 4af7b64

Browse files
scopmarckhouzam
authored andcommitted
refactor: apply golangci-lint autofixes, work around false positives
1 parent 75790e4 commit 4af7b64

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

completions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func (c *Command) getCompletions(args []string) (*Command, []Completion, ShellCo
375375
// Error while attempting to parse flags
376376
if flagErr != nil {
377377
// If error type is flagCompError and we don't want flagCompletion we should ignore the error
378-
if _, ok := flagErr.(*flagCompError); !(ok && !flagCompletion) {
378+
if _, ok := flagErr.(*flagCompError); !ok || flagCompletion {
379379
return finalCmd, []Completion{}, ShellCompDirectiveDefault, flagErr
380380
}
381381
}
@@ -773,7 +773,7 @@ See each sub-command's help for details on how to use the generated script.
773773
// shell completion for it (prog __complete completion '')
774774
subCmd, cmdArgs, err := c.Find(args)
775775
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) {
777777
// The completion command is not being called or being completed so we remove it.
778778
c.RemoveCommand(completionCmd)
779779
return

completions_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,7 +2899,7 @@ func TestCompletionFuncCompatibility(t *testing.T) {
28992899
var userComp func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective)
29002900

29012901
// check against new signature
2902-
var _ CompletionFunc = userComp
2902+
var _ CompletionFunc = userComp //nolint:staticcheck // LHS type is needed for this use case
29032903

29042904
// check Command accepts
29052905
cmd := Command{
@@ -2913,8 +2913,7 @@ func TestCompletionFuncCompatibility(t *testing.T) {
29132913
var userComp func(cmd *Command, args []string, toComplete string) ([]Completion, ShellCompDirective)
29142914

29152915
// check against new signature
2916-
var _ CompletionFunc = userComp
2917-
2916+
var _ CompletionFunc = userComp //nolint:staticcheck // LHS type is needed for this use case
29182917
// check Command accepts
29192918
cmd := Command{
29202919
ValidArgsFunction: userComp,
@@ -2927,8 +2926,8 @@ func TestCompletionFuncCompatibility(t *testing.T) {
29272926
var userComp CompletionFunc
29282927

29292928
// check helper against old signature
2930-
var _ func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) = userComp
2931-
var _ func(cmd *Command, args []string, toComplete string) ([]Completion, ShellCompDirective) = userComp
2929+
var _ func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) = userComp //nolint:staticcheck // LHS type is needed for this use case
2930+
var _ func(cmd *Command, args []string, toComplete string) ([]Completion, ShellCompDirective) = userComp //nolint:staticcheck // LHS type is needed for this use case
29322931

29332932
// check Command accepts
29342933
cmd := Command{
@@ -2967,7 +2966,7 @@ func TestCompletionFuncCompatibility(t *testing.T) {
29672966
var userComp UserCompletionTypeAliasHelper
29682967

29692968
// Here we are validating the existing type validates the CompletionFunc type
2970-
var _ CompletionFunc = userComp
2969+
var _ CompletionFunc = userComp //nolint:staticcheck // LHS type is needed for this use case
29712970

29722971
cmd := Command{
29732972
ValidArgsFunction: userComp,

doc/man_docs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
212212
manPrintOptions(buf, cmd)
213213
if len(cmd.Example) > 0 {
214214
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)
216216
}
217217
if hasSeeAlso(cmd) {
218218
buf.WriteString("# SEE ALSO\n")
@@ -240,7 +240,7 @@ func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
240240
buf.WriteString(strings.Join(seealsos, ", ") + "\n")
241241
}
242242
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"))
244244
}
245245
return buf.Bytes()
246246
}

doc/md_docs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
6969
}
7070

7171
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())
7373
}
7474

7575
if len(cmd.Example) > 0 {
7676
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)
7878
}
7979

8080
if err := printOptions(buf, cmd, name); err != nil {
@@ -87,7 +87,7 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
8787
pname := parent.CommandPath()
8888
link := pname + markdownExtension
8989
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)
9191
cmd.VisitParents(func(c *cobra.Command) {
9292
if c.DisableAutoGenTag {
9393
cmd.DisableAutoGenTag = c.DisableAutoGenTag
@@ -105,7 +105,7 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
105105
cname := name + " " + child.Name()
106106
link := cname + markdownExtension
107107
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)
109109
}
110110
buf.WriteString("\n")
111111
}

doc/rest_docs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ func GenReSTCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string, str
8282
buf.WriteString("\n" + long + "\n\n")
8383

8484
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())
8686
}
8787

8888
if len(cmd.Example) > 0 {
8989
buf.WriteString("Examples\n")
9090
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, " "))
9292
}
9393

9494
if err := printOptionsReST(buf, cmd, name); err != nil {
@@ -101,7 +101,7 @@ func GenReSTCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string, str
101101
parent := cmd.Parent()
102102
pname := parent.CommandPath()
103103
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)
105105
cmd.VisitParents(func(c *cobra.Command) {
106106
if c.DisableAutoGenTag {
107107
cmd.DisableAutoGenTag = c.DisableAutoGenTag
@@ -118,7 +118,7 @@ func GenReSTCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string, str
118118
}
119119
cname := name + " " + child.Name()
120120
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)
122122
}
123123
buf.WriteString("\n")
124124
}

doc/yaml_docs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func genFlagResult(flags *pflag.FlagSet) []cmdOption {
153153
// Todo, when we mark a shorthand is deprecated, but specify an empty message.
154154
// The flag.ShorthandDeprecated is empty as the shorthand is deprecated.
155155
// 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 {
157157
opt := cmdOption{
158158
flag.Name,
159159
flag.Shorthand,

0 commit comments

Comments
 (0)