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

Unified Diff: pkg/analyzer_experimental/lib/src/services/formatter_impl.dart

Issue 23458038: Ensure formatted CUs end with a newline (dartbug.com/13188). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer_experimental/lib/src/services/writer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer_experimental/lib/src/services/formatter_impl.dart
===================================================================
--- pkg/analyzer_experimental/lib/src/services/formatter_impl.dart (revision 27350)
+++ pkg/analyzer_experimental/lib/src/services/formatter_impl.dart (working copy)
@@ -455,6 +455,9 @@
// Handle trailing whitespace
token(node.endToken /* EOF */);
+
+ // Be a good citizen, end with a NL
+ ensureTrailingNewline();
}
visitConditionalExpression(ConditionalExpression node) {
@@ -1210,7 +1213,7 @@
/// Append the given [string] to the source writer if it's non-null.
append(String string) {
- if (string != null) {
+ if (string != null && !string.isEmpty) {
writer.print(string);
}
}
@@ -1266,6 +1269,14 @@
return lines;
}
+
+ ensureTrailingNewline() {
+ if (writer.lastToken is! NewlineToken) {
+ writer.newline();
+ }
+ }
+
+
/// Test if this [comment] is at the end of a line.
bool isAtEOL(Token comment) =>
comment != null && comment.toString().trim().startsWith(twoSlashes) &&
« no previous file with comments | « no previous file | pkg/analyzer_experimental/lib/src/services/writer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698