Skip to content

Commit

Permalink
refactor: Remove unnecessary 'async' keyword across the codebase [DCM] (
Browse files Browse the repository at this point in the history
#2803)

Remove unnecessary 'async' keyword across the codebase.
This is following the DCM rule
[avoid-redundant-async](https://dcm.dev/docs/rules/common/avoid-redundant-async)
Sadly we cannot enable the rule, as it has 3 false positives.
  • Loading branch information
luanpotter authored Oct 9, 2023
1 parent 9b16b17 commit 2dfe0e5
Show file tree
Hide file tree
Showing 25 changed files with 41 additions and 43 deletions.
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 @@ -57,7 +57,7 @@ class LapLine extends BodyComponent with ContactCallbacks {
late final Rect _scaledRect = (size * 10).toRect();
late final Rect _drawRect = size.toRect();

Future<Image> createFinishOverlay() async {
Future<Image> createFinishOverlay() {
final recorder = PictureRecorder();
final canvas = Canvas(recorder, _scaledRect);
final step = _scaledRect.width / 2;
Expand Down
2 changes: 1 addition & 1 deletion examples/games/rogue_shooter/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import 'package:flame/game.dart';
import 'package:flutter/widgets.dart';
import 'package:rogue_shooter/rogue_shooter_game.dart';

void main() async {
void main() {
runApp(GameWidget(game: RogueShooterGame()));
}
2 changes: 1 addition & 1 deletion packages/flame/lib/src/components/parallax_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension ParallaxComponentExtension on FlameGame {
int? priority,
FilterQuality? filterQuality,
ComponentKey? key,
}) async {
}) {
return ParallaxComponent.load(
dataList,
baseVelocity: baseVelocity,
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 @@ -83,7 +83,7 @@ class ImageComposition {
void clear() => _composes.clear();

/// Compose all the images into a single composition.
Future<Image> compose() async {
Future<Image> compose() {
final result = _composeCore();

return result.picture.toImageSafe(
Expand Down
2 changes: 1 addition & 1 deletion packages/flame/lib/src/sprite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Sprite {
/// **Note:** This is a heavy async operation and should not be called inside
/// the game loop. Remember to call dispose on the [Image] object once you
/// aren't going to use it anymore.
Future<Image> toImage() async {
Future<Image> toImage() {
final composition = ImageComposition()
..add(image, _zeroPosition, source: src);
return composition.compose();
Expand Down
5 changes: 2 additions & 3 deletions packages/flame/test/cache/assets_cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ void main() {
expect(file, isA<String>());

expect(
() async =>
assetsCache.readBinaryFile(fixture('test_text_file.txt').path),
() => assetsCache.readBinaryFile(fixture('test_text_file.txt').path),
failsAssert('"$fileName" was previously loaded as a text file'),
);
});
Expand All @@ -39,7 +38,7 @@ void main() {
expect(file, isA<Uint8List>());

expect(
() async => assetsCache.readFile(fixture('cave_ace.fa').path),
() => assetsCache.readFile(fixture('cave_ace.fa').path),
failsAssert('"$fileName" was previously loaded as a binary file'),
);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/flame/test/cache/memory_cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void main() {
expect(cache.size, 1);
});

test('clear', () async {
test('clear', () {
final cache = MemoryCache<int, String>();
cache.setValue(0, 'bla');
expect(cache.containsKey(0), true);
Expand All @@ -39,7 +39,7 @@ void main() {
expect(cache.size, 0);
});

test('clearCache', () async {
test('clearCache', () {
final cache = MemoryCache<int, String>();
cache.setValue(0, 'bla');
cache.setValue(1, 'ble');
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 @@ -8,7 +8,7 @@ import 'package:flutter_test/flutter_test.dart';

void main() {
group('TextBoxComponent', () {
test('size is properly computed', () async {
test('size is properly computed', () {
final c = TextBoxComponent(
text: 'The quick brown fox jumps over the lazy dog.',
boxConfig: TextBoxConfig(
Expand All @@ -20,7 +20,7 @@ void main() {
expect(c.size.y, greaterThan(1));
});

test('size is properly computed with new line character', () async {
test('size is properly computed with new line character', () {
final c = TextBoxComponent(
text: 'The quick brown fox \n jumps over the lazy dog.',
boxConfig: TextBoxConfig(
Expand All @@ -32,7 +32,7 @@ void main() {
expect(c.size.y, 256);
});

test('lines are properly computed with new line character', () async {
test('lines are properly computed with new line character', () {
final c = TextBoxComponent(
text: 'The quick brown fox \n jumps over the lazy dog.',
boxConfig: TextBoxConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import 'package:flutter_test/flutter_test.dart';

void main() {
group('SingleGameInstance', () {
test('game instance becomes statically available', () async {
test('game instance becomes statically available', () {
final game = SingletonGame()
..onGameResize(Vector2.all(100))
..onMount();
expect(Component.staticGameInstance, game);
game.onRemove();
});

test('guard against multiple game instances', () async {
test('guard against multiple game instances', () {
final game = SingletonGame()
..onGameResize(Vector2.all(100))
..onMount();
Expand Down
4 changes: 2 additions & 2 deletions packages/flame/test/particles/curved_particle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import 'package:flutter_test/flutter_test.dart';

void main() {
group('CurvedParticle', () {
test('A Particle which applies certain Curve', () async {
test('A Particle which applies certain Curve', () {
final particle = CurvedParticle();

expect(particle.curve, Curves.linear);
});

test('A Particle which applies certain Curve', () async {
test('A Particle which applies certain Curve', () {
final particle = CurvedParticle(curve: Curves.decelerate);

expect(particle.curve, Curves.decelerate);
Expand Down
13 changes: 6 additions & 7 deletions packages/flame/test/sprite_animation_ticker_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ void main() {
animationTicker.update(1);
});

test('completed completes when the animation has already completed',
() async {
test('completed completes when the animation has already completed', () {
final sprite = MockSprite();
final animationTicker = SpriteAnimation.spriteList(
[sprite],
Expand All @@ -115,7 +114,7 @@ void main() {
});

test("completed doesn't complete when the animation is yet to complete",
() async {
() {
final sprite = MockSprite();
final animationTicker = SpriteAnimation.spriteList(
[sprite],
Expand All @@ -126,7 +125,7 @@ void main() {
expectLater(animationTicker.completed, doesNotComplete);
});

test("completed doesn't complete when animation is looping", () async {
test("completed doesn't complete when animation is looping", () {
final sprite = MockSprite();
final animationTicker =
SpriteAnimation.spriteList([sprite], stepTime: 1).createTicker();
Expand All @@ -136,7 +135,7 @@ void main() {

test(
"completed doesn't complete when animation is looping and on last frame",
() async {
() {
final sprite = MockSprite();
final animationTicker =
SpriteAnimation.spriteList([sprite], stepTime: 1).createTicker();
Expand All @@ -146,7 +145,7 @@ void main() {
},
);

test("completed doesn't complete after the animation is reset", () async {
test("completed doesn't complete after the animation is reset", () {
final sprite = MockSprite();
final animationTicker = SpriteAnimation.spriteList(
[sprite],
Expand All @@ -163,7 +162,7 @@ void main() {
expect(animationTicker.completeCompleter!.isCompleted, false);
});

test('paused pauses ticket', () async {
test('paused pauses ticket', () {
final sprite = MockSprite();
final animationTicker = SpriteAnimation.spriteList(
[sprite, sprite],
Expand Down
2 changes: 1 addition & 1 deletion packages/flame/test/spritesheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void main() {
when(() => image.width).thenReturn(100);
when(() => image.height).thenReturn(100);

test('calculates all field from SpriteSheet', () async {
test('calculates all field from SpriteSheet', () {
final spriteSheet = SpriteSheet(
image: image,
srcSize: Vector2(1, 2),
Expand Down
4 changes: 2 additions & 2 deletions packages/flame_audio/lib/flame_audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class FlameAudio {
}

/// Plays a single run of the given [file], with a given [volume].
static Future<AudioPlayer> play(String file, {double volume = 1.0}) async {
static Future<AudioPlayer> play(String file, {double volume = 1.0}) {
return _preparePlayer(
file,
volume,
Expand All @@ -72,7 +72,7 @@ class FlameAudio {
}

/// Plays, and keeps looping the given [file].
static Future<AudioPlayer> loop(String file, {double volume = 1.0}) async {
static Future<AudioPlayer> loop(String file, {double volume = 1.0}) {
return _preparePlayer(
file,
volume,
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_fire_atlas/lib/flame_fire_atlas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:flame/sprite.dart';
/// Adds FireAtlas loading methods to Flame [Game].
extension FireAtlasExtensions on Game {
/// Load a [FireAtlas] instances from the given [asset]
Future<FireAtlas> loadFireAtlas(String asset) async {
Future<FireAtlas> loadFireAtlas(String asset) {
return FireAtlas.loadAsset(
asset,
assets: assets,
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_jenny/jenny/test/dialogue_runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void main() {
commands: ['this'],
);

test('Dialogue runs node before finishing the previous one', () async {
test('Dialogue runs node before finishing the previous one', () {
final yarn = YarnProject()
..parse(
dedent('''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void main() {
);
});

test('<<jump>> with unknown destination', () async {
test('<<jump>> with unknown destination', () {
final yarn = YarnProject()
..parse(
'title:A\n'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void main() {
);
});

test('<<visit>> with unknown destination', () async {
test('<<visit>> with unknown destination', () {
final yarn = YarnProject()
..parse(
'title: A\n'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void main() {
expect(diceFn.value, 3);
});

test('dice(0)', () async {
test('dice(0)', () {
final diceFn = DiceFn(const NumLiteral(0), YarnProject());
expect(
() => diceFn.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void main() {
expect(max, 20);
});

test('random range with min == max', () async {
test('random range with min == max', () {
final fn = RandomRangeFn(
const NumLiteral(0),
const NumLiteral(0),
Expand All @@ -61,7 +61,7 @@ void main() {
expect(fn.value, 0);
});

test('random range with min > max', () async {
test('random range with min > max', () {
final fn = RandomRangeFn(
const NumLiteral(10),
const NumLiteral(0),
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_lottie/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flame/game.dart';
import 'package:flame_lottie/flame_lottie.dart';
import 'package:flutter/material.dart';

void main() async {
void main() {
runApp(GameWidget(game: LottieExampleGame()));
}

Expand Down
2 changes: 1 addition & 1 deletion packages/flame_rive/test/flame_rive_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main() {
expect(artboard.name, artboardName);
});

test('Load an artboard that does not exist', () async {
test('Load an artboard that does not exist', () {
expect(
() => loadArtboard(
riveFile,
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_test/lib/src/test_flame_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Future<T> initializeGame<T extends FlameGame>(CreateFunction<T> create) async {
return game;
}

Future<FlameGame> initializeFlameGame() async => initializeGame(FlameGame.new);
Future<FlameGame> initializeFlameGame() => initializeGame(FlameGame.new);

typedef CreateFunction<T> = T Function();
typedef AsyncVoidFunction = Future<void> Function();
Expand Down
2 changes: 1 addition & 1 deletion packages/flame_tiled/lib/src/renderable_tile_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class RenderableTiledMap {
required TiledAtlas atlas,
bool? ignoreFlip,
Images? images,
}) async {
}) {
final visibleLayers = layers.where((layer) => layer.visible);

final layerLoaders = visibleLayers.map((layer) async {
Expand Down
4 changes: 2 additions & 2 deletions packages/flame_tiled/test/tile_atlas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {
});

group('loadImages', () {
setUp(() async {
setUp(() {
TiledAtlas.atlasMap.clear();
Flame.bundle = TestAssetBundle(
imageNames: [
Expand Down Expand Up @@ -136,7 +136,7 @@ void main() {
});

group('Single tileset map', () {
setUp(() async {
setUp(() {
TiledAtlas.atlasMap.clear();
Flame.bundle = TestAssetBundle(
imageNames: [
Expand Down
6 changes: 3 additions & 3 deletions packages/flame_tiled/test/tiled_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void main() {
tiled = await TiledComponent.load('map.tmx', Vector2.all(16));
});

test('correct loads the file', () async {
test('correct loads the file', () {
expect(tiled.tileMap.renderableLayers.length, equals(3));
});

Expand All @@ -51,7 +51,7 @@ void main() {
});

group('is positionable', () {
test('size, width, and height are readable - not writable', () async {
test('size, width, and height are readable - not writable', () {
expect(tiled.size, Vector2(512.0, 2048.0));
expect(tiled.width, 512);
expect(tiled.height, 2048);
Expand All @@ -64,7 +64,7 @@ void main() {
expect(tiled.size, Vector2(512.0, 2048.0));
});

test('from constructor', () async {
test('from constructor', () {
final map = TiledComponent(
tiled.tileMap,
position: Vector2(10, 20),
Expand Down

0 comments on commit 2dfe0e5

Please sign in to comment.