Skip to content

Commit 6c8fcc6

Browse files
committed
Don't put spaces in empty for loop clauses.
Fix #132. BUG=#132 [email protected] Review URL: https://chromiumcodereview.appspot.com//815423003
1 parent 65cf7ef commit 6c8fcc6

File tree

4 files changed

+31
-20
lines changed

4 files changed

+31
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 0.1.3
22

33
* Split different operators with the same precedence equally (#130).
4+
* No spaces for empty for loop clauses (#132).
45

56
# 0.1.2
67

lib/src/source_visitor.dart

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -753,36 +753,32 @@ class SourceVisitor implements AstVisitor {
753753
// The initialization clause.
754754
if (node.initialization != null) {
755755
visit(node.initialization);
756-
} else {
757-
if (node.variables == null) {
758-
space();
759-
} else {
760-
// Indent split variables more so they aren't at the same level
761-
// as the rest of the loop clauses.
762-
_writer.indent(4);
756+
} else if (node.variables != null) {
757+
// Indent split variables more so they aren't at the same level
758+
// as the rest of the loop clauses.
759+
_writer.indent(4);
763760

764-
var declaration = node.variables;
765-
visitDeclarationMetadata(declaration.metadata);
766-
modifier(declaration.keyword);
767-
visit(declaration.type, after: space);
761+
var declaration = node.variables;
762+
visitDeclarationMetadata(declaration.metadata);
763+
modifier(declaration.keyword);
764+
visit(declaration.type, after: space);
768765

769-
visitCommaSeparatedNodes(declaration.variables, between: () {
770-
_writer.multisplit(space: true, nest: true);
771-
});
766+
visitCommaSeparatedNodes(declaration.variables, between: () {
767+
_writer.multisplit(space: true, nest: true);
768+
});
772769

773-
_writer.unindent(4);
774-
}
770+
_writer.unindent(4);
775771
}
776772

777773
token(node.leftSeparator);
778-
_writer.multisplit(nest: true, space: true);
779774

780775
// The condition clause.
776+
if (node.condition != null) _writer.multisplit(nest: true, space: true);
781777
visit(node.condition);
782778
token(node.rightSeparator);
783779

784780
// The update clause.
785-
if (node.updaters != null) {
781+
if (node.updaters.isNotEmpty) {
786782
_writer.multisplit(nest: true, space: true);
787783
visitCommaSeparatedNodes(node.updaters,
788784
between: () => _writer.multisplit(nest: true, space: true));

test/regression/132.stmt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
>>>
2+
for (; i < words.length; i++) {
3+
buffer.write(' ');
4+
buffer.write(words[i]);
5+
}
6+
<<<
7+
for (; i < words.length; i++) {
8+
buffer.write(' ');
9+
buffer.write(words[i]);
10+
}

test/whitespace/for.stmt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ for (var i = 0;i<100;i++) {
77
for (var i = 0; i < 100; i++) {
88
print(i);
99
}
10-
>>> empty clauses TODO(rnystrom): Is this what we want?
10+
>>> empty clauses
1111
for(;;);
1212
<<<
13-
for ( ; ; );
13+
for (;;);
14+
>>> empty initializer clause
15+
for ( ; foo; bar) {}
16+
<<<
17+
for (; foo; bar) {}
1418
>>> whitespace
1519
for (var file in files ) {
1620
print(file);

0 commit comments

Comments
 (0)