Skip to content

Commit

Permalink
Enforce strict casts rule
Browse files Browse the repository at this point in the history
The `strict-casts` analyzer option is enabled on `flutter/website` sample code and possibly makes sense to enable here as well. It is the modern version of the old “implicit-casts” strong mode option.
https://dart.dev/tools/analysis#enabling-additional-type-checks
  • Loading branch information
filiph committed Jan 3, 2024
1 parent 1f2fceb commit 2300131
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions samples/ads/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
include: package:flutter_lints/flutter.yaml

analyzer:
language:
strict-casts: true

linter:
rules:
# Remove or force lint rules by adding lines like the following.
Expand Down
4 changes: 4 additions & 0 deletions samples/multiplayer/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
include: package:flutter_lints/flutter.yaml

analyzer:
language:
strict-casts: true

linter:
rules:
# Remove or force lint rules by adding lines like the following.
Expand Down
2 changes: 1 addition & 1 deletion samples/multiplayer/lib/game_internals/playing_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PlayingCard {
return PlayingCard(
CardSuit.values
.singleWhere((e) => e.internalRepresentation == json['suit']),
json['value'],
json['value'] as int,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class FirestoreController {
DocumentSnapshot<Map<String, dynamic>> snapshot,
SnapshotOptions? options,
) {
final data = snapshot.data()?['cards'];
final data = snapshot.data()?['cards'] as List?;

if (data == null) {
_log.info('No data found on Firestore, returning empty list');
Expand Down
4 changes: 4 additions & 0 deletions templates/basic/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
include: package:flutter_lints/flutter.yaml

analyzer:
language:
strict-casts: true

linter:
rules:
# Remove or force lint rules by adding lines like the following.
Expand Down
4 changes: 4 additions & 0 deletions templates/card/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
include: package:flutter_lints/flutter.yaml

analyzer:
language:
strict-casts: true

linter:
rules:
# Remove or force lint rules by adding lines like the following.
Expand Down
2 changes: 1 addition & 1 deletion templates/card/lib/game_internals/playing_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PlayingCard {
return PlayingCard(
CardSuit.values
.singleWhere((e) => e.internalRepresentation == json['suit']),
json['value'],
json['value'] as int,
);
}

Expand Down
4 changes: 4 additions & 0 deletions templates/endless_runner/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
include: package:flutter_lints/flutter.yaml

analyzer:
language:
strict-casts: true

0 comments on commit 2300131

Please sign in to comment.