diff --git a/lib/src/Formatters/BinaryExpressionFormatter.dart b/lib/src/Formatters/BinaryExpressionFormatter.dart index f88ffb2..2b545dd 100644 --- a/lib/src/Formatters/BinaryExpressionFormatter.dart +++ b/lib/src/Formatters/BinaryExpressionFormatter.dart @@ -4,6 +4,7 @@ import 'package:analyzer/dart/ast/ast.dart'; import '../Constants/Constants.dart'; import '../Data/Config.dart'; +import '../Data/ConfigExtension.dart'; import '../FormatState.dart'; import '../Tools/StringTools.dart'; import 'IFormatter.dart'; @@ -27,8 +28,8 @@ class BinaryExpressionFormatter extends IFormatter formatState.copyEntity(node.leftOperand, astVisitor, '$methodName/node.leftOperand'); formatState.pushLevel('$methodName/node.leftOperand/after'); - formatState.copyEntity(node.operator, astVisitor, '$methodName/node.operator'); - formatState.copyEntity(node.rightOperand, astVisitor, '$methodName/node.rightOperand'); + formatState.copyEntity(node.operator, astVisitor, '$methodName/node.operator', config.space1); + formatState.copyEntity(node.rightOperand, astVisitor, '$methodName/node.rightOperand', config.space1); formatState.popLevelAndIndent(); if (Constants.DEBUG_I_FORMATTER) log('END $methodName(${StringTools.toDisplayString(node, Constants.MAX_DEBUG_LENGTH)})', --formatState.logIndent); diff --git a/lib/src/Formatters/ForPartsWithDeclarationsFormatter.dart b/lib/src/Formatters/ForPartsWithDeclarationsFormatter.dart index 3aa6c71..e38b581 100644 --- a/lib/src/Formatters/ForPartsWithDeclarationsFormatter.dart +++ b/lib/src/Formatters/ForPartsWithDeclarationsFormatter.dart @@ -28,9 +28,9 @@ class ForPartsWithDeclarationsFormatter extends IFormatter formatState.copyEntity(node.variables, astVisitor, '$methodName/node.variables'); formatState.copyEntity(node.leftSeparator, astVisitor, '$methodName/node.leftSeparator', config.space0); - formatState.copyEntity(node.condition, astVisitor, '$methodName/node.condition'); + formatState.copyEntity(node.condition, astVisitor, '$methodName/node.condition', config.space1); formatState.copyEntity(node.rightSeparator, astVisitor, '$methodName/node.rightSeparator', config.space0); - formatState.acceptListWithComma(node.updaters, null, astVisitor, '$methodName/node.updaters');//, config.space1); + formatState.acceptListWithComma(node.updaters, null, astVisitor, '$methodName/node.updaters', config.space1); if (Constants.DEBUG_I_FORMATTER) log('END $methodName(${StringTools.toDisplayString(node, Constants.MAX_DEBUG_LENGTH)})', --formatState.logIndent); } diff --git a/lib/src/Formatters/VariableDeclarationFormatter.dart b/lib/src/Formatters/VariableDeclarationFormatter.dart index c2233cc..ddce6e0 100644 --- a/lib/src/Formatters/VariableDeclarationFormatter.dart +++ b/lib/src/Formatters/VariableDeclarationFormatter.dart @@ -4,6 +4,7 @@ import 'package:analyzer/dart/ast/ast.dart'; import '../Constants/Constants.dart'; import '../Data/Config.dart'; +import '../Data/ConfigExtension.dart'; import '../FormatState.dart'; import '../Tools/StringTools.dart'; import 'IFormatter.dart'; @@ -45,7 +46,7 @@ class VariableDeclarationFormatter extends IFormatter if (pushLevel) formatState.pushLevel('$methodName/node.name/after'); - formatState.copyEntity(node.equals, astVisitor, '$methodName/node.equals'); + formatState.copyEntity(node.equals, astVisitor, '$methodName/node.equals', config.space1); if (node.initializer is AdjacentStrings) { @@ -73,7 +74,7 @@ class VariableDeclarationFormatter extends IFormatter formatState.popLevelAndIndent(); } else - formatState.copyEntity(node.initializer, astVisitor, '$methodName/node.initializer'); + formatState.copyEntity(node.initializer, astVisitor, '$methodName/node.initializer', config.space1); if (pushLevel) formatState.popLevelAndIndent(); diff --git a/test/ExplicitTests/Formatter/Playground14_test.dart b/test/ExplicitTests/Formatter/Playground14_test.dart new file mode 100644 index 0000000..890e1c3 --- /dev/null +++ b/test/ExplicitTests/Formatter/Playground14_test.dart @@ -0,0 +1,32 @@ +import 'package:dart_format/src/Data/Config.dart'; +import 'package:dart_format/src/Formatter.dart'; +import 'package:test/test.dart'; + +import '../../TestTools/TestTools.dart'; + +void main() +{ + TestTools.init(); + + final Config config = Config.experimental(); + final Formatter formatter = Formatter(config); + + group('Playground 14', () + { + test('format: void f() { for(int i=0;i<10;i++); }', () + { + const String inputText = 'void f() { for(int i=0;i<10;i++); }'; + const String expectedText = + 'void f()\n' + '{\n' + ' for (int i = 0; i < 10; i++);\n' + '}\n'; + + final String actualText = formatter.format(inputText); + + TestTools.expect(actualText, equals(expectedText)); + } + ); + } + ); +} diff --git a/test/Formatters/ForPartsWithDeclarationsFormatter_test.dart b/test/Formatters/ForPartsWithDeclarationsFormatter_test.dart index 3ac344a..cca86ad 100644 --- a/test/Formatters/ForPartsWithDeclarationsFormatter_test.dart +++ b/test/Formatters/ForPartsWithDeclarationsFormatter_test.dart @@ -22,6 +22,10 @@ void main() TestVisitor(13, 'int i=0,j=0'), TestVisitor(26, 'i++'), TestVisitor(30, 'j--') + ], + testConfigs: [ + TestConfig.none(), + TestConfig('int i=0,j=0;; i++,j--') ] ), TestGroupConfig( @@ -32,8 +36,8 @@ void main() name: 'ForPartsWithDeclarations: int i = 0; i < 10; i++ (normal spacing)', astVisitors: >[ TestVisitor(13, 'int i = 0'), - TestVisitor(23, ' i < 10'), - TestVisitor(31, ' i++') + TestVisitor(24, 'i < 10'), + TestVisitor(32, 'i++') ] ), TestGroupConfig( @@ -49,7 +53,7 @@ void main() ], testConfigs: [ TestConfig.none(), - TestConfig('int i=0;i<10;i++') + TestConfig('int i=0; i<10; i++') ] ), TestGroupConfig( @@ -60,12 +64,12 @@ void main() name: 'ForPartsWithDeclarations: int i = 0; i < 10; i++ (too much spacing)', astVisitors: >[ TestVisitor(13, 'int i = 0'), - TestVisitor(28, ' i < 10'), - TestVisitor(41, ' i++') + TestVisitor(30, 'i < 10'), + TestVisitor(43, 'i++') ], testConfigs: [ TestConfig.none(), - TestConfig('int i = 0; i < 10; i++') + TestConfig('int i = 0; i < 10; i++') ] ) ]; diff --git a/test/Formatters/VariableDeclarationFormatter_test.dart b/test/Formatters/VariableDeclarationFormatter_test.dart index 9b02cbf..f2609a6 100644 --- a/test/Formatters/VariableDeclarationFormatter_test.dart +++ b/test/Formatters/VariableDeclarationFormatter_test.dart @@ -20,6 +20,10 @@ void main() name: 'VariableDeclaration i=f.a.b', astVisitors: >[ TestVisitor(6, 'f.a.b') + ], + testConfigs: [ + TestConfig.none(), + TestConfig('i = f.a.b') ] ), TestGroupConfig( @@ -33,7 +37,7 @@ void main() ], testConfigs: [ TestConfig.none(), - TestConfig('i\n =f.a.b') + TestConfig('i\n = f.a.b') ] ), TestGroupConfig( @@ -47,7 +51,7 @@ void main() ], testConfigs: [ TestConfig.none(), - TestConfig('i=\n f.a.b') + TestConfig('i =\n f.a.b') ] ), TestGroupConfig(