@@ -143,7 +143,7 @@ func processFile(filename string, in io.Reader, out io.Writer, argType argumentT
143
143
return err
144
144
}
145
145
146
- if ! bytes . Equal (src , res ) {
146
+ if ! compareByLine (src , res ) {
147
147
// formatting has changed
148
148
if * list {
149
149
fmt .Fprintln (out , filename )
@@ -183,6 +183,26 @@ func processFile(filename string, in io.Reader, out io.Writer, argType argumentT
183
183
return err
184
184
}
185
185
186
+ func compareByLine (src , dst []byte ) bool {
187
+ src = bytes .Replace (src , []byte ("\r \n " ), []byte ("\n " ), - 1 )
188
+ // dst is already normalized by imports.Process
189
+
190
+ linesA := bytes .Split (src , []byte ("\n " ))
191
+ linesB := bytes .Split (dst , []byte ("\n " ))
192
+
193
+ if len (linesA ) != len (linesB ) {
194
+ return false
195
+ }
196
+
197
+ for i := range linesA {
198
+ if ! bytes .Equal (linesA [i ], linesB [i ]) {
199
+ return false
200
+ }
201
+ }
202
+
203
+ return true
204
+ }
205
+
186
206
func visitFile (path string , f os.FileInfo , err error ) error {
187
207
if err == nil && isGoFile (f ) {
188
208
err = processFile (path , nil , os .Stdout , multipleArg )
0 commit comments