LEFT | RIGHT |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "flag" | 9 "flag" |
10 "fmt" | 10 "fmt" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 os.Exit(exitCode) | 97 os.Exit(exitCode) |
98 } | 98 } |
99 | 99 |
100 const parserMode = parser.ParseComments | 100 const parserMode = parser.ParseComments |
101 | 101 |
102 func gofmtFile(f *ast.File) ([]byte, error) { | 102 func gofmtFile(f *ast.File) ([]byte, error) { |
103 var buf bytes.Buffer | 103 var buf bytes.Buffer |
104 ast.SortImports(fset, f) | |
105 if err := format.Node(&buf, fset, f); err != nil { | 104 if err := format.Node(&buf, fset, f); err != nil { |
106 return nil, err | 105 return nil, err |
107 } | 106 } |
108 return buf.Bytes(), nil | 107 return buf.Bytes(), nil |
109 } | 108 } |
110 | 109 |
111 func processFile(filename string, useStdin bool) error { | 110 func processFile(filename string, useStdin bool) error { |
112 var f *os.File | 111 var f *os.File |
113 var err error | 112 var err error |
114 var fixlog bytes.Buffer | 113 var fixlog bytes.Buffer |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 f2.Write(b2) | 249 f2.Write(b2) |
251 | 250 |
252 data, err = exec.Command("diff", "-u", f1.Name(), f2.Name()).CombinedOut
put() | 251 data, err = exec.Command("diff", "-u", f1.Name(), f2.Name()).CombinedOut
put() |
253 if len(data) > 0 { | 252 if len(data) > 0 { |
254 // diff exits with a non-zero status when the files don't match. | 253 // diff exits with a non-zero status when the files don't match. |
255 // Ignore that failure as long as we get output. | 254 // Ignore that failure as long as we get output. |
256 err = nil | 255 err = nil |
257 } | 256 } |
258 return | 257 return |
259 } | 258 } |
LEFT | RIGHT |