Fix linting issues: canonicalheader, embeddedstructfieldcheck, iotamixing, makezero, testableexamples, wastedassign, usetesting, tparallel, unconvert, intrange, iface
- canonicalheader: fix cacheTTL header value to canonical form - embeddedstructfieldcheck: move embedded fields before regular fields in 4 structs - iotamixing: split const blocks mixing iota with non-iota constants - makezero: use make([]T, 0, n) instead of make([]T, n) before appending - testableexamples: add missing Output: comment to ExampleOption_UnwrapOrZero - wastedassign: remove wasted initial assignments in 4 locations - usetesting: replace os.MkdirTemp/os.Setenv with t.TempDir/t.Setenv in tests - tparallel: add t.Parallel() to 8 top-level test functions - unconvert: remove 16 unnecessary type conversions - intrange: convert 3 for loops to use integer range syntax - iface: consolidate identical EditPrompter and Prompt interfaces via type alias Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
6c11ecd9ab
commit
dca59d52b6
113 changed files with 222 additions and 287 deletions
|
|
@ -171,11 +171,7 @@ func TestManPrintFlagsHidesShortDeprecated(t *testing.T) {
|
|||
|
||||
func TestGenManTree(t *testing.T) {
|
||||
c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}
|
||||
tmpdir, err := os.MkdirTemp("", "test-gen-man-tree")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create tmpdir: %s", err.Error())
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
tmpdir := t.TempDir()
|
||||
|
||||
if err := GenManTree(c, tmpdir); err != nil {
|
||||
t.Fatalf("GenManTree failed: %s", err.Error())
|
||||
|
|
@ -310,7 +306,7 @@ func BenchmarkGenManToFile(b *testing.B) {
|
|||
defer file.Close()
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for range b.N {
|
||||
if err := renderMan(rootCmd, nil, file); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ func printAliases(w io.Writer, cmd *cobra.Command) {
|
|||
fmt.Fprint(w, text.FormatSlice(strings.Split(strings.Join(root.BuildAliasList(cmd, cmd.Aliases), ", "), ","), 0, 0, "", "", true))
|
||||
fmt.Fprint(w, "\n\n")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func printOptions(w io.Writer, cmd *cobra.Command) error {
|
||||
|
|
@ -80,7 +79,6 @@ var defaultValFormats = map[string]string{
|
|||
}
|
||||
|
||||
func getDefaultValueDisplayString(f *pflag.Flag) string {
|
||||
|
||||
if hiddenFlagDefaults[f.DefValue] || hiddenFlagDefaults[f.Value.Type()] {
|
||||
return ""
|
||||
}
|
||||
|
|
@ -89,7 +87,6 @@ func getDefaultValueDisplayString(f *pflag.Flag) string {
|
|||
return fmt.Sprintf(dvf, f.Value)
|
||||
}
|
||||
return fmt.Sprintf(" (default %s)", f.Value)
|
||||
|
||||
}
|
||||
|
||||
type flagView struct {
|
||||
|
|
|
|||
|
|
@ -101,11 +101,7 @@ func TestGenMdJSONFields(t *testing.T) {
|
|||
|
||||
func TestGenMdTree(t *testing.T) {
|
||||
c := &cobra.Command{Use: "do [OPTIONS] arg1 arg2"}
|
||||
tmpdir, err := os.MkdirTemp("", "test-gen-md-tree")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create tmpdir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpdir)
|
||||
tmpdir := t.TempDir()
|
||||
|
||||
if err := GenMarkdownTreeCustom(c, tmpdir, func(s string) string { return s }, func(s string) string { return s }); err != nil {
|
||||
t.Fatalf("GenMarkdownTree failed: %v", err)
|
||||
|
|
@ -126,7 +122,7 @@ func BenchmarkGenMarkdownToFile(b *testing.B) {
|
|||
linkHandler := func(s string) string { return s }
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for range b.N {
|
||||
if err := genMarkdownCustom(rootCmd, file, linkHandler); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
|
@ -134,7 +130,6 @@ func BenchmarkGenMarkdownToFile(b *testing.B) {
|
|||
}
|
||||
|
||||
func TestPrintFlagsHTMLShowsDefaultValues(t *testing.T) {
|
||||
|
||||
type TestOptions struct {
|
||||
Limit int
|
||||
Template string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue