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 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 return success; | 61 return success; |
62 } | 62 } |
63 | 63 |
64 /// Runs the formatter on [file]. | 64 /// Runs the formatter on [file]. |
65 /// | 65 /// |
66 /// Returns `true` if successful or `false` if an error occurred. | 66 /// Returns `true` if successful or `false` if an error occurred. |
67 bool processFile(FormatterOptions options, File file, {String label}) { | 67 bool processFile(FormatterOptions options, File file, {String label}) { |
68 if (label == null) label = file.path; | 68 if (label == null) label = file.path; |
69 | 69 |
70 var formatter = new DartFormatter(pageWidth: options.pageWidth); | 70 var formatter = |
| 71 new DartFormatter(indent: options.indent, pageWidth: options.pageWidth); |
71 try { | 72 try { |
72 var source = new SourceCode(file.readAsStringSync(), uri: file.path); | 73 var source = new SourceCode(file.readAsStringSync(), uri: file.path); |
73 options.reporter.beforeFile(file, label); | 74 options.reporter.beforeFile(file, label); |
74 var output = formatter.formatSource(source); | 75 var output = formatter.formatSource(source); |
75 options.reporter | 76 options.reporter |
76 .afterFile(file, label, output, changed: source.text != output.text); | 77 .afterFile(file, label, output, changed: source.text != output.text); |
77 return true; | 78 return true; |
78 } on FormatterException catch (err) { | 79 } on FormatterException catch (err) { |
79 var color = Platform.operatingSystem != "windows" && | 80 var color = Platform.operatingSystem != "windows" && |
80 stdioType(stderr) == StdioType.TERMINAL; | 81 stdioType(stderr) == StdioType.TERMINAL; |
81 | 82 |
82 stderr.writeln(err.message(color: color)); | 83 stderr.writeln(err.message(color: color)); |
83 } catch (err, stack) { | 84 } catch (err, stack) { |
84 stderr.writeln('''Hit a bug in the formatter when formatting $label. | 85 stderr.writeln('''Hit a bug in the formatter when formatting $label. |
85 Please report at: github.com/dart-lang/dart_style/issues | 86 Please report at: github.com/dart-lang/dart_style/issues |
86 $err | 87 $err |
87 $stack'''); | 88 $stack'''); |
88 } | 89 } |
89 | 90 |
90 return false; | 91 return false; |
91 } | 92 } |
OLD | NEW |