From b6fab751e1f3f61f1bc8305f7c90d64d7afab38d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 12 Feb 2026 18:58:15 +0100 Subject: [PATCH] modernize some code Results of running the modernize command; go install golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest modernize -fix ./... Signed-off-by: Sebastiaan van Stijn --- clidocstool.go | 2 +- clidocstool_md.go | 6 +++--- markdown.go | 2 +- markdown_test.go | 2 -- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/clidocstool.go b/clidocstool.go index 6b853ca..40cf54f 100644 --- a/clidocstool.go +++ b/clidocstool.go @@ -174,7 +174,7 @@ func copyFile(src string, dst string) error { func getAliases(cmd *cobra.Command) []string { if a := cmd.Annotations["aliases"]; a != "" { aliases := strings.Split(a, ",") - for i := 0; i < len(aliases); i++ { + for i := range aliases { aliases[i] = strings.TrimSpace(aliases[i]) } return aliases diff --git a/clidocstool_md.go b/clidocstool_md.go index 4d52405..920f219 100644 --- a/clidocstool_md.go +++ b/clidocstool_md.go @@ -110,10 +110,10 @@ func (c *Client) GenMarkdownTree(cmd *cobra.Command) error { cs := string(content) - start := strings.Index(cs, "") + before, _, ok := strings.Cut(cs, "") end := strings.Index(cs, "") - if start == -1 { + if !ok { return fmt.Errorf("no start marker in %s", mdFile) } if end == -1 { @@ -124,7 +124,7 @@ func (c *Client) GenMarkdownTree(cmd *cobra.Command) error { if err != nil { return err } - cont := cs[:start] + "" + "\n" + out + "\n" + cs[end:] + cont := before + "" + "\n" + out + "\n" + cs[end:] fi, err := os.Stat(targetPath) if err != nil { diff --git a/markdown.go b/markdown.go index bd85487..3517278 100644 --- a/markdown.go +++ b/markdown.go @@ -74,7 +74,7 @@ func cleanupMarkDown(mdString string) (md string, anchors []string) { var id string // replace trailing whitespace per line, and handle custom anchors lines := strings.Split(mdString, "\n") - for i := 0; i < len(lines); i++ { + for i := range lines { lines[i] = strings.TrimRightFunc(lines[i], unicode.IsSpace) lines[i], id = convertHTMLAnchor(lines[i]) if id != "" { diff --git a/markdown_test.go b/markdown_test.go index 97c9e20..4ab4424 100644 --- a/markdown_test.go +++ b/markdown_test.go @@ -101,7 +101,6 @@ Last line.`, }, } for _, tc := range tests { - tc := tc t.Run(tc.doc, func(t *testing.T) { out, _ := cleanupMarkDown(tc.in) if out != tc.expected { @@ -147,7 +146,6 @@ func TestConvertHTMLAnchor(t *testing.T) { }, } for _, tc := range tests { - tc := tc t.Run(tc.in, func(t *testing.T) { out, id := convertHTMLAnchor(tc.in) if id != tc.id {