Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add more lint rules #1703

Merged
merged 7 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions doc/flame/examples/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ environment:
flutter: ^2.10.0

dependencies:
flame: ^1.1.1
flutter:
sdk: flutter
flame:
path: ../../../packages/flame

dev_dependencies:
flame_lint: ^0.0.1
5 changes: 4 additions & 1 deletion doc/tutorials/klondike/app/lib/step3/rank.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import 'package:klondike/step3/klondike_game.dart';
@immutable
class Rank {
factory Rank.fromInt(int value) {
assert(value >= 1 && value <= 13);
assert(
value >= 1 && value <= 13,
'value is outside of the bounds of what a rank can be',
);
return _singletons[value - 1];
}

Expand Down
5 changes: 4 additions & 1 deletion doc/tutorials/klondike/app/lib/step3/suit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import 'package:klondike/step3/klondike_game.dart';
@immutable
class Suit {
factory Suit.fromInt(int index) {
assert(index >= 0 && index <= 3);
assert(
index >= 0 && index <= 3,
'index is outside of the bounds of what a suit can be',
);
return _singletons[index];
}

Expand Down
3 changes: 1 addition & 2 deletions doc/tutorials/klondike/app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ environment:
sdk: ^2.15.0

dependencies:
flame: ^1.1.1
flutter:
sdk: flutter
flame:
path: ../../../../packages/flame

dev_dependencies:
flame_lint: ^0.0.1
Expand Down
3 changes: 1 addition & 2 deletions examples/games/padracing/lib/game_over.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart' hide Image, Gradient;

import 'package:padracing/menu_card.dart';
import 'package:padracing/padracing_game.dart';

Expand Down Expand Up @@ -29,8 +28,8 @@ class GameOver extends StatelessWidget {
),
const SizedBox(height: 10),
ElevatedButton(
child: const Text('Restart'),
onPressed: game.reset,
child: const Text('Restart'),
),
],
),
Expand Down
5 changes: 2 additions & 3 deletions examples/games/padracing/lib/tire.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,8 @@ class Tire extends BodyComponent<PadRacingGame> {
if (isTurnableTire && isTurning) {
final turnPerTimeStep = _turnSpeedPerSecond * dt;
final angleNow = joint.jointAngle();
final angleToTurn = (desiredAngle - angleNow)
.clamp(-turnPerTimeStep, turnPerTimeStep)
.toDouble();
final angleToTurn =
(desiredAngle - angleNow).clamp(-turnPerTimeStep, turnPerTimeStep);
final angle = angleNow + angleToTurn;
joint.setLimits(angle, angle);
} else {
Expand Down
6 changes: 3 additions & 3 deletions examples/games/padracing/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ environment:
sdk: ">=2.16.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
flame: ^1.1.1
flame_forge2d: ^0.11.0
flutter:
sdk: flutter
google_fonts: ^2.3.2
url_launcher: ^6.1.2

dev_dependencies:
flame_lint: ^0.0.1
flutter_test:
sdk: flutter
flame_lint: ^0.0.1

flutter:
uses-material-design: true
1 change: 0 additions & 1 deletion examples/games/trex/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ environment:

dependencies:
flame: ^1.1.1
google_fonts: ^2.3.2
flutter:
sdk: flutter

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,10 @@ class Ant extends PositionComponent {
travelDirection = -travelDirection;
}
final nextIndex = travelPathNodeIndex + travelDirection;
assert(nextIndex >= 0 && nextIndex < travelPath.length);
assert(
nextIndex >= 0 && nextIndex < travelPath.length,
'nextIndex is outside of the bounds of travelPath',
);
final nextPosition = travelPath[nextIndex];
var nextAngle =
angle = -(nextPosition - position).angleToSigned(Vector2(0, -1));
Expand Down Expand Up @@ -480,7 +483,7 @@ class InsectLeg {
path = Path(),
foot = Vector2.zero() {
final ok = placeFoot(Vector2(x1, y1));
assert(ok);
assert(ok, 'The foot was not properly placed');
}

/// Place where the leg is attached to the body
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,26 +213,26 @@ class _CoordinateSystemsState extends State<CoordinateSystemsWidget> {
required bool start,
}) {
final add = Container(
margin: const EdgeInsets.all(32),
child: Center(
child: TextButton(
child: const Text('+'),
onPressed: () => setState(() => blocks[index]++),
),
),
margin: const EdgeInsets.all(32),
);
return [
if (start) add,
for (int i = 1; i <= blocks[index]; i++)
GestureDetector(
child: Container(
margin: const EdgeInsets.all(32),
child: Center(
child: RotatedBox(
quarterTurns: rotated ? 1 : 0,
child: Text('Block $i'),
),
),
margin: const EdgeInsets.all(32),
),
onTap: () => setState(() => blocks[index]--),
),
Expand Down
4 changes: 2 additions & 2 deletions examples/lib/stories/effects/rotate_effect_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Compass extends PositionComponent {

class CompassArrow extends PositionComponent {
CompassArrow({required double width, required double radius})
: assert(width <= radius),
: assert(width <= radius, 'The width is larger than the radius'),
_radius = radius,
_width = width,
super(size: Vector2(width, 2 * radius), anchor: Anchor.center);
Expand Down Expand Up @@ -154,7 +154,7 @@ class CompassArrow extends PositionComponent {

class CompassRim extends PositionComponent {
CompassRim({required double radius, required double width})
: assert(radius > width),
: assert(radius > width, 'The width is larger than the radius'),
_radius = radius,
_width = width,
super(
Expand Down
10 changes: 8 additions & 2 deletions examples/lib/stories/experimental/shapes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ class ShapesExample extends FlameGame {

class ShapesComponent extends Component {
ShapesComponent(this.shapes, List<Color> colors)
: assert(shapes.length == colors.length),
: assert(
shapes.length == colors.length,
'The shapes and colors lists have to be of the same length',
),
paints = colors
.map(
(color) => Paint()
Expand All @@ -70,7 +73,10 @@ class ShapesComponent extends Component {

class DotsComponent extends Component {
DotsComponent(this.shapes, this.shapeColors)
: assert(shapes.length == shapeColors.length);
: assert(
shapes.length == shapeColors.length,
'The shapes and shapeColors lists have to be of the same length',
);

final List<Shape> shapes;
final List<Color> shapeColors;
Expand Down
2 changes: 1 addition & 1 deletion examples/lib/stories/widgets/sprite_button_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Widget spriteButtonBuilder(DashbookContext ctx) {
pressedSrcPosition: Vector2(0, 20),
pressedSrcSize: Vector2(60, 20),
onPressed: () {
print('Pressed');
// Do something
},
label: const Text(
'Sprite Button',
Expand Down
10 changes: 5 additions & 5 deletions examples/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ environment:
flutter: ">=2.10.0"

dependencies:
dashbook: 0.1.6
flame: ^1.1.1
flame_svg: ^1.2.0
flame_forge2d: ^0.11.0
dashbook: 0.1.6
google_fonts: ^2.3.2
flame_svg: ^1.2.0
flutter:
sdk: flutter
trex_game:
path: games/trex
google_fonts: ^2.3.2
padracing:
path: games/padracing
trex_game:
path: games/trex

dev_dependencies:
flame_lint: ^0.0.1
Expand Down
6 changes: 2 additions & 4 deletions packages/flame/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ environment:
flutter: ">=2.10.0"

dependencies:
flame:
path: ../
flame: ^1.1.1
flutter:
sdk: flutter

dev_dependencies:
flame_lint: ^0.0.1
flutter_test:
sdk: flutter
flame_lint:
path: ../../flame_lint
2 changes: 1 addition & 1 deletion packages/flame/lib/src/anchor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Anchor {
///
/// If you need to convert anchors to serializable data (like JSON),
/// use the `toString()` and `valueOf` methods.
static Anchor valueOf(String name) {
factory Anchor.valueOf(String name) {
if (_valueNames.containsValue(name)) {
return _valueNames.entries.singleWhere((e) => e.value == name).key;
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/flame/lib/src/components/component_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ComponentSet extends QueryableOrderedSet<Component> {
);

@Deprecated('Use ComponentSet.new instead; will be removed in 1.3.0')
static ComponentSet createDefault() => ComponentSet();
ComponentSet.createDefault() : this();

/// Components whose priority changed since the last update.
///
Expand Down
1 change: 1 addition & 0 deletions packages/flame/lib/src/components/particle_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:flame/src/particles/particle.dart';
class ParticleComponent extends Component {
Particle particle;

@Deprecated('Will be removed after v1.1, use ParticleSystemComponent instead')
ParticleComponent(this.particle);

/// Returns progress of the child [Particle].
Expand Down
2 changes: 1 addition & 1 deletion packages/flame/lib/src/game/flame_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class FlameGame extends Component with Game {
var repeat = true;
while (repeat) {
// Give chance to other futures to execute first
await Future<void>.delayed(const Duration());
await Future<void>.delayed(Duration.zero);
repeat = false;
descendants(includeSelf: true).forEach(
(Component child) {
Expand Down
12 changes: 6 additions & 6 deletions packages/flame/lib/src/geometry/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class Line {

const Line(this.a, this.b, this.c);

static Line fromPoints(Vector2 p1, Vector2 p2) {
final a = p2.y - p1.y;
final b = p1.x - p2.x;
final c = p2.y * p1.x - p1.y * p2.x;
return Line(a, b, c);
}
Line.fromPoints(Vector2 p1, Vector2 p2)
: this(
p2.y - p1.y,
p1.x - p2.x,
p2.y * p1.x - p1.y * p2.x,
);

/// Returns an empty list if there is no intersection
/// If the lines are concurrent it returns one point in the list.
Expand Down
2 changes: 1 addition & 1 deletion packages/flame/lib/src/image_composition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ImageComposition {
/// Compose all the images into a single composition.
Future<Image> compose() async {
// Rect used to determine how big the output image will be.
var output = const Rect.fromLTWH(0, 0, 0, 0);
var output = Rect.zero;
final recorder = PictureRecorder();
final canvas = Canvas(recorder);

Expand Down
4 changes: 2 additions & 2 deletions packages/flame/lib/src/widgets/nine_tile_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ class NineTileBoxWidget extends StatelessWidget {
destTileSize: destTileSize,
width: width,
height: height,
child: child,
padding: padding,
child: child,
);
},
errorBuilder: errorBuilder,
Expand Down Expand Up @@ -152,8 +152,8 @@ class InternalNineTileBox extends StatelessWidget {
destTileSize: destTileSize,
),
child: Container(
child: child,
padding: padding,
child: child,
),
),
);
Expand Down
10 changes: 5 additions & 5 deletions packages/flame/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ environment:
flutter: ">=2.10.0"

dependencies:
collection: ^1.15.0
flutter:
sdk: flutter
meta: ^1.7.0
collection: ^1.15.0
ordered_set: ^5.0.0
vector_math: ^2.1.1

dev_dependencies:
dartdoc: ^4.1.0
mocktail: ^0.3.0
canvas_test: ^0.2.0
flame_test: ^1.4.0
dartdoc: ^4.1.0
flame_lint: ^0.0.1
test: any
flame_test: ^1.4.0
flutter_test:
sdk: flutter
mocktail: ^0.3.0
test: any
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void main() {
}
final totalTime = DateTime.now().millisecondsSinceEpoch -
startTime.millisecondsSinceEpoch;
// ignore:avoid_print
print(
'$totalTime ms\n'
'${1000 / (totalTime / ticks)} runs per second\n'
Expand Down
2 changes: 1 addition & 1 deletion packages/flame/test/game/game_widget/game_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ FlameTester<_MyGame> myGame({required bool open}) {
return FlameTester(
_MyGame.new,
pumpWidget: (gameWidget, tester) async {
await tester.pumpWidget(_Wrapper(child: gameWidget, open: open));
await tester.pumpWidget(_Wrapper(open: open, child: gameWidget));
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/flame/test/text/sprite_font_renderer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Future<SpriteFontRenderer> createRenderer({
const lines = [
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz',
'0123456789.,:;—_!?@\$%+-=/*',
r'0123456789.,:;—_!?@$%+-=/*',
'#^&()[]{}<>|\\\'"`~←→↑↓ ',
];
return SpriteFontRenderer(
Expand Down
9 changes: 3 additions & 6 deletions packages/flame_audio/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ environment:
sdk: ">=2.16.0 <3.0.0"

dependencies:
flame:
path: ../../flame
flame_audio:
path: ../
flame: ^1.1.1
flame_audio: ^1.0.2
flutter:
sdk: flutter

dev_dependencies:
flame_lint:
path: ../../flame_lint
flame_lint: ^0.0.1

flutter:
assets:
Expand Down
Loading