Skip to content

Commit

Permalink
Adding "fix spaces".
Browse files Browse the repository at this point in the history
  • Loading branch information
eggnstone committed Sep 14, 2024
1 parent 587af5f commit a7f796f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 14 deletions.
5 changes: 3 additions & 2 deletions lib/src/Formatters/BinaryExpressionFormatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/Formatters/ForPartsWithDeclarationsFormatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/src/Formatters/VariableDeclarationFormatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
Expand Down
32 changes: 32 additions & 0 deletions test/ExplicitTests/Formatter/Playground14_test.dart
Original file line number Diff line number Diff line change
@@ -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));
}
);
}
);
}
16 changes: 10 additions & 6 deletions test/Formatters/ForPartsWithDeclarationsFormatter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ void main()
TestVisitor<VariableDeclarationList>(13, 'int i=0,j=0'),
TestVisitor<PostfixExpression>(26, 'i++'),
TestVisitor<PostfixExpression>(30, 'j--')
],
testConfigs: <TestConfig>[
TestConfig.none(),
TestConfig('int i=0,j=0;; i++,j--')
]
),
TestGroupConfig(
Expand All @@ -32,8 +36,8 @@ void main()
name: 'ForPartsWithDeclarations: int i = 0; i < 10; i++ (normal spacing)',
astVisitors: <TestVisitor<void>>[
TestVisitor<VariableDeclarationList>(13, 'int i = 0'),
TestVisitor<BinaryExpression>(23, ' i < 10'),
TestVisitor<PostfixExpression>(31, ' i++')
TestVisitor<BinaryExpression>(24, 'i < 10'),
TestVisitor<PostfixExpression>(32, 'i++')
]
),
TestGroupConfig(
Expand All @@ -49,7 +53,7 @@ void main()
],
testConfigs: <TestConfig>[
TestConfig.none(),
TestConfig('int i=0;i<10;i++')
TestConfig('int i=0; i<10; i++')
]
),
TestGroupConfig(
Expand All @@ -60,12 +64,12 @@ void main()
name: 'ForPartsWithDeclarations: int i = 0; i < 10; i++ (too much spacing)',
astVisitors: <TestVisitor<void>>[
TestVisitor<VariableDeclarationList>(13, 'int i = 0'),
TestVisitor<BinaryExpression>(28, ' i < 10'),
TestVisitor<PostfixExpression>(41, ' i++')
TestVisitor<BinaryExpression>(30, 'i < 10'),
TestVisitor<PostfixExpression>(43, 'i++')
],
testConfigs: <TestConfig>[
TestConfig.none(),
TestConfig('int i = 0; i < 10; i++')
TestConfig('int i = 0; i < 10; i++')
]
)
];
Expand Down
8 changes: 6 additions & 2 deletions test/Formatters/VariableDeclarationFormatter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ void main()
name: 'VariableDeclaration i=f.a.b',
astVisitors: <TestVisitor<void>>[
TestVisitor<PropertyAccess>(6, 'f.a.b')
],
testConfigs: <TestConfig>[
TestConfig.none(),
TestConfig('i = f.a.b')
]
),
TestGroupConfig(
Expand All @@ -33,7 +37,7 @@ void main()
],
testConfigs: <TestConfig>[
TestConfig.none(),
TestConfig('i\n =f.a.b')
TestConfig('i\n = f.a.b')
]
),
TestGroupConfig(
Expand All @@ -47,7 +51,7 @@ void main()
],
testConfigs: <TestConfig>[
TestConfig.none(),
TestConfig('i=\n f.a.b')
TestConfig('i =\n f.a.b')
]
),
TestGroupConfig(
Expand Down

0 comments on commit a7f796f

Please sign in to comment.