| OLD | NEW |
| 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 |
| 11 import 'dart_formatter.dart'; | 11 import 'dart_formatter.dart'; |
| 12 import 'formatter_exception.dart'; | 12 import 'exceptions.dart'; |
| 13 import 'formatter_options.dart'; | 13 import 'formatter_options.dart'; |
| 14 import 'source_code.dart'; | 14 import 'source_code.dart'; |
| 15 | 15 |
| 16 /// Runs the formatter on every .dart file in [path] (and its subdirectories), | 16 /// Runs the formatter on every .dart file in [path] (and its subdirectories), |
| 17 /// and replaces them with their formatted output. | 17 /// and replaces them with their formatted output. |
| 18 /// | 18 /// |
| 19 /// Returns `true` if successful or `false` if an error occurred in any of the | 19 /// Returns `true` if successful or `false` if an error occurred in any of the |
| 20 /// files. | 20 /// files. |
| 21 bool processDirectory(FormatterOptions options, Directory directory) { | 21 bool processDirectory(FormatterOptions options, Directory directory) { |
| 22 options.reporter.showDirectory(directory.path); | 22 options.reporter.showDirectory(directory.path); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 options.reporter.beforeFile(file, label); | 74 options.reporter.beforeFile(file, label); |
| 75 var output = formatter.formatSource(source); | 75 var output = formatter.formatSource(source); |
| 76 options.reporter | 76 options.reporter |
| 77 .afterFile(file, label, output, changed: source.text != output.text); | 77 .afterFile(file, label, output, changed: source.text != output.text); |
| 78 return true; | 78 return true; |
| 79 } on FormatterException catch (err) { | 79 } on FormatterException catch (err) { |
| 80 var color = Platform.operatingSystem != "windows" && | 80 var color = Platform.operatingSystem != "windows" && |
| 81 stdioType(stderr) == StdioType.TERMINAL; | 81 stdioType(stderr) == StdioType.TERMINAL; |
| 82 | 82 |
| 83 stderr.writeln(err.message(color: color)); | 83 stderr.writeln(err.message(color: color)); |
| 84 } on UnexpectedOutputException catch (err) { |
| 85 stderr.writeln('''Hit a bug in the formatter when formatting $label. |
| 86 $err |
| 87 Please report at github.com/dart-lang/dart_style/issues.'''); |
| 84 } catch (err, stack) { | 88 } catch (err, stack) { |
| 85 stderr.writeln('''Hit a bug in the formatter when formatting $label. | 89 stderr.writeln('''Hit a bug in the formatter when formatting $label. |
| 86 Please report at: github.com/dart-lang/dart_style/issues | 90 Please report at github.com/dart-lang/dart_style/issues. |
| 87 $err | 91 $err |
| 88 $stack'''); | 92 $stack'''); |
| 89 } | 93 } |
| 90 | 94 |
| 91 return false; | 95 return false; |
| 92 } | 96 } |
| OLD | NEW |