diff --git a/changedlines.go b/changedlines.go index 1526cf8..5cc0529 100644 --- a/changedlines.go +++ b/changedlines.go @@ -73,7 +73,7 @@ func (d *diffIndex) repoDiff(repo string) *repoDiff { parseUnifiedDiff(string(out), rd) } if out, err := exec.Command("git", "-C", repo, "ls-files", "--others", "--exclude-standard").Output(); err == nil { - for _, f := range strings.Split(strings.TrimSpace(string(out)), "\n") { + for f := range strings.SplitSeq(strings.TrimSpace(string(out)), "\n") { if f != "" { rd.untracked[filepath.ToSlash(f)] = true } @@ -106,7 +106,7 @@ func parseUnifiedDiff(diff string, rd *repoDiff) { if rd.changed[cur] == nil { rd.changed[cur] = map[int]bool{} } - for i := 0; i < count; i++ { + for i := range count { rd.changed[cur][start+i] = true } } @@ -116,18 +116,18 @@ func parseUnifiedDiff(diff string, rd *repoDiff) { // parseHunkNewRange extracts (start, count) from the `+c,d` part of a hunk // header like `@@ -a,b +c,d @@`. A missing `,d` means count 1. func parseHunkNewRange(header string) (int, int) { - plus := strings.IndexByte(header, '+') - if plus < 0 { + _, after, ok := strings.Cut(header, "+") + if !ok { return 0, 0 } - rest := header[plus+1:] + rest := after if sp := strings.IndexByte(rest, ' '); sp >= 0 { rest = rest[:sp] } start, count := 0, 1 - if comma := strings.IndexByte(rest, ','); comma >= 0 { - start, _ = strconv.Atoi(rest[:comma]) - count, _ = strconv.Atoi(rest[comma+1:]) + if before, after, ok := strings.Cut(rest, ","); ok { + start, _ = strconv.Atoi(before) + count, _ = strconv.Atoi(after) } else { start, _ = strconv.Atoi(rest) } diff --git a/toolbar.go b/toolbar.go index 2a23177..2b6e5d6 100644 --- a/toolbar.go +++ b/toolbar.go @@ -68,10 +68,7 @@ func checkToolbarInjection(root string) []toolbarViolation { } bodyStart := fset.Position(fn.Body.Pos()).Offset - bodyEnd := fset.Position(fn.Body.End()).Offset - if bodyEnd > len(srcText) { - bodyEnd = len(srcText) - } + bodyEnd := min(fset.Position(fn.Body.End()).Offset, len(srcText)) body := srcText[bodyStart:bodyEnd] hasSiteSettings := strings.Contains(body, "getSiteSettings")