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

Side by Side Diff: pkg/analyzer/bin/formatter.dart

Issue 130843005: Fix to ensure only modified files are written to (dartbug.com/16093). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env dart 1 #!/usr/bin/env dart
2 2
3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
4 // for details. All rights reserved. Use of this source code is governed by a 4 // for details. All rights reserved. Use of this source code is governed by a
5 // BSD-style license that can be found in the LICENSE file. 5 // BSD-style license that can be found in the LICENSE file.
6 6
7 import 'dart:convert'; 7 import 'dart:convert';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:args/args.dart'; 10 import 'package:args/args.dart';
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 if (_isDartFile(file)) { 106 if (_isDartFile(file)) {
107 if (_isPatchFile(file) && !paths.contains(file.path)) { 107 if (_isPatchFile(file) && !paths.contains(file.path)) {
108 _log('Skipping patch file "${file.path}"'); 108 _log('Skipping patch file "${file.path}"');
109 return; 109 return;
110 } 110 }
111 try { 111 try {
112 var buffer = new StringBuffer(); 112 var buffer = new StringBuffer();
113 var rawSource = file.readAsStringSync(); 113 var rawSource = file.readAsStringSync();
114 var formatted = _format(rawSource, CodeKind.COMPILATION_UNIT); 114 var formatted = _format(rawSource, CodeKind.COMPILATION_UNIT);
115 if (overwriteFileContents) { 115 if (overwriteFileContents) {
116 file.writeAsStringSync(formatted); 116 // Only touch files files whose contents will be changed
117 if (rawSource != formatted) {
118 file.writeAsStringSync(formatted);
119 }
117 } else { 120 } else {
118 print(formatted); 121 print(formatted);
119 } 122 }
120 } catch (e) { 123 } catch (e) {
121 _log('Unable to format "${file.path}": $e'); 124 _log('Unable to format "${file.path}": $e');
122 } 125 }
123 } 126 }
124 } 127 }
125 128
126 _isPatchFile(file) => file.path.endsWith('_patch.dart'); 129 _isPatchFile(file) => file.path.endsWith('_patch.dart');
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 'offset': formatResult.selection.offset, 199 'offset': formatResult.selection.offset,
197 'length': formatResult.selection.length 200 'length': formatResult.selection.length
198 } 201 }
199 }); 202 });
200 203
201 /// Log the given [msg]. 204 /// Log the given [msg].
202 _log(String msg) { 205 _log(String msg) {
203 //TODO(pquitslund): add proper log support 206 //TODO(pquitslund): add proper log support
204 print(msg); 207 print(msg);
205 } 208 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698