Merge pull request #365 from hezhizhen/staticcheck

de-capitalize errors to make staticcheck happy
This commit is contained in:
Masayuki Matsuki 2023-02-23 18:46:40 +09:00 committed by GitHub
commit 67a22bf1f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 12 additions and 10 deletions

View file

@ -153,7 +153,7 @@ func look(name string) error {
switch len(reposFound) {
case 0:
return fmt.Errorf("No repository found")
return fmt.Errorf("no repository found")
case 1:
repo := reposFound[0]
cmd := exec.Command(detectShell())

View file

@ -264,7 +264,7 @@ func TestLook(t *testing.T) {
}
err = look("github.com/motemen/_unknown")
expect := "No repository found"
expect := "no repository found"
if !strings.HasPrefix(fmt.Sprintf("%s", err), expect) {
t.Errorf("error should has prefix %q, but: %s", expect, err)
}

View file

@ -90,7 +90,7 @@ var commandDocs = map[string]commandDoc{
// Makes template conditionals to generate per-command documents.
func mkCommandsTemplate(genTemplate func(commandDoc) string) string {
template := "{{if false}}"
for _, command := range append(commands) {
for _, command := range commands {
template = template + fmt.Sprintf("{{else if (eq .Name %q)}}%s", command.Name, genTemplate(commandDocs[command.Name]))
}
return template + "{{end}}"

View file

@ -27,7 +27,7 @@ type getter struct {
func (g *getter) get(argURL string) error {
u, err := newURL(argURL, g.ssh, false)
if err != nil {
return fmt.Errorf("Could not parse URL %q: %w", argURL, err)
return fmt.Errorf("could not parse URL %q: %w", argURL, err)
}
branch := g.branch
if pos := strings.LastIndexByte(u.Path, '@'); pos >= 0 {

View file

@ -21,13 +21,12 @@ func captureReader(block func()) (*os.File, *os.File, error) {
if err != nil {
return nil, nil, err
}
defer wOut.Close()
rErr, wErr, err := os.Pipe()
if err != nil {
return nil, nil, err
}
defer wOut.Close()
defer wErr.Close()
var stdout, stderr *os.File
@ -74,9 +73,12 @@ func captureWithInput(in []string, block func()) (string, string, error) {
return "", "", err
}
defer rIn.Close()
var stdin *os.File
os.Stdin, stdin = rIn, os.Stdin
defer func() { os.Stdin = stdin }()
for _, line := range in {
fmt.Fprintln(wIn, line)
}

View file

@ -50,7 +50,7 @@ func TestNewRemoteRepository(t *testing.T) {
if repo.IsValid() != tc.valid {
t.Errorf("repo.IsValid() should be %v, but %v", tc.valid, repo.IsValid())
}
vcs, u, err := repo.VCS()
vcs, u, _ := repo.VCS()
if vcs != tc.vcsBackend {
t.Errorf("got: %+v, expect: %+v", vcs, tc.vcsBackend)
}

2
url.go
View file

@ -148,7 +148,7 @@ func newURL(ref string, ssh, forceMe bool) (*url.URL, error) {
if ssh {
// Assume Git repository if `-p` is given.
if u, err = convertGitURLHTTPToSSH(u); err != nil {
return nil, fmt.Errorf("Could not convert URL %q: %w", u, err)
return nil, fmt.Errorf("could not convert URL %q: %w", u, err)
}
}

4
vcs.go
View file

@ -271,7 +271,7 @@ var MercurialBackend = &VCSBackend{
var DarcsBackend = &VCSBackend{
Clone: func(vg *vcsGetOption) error {
if vg.branch != "" {
return errors.New("Darcs does not support branch")
return errors.New("darcs does not support branch")
}
dir, _ := filepath.Split(vg.dir)
@ -313,7 +313,7 @@ const fossilRepoName = ".fossil" // same as Go
var FossilBackend = &VCSBackend{
Clone: func(vg *vcsGetOption) error {
if vg.branch != "" {
return errors.New("Fossil does not support cloning specific branch")
return errors.New("fossil does not support cloning specific branch")
}
if err := os.MkdirAll(vg.dir, 0755); err != nil {
return err