Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: lib/src/io.dart

Issue 850953004: Don't touch files whose contents do not change. Fix #127. (Closed) Base URL: https://github.com/dart-lang/dart_style.git@master
Patch Set: Update changelog. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | test/io_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart_style.src.io; 5 library dart_style.src.io;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:path/path.dart' as p; 9 import 'package:path/path.dart' as p;
10 10
(...skipping 20 matching lines...) Expand all
31 } 31 }
32 } 32 }
33 33
34 /// Runs the formatter on [file]. 34 /// Runs the formatter on [file].
35 void processFile(File file, {String label, bool overwrite, int pageWidth}) { 35 void processFile(File file, {String label, bool overwrite, int pageWidth}) {
36 if (label == null) label = file.path; 36 if (label == null) label = file.path;
37 if (overwrite == null) overwrite = false; 37 if (overwrite == null) overwrite = false;
38 38
39 var formatter = new DartFormatter(pageWidth: pageWidth); 39 var formatter = new DartFormatter(pageWidth: pageWidth);
40 try { 40 try {
41 var output = formatter.format(file.readAsStringSync(), uri: file.path); 41 var source = file.readAsStringSync();
42 var output = formatter.format(source, uri: file.path);
42 if (overwrite) { 43 if (overwrite) {
43 file.writeAsStringSync(output); 44 if (source != output) {
44 print("Formatted $label"); 45 file.writeAsStringSync(output);
46 print("Formatted $label");
47 } else {
48 print("Unchanged $label");
49 }
45 } else { 50 } else {
46 // Don't add an extra newline. 51 // Don't add an extra newline.
47 stdout.write(output); 52 stdout.write(output);
48 } 53 }
49 } on FormatterException catch (err) { 54 } on FormatterException catch (err) {
50 stderr.writeln(err.message()); 55 stderr.writeln(err.message());
51 } catch (err, stack) { 56 } catch (err, stack) {
52 stderr.writeln('''Hit a bug in the formatter when formatting $label 57 stderr.writeln('''Hit a bug in the formatter when formatting $label
53 Please report at: github.com/dart-lang/dart_style/issues 58 Please report at: github.com/dart-lang/dart_style/issues
54 $err 59 $err
55 $stack'''); 60 $stack''');
56 } 61 }
57 } 62 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | test/io_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698