Skip to content

Commit bad2919

Browse files
authored
Merge pull request #77 from thaJeztah/modernize
modernize some code
2 parents b42badc + b6fab75 commit bad2919

4 files changed

Lines changed: 5 additions & 7 deletions

File tree

clidocstool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func copyFile(src string, dst string) error {
174174
func getAliases(cmd *cobra.Command) []string {
175175
if a := cmd.Annotations["aliases"]; a != "" {
176176
aliases := strings.Split(a, ",")
177-
for i := 0; i < len(aliases); i++ {
177+
for i := range aliases {
178178
aliases[i] = strings.TrimSpace(aliases[i])
179179
}
180180
return aliases

clidocstool_md.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ func (c *Client) GenMarkdownTree(cmd *cobra.Command) error {
110110

111111
cs := string(content)
112112

113-
start := strings.Index(cs, "<!---MARKER_GEN_START-->")
113+
before, _, ok := strings.Cut(cs, "<!---MARKER_GEN_START-->")
114114
end := strings.Index(cs, "<!---MARKER_GEN_END-->")
115115

116-
if start == -1 {
116+
if !ok {
117117
return fmt.Errorf("no start marker in %s", mdFile)
118118
}
119119
if end == -1 {
@@ -124,7 +124,7 @@ func (c *Client) GenMarkdownTree(cmd *cobra.Command) error {
124124
if err != nil {
125125
return err
126126
}
127-
cont := cs[:start] + "<!---MARKER_GEN_START-->" + "\n" + out + "\n" + cs[end:]
127+
cont := before + "<!---MARKER_GEN_START-->" + "\n" + out + "\n" + cs[end:]
128128

129129
fi, err := os.Stat(targetPath)
130130
if err != nil {

markdown.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func cleanupMarkDown(mdString string) (md string, anchors []string) {
7474
var id string
7575
// replace trailing whitespace per line, and handle custom anchors
7676
lines := strings.Split(mdString, "\n")
77-
for i := 0; i < len(lines); i++ {
77+
for i := range lines {
7878
lines[i] = strings.TrimRightFunc(lines[i], unicode.IsSpace)
7979
lines[i], id = convertHTMLAnchor(lines[i])
8080
if id != "" {

markdown_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ Last line.`,
101101
},
102102
}
103103
for _, tc := range tests {
104-
tc := tc
105104
t.Run(tc.doc, func(t *testing.T) {
106105
out, _ := cleanupMarkDown(tc.in)
107106
if out != tc.expected {
@@ -147,7 +146,6 @@ func TestConvertHTMLAnchor(t *testing.T) {
147146
},
148147
}
149148
for _, tc := range tests {
150-
tc := tc
151149
t.Run(tc.in, func(t *testing.T) {
152150
out, id := convertHTMLAnchor(tc.in)
153151
if id != tc.id {

0 commit comments

Comments
 (0)