From cefa808653e45656cb8c13e1d7f2058610fde8fb Mon Sep 17 00:00:00 2001 From: yulog <29723448+yulog@users.noreply.github.com> Date: Sun, 15 Feb 2026 19:45:03 +0900 Subject: [PATCH] chore: exec go fix ./... --- getter.go | 4 ++-- local_repository.go | 11 +++-------- logger/log.go | 2 +- vcs.go | 12 ++++++------ 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/getter.go b/getter.go index d6eb24f..ce7d917 100644 --- a/getter.go +++ b/getter.go @@ -149,8 +149,8 @@ func detectLocalRepoRoot(remotePath, repoPath string) string { pathParts = pathParts[1:] for i := 0; i < len(pathParts); i++ { subPath := "/" + path.Join(pathParts[i:]...) - if subIdx := strings.Index(remotePath, subPath); subIdx >= 0 { - return remotePath[0:subIdx] + subPath + if before, _, ok := strings.Cut(remotePath, subPath); ok { + return before + subPath } } return "" diff --git a/local_repository.go b/local_repository.go index 8444824..500da67 100644 --- a/local_repository.go +++ b/local_repository.go @@ -6,6 +6,7 @@ import ( "net/url" "os" "path/filepath" + "slices" "strings" "sync" @@ -166,7 +167,7 @@ func (repo *LocalRepository) repoRootCandidates() []string { hostRoot := filepath.Join(repo.RootPath, repo.PathParts[0]) nonHostParts := repo.PathParts[1:] candidates := make([]string, len(nonHostParts)) - for i := 0; i < len(nonHostParts); i++ { + for i := range nonHostParts { candidates[i] = filepath.Join(append( []string{hostRoot}, nonHostParts[0:len(nonHostParts)-i]...)...) } @@ -184,13 +185,7 @@ func (repo *LocalRepository) IsUnderPrimaryRoot() bool { // Matches checks if any subpath of the local repository equals the query. func (repo *LocalRepository) Matches(pathQuery string) bool { - for _, p := range repo.Subpaths() { - if p == pathQuery { - return true - } - } - - return false + return slices.Contains(repo.Subpaths(), pathQuery) } // VCS returns VCSBackend of the repository diff --git a/logger/log.go b/logger/log.go index 76bf663..8fed279 100644 --- a/logger/log.go +++ b/logger/log.go @@ -71,6 +71,6 @@ func Log(prefix, message string) { } // Logf outputs log with format -func Logf(prefix, msg string, args ...interface{}) { +func Logf(prefix, msg string, args ...any) { Log(prefix, fmt.Sprintf(msg, args...)) } diff --git a/vcs.go b/vcs.go index 8e28ee3..617f797 100644 --- a/vcs.go +++ b/vcs.go @@ -193,8 +193,8 @@ func replaceOnce(reg *regexp.Regexp, str, replace string) string { } func svnBase(p string) string { - if strings.HasSuffix(p, trunk) { - return strings.TrimSuffix(p, trunk) + if before, ok := strings.CutSuffix(p, trunk); ok { + return before } return replaceOnce(svnReg, p, "") } @@ -394,8 +394,8 @@ var DarcsBackend = &VCSBackend{ if err != nil { return "", fmt.Errorf("failed to show repo: %w", err) } - lines := strings.Split(string(output), "\n") - for _, line := range lines { + lines := strings.SplitSeq(string(output), "\n") + for line := range lines { if strings.HasPrefix(strings.TrimSpace(line), "Default Remote:") { parts := strings.SplitN(line, ":", 2) if len(parts) == 2 { @@ -441,8 +441,8 @@ var PijulBackend = &VCSBackend{ if err != nil { return "", fmt.Errorf("failed to list remotes: %w", err) } - lines := strings.Split(strings.TrimSpace(string(output)), "\n") - for _, line := range lines { + lines := strings.SplitSeq(strings.TrimSpace(string(output)), "\n") + for line := range lines { trimmed := strings.TrimSpace(line) if trimmed != "" { // First non-empty line is the first remote