Skip to content

Commit

Permalink
refactor: Add new lint rules (#2477)
Browse files Browse the repository at this point in the history
This PR adds the following lint rules to our list:

```
always_put_required_named_parameters_first
avoid_multiple_declarations_per_line
avoid_positional_boolean_parameters
avoid_returning_null_for_void
avoid_returning_this
avoid_unnecessary_containers
enable_null_safety
library_private_types_in_public_api
no_leading_underscores_for_library_prefixes
no_leading_underscores_for_local_identifiers
prefer_null_aware_method_calls
tighten_type_of_initializing_formals
unnecessary_late
use_setters_to_change_properties
```

And these rules were considered, and some changes were made according to
them as a clean-up, but in many places they didn't make sense
(`prefer_asserts_with_message` I would have included, but there were too
many places that needed to be changes):

```
collection_methods_unrelated_type
prefer_asserts_with_message
avoid_renaming_method_parameters
```
  • Loading branch information
spydon committed Apr 13, 2023
1 parent 78b585f commit dbda37b
Show file tree
Hide file tree
Showing 150 changed files with 571 additions and 504 deletions.
12 changes: 6 additions & 6 deletions doc/flame/examples/lib/drag_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ class DragTarget extends PositionComponent with DragCallbacks {
final Map<int, Trail> _trails = {};

@override
void onGameResize(Vector2 canvasSize) {
super.onGameResize(canvasSize);
size = canvasSize - Vector2(100, 75);
if (size.x < 100 || size.y < 100) {
size = canvasSize * 0.9;
void onGameResize(Vector2 size) {
super.onGameResize(size);
this.size = size - Vector2(100, 75);
if (this.size.x < 100 || this.size.y < 100) {
this.size = size * 0.9;
}
position = canvasSize / 2;
position = size / 2;
}

@override
Expand Down
2 changes: 1 addition & 1 deletion doc/flame/examples/lib/ember.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import 'package:flame/flame.dart';

class EmberPlayer extends SpriteAnimationComponent with TapCallbacks {
EmberPlayer({
void Function(EmberPlayer)? onTap,
required super.position,
required super.size,
void Function(EmberPlayer)? onTap,
}) : _onTap = onTap,
super();

Expand Down
4 changes: 2 additions & 2 deletions doc/flame/examples/lib/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ class PauseRoute extends Route {
}

@override
void onPop(Route previousRoute) {
previousRoute
void onPop(Route nextRoute) {
nextRoute
..resumeTime()
..removeRenderEffect();
}
Expand Down
12 changes: 6 additions & 6 deletions doc/flame/examples/lib/tap_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ class TapTarget extends PositionComponent with TapCallbacks {
final Map<int, ExpandingCircle> _circles = {};

@override
void onGameResize(Vector2 canvasSize) {
super.onGameResize(canvasSize);
size = canvasSize - Vector2(100, 75);
if (size.x < 100 || size.y < 100) {
size = canvasSize * 0.9;
void onGameResize(Vector2 size) {
super.onGameResize(size);
this.size = size - Vector2(100, 75);
if (this.size.x < 100 || this.size.y < 100) {
this.size = size * 0.9;
}
position = canvasSize / 2;
position = size / 2;
}

@override
Expand Down
14 changes: 7 additions & 7 deletions doc/tutorials/klondike/app/lib/step3/components/card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Card extends PositionComponent {
const Radius.circular(KlondikeGame.cardRadius),
);
static final RRect backRRectInner = cardRRect.deflate(40);
static late final Sprite flameSprite = klondikeSprite(1367, 6, 357, 501);
static final Sprite flameSprite = klondikeSprite(1367, 6, 357, 501);

void _renderBack(Canvas canvas) {
canvas.drawRRect(cardRRect, backBackgroundPaint);
Expand All @@ -71,14 +71,14 @@ class Card extends PositionComponent {
Color(0x880d8bff),
BlendMode.srcATop,
);
static late final Sprite redJack = klondikeSprite(81, 565, 562, 488);
static late final Sprite redQueen = klondikeSprite(717, 541, 486, 515);
static late final Sprite redKing = klondikeSprite(1305, 532, 407, 549);
static late final Sprite blackJack = klondikeSprite(81, 565, 562, 488)
static final Sprite redJack = klondikeSprite(81, 565, 562, 488);
static final Sprite redQueen = klondikeSprite(717, 541, 486, 515);
static final Sprite redKing = klondikeSprite(1305, 532, 407, 549);
static final Sprite blackJack = klondikeSprite(81, 565, 562, 488)
..paint = blueFilter;
static late final Sprite blackQueen = klondikeSprite(717, 541, 486, 515)
static final Sprite blackQueen = klondikeSprite(717, 541, 486, 515)
..paint = blueFilter;
static late final Sprite blackKing = klondikeSprite(1305, 532, 407, 549)
static final Sprite blackKing = klondikeSprite(1305, 532, 407, 549)
..paint = blueFilter;

void _renderFront(Canvas canvas) {
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/klondike/app/lib/step3/rank.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Rank {
final Sprite redSprite;
final Sprite blackSprite;

static late final List<Rank> _singletons = [
static final List<Rank> _singletons = [
Rank._(1, 'A', 335, 164, 789, 161, 120, 129),
Rank._(2, '2', 20, 19, 15, 322, 83, 125),
Rank._(3, '3', 122, 19, 117, 322, 80, 127),
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/klondike/app/lib/step3/suit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Suit {
final String label;
final Sprite sprite;

static late final List<Suit> _singletons = [
static final List<Suit> _singletons = [
Suit._(0, '♥', 1176, 17, 172, 183),
Suit._(1, '♦', 973, 14, 177, 182),
Suit._(2, '♣', 974, 226, 184, 172),
Expand Down
14 changes: 7 additions & 7 deletions doc/tutorials/klondike/app/lib/step4/components/card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Card extends PositionComponent with DragCallbacks {
const Radius.circular(KlondikeGame.cardRadius),
);
static final RRect backRRectInner = cardRRect.deflate(40);
static late final Sprite flameSprite = klondikeSprite(1367, 6, 357, 501);
static final Sprite flameSprite = klondikeSprite(1367, 6, 357, 501);

void _renderBack(Canvas canvas) {
canvas.drawRRect(cardRRect, backBackgroundPaint);
Expand All @@ -80,14 +80,14 @@ class Card extends PositionComponent with DragCallbacks {
Color(0x880d8bff),
BlendMode.srcATop,
);
static late final Sprite redJack = klondikeSprite(81, 565, 562, 488);
static late final Sprite redQueen = klondikeSprite(717, 541, 486, 515);
static late final Sprite redKing = klondikeSprite(1305, 532, 407, 549);
static late final Sprite blackJack = klondikeSprite(81, 565, 562, 488)
static final Sprite redJack = klondikeSprite(81, 565, 562, 488);
static final Sprite redQueen = klondikeSprite(717, 541, 486, 515);
static final Sprite redKing = klondikeSprite(1305, 532, 407, 549);
static final Sprite blackJack = klondikeSprite(81, 565, 562, 488)
..paint = blueFilter;
static late final Sprite blackQueen = klondikeSprite(717, 541, 486, 515)
static final Sprite blackQueen = klondikeSprite(717, 541, 486, 515)
..paint = blueFilter;
static late final Sprite blackKing = klondikeSprite(1305, 532, 407, 549)
static final Sprite blackKing = klondikeSprite(1305, 532, 407, 549)
..paint = blueFilter;

void _renderFront(Canvas canvas) {
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/klondike/app/lib/step4/rank.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Rank {
final Sprite redSprite;
final Sprite blackSprite;

static late final List<Rank> _singletons = [
static final List<Rank> _singletons = [
Rank._(1, 'A', 335, 164, 789, 161, 120, 129),
Rank._(2, '2', 20, 19, 15, 322, 83, 125),
Rank._(3, '3', 122, 19, 117, 322, 80, 127),
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/klondike/app/lib/step4/suit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Suit {
final String label;
final Sprite sprite;

static late final List<Suit> _singletons = [
static final List<Suit> _singletons = [
Suit._(0, '♥', 1176, 17, 172, 183),
Suit._(1, '♦', 973, 14, 177, 182),
Suit._(2, '♣', 974, 226, 184, 172),
Expand Down
6 changes: 3 additions & 3 deletions doc/tutorials/platformer/app/lib/ember_quest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class EmberQuestGame extends FlameGame
'star.png',
'water_enemy.png',
]);
initializeGame(true);
initializeGame(loadHud: true);
}

@override
Expand Down Expand Up @@ -90,7 +90,7 @@ class EmberQuestGame extends FlameGame
}
}

void initializeGame(bool loadHud) {
void initializeGame({required bool loadHud}) {
// Assume that size.x < 3200
final segmentsToLoad = (size.x / 640).ceil();
segmentsToLoad.clamp(0, segments.length);
Expand All @@ -111,6 +111,6 @@ class EmberQuestGame extends FlameGame
void reset() {
starsCollected = 0;
health = 3;
initializeGame(false);
initializeGame(loadHud: false);
}
}
2 changes: 1 addition & 1 deletion doc/tutorials/platformer/app/lib/overlays/game_over.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import '../ember_quest.dart';
class GameOver extends StatelessWidget {
// Reference to parent game.
final EmberQuestGame game;
const GameOver({super.key, required this.game});
const GameOver({required this.game, super.key});

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion doc/tutorials/platformer/app/lib/overlays/main_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class MainMenu extends StatelessWidget {
// Reference to parent game.
final EmberQuestGame game;

const MainMenu({super.key, required this.game});
const MainMenu({required this.game, super.key});

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion examples/games/padracing/lib/lap_line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:padracing/car.dart';
import 'package:padracing/game_colors.dart';

class LapLine extends BodyComponent with ContactCallbacks {
LapLine(this.id, this.position, this.size, this.isFinish)
LapLine(this.id, this.position, this.size, {required this.isFinish})
: super(priority: 1);

final int id;
Expand Down
6 changes: 3 additions & 3 deletions examples/games/padracing/lib/menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ class Menu extends StatelessWidget {
),
recognizer: TapGestureRecognizer()
..onTap = () {
final _url =
Uri.parse('https://github.com/spydon');
launchUrl(_url);
launchUrl(
Uri.parse('https://github.com/spydon'),
);
},
),
],
Expand Down
2 changes: 1 addition & 1 deletion examples/games/padracing/lib/menu_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/material.dart' hide Image, Gradient;
import 'package:padracing/game_colors.dart';

class MenuCard extends StatelessWidget {
const MenuCard({super.key, required this.children});
const MenuCard({required this.children, super.key});

final List<Widget> children;

Expand Down
6 changes: 3 additions & 3 deletions examples/games/padracing/lib/padracing_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class PadRacingGame extends Forge2DGame with KeyboardEvents {
final walls = createWalls(trackSize);
final bigBall = Ball(position: Vector2(200, 245), isMovable: false);
cameraWorld.addAll([
LapLine(1, Vector2(25, 50), Vector2(50, 5), false),
LapLine(2, Vector2(25, 70), Vector2(50, 5), false),
LapLine(3, Vector2(52.5, 25), Vector2(5, 50), true),
LapLine(1, Vector2(25, 50), Vector2(50, 5), isFinish: false),
LapLine(2, Vector2(25, 70), Vector2(50, 5), isFinish: false),
LapLine(3, Vector2(52.5, 25), Vector2(5, 50), isFinish: true),
bigBall,
...walls,
...createBalls(trackSize, walls, bigBall),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ class BulletComponent extends SpriteAnimationComponent
}

@override
void onCollisionStart(Set<Vector2> points, PositionComponent other) {
super.onCollisionStart(points, other);
void onCollisionStart(
Set<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
if (other is EnemyComponent) {
other.takeHit();
removeFromParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ class PlayerComponent extends SpriteAnimationComponent
}

@override
void onCollisionStart(Set<Vector2> points, PositionComponent other) {
super.onCollisionStart(points, other);
void onCollisionStart(
Set<Vector2> intersectionPoints,
PositionComponent other,
) {
super.onCollisionStart(intersectionPoints, other);
if (other is EnemyComponent) {
other.takeHit();
}
Expand Down
4 changes: 2 additions & 2 deletions examples/games/rogue_shooter/lib/rogue_shooter_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class RogueShooterGame extends FlameGame
}

@override
void onPanUpdate(DragUpdateInfo details) {
player.position += details.delta.game;
void onPanUpdate(DragUpdateInfo info) {
player.position += info.delta.game;
}

void increaseScore() {
Expand Down
4 changes: 2 additions & 2 deletions examples/games/trex/lib/background/cloud.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class Cloud extends SpriteComponent
}

@override
void onGameResize(Vector2 gameSize) {
super.onGameResize(gameSize);
void onGameResize(Vector2 size) {
super.onGameResize(size);
y = ((absolutePosition.y / 2 - (maxSkyLevel - minSkyLevel)) +
random.fromRange(minSkyLevel, maxSkyLevel)) -
absolutePositionOf(absoluteTopLeftPosition).y;
Expand Down
6 changes: 3 additions & 3 deletions examples/games/trex/lib/background/horizon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class Horizon extends PositionComponent with HasGameRef<TRexGame> {
}

@override
void onGameResize(Vector2 gameSize) {
super.onGameResize(gameSize);
void onGameResize(Vector2 size) {
super.onGameResize(size);
final newLines = _generateLines();
groundLayers.addAll(newLines);
addAll(newLines);
y = (gameSize.y / 2) + 21.0;
y = (size.y / 2) + 21.0;
}

void reset() {
Expand Down
16 changes: 8 additions & 8 deletions examples/games/trex/lib/game_over.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class GameOverText extends SpriteComponent with HasGameRef<TRexGame> {
}

@override
void onGameResize(Vector2 gameSize) {
super.onGameResize(gameSize);
x = gameSize.x / 2;
y = gameSize.y * .25;
void onGameResize(Vector2 size) {
super.onGameResize(size);
x = size.x / 2;
y = size.y * .25;
}
}

Expand All @@ -53,9 +53,9 @@ class GameOverRestart extends SpriteComponent with HasGameRef<TRexGame> {
}

@override
void onGameResize(Vector2 gameSize) {
super.onGameResize(gameSize);
x = gameSize.x / 2;
y = gameSize.y * .75;
void onGameResize(Vector2 size) {
super.onGameResize(size);
x = size.x / 2;
y = size.y * .75;
}
}
2 changes: 1 addition & 1 deletion examples/games/trex/lib/obstacle/obstacle_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class ObstacleTypeSettings {
required this.multipleAt,
required this.minGap,
required this.minSpeed,
required this.generateHitboxes,
this.numFrames,
this.frameRate,
this.speedOffset,
required this.generateHitboxes,
});

final ObstacleType type;
Expand Down
4 changes: 2 additions & 2 deletions examples/lib/commons/commons.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
String baseLink(String path) {
const _basePath =
const basePath =
'https://github.com/flame-engine/flame/blob/main/examples/lib/stories/';

return '$_basePath$path';
return '$basePath$path';
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class BasicAudioExample extends FlameGame with TapDetector {
}

@override
void onTapDown(TapDownInfo details) {
if (button.containsPoint(details.eventPosition.game)) {
void onTapDown(TapDownInfo info) {
if (button.containsPoint(info.eventPosition.game)) {
fireTwo();
} else {
fireOne();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class CalculatePrimeNumber extends PositionComponent
}

@override
void update(double t) {
_interval.update(t);
void update(double dt) {
_interval.update(dt);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class AnimatedBodyExample extends Forge2DGame with TapDetector {
}

@override
void onTapDown(TapDownInfo details) {
super.onTapDown(details);
final position = details.eventPosition.game;
void onTapDown(TapDownInfo info) {
super.onTapDown(info);
final position = info.eventPosition.game;
final spriteSize = Vector2.all(10);
final animationComponent = SpriteAnimationComponent(
animation: animation,
Expand Down
Loading

0 comments on commit dbda37b

Please sign in to comment.