Remove some extra spaces in unformatted output (#2403)
The space following the `async` and similar modifiers was always a
double space because either branch following it emits a string with a
leading space.
The spaces following an opening brace,and following or preceding a
closing brace, are not ever present in formatted code, and are not
useful in unformatted code.
diff --git a/pkgs/code_builder/lib/src/emitter.dart b/pkgs/code_builder/lib/src/emitter.dart
index 26fb257..d095a91 100644
--- a/pkgs/code_builder/lib/src/emitter.dart
+++ b/pkgs/code_builder/lib/src/emitter.dart
@@ -169,7 +169,7 @@
out.writeln();
}
_visitMethods(spec.methods, out);
- out.writeln(' }');
+ out.writeln('}');
return out;
}
@@ -198,13 +198,13 @@
',',
);
}
- out.write(' {');
+ out.write(' {');
for (var f in spec.fields) {
visitField(f, out);
out.writeln();
}
_visitMethods(spec.methods, out);
- out.write(' }');
+ out.write('}');
return out;
}
@@ -292,9 +292,9 @@
spec.body!.accept(this, output);
output.write(';');
} else {
- output.write(' { ');
+ output.write(' {');
spec.body!.accept(this, output);
- output.write(' }');
+ output.write('}');
}
} else {
output.write(';');
@@ -326,7 +326,7 @@
out.writeln();
}
_visitMethods(spec.methods, out);
- out.writeln(' }');
+ out.writeln('}');
return out;
}
@@ -735,24 +735,24 @@
if (spec.modifier != null) {
switch (spec.modifier!) {
case MethodModifier.async:
- output.write(' async ');
+ output.write(' async');
break;
case MethodModifier.asyncStar:
- output.write(' async* ');
+ output.write(' async*');
break;
case MethodModifier.syncStar:
- output.write(' sync* ');
+ output.write(' sync*');
break;
}
}
if (_isLambdaMethod(spec)) {
output.write(' => ');
} else {
- output.write(' { ');
+ output.write(' {');
}
spec.body!.accept(this, output);
if (!_isLambdaMethod(spec)) {
- output.write(' } ');
+ output.write('}');
}
} else {
output.write(';');
@@ -869,7 +869,7 @@
', ',
);
}
- out.write(' { ');
+ out.write(' {');
for (var v in spec.values) {
v.docs.forEach(out.writeln);
for (var a in v.annotations) {
@@ -922,7 +922,7 @@
out.writeln();
}
_visitMethods(spec.methods, out);
- out.writeln(' }');
+ out.writeln('}');
return out;
}
}
diff --git a/pkgs/code_builder/test/specs/method_test.dart b/pkgs/code_builder/test/specs/method_test.dart
index 0a33621..6f4a053 100644
--- a/pkgs/code_builder/test/specs/method_test.dart
+++ b/pkgs/code_builder/test/specs/method_test.dart
@@ -768,7 +768,7 @@
..body = const Code(''),
).closure,
equalsDart(r'''
- (a) { }
+ (a) {}
'''),
);
});