summaryrefslogtreecommitdiff
path: root/src/cmd/gofmt/gofmt.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/gofmt/gofmt.go')
-rw-r--r--src/cmd/gofmt/gofmt.go18
1 files changed, 4 insertions, 14 deletions
diff --git a/src/cmd/gofmt/gofmt.go b/src/cmd/gofmt/gofmt.go
index ea1c1b00f..975ae6ac6 100644
--- a/src/cmd/gofmt/gofmt.go
+++ b/src/cmd/gofmt/gofmt.go
@@ -22,7 +22,6 @@ import (
"strings"
)
-
var (
// main operation modes
list = flag.Bool("l", false, "list files whose formatting differs from gofmt's")
@@ -30,6 +29,7 @@ var (
rewriteRule = flag.String("r", "", "rewrite rule (e.g., 'α[β:len(α)] -> α[β:]')")
simplifyAST = flag.Bool("s", false, "simplify code")
doDiff = flag.Bool("d", false, "display diffs instead of rewriting files")
+ allErrors = flag.Bool("e", false, "print all (including spurious) errors")
// layout control
comments = flag.Bool("comments", true, "print comments")
@@ -41,7 +41,6 @@ var (
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to this file")
)
-
var (
fset = token.NewFileSet()
exitCode = 0
@@ -50,28 +49,27 @@ var (
printerMode uint
)
-
func report(err os.Error) {
scanner.PrintError(os.Stderr, err)
exitCode = 2
}
-
func usage() {
fmt.Fprintf(os.Stderr, "usage: gofmt [flags] [path ...]\n")
flag.PrintDefaults()
os.Exit(2)
}
-
func initParserMode() {
parserMode = uint(0)
if *comments {
parserMode |= parser.ParseComments
}
+ if *allErrors {
+ parserMode |= parser.SpuriousErrors
+ }
}
-
func initPrinterMode() {
printerMode = uint(0)
if *tabIndent {
@@ -82,13 +80,11 @@ func initPrinterMode() {
}
}
-
func isGoFile(f *os.FileInfo) bool {
// ignore non-Go files
return f.IsRegular() && !strings.HasPrefix(f.Name, ".") && strings.HasSuffix(f.Name, ".go")
}
-
// If in == nil, the source is the contents of the file with the given filename.
func processFile(filename string, in io.Reader, out io.Writer) os.Error {
if in == nil {
@@ -153,14 +149,12 @@ func processFile(filename string, in io.Reader, out io.Writer) os.Error {
return err
}
-
type fileVisitor chan os.Error
func (v fileVisitor) VisitDir(path string, f *os.FileInfo) bool {
return true
}
-
func (v fileVisitor) VisitFile(path string, f *os.FileInfo) {
if isGoFile(f) {
v <- nil // synchronize error handler
@@ -170,7 +164,6 @@ func (v fileVisitor) VisitFile(path string, f *os.FileInfo) {
}
}
-
func walkDir(path string) {
v := make(fileVisitor)
go func() {
@@ -184,7 +177,6 @@ func walkDir(path string) {
}
}
-
func main() {
// call gofmtMain in a separate function
// so that it can use defer and have them
@@ -193,7 +185,6 @@ func main() {
os.Exit(exitCode)
}
-
func gofmtMain() {
flag.Usage = usage
flag.Parse()
@@ -241,7 +232,6 @@ func gofmtMain() {
}
}
-
func diff(b1, b2 []byte) (data []byte, err os.Error) {
f1, err := ioutil.TempFile("", "gofmt")
if err != nil {