Adds checking for trailling commas on the project (#670)

* Testing a new linter option for trailling commas

* Checking trailling commas on linter
This commit is contained in:
Erick
2021-02-18 11:31:45 -03:00
committed by GitHub
parent e712d423dd
commit 19ff80a0eb
17 changed files with 254 additions and 186 deletions

View File

@ -6,6 +6,9 @@ analyzer:
implicit-casts: false implicit-casts: false
implicit-dynamic: false implicit-dynamic: false
plugins:
- dart_code_metrics
linter: linter:
rules: rules:
- always_declare_return_types - always_declare_return_types
@ -72,3 +75,12 @@ linter:
- use_rethrow_when_possible - use_rethrow_when_possible
- unnecessary_new - unnecessary_new
dart_code_metrics:
rules:
- prefer-trailing-comma
metrics:
number-of-arguments: 8
number-of-methods: 28
lines-of-executable-code: 200
cyclomatic-complexity: 36

View File

@ -23,7 +23,11 @@ class TapableSquare extends PositionComponent with Tapable {
Paint _randomPaint() { Paint _randomPaint() {
final rng = math.Random(); final rng = math.Random();
final color = Color.fromRGBO( final color = Color.fromRGBO(
rng.nextInt(256), rng.nextInt(256), rng.nextInt(256), 0.9); rng.nextInt(256),
rng.nextInt(256),
rng.nextInt(256),
0.9,
);
return PaletteEntry(color).paint; return PaletteEntry(color).paint;
} }

View File

@ -308,7 +308,8 @@ class MyGame extends BaseGame {
(i % perLine) * colWidth - halfCellSize.x + imageSize, (i % perLine) * colWidth - halfCellSize.x + imageSize,
(i ~/ perLine) * rowHeight - halfCellSize.y + imageSize, (i ~/ perLine) * rowHeight - halfCellSize.y + imageSize,
), ),
child: reusableImageParticle), child: reusableImageParticle,
),
); );
} }
@ -475,7 +476,7 @@ class MyGame extends BaseGame {
.moving(to: cellSizeOffset.scale(1, -1)) .moving(to: cellSizeOffset.scale(1, -1))
.scaled(2) .scaled(2)
.translated(halfCellSizeOffset.scale(-1, 1)) .translated(halfCellSizeOffset.scale(-1, 1))
.accelerated(acceleration: halfCellSizeOffset.scale(-5, 5)) .accelerated(acceleration: halfCellSizeOffset.scale(-5, 5)),
]); ]);
} }
@ -488,7 +489,10 @@ class MyGame extends BaseGame {
if (debugMode) { if (debugMode) {
fpsTextConfig.render( fpsTextConfig.render(
canvas, '${fps(120).toStringAsFixed(2)}fps', Vector2(0, size.y - 24)); canvas,
'${fps(120).toStringAsFixed(2)}fps',
Vector2(0, size.y - 24),
);
} }
} }

View File

@ -28,7 +28,9 @@ class MyGame extends BaseGame {
final spriteSize = Vector2(80.0, 90.0); final spriteSize = Vector2(80.0, 90.0);
final vampireComponent = SpriteAnimationComponent.fromSpriteAnimation( final vampireComponent = SpriteAnimationComponent.fromSpriteAnimation(
spriteSize, vampireAnimation) spriteSize,
vampireAnimation,
)
..x = 150 ..x = 150
..y = 100; ..y = 100;

View File

@ -43,7 +43,8 @@ class MyTextBox extends TextBoxComponent {
innerRect, innerRect,
Paint() Paint()
..color = BasicPalette.white.color ..color = BasicPalette.white.color
..style = PaintingStyle.stroke); ..style = PaintingStyle.stroke,
);
} }
} }

View File

@ -16,15 +16,17 @@ class MyGameApp extends StatelessWidget {
child: const Text('Game'), child: const Text('Game'),
onPressed: () { onPressed: () {
Navigator.of(context).pushNamed('/game'); Navigator.of(context).pushNamed('/game');
}), },
),
ElevatedButton( ElevatedButton(
child: const Text('BaseGame'), child: const Text('BaseGame'),
onPressed: () { onPressed: () {
Navigator.of(context).pushNamed('/base_game'); Navigator.of(context).pushNamed('/base_game');
}) },
),
]), ]),
'/game': (BuildContext context) => GameWidget(game: MyGame()), '/game': (BuildContext context) => GameWidget(game: MyGame()),
'/base_game': (BuildContext context) => GameWidget(game: MyBaseGame()) '/base_game': (BuildContext context) => GameWidget(game: MyBaseGame()),
}); });
} }
} }

View File

@ -54,7 +54,8 @@ void main() async {
), ),
), ),
), ),
)); ),
);
final buttonsImage = await Flame.images.load('buttons.png'); final buttonsImage = await Flame.images.load('buttons.png');
final _buttons = SpriteSheet( final _buttons = SpriteSheet(

View File

@ -101,7 +101,14 @@ class ImageComposition {
); );
_composes.add(_Composed( _composes.add(_Composed(
image, position, source, angle, anchor, isAntiAlias, blendMode)); image,
position,
source,
angle,
anchor,
isAntiAlias,
blendMode,
));
} }
void clear() => _composes.clear(); void clear() => _composes.clear();

View File

@ -7,7 +7,7 @@ enum JoystickMoveDirectional {
MOVE_DOWN_RIGHT, MOVE_DOWN_RIGHT,
MOVE_DOWN_LEFT, MOVE_DOWN_LEFT,
MOVE_LEFT, MOVE_LEFT,
IDLE IDLE,
} }
enum ActionEvent { DOWN, UP, MOVE, CANCEL } enum ActionEvent { DOWN, UP, MOVE, CANCEL }

View File

@ -113,7 +113,8 @@ abstract class PositionComponent extends BaseComponent {
final corners = [ final corners = [
rotatePoint(absoluteTopLeftPosition), // Top-left rotatePoint(absoluteTopLeftPosition), // Top-left
rotatePoint( rotatePoint(
absoluteTopLeftPosition + Vector2(0.0, size.y)), // Bottom-left absoluteTopLeftPosition + Vector2(0.0, size.y),
), // Bottom-left
rotatePoint(absoluteTopLeftPosition + size), // Bottom-right rotatePoint(absoluteTopLeftPosition + size), // Bottom-right
rotatePoint(absoluteTopLeftPosition + Vector2(size.x, 0.0)), // Top-right rotatePoint(absoluteTopLeftPosition + Vector2(size.x, 0.0)), // Top-right
]; ];

View File

@ -148,7 +148,11 @@ abstract class Particle {
/// in radians with [RotatingParticle] /// in radians with [RotatingParticle]
Particle rotated([double angle = 0]) { Particle rotated([double angle = 0]) {
return RotatingParticle( return RotatingParticle(
child: this, lifespan: _lifespan, from: angle, to: angle); child: this,
lifespan: _lifespan,
from: angle,
to: angle,
);
} }
/// Rotates this particle from given angle /// Rotates this particle from given angle

View File

@ -14,6 +14,7 @@ dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter
test: ^1.9.4 test: ^1.9.4
dart_code_metrics: ^2.4.0
environment: environment:
sdk: ">=2.7.0 <3.0.0" sdk: ">=2.7.0 <3.0.0"

View File

@ -18,6 +18,12 @@ done
cd . cd .
flutter pub get flutter pub get
result=$(flutter pub run dart_code_metrics:metrics .)
if [ "$result" != "" ]; then
echo "flutter dart code metrics issues: $1"
echo "$result"
exit 1
fi
result=$(flutter analyze .) result=$(flutter analyze .)
if ! echo "$result" | grep -q "No issues found!"; then if ! echo "$result" | grep -q "No issues found!"; then
echo "$result" echo "$result"

View File

@ -75,7 +75,8 @@ void main() {
expect(true, game.components.contains(component)); expect(true, game.components.contains(component));
}); });
test('when the component has onLoad function, adds after load completion', test(
'when the component has onLoad function, adds after load completion',
() async { () async {
final MyGame game = MyGame(); final MyGame game = MyGame();
final MyAsyncComponent component = MyAsyncComponent(); final MyAsyncComponent component = MyAsyncComponent();
@ -89,7 +90,8 @@ void main() {
expect(component.gameSize, size); expect(component.gameSize, size);
expect(component.gameRef, game); expect(component.gameRef, game);
}); },
);
test('prepare adds gameRef and calls onGameResize', () { test('prepare adds gameRef and calls onGameResize', () {
final MyGame game = MyGame(); final MyGame game = MyGame();
@ -127,7 +129,8 @@ void main() {
expect(game.components.contains(component), true); expect(game.components.contains(component), true);
}); });
flutter.testWidgets('component render and update is called', flutter.testWidgets(
'component render and update is called',
(flutter.WidgetTester tester) async { (flutter.WidgetTester tester) async {
final MyGame game = MyGame(); final MyGame game = MyGame();
final MyComponent component = MyComponent(); final MyComponent component = MyComponent();
@ -152,7 +155,8 @@ void main() {
); );
expect(component.isRenderCalled, true); expect(component.isRenderCalled, true);
renderBox.detach(); renderBox.detach();
}); },
);
test('onRemove is only called once on component', () { test('onRemove is only called once on component', () {
final MyGame game = MyGame(); final MyGame game = MyGame();

View File

@ -107,7 +107,8 @@ void main() {
}, },
); );
testWidgets('CombinedEffect alternation can peak', testWidgets(
'CombinedEffect alternation can peak',
(WidgetTester tester) async { (WidgetTester tester) async {
final PositionComponent positionComponent = component(); final PositionComponent positionComponent = component();
effectTest( effectTest(
@ -120,7 +121,8 @@ void main() {
shouldComplete: false, shouldComplete: false,
iterations: 0.5, iterations: 0.5,
); );
}); },
);
testWidgets('CombinedEffect can be infinite', (WidgetTester tester) async { testWidgets('CombinedEffect can be infinite', (WidgetTester tester) async {
final PositionComponent positionComponent = component(); final PositionComponent positionComponent = component();
@ -136,7 +138,8 @@ void main() {
); );
}); });
testWidgets('CombinedEffect can contain alternating MoveEffect', testWidgets(
'CombinedEffect can contain alternating MoveEffect',
(WidgetTester tester) async { (WidgetTester tester) async {
final PositionComponent positionComponent = component(); final PositionComponent positionComponent = component();
effectTest( effectTest(
@ -148,9 +151,11 @@ void main() {
expectedSize: argumentSize, expectedSize: argumentSize,
shouldComplete: true, shouldComplete: true,
); );
}); },
);
testWidgets('CombinedEffect can contain alternating RotateEffect', testWidgets(
'CombinedEffect can contain alternating RotateEffect',
(WidgetTester tester) async { (WidgetTester tester) async {
final PositionComponent positionComponent = component(); final PositionComponent positionComponent = component();
effectTest( effectTest(
@ -162,9 +167,11 @@ void main() {
expectedSize: argumentSize, expectedSize: argumentSize,
shouldComplete: true, shouldComplete: true,
); );
}); },
);
testWidgets('CombinedEffect can contain alternating ScaleEffect', testWidgets(
'CombinedEffect can contain alternating ScaleEffect',
(WidgetTester tester) async { (WidgetTester tester) async {
final PositionComponent positionComponent = component(); final PositionComponent positionComponent = component();
effectTest( effectTest(
@ -176,5 +183,6 @@ void main() {
expectedSize: positionComponent.size.clone(), expectedSize: positionComponent.size.clone(),
shouldComplete: true, shouldComplete: true,
); );
}); },
);
} }

View File

@ -87,8 +87,11 @@ void effectTest(
); );
} }
expect(effect.hasCompleted(), shouldComplete, reason: "Effect shouldFinish"); expect(effect.hasCompleted(), shouldComplete, reason: "Effect shouldFinish");
expect(callback.isCalled, shouldComplete, expect(
reason: "Callback was treated wrong"); callback.isCalled,
shouldComplete,
reason: "Callback was treated wrong",
);
game.update(0.0); // Since effects are removed before they are updated game.update(0.0); // Since effects are removed before they are updated
expect(component.effects.isEmpty, shouldComplete); expect(component.effects.isEmpty, shouldComplete);
} }

View File

@ -106,7 +106,8 @@ void main() {
}, },
); );
testWidgets('SequenceEffect alternation can peak', testWidgets(
'SequenceEffect alternation can peak',
(WidgetTester tester) async { (WidgetTester tester) async {
final PositionComponent positionComponent = component(); final PositionComponent positionComponent = component();
effectTest( effectTest(
@ -119,7 +120,8 @@ void main() {
shouldComplete: false, shouldComplete: false,
iterations: 0.5, iterations: 0.5,
); );
}); },
);
testWidgets('SequenceEffect can be infinite', (WidgetTester tester) async { testWidgets('SequenceEffect can be infinite', (WidgetTester tester) async {
final PositionComponent positionComponent = component(); final PositionComponent positionComponent = component();
@ -135,7 +137,8 @@ void main() {
); );
}); });
testWidgets('SequenceEffect can contain alternating MoveEffect', testWidgets(
'SequenceEffect can contain alternating MoveEffect',
(WidgetTester tester) async { (WidgetTester tester) async {
final PositionComponent positionComponent = component(); final PositionComponent positionComponent = component();
effectTest( effectTest(
@ -147,9 +150,11 @@ void main() {
expectedSize: argumentSize, expectedSize: argumentSize,
shouldComplete: true, shouldComplete: true,
); );
}); },
);
testWidgets('SequenceEffect can contain alternating RotateEffect', testWidgets(
'SequenceEffect can contain alternating RotateEffect',
(WidgetTester tester) async { (WidgetTester tester) async {
final PositionComponent positionComponent = component(); final PositionComponent positionComponent = component();
effectTest( effectTest(
@ -161,9 +166,11 @@ void main() {
expectedSize: argumentSize, expectedSize: argumentSize,
shouldComplete: true, shouldComplete: true,
); );
}); },
);
testWidgets('SequenceEffect can contain alternating ScaleEffect', testWidgets(
'SequenceEffect can contain alternating ScaleEffect',
(WidgetTester tester) async { (WidgetTester tester) async {
final PositionComponent positionComponent = component(); final PositionComponent positionComponent = component();
effectTest( effectTest(
@ -175,5 +182,6 @@ void main() {
expectedSize: positionComponent.size.clone(), expectedSize: positionComponent.size.clone(),
shouldComplete: true, shouldComplete: true,
); );
}); },
);
} }