Skip to content

Commit 6b5f577

Browse files
authored
More linting (#2099)
* Address gocritic findings, enable it * Enable gosimple, no new findings to address
1 parent bd914e5 commit 6b5f577

File tree

6 files changed

+17
-20
lines changed

6 files changed

+17
-20
lines changed

Diff for: .golangci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ linters:
2929
- gas
3030
#- gochecknoinits
3131
- goconst
32-
#- gocritic
32+
- gocritic
3333
#- gocyclo
3434
#- gofmt
3535
- goimports
3636
- golint
3737
#- gomnd
3838
#- goprintffuncname
3939
#- gosec
40-
#- gosimple
40+
- gosimple
4141
- govet
4242
- ineffassign
4343
- interfacer

Diff for: bash_completions.go

+10-13
Original file line numberDiff line numberDiff line change
@@ -597,19 +597,16 @@ func writeRequiredFlag(buf io.StringWriter, cmd *Command) {
597597
if nonCompletableFlag(flag) {
598598
return
599599
}
600-
for key := range flag.Annotations {
601-
switch key {
602-
case BashCompOneRequiredFlag:
603-
format := " must_have_one_flag+=(\"--%s"
604-
if flag.Value.Type() != "bool" {
605-
format += "="
606-
}
607-
format += cbn
608-
WriteStringAndCheck(buf, fmt.Sprintf(format, flag.Name))
609-
610-
if len(flag.Shorthand) > 0 {
611-
WriteStringAndCheck(buf, fmt.Sprintf(" must_have_one_flag+=(\"-%s"+cbn, flag.Shorthand))
612-
}
600+
if _, ok := flag.Annotations[BashCompOneRequiredFlag]; ok {
601+
format := " must_have_one_flag+=(\"--%s"
602+
if flag.Value.Type() != "bool" {
603+
format += "="
604+
}
605+
format += cbn
606+
WriteStringAndCheck(buf, fmt.Sprintf(format, flag.Name))
607+
608+
if len(flag.Shorthand) > 0 {
609+
WriteStringAndCheck(buf, fmt.Sprintf(" must_have_one_flag+=(\"-%s"+cbn, flag.Shorthand))
613610
}
614611
}
615612
})

Diff for: command_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2777,7 +2777,7 @@ func TestFind(t *testing.T) {
27772777

27782778
func TestUnknownFlagShouldReturnSameErrorRegardlessOfArgPosition(t *testing.T) {
27792779
testCases := [][]string{
2780-
//{"--unknown", "--namespace", "foo", "child", "--bar"}, // FIXME: This test case fails, returning the error `unknown command "foo" for "root"` instead of the expected error `unknown flag: --unknown`
2780+
// {"--unknown", "--namespace", "foo", "child", "--bar"}, // FIXME: This test case fails, returning the error `unknown command "foo" for "root"` instead of the expected error `unknown flag: --unknown`
27812781
{"--namespace", "foo", "--unknown", "child", "--bar"},
27822782
{"--namespace", "foo", "child", "--unknown", "--bar"},
27832783
{"--namespace", "foo", "child", "--bar", "--unknown"},

Diff for: doc/man_docs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func fillHeader(header *GenManHeader, name string, disableAutoGen bool) error {
133133
}
134134
header.Date = &now
135135
}
136-
header.date = (*header.Date).Format("Jan 2006")
136+
header.date = header.Date.Format("Jan 2006")
137137
if header.Source == "" && !disableAutoGen {
138138
header.Source = "Auto generated by spf13/cobra"
139139
}

Diff for: doc/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func hasSeeAlso(cmd *cobra.Command) bool {
4040
// that do not contain \n.
4141
func forceMultiLine(s string) string {
4242
if len(s) > 60 && !strings.Contains(s, "\n") {
43-
s = s + "\n"
43+
s += "\n"
4444
}
4545
return s
4646
}

Diff for: powershell_completions.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
func genPowerShellComp(buf io.StringWriter, name string, includeDesc bool) {
2929
// Variables should not contain a '-' or ':' character
3030
nameForVar := name
31-
nameForVar = strings.Replace(nameForVar, "-", "_", -1)
32-
nameForVar = strings.Replace(nameForVar, ":", "_", -1)
31+
nameForVar = strings.ReplaceAll(nameForVar, "-", "_")
32+
nameForVar = strings.ReplaceAll(nameForVar, ":", "_")
3333

3434
compCmd := ShellCompRequestCmd
3535
if !includeDesc {

0 commit comments

Comments
 (0)