mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-29 16:05:47 +08:00
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:
@ -6,6 +6,9 @@ analyzer:
|
||||
implicit-casts: false
|
||||
implicit-dynamic: false
|
||||
|
||||
plugins:
|
||||
- dart_code_metrics
|
||||
|
||||
linter:
|
||||
rules:
|
||||
- always_declare_return_types
|
||||
@ -72,3 +75,12 @@ linter:
|
||||
- use_rethrow_when_possible
|
||||
- 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
|
||||
|
||||
|
||||
@ -23,7 +23,11 @@ class TapableSquare extends PositionComponent with Tapable {
|
||||
Paint _randomPaint() {
|
||||
final rng = math.Random();
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -308,7 +308,8 @@ class MyGame extends BaseGame {
|
||||
(i % perLine) * colWidth - halfCellSize.x + 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))
|
||||
.scaled(2)
|
||||
.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) {
|
||||
fpsTextConfig.render(
|
||||
canvas, '${fps(120).toStringAsFixed(2)}fps', Vector2(0, size.y - 24));
|
||||
canvas,
|
||||
'${fps(120).toStringAsFixed(2)}fps',
|
||||
Vector2(0, size.y - 24),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +28,9 @@ class MyGame extends BaseGame {
|
||||
final spriteSize = Vector2(80.0, 90.0);
|
||||
|
||||
final vampireComponent = SpriteAnimationComponent.fromSpriteAnimation(
|
||||
spriteSize, vampireAnimation)
|
||||
spriteSize,
|
||||
vampireAnimation,
|
||||
)
|
||||
..x = 150
|
||||
..y = 100;
|
||||
|
||||
|
||||
@ -43,7 +43,8 @@ class MyTextBox extends TextBoxComponent {
|
||||
innerRect,
|
||||
Paint()
|
||||
..color = BasicPalette.white.color
|
||||
..style = PaintingStyle.stroke);
|
||||
..style = PaintingStyle.stroke,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -16,15 +16,17 @@ class MyGameApp extends StatelessWidget {
|
||||
child: const Text('Game'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushNamed('/game');
|
||||
}),
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
child: const Text('BaseGame'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushNamed('/base_game');
|
||||
})
|
||||
},
|
||||
),
|
||||
]),
|
||||
'/game': (BuildContext context) => GameWidget(game: MyGame()),
|
||||
'/base_game': (BuildContext context) => GameWidget(game: MyBaseGame())
|
||||
'/base_game': (BuildContext context) => GameWidget(game: MyBaseGame()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,7 +54,8 @@ void main() async {
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
),
|
||||
);
|
||||
|
||||
final buttonsImage = await Flame.images.load('buttons.png');
|
||||
final _buttons = SpriteSheet(
|
||||
|
||||
@ -101,7 +101,14 @@ class ImageComposition {
|
||||
);
|
||||
|
||||
_composes.add(_Composed(
|
||||
image, position, source, angle, anchor, isAntiAlias, blendMode));
|
||||
image,
|
||||
position,
|
||||
source,
|
||||
angle,
|
||||
anchor,
|
||||
isAntiAlias,
|
||||
blendMode,
|
||||
));
|
||||
}
|
||||
|
||||
void clear() => _composes.clear();
|
||||
|
||||
@ -7,7 +7,7 @@ enum JoystickMoveDirectional {
|
||||
MOVE_DOWN_RIGHT,
|
||||
MOVE_DOWN_LEFT,
|
||||
MOVE_LEFT,
|
||||
IDLE
|
||||
IDLE,
|
||||
}
|
||||
|
||||
enum ActionEvent { DOWN, UP, MOVE, CANCEL }
|
||||
|
||||
@ -113,7 +113,8 @@ abstract class PositionComponent extends BaseComponent {
|
||||
final corners = [
|
||||
rotatePoint(absoluteTopLeftPosition), // Top-left
|
||||
rotatePoint(
|
||||
absoluteTopLeftPosition + Vector2(0.0, size.y)), // Bottom-left
|
||||
absoluteTopLeftPosition + Vector2(0.0, size.y),
|
||||
), // Bottom-left
|
||||
rotatePoint(absoluteTopLeftPosition + size), // Bottom-right
|
||||
rotatePoint(absoluteTopLeftPosition + Vector2(size.x, 0.0)), // Top-right
|
||||
];
|
||||
|
||||
@ -148,7 +148,11 @@ abstract class Particle {
|
||||
/// in radians with [RotatingParticle]
|
||||
Particle rotated([double angle = 0]) {
|
||||
return RotatingParticle(
|
||||
child: this, lifespan: _lifespan, from: angle, to: angle);
|
||||
child: this,
|
||||
lifespan: _lifespan,
|
||||
from: angle,
|
||||
to: angle,
|
||||
);
|
||||
}
|
||||
|
||||
/// Rotates this particle from given angle
|
||||
|
||||
@ -14,6 +14,7 @@ dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
test: ^1.9.4
|
||||
dart_code_metrics: ^2.4.0
|
||||
|
||||
environment:
|
||||
sdk: ">=2.7.0 <3.0.0"
|
||||
|
||||
@ -18,6 +18,12 @@ done
|
||||
|
||||
cd .
|
||||
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 .)
|
||||
if ! echo "$result" | grep -q "No issues found!"; then
|
||||
echo "$result"
|
||||
|
||||
@ -75,7 +75,8 @@ void main() {
|
||||
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 {
|
||||
final MyGame game = MyGame();
|
||||
final MyAsyncComponent component = MyAsyncComponent();
|
||||
@ -89,7 +90,8 @@ void main() {
|
||||
|
||||
expect(component.gameSize, size);
|
||||
expect(component.gameRef, game);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
test('prepare adds gameRef and calls onGameResize', () {
|
||||
final MyGame game = MyGame();
|
||||
@ -127,7 +129,8 @@ void main() {
|
||||
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 {
|
||||
final MyGame game = MyGame();
|
||||
final MyComponent component = MyComponent();
|
||||
@ -152,7 +155,8 @@ void main() {
|
||||
);
|
||||
expect(component.isRenderCalled, true);
|
||||
renderBox.detach();
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
test('onRemove is only called once on component', () {
|
||||
final MyGame game = MyGame();
|
||||
|
||||
@ -107,7 +107,8 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('CombinedEffect alternation can peak',
|
||||
testWidgets(
|
||||
'CombinedEffect alternation can peak',
|
||||
(WidgetTester tester) async {
|
||||
final PositionComponent positionComponent = component();
|
||||
effectTest(
|
||||
@ -120,7 +121,8 @@ void main() {
|
||||
shouldComplete: false,
|
||||
iterations: 0.5,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('CombinedEffect can be infinite', (WidgetTester tester) async {
|
||||
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 {
|
||||
final PositionComponent positionComponent = component();
|
||||
effectTest(
|
||||
@ -148,9 +151,11 @@ void main() {
|
||||
expectedSize: argumentSize,
|
||||
shouldComplete: true,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('CombinedEffect can contain alternating RotateEffect',
|
||||
testWidgets(
|
||||
'CombinedEffect can contain alternating RotateEffect',
|
||||
(WidgetTester tester) async {
|
||||
final PositionComponent positionComponent = component();
|
||||
effectTest(
|
||||
@ -162,9 +167,11 @@ void main() {
|
||||
expectedSize: argumentSize,
|
||||
shouldComplete: true,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('CombinedEffect can contain alternating ScaleEffect',
|
||||
testWidgets(
|
||||
'CombinedEffect can contain alternating ScaleEffect',
|
||||
(WidgetTester tester) async {
|
||||
final PositionComponent positionComponent = component();
|
||||
effectTest(
|
||||
@ -176,5 +183,6 @@ void main() {
|
||||
expectedSize: positionComponent.size.clone(),
|
||||
shouldComplete: true,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@ -87,8 +87,11 @@ void effectTest(
|
||||
);
|
||||
}
|
||||
expect(effect.hasCompleted(), shouldComplete, reason: "Effect shouldFinish");
|
||||
expect(callback.isCalled, shouldComplete,
|
||||
reason: "Callback was treated wrong");
|
||||
expect(
|
||||
callback.isCalled,
|
||||
shouldComplete,
|
||||
reason: "Callback was treated wrong",
|
||||
);
|
||||
game.update(0.0); // Since effects are removed before they are updated
|
||||
expect(component.effects.isEmpty, shouldComplete);
|
||||
}
|
||||
|
||||
@ -106,7 +106,8 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('SequenceEffect alternation can peak',
|
||||
testWidgets(
|
||||
'SequenceEffect alternation can peak',
|
||||
(WidgetTester tester) async {
|
||||
final PositionComponent positionComponent = component();
|
||||
effectTest(
|
||||
@ -119,7 +120,8 @@ void main() {
|
||||
shouldComplete: false,
|
||||
iterations: 0.5,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('SequenceEffect can be infinite', (WidgetTester tester) async {
|
||||
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 {
|
||||
final PositionComponent positionComponent = component();
|
||||
effectTest(
|
||||
@ -147,9 +150,11 @@ void main() {
|
||||
expectedSize: argumentSize,
|
||||
shouldComplete: true,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('SequenceEffect can contain alternating RotateEffect',
|
||||
testWidgets(
|
||||
'SequenceEffect can contain alternating RotateEffect',
|
||||
(WidgetTester tester) async {
|
||||
final PositionComponent positionComponent = component();
|
||||
effectTest(
|
||||
@ -161,9 +166,11 @@ void main() {
|
||||
expectedSize: argumentSize,
|
||||
shouldComplete: true,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('SequenceEffect can contain alternating ScaleEffect',
|
||||
testWidgets(
|
||||
'SequenceEffect can contain alternating ScaleEffect',
|
||||
(WidgetTester tester) async {
|
||||
final PositionComponent positionComponent = component();
|
||||
effectTest(
|
||||
@ -175,5 +182,6 @@ void main() {
|
||||
expectedSize: positionComponent.size.clone(),
|
||||
shouldComplete: true,
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user