| OLD | NEW |
| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 _formatDirectory(dir) => dir.listSync(followLinks: FOLLOW_LINKS) | 147 _formatDirectory(dir) => dir.listSync(followLinks: FOLLOW_LINKS) |
| 148 .forEach((resource) => _formatResource(resource)); | 148 .forEach((resource) => _formatResource(resource)); |
| 149 | 149 |
| 150 _formatFile(file) { | 150 _formatFile(file) { |
| 151 if (_isDartFile(file)) { | 151 if (_isDartFile(file)) { |
| 152 if (_isPatchFile(file) && !paths.contains(file.path)) { | 152 if (_isPatchFile(file) && !paths.contains(file.path)) { |
| 153 _log('Skipping patch file "${file.path}"'); | 153 _log('Skipping patch file "${file.path}"'); |
| 154 return; | 154 return; |
| 155 } | 155 } |
| 156 try { | 156 try { |
| 157 var buffer = new StringBuffer(); | |
| 158 var rawSource = file.readAsStringSync(); | 157 var rawSource = file.readAsStringSync(); |
| 159 var formatted = _format(rawSource, CodeKind.COMPILATION_UNIT); | 158 var formatted = _format(rawSource, CodeKind.COMPILATION_UNIT); |
| 160 if (overwriteFileContents) { | 159 if (overwriteFileContents) { |
| 161 // Only touch files files whose contents will be changed | 160 // Only touch files files whose contents will be changed |
| 162 if (rawSource != formatted) { | 161 if (rawSource != formatted) { |
| 163 file.writeAsStringSync(formatted); | 162 file.writeAsStringSync(formatted); |
| 164 } | 163 } |
| 165 } else { | 164 } else { |
| 166 print(formatted); | 165 print(formatted); |
| 167 } | 166 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 'offset': formatResult.selection.offset, | 250 'offset': formatResult.selection.offset, |
| 252 'length': formatResult.selection.length | 251 'length': formatResult.selection.length |
| 253 } | 252 } |
| 254 }); | 253 }); |
| 255 | 254 |
| 256 /// Log the given [msg]. | 255 /// Log the given [msg]. |
| 257 _log(String msg) { | 256 _log(String msg) { |
| 258 //TODO(pquitslund): add proper log support | 257 //TODO(pquitslund): add proper log support |
| 259 print(msg); | 258 print(msg); |
| 260 } | 259 } |
| OLD | NEW |