]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/fsys: rewrite non-idiomatic if statements
authorRuss Cox <rsc@golang.org>
Fri, 23 Oct 2020 00:55:38 +0000 (20:55 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 26 Oct 2020 16:58:50 +0000 (16:58 +0000)
https://golang.org/doc/effective_go.html#if

Change-Id: I4d868e05c7827638f45b3b06d8762f5a298d56f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/264537
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/fsys/fsys.go

index 814e3237011e2408640064e1f033e1cb4d376e3c..3275c3faf7855c3577aa600df30c61583e513a85 100644 (file)
@@ -249,11 +249,11 @@ func readDir(dir string) ([]fs.FileInfo, error) {
 
        if os.IsNotExist(err) {
                return nil, err
-       } else if dirfi, staterr := os.Stat(dir); staterr == nil && !dirfi.IsDir() {
+       }
+       if dirfi, staterr := os.Stat(dir); staterr == nil && !dirfi.IsDir() {
                return nil, &fs.PathError{Op: "ReadDir", Path: dir, Err: errNotDir}
-       } else {
-               return nil, err
        }
+       return nil, err
 }
 
 // ReadDir provides a slice of fs.FileInfo entries corresponding
@@ -267,7 +267,8 @@ func ReadDir(dir string) ([]fs.FileInfo, error) {
        dirNode := overlay[dir]
        if dirNode == nil {
                return readDir(dir)
-       } else if dirNode.isDeleted() {
+       }
+       if dirNode.isDeleted() {
                return nil, &fs.PathError{Op: "ReadDir", Path: dir, Err: fs.ErrNotExist}
        }
        diskfis, err := readDir(dir)
@@ -331,17 +332,18 @@ func Open(path string) (*os.File, error) {
                        return nil, &fs.PathError{Op: "Open", Path: path, Err: errors.New("fsys.Open doesn't support opening directories yet")}
                }
                return os.Open(node.actualFilePath)
-       } else if parent, ok := parentIsOverlayFile(filepath.Dir(cpath)); ok {
+       }
+       if parent, ok := parentIsOverlayFile(filepath.Dir(cpath)); ok {
                // The file is deleted explicitly in the Replace map,
                // or implicitly because one of its parent directories was
                // replaced by a file.
                return nil, &fs.PathError{
                        Op:   "Open",
                        Path: path,
-                       Err:  fmt.Errorf("file %s does not exist: parent directory %s is replaced by a file in overlay", path, parent)}
-       } else {
-               return os.Open(cpath)
+                       Err:  fmt.Errorf("file %s does not exist: parent directory %s is replaced by a file in overlay", path, parent),
+               }
        }
+       return os.Open(cpath)
 }
 
 // IsDirWithGoFiles reports whether dir is a directory containing Go files
@@ -350,7 +352,8 @@ func IsDirWithGoFiles(dir string) (bool, error) {
        fis, err := ReadDir(dir)
        if os.IsNotExist(err) || errors.Is(err, errNotDir) {
                return false, nil
-       } else if err != nil {
+       }
+       if err != nil {
                return false, err
        }
 
@@ -377,7 +380,8 @@ func IsDirWithGoFiles(dir string) (bool, error) {
                actualFilePath, _ := OverlayPath(filepath.Join(dir, fi.Name()))
                if fi, err := os.Stat(actualFilePath); err == nil && fi.Mode().IsRegular() {
                        return true, nil
-               } else if err != nil && firstErr == nil {
+               }
+               if err != nil && firstErr == nil {
                        firstErr = err
                }
        }