Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 1 addition & 18 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,6 @@ jobs:
echo "$non_formatted_files"
test -z "$non_formatted_files"

staticcheck:
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: Set up staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

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

Copy link
Member

Choose a reason for hiding this comment

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

Why remove it? Does new golang-ci-lint v2 include staticcheck?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Just FYI, the staticcheck linter in Golangci-lint V1 is not the same as the standalone Staticcheck linter. The V1 docs included an additional statement that says (golangci/golangci-lint#2894):

It's not the same thing as the staticcheck binary. The author of staticcheck doesn't support or approve the use of staticcheck as a library inside golangci-lint.

This statement has been removed in V2.

In V1, stylecheck, gosimple, and staticcheck cover the 4 options of the standalone Staticcheck linter. They have been merged in golangci/golangci-lint#5487, that means the staticcheck in Golangci-lint V2 now actually works like the standalone Staticcheck linter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the context!

I think with v2 we should be safe unless I'm missing something?

golangci-lint:
runs-on: ubuntu-latest

Expand All @@ -64,6 +47,6 @@ jobs:
uses: actions/checkout@v4

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v7
with:
version: latest
20 changes: 19 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# https://golangci-lint.run/usage/configuration/
version: "2"
linters:
enable:
- makezero
- misspell
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
Copy link
Member

Choose a reason for hiding this comment

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

Did you copy this config from somewhere else? Because we only have the examples directory https://github.com/urfave/cli/tree/main/examples

Since our examples code are minimal, I think we should be able to include them in the linter too and not cause any errors. What do you think?

Copy link
Contributor Author

@mrueg mrueg Apr 1, 2025

Choose a reason for hiding this comment

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

This was auto-generated by golangci-lint migrate. I think right now it passes lint, so we can keep it like that.

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
Loading