Skip to content

chore: Bump golangci-lint to v2 #2083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 6 additions & 23 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
format:
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable

- name: Clone repository
uses: actions/checkout@v4

Comment on lines +20 to -27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2025-04-02_10-05

This fixes that the CI cache isn't getting used because of the order of our clone and Go setup.

- name: Set up gofumpt
run: go install mvdan.cc/gofumpt@latest

Expand All @@ -34,36 +34,19 @@ jobs:
echo "$non_formatted_files"
test -z "$non_formatted_files"

staticcheck:
golangci-lint:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable

steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Set up staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Run staticcheck
run: staticcheck ./...

golangci-lint:
runs-on: ubuntu-latest

steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable

- name: Clone repository
uses: actions/checkout@v4

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v7
with:
version: latest
5 changes: 4 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# https://golangci-lint.run/usage/configuration/
version: "2"
linters:
enable:
- makezero
- misspell
exclusions:
presets:
- std-error-handling
18 changes: 9 additions & 9 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2760,7 +2760,7 @@ func TestFlagAction(t *testing.T) {
if v[0] == "err" {
return fmt.Errorf("error string slice")
}
_, err := cmd.Root().Writer.Write([]byte(fmt.Sprintf("%v ", v)))
_, err := fmt.Fprintf(cmd.Root().Writer, "%v ", v)
return err
},
},
Expand All @@ -2771,7 +2771,7 @@ func TestFlagAction(t *testing.T) {
if !v {
return fmt.Errorf("value is false")
}
_, err := cmd.Root().Writer.Write([]byte(fmt.Sprintf("%t ", v)))
_, err := fmt.Fprintf(cmd.Root().Writer, "%t ", v)
return err
},
},
Expand All @@ -2782,7 +2782,7 @@ func TestFlagAction(t *testing.T) {
if v == 0 {
return fmt.Errorf("empty duration")
}
_, err := cmd.Root().Writer.Write([]byte(v.String() + " "))
_, err := fmt.Fprintf(cmd.Root().Writer, v.String()+" ")
return err
},
},
Expand All @@ -2793,7 +2793,7 @@ func TestFlagAction(t *testing.T) {
if v < 0 {
return fmt.Errorf("negative float64")
}
_, err := cmd.Root().Writer.Write([]byte(strconv.FormatFloat(v, 'f', -1, 64) + " "))
_, err := fmt.Fprintf(cmd.Root().Writer, strconv.FormatFloat(v, 'f', -1, 64)+" ")
return err
},
},
Expand All @@ -2804,7 +2804,7 @@ func TestFlagAction(t *testing.T) {
if len(v) > 0 && v[0] < 0 {
return fmt.Errorf("invalid float64 slice")
}
_, err := cmd.Root().Writer.Write([]byte(fmt.Sprintf("%v ", v)))
_, err := fmt.Fprintf(cmd.Root().Writer, "%v ", v)
return err
},
},
Expand All @@ -2815,7 +2815,7 @@ func TestFlagAction(t *testing.T) {
if v < 0 {
return fmt.Errorf("negative int")
}
_, err := cmd.Root().Writer.Write([]byte(fmt.Sprintf("%v ", v)))
_, err := fmt.Fprintf(cmd.Root().Writer, "%v ", v)
return err
},
},
Expand All @@ -2826,7 +2826,7 @@ func TestFlagAction(t *testing.T) {
if len(v) > 0 && v[0] < 0 {
return fmt.Errorf("invalid int slice")
}
_, err := cmd.Root().Writer.Write([]byte(fmt.Sprintf("%v ", v)))
_, err := fmt.Fprintf(cmd.Root().Writer, "%v ", v)
return err
},
},
Expand All @@ -2853,7 +2853,7 @@ func TestFlagAction(t *testing.T) {
if v == 0 {
return fmt.Errorf("zero uint64")
}
_, err := cmd.Root().Writer.Write([]byte(fmt.Sprintf("%v ", v)))
_, err := fmt.Fprintf(cmd.Root().Writer, "%v ", v)
return err
},
},
Expand All @@ -2864,7 +2864,7 @@ func TestFlagAction(t *testing.T) {
if _, ok := v["err"]; ok {
return fmt.Errorf("error string map")
}
_, err := cmd.Root().Writer.Write([]byte(fmt.Sprintf("%v", v)))
_, err := fmt.Fprintf(cmd.Root().Writer, "%v", v)
return err
},
},
Expand Down
28 changes: 15 additions & 13 deletions fish.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ func (cmd *Command) prepareFishCommands(commands []*Command, allCommands *[]stri
completions := []string{}
for _, command := range commands {
var completion strings.Builder
completion.WriteString(fmt.Sprintf(
fmt.Fprintf(&completion,
"complete -r -c %s -n '%s' -a '%s'",
cmd.Name,
cmd.fishSubcommandHelper(previousCommands),
strings.Join(command.Names(), " "),
))
)

if command.Usage != "" {
completion.WriteString(fmt.Sprintf(" -d '%s'",
escapeSingleQuotes(command.Usage)))
fmt.Fprintf(&completion,
" -d '%s'",
escapeSingleQuotes(command.Usage))
}

if !command.HideHelp {
Expand Down Expand Up @@ -112,23 +113,23 @@ func (cmd *Command) prepareFishFlags(flags []Flag, previousCommands []string) []
completions := []string{}
for _, f := range flags {
completion := &strings.Builder{}
completion.WriteString(fmt.Sprintf(
fmt.Fprintf(completion,
"complete -c %s -n '%s'",
cmd.Name,
cmd.fishSubcommandHelper(previousCommands),
))
)

fishAddFileFlag(f, completion)

for idx, opt := range f.Names() {
if idx == 0 {
completion.WriteString(fmt.Sprintf(
fmt.Fprintf(completion,
" -l %s", strings.TrimSpace(opt),
))
)
} else {
completion.WriteString(fmt.Sprintf(
fmt.Fprintf(completion,
" -s %s", strings.TrimSpace(opt),
))
)
}
}

Expand All @@ -138,8 +139,9 @@ func (cmd *Command) prepareFishFlags(flags []Flag, previousCommands []string) []
}

if flag.GetUsage() != "" {
completion.WriteString(fmt.Sprintf(" -d '%s'",
escapeSingleQuotes(flag.GetUsage())))
fmt.Fprintf(completion,
" -d '%s'",
escapeSingleQuotes(flag.GetUsage()))
}
}

Expand Down Expand Up @@ -175,5 +177,5 @@ func (cmd *Command) fishSubcommandHelper(allCommands []string) string {
}

func escapeSingleQuotes(input string) string {
return strings.Replace(input, `'`, `\'`, -1)
return strings.ReplaceAll(input, `'`, `\'`)
}
4 changes: 2 additions & 2 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func printHelpCustom(out io.Writer, templ string, data interface{}, customFuncs
handleTemplateError(err)
}

if _, err := t.New("visibleGlobalFlagCategoryTemplate").Parse(strings.Replace(visibleFlagCategoryTemplate, "OPTIONS", "GLOBAL OPTIONS", -1)); err != nil {
if _, err := t.New("visibleGlobalFlagCategoryTemplate").Parse(strings.ReplaceAll(visibleFlagCategoryTemplate, "OPTIONS", "GLOBAL OPTIONS")); err != nil {
handleTemplateError(err)
}

Expand Down Expand Up @@ -513,7 +513,7 @@ func subtract(a, b int) int {

func indent(spaces int, v string) string {
pad := strings.Repeat(" ", spaces)
return pad + strings.Replace(v, "\n", "\n"+pad, -1)
return pad + strings.ReplaceAll(v, "\n", "\n"+pad)
}

func nindent(spaces int, v string) string {
Expand Down