Skip to content

Commit

Permalink
feat: Expand flame_lint to respect required pub.dev checks (#3139)
Browse files Browse the repository at this point in the history
Expand flame_lint to respect required pub.dev checks.

We are currently losing pub points due to lint violations:


![image](https://github.com/flame-engine/flame/assets/882703/b6a6cf0a-aea1-4e75-b1cb-611d5f8a154c)

Turns out `flame_lint` does not respect lints/core which is being
enforced now by pub.

This adds that as a dependency on `flame_lint`, updates `flutter_lint`
for the packages that use that, and fix all existing violations (luckily
very few).

This change will ensure that us and everyone else who uses `flame_lint`
get all the points they deserve on pub. We can consider expanding to
`lints/recommended` in the future, but that is definitely not a
requirement at this stage (and a much bigger change).
  • Loading branch information
luanpotter committed Apr 28, 2024
1 parent c8c8cc4 commit 6e80bf5
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 21 deletions.
8 changes: 4 additions & 4 deletions doc/tutorials/platformer/app/lib/ember_quest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ class EmberQuestGame extends FlameGame
void loadGameSegments(int segmentIndex, double xPositionOffset) {
for (final block in segments[segmentIndex]) {
final component = switch (block.blockType) {
GroundBlock => GroundBlock(
GroundBlock _ => GroundBlock(
gridPosition: block.gridPosition,
xOffset: xPositionOffset,
),
PlatformBlock => PlatformBlock(
PlatformBlock _ => PlatformBlock(
gridPosition: block.gridPosition,
xOffset: xPositionOffset,
),
Star => Star(
Star _ => Star(
gridPosition: block.gridPosition,
xOffset: xPositionOffset,
),
WaterEnemy => WaterEnemy(
WaterEnemy _ => WaterEnemy(
gridPosition: block.gridPosition,
xOffset: xPositionOffset,
),
Expand Down
7 changes: 4 additions & 3 deletions packages/flame/lib/src/widgets/base_future_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ class BaseFutureBuilder<T> extends StatelessWidget {
case ConnectionState.active:
return loadingBuilder?.call(context) ?? const SizedBox();
case ConnectionState.done:
if (snapshot.hasData) {
return builder(context, snapshot.data!);
}
if (snapshot.hasError) {
return errorBuilder?.call(context) ?? const SizedBox();
}
final data = snapshot.data;
if (data != null) {
return builder(context, data);
}
return loadingBuilder?.call(context) ?? const SizedBox();
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ void main() {
(game) async {
final onComplete = MockOnCompleteCallback();

when(onComplete).thenReturn(null);
when(onComplete.call).thenReturn(null);

final component = ScrollTextBoxComponent(
size: Vector2(200, 100),
text: 'Short text',
onComplete: onComplete,
onComplete: onComplete.call,
);
await game.ensureAdd(component);

game.update(0.1);

verify(onComplete).called(1);
verify(onComplete.call).called(1);
},
);

Expand All @@ -30,19 +30,19 @@ void main() {
(game) async {
final onComplete = MockOnCompleteCallback();

when(onComplete).thenReturn(null);
when(onComplete.call).thenReturn(null);

final component = ScrollTextBoxComponent(
size: Vector2(200, 100),
text: '''Long text that will definitely require scrolling to be
fully visible in the given size of the ScrollTextBoxComponent.''',
onComplete: onComplete,
onComplete: onComplete.call,
);
await game.ensureAdd(component);

game.update(0.1);

verify(onComplete).called(1);
verify(onComplete.call).called(1);
},
);

Expand Down
6 changes: 3 additions & 3 deletions packages/flame/test/components/text_box_component_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,18 @@ void main() {
(game) async {
final onComplete = MockOnCompleteCallback();

when(onComplete).thenReturn(null);
when(onComplete.call).thenReturn(null);

final component = ScrollTextBoxComponent(
size: Vector2(200, 100),
text: 'Short text',
onComplete: onComplete,
onComplete: onComplete.call,
);
await game.ensureAdd(component);

game.update(0.1);

verify(onComplete).called(1);
verify(onComplete.call).called(1);
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ void main() {
final ec = EffectController(
duration: 1,
reverseDuration: 1,
onMax: mockOnMax,
onMin: mockOnMin,
onMax: mockOnMax.call,
onMin: mockOnMin.call,
infinite: true,
);

Expand Down
4 changes: 2 additions & 2 deletions packages/flame/test/extensions/canvas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void main() {

final drawFunction = MocktailDrawFunction();
when(() => drawFunction.call(canvas)).thenReturn(null);
canvas.renderAt(Vector2(1, 1), drawFunction);
canvas.renderAt(Vector2(1, 1), drawFunction.call);
verify(canvas.save).called(1);
verify(() => canvas.translateVector(Vector2(1, 1))).called(1);
verify(() => drawFunction(canvas)).called(1);
Expand All @@ -54,7 +54,7 @@ void main() {

final drawFunction = MocktailDrawFunction();
when(() => drawFunction.call(canvas)).thenReturn(null);
canvas.renderRotated(0.5, Vector2(1, 1), drawFunction);
canvas.renderRotated(0.5, Vector2(1, 1), drawFunction.call);
verify(canvas.save).called(1);
verify(() => canvas.translateVector(Vector2(1, 1))).called(1);
verify(() => canvas.rotate(.5)).called(1);
Expand Down
1 change: 0 additions & 1 deletion packages/flame_bloc/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ dev_dependencies:
dartdoc: ^6.3.0
flame_lint: ^1.1.2
flame_test: ^1.16.1
flutter_lints: ^2.0.1
flutter_test:
sdk: flutter
mocktail: ^1.0.1
2 changes: 2 additions & 0 deletions packages/flame_lint/lib/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Source of linter options:
# https://dart-lang.github.io/linter/lints/options/options.html

include: package:lints/core.yaml

analyzer:
exclude:
- "**/*.g.dart"
Expand Down
3 changes: 3 additions & 0 deletions packages/flame_lint/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ funding:
environment:
sdk: ">=3.0.0 <4.0.0"

dependencies:
lints: ^3.0.0

dev_dependencies:
dartdoc: ^6.3.0

0 comments on commit 6e80bf5

Please sign in to comment.