feat: Add more lint rules (#1703)

Adds some more lint rules and fixes the issues those rules pointed out.
This commit is contained in:
Lukas Klingsbo
2022-06-06 21:23:25 +02:00
committed by GitHub
parent a15eda0b67
commit 49252f8ef2
50 changed files with 141 additions and 140 deletions

View File

@ -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

View File

@ -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];
}

View File

@ -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];
}

View File

@ -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

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart' hide Image, Gradient;
import 'package:padracing/menu_card.dart';
import 'package:padracing/padracing_game.dart';
@ -29,8 +28,8 @@ class GameOver extends StatelessWidget {
),
const SizedBox(height: 10),
ElevatedButton(
child: const Text('Restart'),
onPressed: game.reset,
child: const Text('Restart'),
),
],
),

View File

@ -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 {

View File

@ -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

View File

@ -11,7 +11,6 @@ environment:
dependencies:
flame: ^1.1.1
google_fonts: ^2.3.2
flutter:
sdk: flutter

View File

@ -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));
@ -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

View File

@ -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]--),
),

View File

@ -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);
@ -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(

View File

@ -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()
@ -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;

View File

@ -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',

View File

@ -10,17 +10,17 @@ environment:
flutter: ">=2.10.0"
dependencies:
flame: ^1.1.1
flame_svg: ^1.2.0
flame_forge2d: ^0.11.0
dashbook: 0.1.6
google_fonts: ^2.3.2
flame: ^1.1.1
flame_forge2d: ^0.11.0
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

View File

@ -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

View File

@ -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 {

View File

@ -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.
///

View File

@ -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].

View File

@ -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) {

View File

@ -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.

View File

@ -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);

View File

@ -107,8 +107,8 @@ class NineTileBoxWidget extends StatelessWidget {
destTileSize: destTileSize,
width: width,
height: height,
child: child,
padding: padding,
child: child,
);
},
errorBuilder: errorBuilder,
@ -152,8 +152,8 @@ class InternalNineTileBox extends StatelessWidget {
destTileSize: destTileSize,
),
child: Container(
child: child,
padding: padding,
child: child,
),
),
);

View File

@ -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

View File

@ -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'

View File

@ -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));
},
);
}

View File

@ -94,7 +94,7 @@ Future<SpriteFontRenderer> createRenderer({
const lines = [
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz',
'0123456789.,:;—_!?@\$%+-=/*',
r'0123456789.,:;—_!?@$%+-=/*',
'#^&()[]{}<>|\\\'"`~←→↑↓ ',
];
return SpriteFontRenderer(

View File

@ -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:

View File

@ -8,11 +8,11 @@ environment:
flutter: ">=2.10.0"
dependencies:
flame: ^1.1.1
audioplayers: ^0.20.1
synchronized: ^3.0.0
flame: ^1.1.1
flutter:
sdk: flutter
synchronized: ^3.0.0
dev_dependencies:
dartdoc: ^4.1.0

View File

@ -9,20 +9,16 @@ environment:
sdk: ">=2.16.0 <3.0.0"
dependencies:
equatable: ^2.0.3
flame_bloc: ^1.4.0
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
equatable: ^2.0.3
flame_bloc:
path: ../
flutter_bloc: ^8.0.1
dev_dependencies:
flame_lint: ^0.0.1
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
flame_lint:
path: ../../flame_lint
flutter:

View File

@ -138,5 +138,6 @@ mixin FlameBloc on FlameGame {
class FlameBlocGame extends FlameGame with FlameBloc {
/// FlameBlocGame constructor with an optional [Camera] as a parameter to
/// FlameGame.
@Deprecated('Use FlameBlocProvider and FlameBlocListener instead')
FlameBlocGame({Camera? camera}) : super(camera: camera);
}

View File

@ -8,18 +8,18 @@ environment:
flutter: ">=2.10.0"
dependencies:
bloc: ^8.0.2
flame: ^1.1.1
flutter:
sdk: flutter
bloc: ^8.0.2
meta: ^1.7.0
flame: ^1.1.1
flutter_bloc: ^8.0.1
meta: ^1.7.0
dev_dependencies:
dartdoc: ^4.1.0
flame_lint: ^0.0.1
flame_test: ^1.4.0
flutter_lints: ^1.0.0
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
flame_test: ^1.4.0
mocktail: ^0.3.0
flame_lint: ^0.0.1

View File

@ -9,19 +9,15 @@ environment:
sdk: ">=2.16.0 <3.0.0"
dependencies:
flame: ^1.1.1
flame_fire_atlas: ^1.0.2
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
flame:
path: ../../flame
flame_fire_atlas:
path: ../
dev_dependencies:
flame_lint: ^0.0.1
flutter_test:
sdk: flutter
flame_lint:
path: ../../flame_lint
flutter:
uses-material-design: true

View File

@ -238,13 +238,13 @@ class FireAtlas {
..['id'] = id
..['imageData'] = imageData
..['selections'] = selectionsJson
..['tileWidth'] = tileWidth.toDouble()
..['tileHeight'] = tileHeight.toDouble();
..['tileWidth'] = tileWidth
..['tileHeight'] = tileHeight;
return json;
}
static FireAtlas _fromJson(Map<String, dynamic> json) {
factory FireAtlas._fromJson(Map<String, dynamic> json) {
final tileHeight = json['tileHeight'] as num?;
final tileWidth = json['tileWidth'] as num?;
final tileSize = json['tileSize'] as num? ?? 0;
@ -297,15 +297,17 @@ class FireAtlas {
}
/// Reads a [FireAtlas] instance from a byte array.
static FireAtlas deserialize(List<int> bytes) {
factory FireAtlas.deserialize(List<int> bytes) {
final unzippedBytes = GZipDecoder().decodeBytes(bytes);
final unzippedString = utf8.decode(unzippedBytes);
return _fromJson(jsonDecode(unzippedString) as Map<String, dynamic>);
return FireAtlas._fromJson(
jsonDecode(unzippedString) as Map<String, dynamic>,
);
}
Image _assertImageLoaded() {
if (_image == null) {
throw 'Atlas is not loaded yet, call "load" before using it';
throw Exception('Atlas is not loaded yet, call "load" before using it');
}
return _image!;

View File

@ -8,14 +8,14 @@ environment:
flutter: ">=2.10.0"
dependencies:
archive: ^3.1.5
flame: ^1.1.1
flutter:
sdk: flutter
flame: ^1.1.1
archive: ^3.1.5
dev_dependencies:
dartdoc: ^4.1.0
flame_lint: ^0.0.1
flutter_test:
sdk: flutter
flame_lint: ^0.0.1
mocktail: ^0.3.0
dartdoc: ^4.1.0

View File

@ -10,18 +10,15 @@ environment:
flutter: ">=2.10.0"
dependencies:
dashbook: ^0.1.6
flame_forge2d: ^0.11.0
flutter:
sdk: flutter
flame_forge2d:
path: ../
dashbook: ^0.1.6
dev_dependencies:
flame_lint: ^0.0.1
flutter_test:
sdk: flutter
flame_lint:
path: ../../flame_lint
flutter:
uses-material-design: true

View File

@ -16,8 +16,8 @@ dependencies:
dev_dependencies:
dartdoc: ^4.1.0
flame_lint: ^0.0.1
flame_test: ^1.4.0
flutter_test:
sdk: flutter
flame_test: ^1.4.0
mocktail: ^0.3.0
test: any

View File

@ -26,6 +26,7 @@ linter:
- avoid_init_to_null
- avoid_js_rounded_ints
- avoid_null_checks_in_equality_operators
- avoid_print
- avoid_private_typedef_functions
- avoid_redundant_argument_values
- avoid_relative_lib_imports
@ -36,6 +37,7 @@ linter:
- avoid_type_to_string
- avoid_types_as_parameter_names
- avoid_unused_constructor_parameters
- avoid_void_async
- await_only_futures
- camel_case_extensions
- camel_case_types
@ -46,6 +48,7 @@ linter:
- constant_identifier_names
- control_flow_in_finally
- curly_braces_in_flow_control_structures
- deprecated_consistency
- directives_ordering
- do_not_use_environment
- empty_catches
@ -69,6 +72,8 @@ linter:
- no_duplicate_case_values
- no_runtimeType_toString
- non_constant_identifier_names
- noop_primitive_operations
- null_closures
- omit_local_variable_types
- package_api_docs
- package_names
@ -82,6 +87,7 @@ linter:
- prefer_const_constructors_in_immutables
- prefer_const_declarations
- prefer_const_literals_to_create_immutables
- prefer_constructors_over_static_methods
- prefer_contains
- prefer_equal_for_default_values
- prefer_final_fields
@ -109,6 +115,8 @@ linter:
- recursive_getters
- require_trailing_commas
- slash_for_doc_comments
- sort_child_properties_last
- sort_pub_dependencies
- sort_unnamed_constructors_first
- test_types_in_equals
- throw_in_finally
@ -117,6 +125,7 @@ linter:
- unnecessary_await_in_return
- unnecessary_brace_in_string_interps
- unnecessary_const
- unnecessary_constructor_name
- unnecessary_getters_setters
- unnecessary_lambdas
- unnecessary_new
@ -133,11 +142,15 @@ linter:
- unnecessary_this
- unrelated_type_equality_checks
- unsafe_html
- use_enums
- use_full_hex_values_for_flutter_colors
- use_function_type_syntax_for_parameters
- use_if_null_to_convert_nulls_to_bools
- use_is_even_rather_than_modulo
- use_key_in_widget_constructors
- use_late_for_private_fields_and_variables
- use_named_constants
- use_raw_strings
- use_rethrow_when_possible
- use_test_throws_matchers
- valid_regexps

View File

@ -9,16 +9,13 @@ environment:
sdk: ">=2.16.0 <3.0.0"
dependencies:
flame: ^1.1.1
flame_oxygen: ^0.1.2
flutter:
sdk: flutter
flame:
path: ../../flame
flame_oxygen:
path: ../
dev_dependencies:
flame_lint:
path: ../../flame_lint
flame_lint: ^0.0.1
flutter:
uses-material-design: true

View File

@ -8,9 +8,9 @@ environment:
flutter: ">=2.10.0"
dependencies:
flame: ^1.1.1
flutter:
sdk: flutter
flame: ^1.1.1
oxygen: ^0.2.0
dev_dependencies:

View File

@ -7,19 +7,16 @@ environment:
sdk: ">=2.16.0 <3.0.0"
dependencies:
rive: 0.8.4
flame_rive:
path: ../
flame:
path: ../../flame
flame: ^1.1.1
flame_rive: ^1.2.0
flutter:
sdk: flutter
rive: 0.8.4
dev_dependencies:
flame_lint: ^0.0.1
flutter_test:
sdk: flutter
flame_lint:
path: ../../flame_lint
flutter:
uses-material-design: true

View File

@ -9,12 +9,12 @@ environment:
dependencies:
flame: ^1.1.1
rive: ^0.8.4
flutter:
sdk: flutter
rive: ^0.8.4
dev_dependencies:
dartdoc: ^4.1.0
flame_lint: ^0.0.1
flutter_test:
sdk: flutter
flame_lint: ^0.0.1

View File

@ -9,17 +9,15 @@ environment:
sdk: ">=2.16.0 <3.0.0"
dependencies:
flame: ^1.1.1
flame_svg: ^1.2.0
flutter:
sdk: flutter
flame: ^1.1.1
flame_svg:
path: ../
dev_dependencies:
flame_lint: ^0.0.1
flutter_test:
sdk: flutter
flame_lint:
path: ../../flame_lint
flutter:
uses-material-design: true

View File

@ -9,12 +9,12 @@ environment:
dependencies:
flame: ^1.1.1
flutter_svg: ^1.0.3
flutter:
sdk: flutter
flutter_svg: ^1.0.3
dev_dependencies:
dartdoc: ^4.1.0
flame_lint: ^0.0.1
test: ^1.17.12
mocktail: ^0.3.0
test: ^1.17.12

View File

@ -8,13 +8,13 @@ environment:
sdk: ">=2.16.0 <3.0.0"
dependencies:
flame: ^1.1.1
flutter:
sdk: flutter
flame: ^1.1.1
dev_dependencies:
flame_test:
path: ../
flame_lint: ^0.0.1
flame_test: ^1.4.0
flutter:
assets:

View File

@ -42,7 +42,7 @@ void testRandom(
int? retry,
int repeatCount = 1,
}) {
assert(repeatCount > 0);
assert(repeatCount > 0, 'repeatCount needs to be a positive number');
for (var i = 0; i < repeatCount; i++) {
final seed0 = seed ?? _seedGenerator.nextInt(_maxSeed);
test(

View File

@ -6,6 +6,7 @@ void main() {
test('without message', () {
expect(
() {
// ignore: prefer_asserts_with_message
assert(2 + 2 == 5);
},
failsAssert(),

View File

@ -6,7 +6,7 @@ void main() {
var instructions = 0;
tearDown(() {
assert(instructions == 9);
assert(instructions == 9, 'There should be exactly 9 instructions');
});
flameGame.test(
'runs all the async tests',

View File

@ -8,8 +8,7 @@ environment:
dependencies:
flame: ^1.1.1
flame_tiled:
path: ../
flame_tiled: ^1.4.0
flutter:
sdk: flutter

View File

@ -8,13 +8,13 @@ environment:
flutter: ">=2.10.0"
dependencies:
flame: ^1.1.1
tiled: ^0.8.1
xml: ^5.3.0
meta: ^1.7.0
collection: ^1.15.0
flame: ^1.1.1
flutter:
sdk: flutter
meta: ^1.7.0
tiled: ^0.8.1
xml: ^5.3.0
dev_dependencies:
dartdoc: ^4.1.0

View File

@ -9,21 +9,18 @@ environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
dashbook: ^0.1.5
flame: ^1.1.1
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
dashbook: ^0.1.5
flame:
path: ../../packages/flame
flutter_markdown: ^0.6.7
flutter_highlight: ^0.7.0
flutter_markdown: ^0.6.7
dev_dependencies:
flame_lint: ^0.0.1
flutter_lints: ^1.0.0
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
flame_lint:
path: ../../packages/flame_lint
flutter:
uses-material-design: true