Stricter lint rules

This commit is contained in:
Vincent Velociter
2023-01-02 15:08:51 +01:00
parent 2f9f0fa0c7
commit 533e1d0f6a
28 changed files with 198 additions and 197 deletions
+7 -14
View File
@@ -7,7 +7,7 @@
# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml
include: package:lint/strict.yaml
analyzer:
language:
@@ -22,20 +22,13 @@ analyzer:
invalid_annotation_target: ignore
linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
require_trailing_commas: false
directives_ordering: false
always_use_package_imports: false
avoid_redundant_argument_values: false
sort_pub_dependencies: false
sort_unnamed_constructors_first: false
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
+1 -1
View File
@@ -13,7 +13,7 @@ class App extends ConsumerWidget {
const App({super.key});
@override
Widget build(context, WidgetRef ref) {
Widget build(BuildContext context, WidgetRef ref) {
final themeMode = ref.watch(themeModeProvider);
final brightness = ref.watch(selectedBrigthnessProvider);
final themeData = ThemeData(
+1 -1
View File
@@ -10,7 +10,7 @@ import '../data/auth_repository.dart';
import './auth_actions_notifier.dart';
class SignInWidget extends ConsumerWidget {
const SignInWidget({Key? key}) : super(key: key);
const SignInWidget({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
@@ -48,6 +48,7 @@ class GameEvent with _$GameEvent {
}
}
// ignore: prefer_constructors_over_static_methods
static GameStateEvent _gameStateEventfromPick(RequiredPick pick) {
return GameStateEvent(
moves: pick('moves').asStringOrThrow(),
@@ -28,7 +28,7 @@ final timeControlPrefProvider = createPrefProvider(
prefKey: 'play.timeControl',
defaultValue: TimeControl.blitz4,
mapFrom: (v) => TimeControl.values.firstWhere(
(e) => v != null ? e.value == TimeInc.fromString(v) : false,
(e) => v != null && e.value == TimeInc.fromString(v),
orElse: () => TimeControl.blitz4),
mapTo: (v) => v.value.toString(),
);
+3 -3
View File
@@ -31,8 +31,8 @@ class GameState with _$GameState {
factory GameState.fromEvent(GameStateEvent event) {
final uciMoves = event.moves.split(' ').where((m) => m.isNotEmpty).toList();
List<Position<Chess>> positions = [Chess.initial];
List<String> sanMoves = [];
final List<Position<Chess>> positions = [Chess.initial];
final List<String> sanMoves = [];
for (final m in uciMoves) {
final move = Move.fromUci(m);
final newPos = positions.last.playToSan(move);
@@ -62,6 +62,6 @@ class GameState with _$GameState {
Map<String, Set<String>> get validMoves => algebraicLegalMoves(position);
bool get isLastMoveCapture {
final lm = sanMoves.isNotEmpty ? sanMoves[sanMoves.length - 1] : null;
return lm != null ? lm.contains('x') : false;
return lm != null && lm.contains('x');
}
}
@@ -33,7 +33,7 @@ class TimeInc {
int get hashCode => Object.hash(time, increment);
@override
toString() => '$time + $increment';
String toString() => '$time + $increment';
}
enum TimeControl {
@@ -37,7 +37,7 @@ class GameStateNotifier extends AutoDisposeNotifier<GameState?> {
state = newState;
}
void onUserMove(GameId gameId, Move move) async {
Future<void> onUserMove(GameId gameId, Move move) async {
final gameRepository = ref.read(gameRepositoryProvider);
final savedState = state;
if (state != null) {
@@ -235,14 +235,14 @@ class _BoardBody extends ConsumerWidget {
rating: game.player.rating,
title: game.player.title,
active: false,
clock: const Duration(milliseconds: 0),
clock: Duration.zero,
);
final opponent = Player(
name: game.opponent.name,
rating: game.opponent.rating,
title: game.opponent.title,
active: false,
clock: const Duration(milliseconds: 0),
clock: Duration.zero,
);
return GameBoardLayout(
@@ -20,7 +20,7 @@ class PlayActionNotifier
final createGameService = ref.read(createGameServiceProvider);
state = const AsyncLoading();
state =
(await (createGameService.aiGameTask(account, side: side).run())).match(
(await createGameService.aiGameTask(account, side: side).run()).match(
(error) => AsyncValue.error(error.message, error.stackTrace),
(game) => AsyncValue.data(game),
);
@@ -13,7 +13,7 @@ class SettingsRepository {
// Theme
Future<bool> setThemeMode(ThemeMode mode) async {
return await _prefs.setString(backgroundModeKey, mode.name);
return _prefs.setString(backgroundModeKey, mode.name);
}
ThemeMode getThemeMode() {
@@ -32,7 +32,7 @@ class SettingsRepository {
// Sound
Future<bool> toggleSound() async {
return await _prefs.setBool(soundMutedKey, !isSoundMuted());
return _prefs.setBool(soundMutedKey, !isSoundMuted());
}
bool isSoundMuted() {
@@ -3,11 +3,12 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../settings/data/settings_repository.dart';
class IsSoundMutedNotifier extends StateNotifier<bool> {
IsSoundMutedNotifier(this.settings, bool initialValue) : super(initialValue);
IsSoundMutedNotifier(this.settings, {required bool initialValue})
: super(initialValue);
final SettingsRepository settings;
void toggleSound() async {
Future<void> toggleSound() async {
final ok = await settings.toggleSound();
if (ok) {
state = settings.isSoundMuted();
@@ -18,6 +19,6 @@ class IsSoundMutedNotifier extends StateNotifier<bool> {
final isSoundMutedProvider =
StateNotifierProvider.autoDispose<IsSoundMutedNotifier, bool>((ref) {
final settingsRepository = ref.watch(settingsRepositoryProvider);
return IsSoundMutedNotifier(
settingsRepository, settingsRepository.isSoundMuted());
return IsSoundMutedNotifier(settingsRepository,
initialValue: settingsRepository.isSoundMuted());
});
@@ -69,7 +69,7 @@ class SettingsScreen extends ConsumerWidget {
),
const SizedBox(height: 30),
authState.maybeWhen(
data: ((data) {
data: (data) {
return data != null
? PlatformCard(
child: ListTile(
@@ -88,7 +88,7 @@ class SettingsScreen extends ConsumerWidget {
),
)
: const SizedBox.shrink();
}),
},
orElse: () => const SizedBox.shrink()),
],
),
@@ -9,7 +9,7 @@ class ThemeModeNotifier extends StateNotifier<ThemeMode> {
final Ref ref;
void changeTheme(ThemeMode theme) async {
Future<void> changeTheme(ThemeMode theme) async {
final repository = ref.read(settingsRepositoryProvider);
final ok = await repository.setThemeMode(theme);
if (ok) {
@@ -5,8 +5,6 @@ part 'featured_player.freezed.dart';
@freezed
class FeaturedPlayer with _$FeaturedPlayer {
const FeaturedPlayer._();
const factory FeaturedPlayer(
{required Side side,
required String name,
@@ -14,6 +12,8 @@ class FeaturedPlayer with _$FeaturedPlayer {
int? rating,
int? seconds}) = _FeaturedPlayer;
const FeaturedPlayer._();
FeaturedPlayer withSeconds(int newSeconds) {
return FeaturedPlayer(
side: side,
+3 -2
View File
@@ -50,6 +50,7 @@ class PlayTime with _$PlayTime {
required Duration total,
required Duration tv,
}) = _PlayTime;
factory PlayTime.fromJson(Map<String, dynamic> json) =>
PlayTime.fromPick(pick(json).required());
@@ -62,8 +63,6 @@ class PlayTime with _$PlayTime {
@freezed
class Profile with _$Profile {
const Profile._();
const factory Profile({
String? country,
String? location,
@@ -74,6 +73,8 @@ class Profile with _$Profile {
String? links,
}) = _Profile;
const Profile._();
String? get fullName => firstName != null && lastName != null
? '$firstName $lastName'
: firstName ?? lastName;
+48 -44
View File
@@ -118,29 +118,30 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
CupertinoSliverRefreshControl(
onRefresh: () => _refreshData(account),
),
account != null
? SliverSafeArea(
top: false,
sliver: SliverPadding(
padding: kBodyPadding,
sliver: SliverList(
delegate: SliverChildListDelegate(
_buildList(context, account),
),
),
if (account != null)
SliverSafeArea(
top: false,
sliver: SliverPadding(
padding: kBodyPadding,
sliver: SliverList(
delegate: SliverChildListDelegate(
_buildList(context, account),
),
)
: SliverFillRemaining(
child: Center(
child: FatButton(
semanticsLabel: context.l10n.signIn,
onPressed: authActionsAsync.isLoading
? null
: () => ref
.read(authActionsProvider.notifier)
.signIn(),
child: Text(context.l10n.signIn))),
),
),
)
else
SliverFillRemaining(
child: Center(
child: FatButton(
semanticsLabel: context.l10n.signIn,
onPressed: authActionsAsync.isLoading
? null
: () => ref
.read(authActionsProvider.notifier)
.signIn(),
child: Text(context.l10n.signIn))),
),
];
},
orElse: () => const [
@@ -172,19 +173,21 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
account.profile != null
? Location(profile: account.profile!)
: kEmptyWidget,
if (account.profile != null)
Location(profile: account.profile!)
else
kEmptyWidget,
const SizedBox(height: 5),
Text(
'${context.l10n.memberSince} ${DateFormat.yMMMMd().format(account.createdAt)}'),
const SizedBox(height: 5),
Text(context.l10n.lastSeenActive(timeago.format(account.seenAt))),
const SizedBox(height: 5),
account.playTime != null
? Text(context.l10n
.tpTimeSpentPlaying(_printDuration(account.playTime!.total)))
: kEmptyWidget,
if (account.playTime != null)
Text(context.l10n
.tpTimeSpentPlaying(_printDuration(account.playTime!.total)))
else
kEmptyWidget,
],
),
const SizedBox(height: 20),
@@ -223,7 +226,7 @@ class PerfCards extends StatelessWidget {
padding: const EdgeInsets.symmetric(vertical: 3.0),
scrollDirection: Axis.horizontal,
itemCount: userPerfs.length,
itemBuilder: ((context, index) {
itemBuilder: (context, index) {
final perf = userPerfs[index];
final userPerf = account.perfs[perf]!;
return SizedBox(
@@ -271,8 +274,8 @@ class PerfCards extends StatelessWidget {
),
),
);
}),
separatorBuilder: ((context, index) => const SizedBox(width: 10)),
},
separatorBuilder: (context, index) => const SizedBox(width: 10),
),
);
}
@@ -288,7 +291,7 @@ class RecentGames extends ConsumerWidget {
final recentGames = ref.watch(recentGamesProvider(account.id));
return recentGames.when(
data: ((data) {
data: (data) {
return Column(
children: ListTile.divideTiles(
color: dividerColor(context),
@@ -328,12 +331,12 @@ class RecentGames extends ConsumerWidget {
);
})).toList(growable: false),
);
}),
error: ((error, stackTrace) {
},
error: (error, stackTrace) {
debugPrint(
'SEVERE: [ProfileScreen] could not load user games; ${error.toString()}\n$stackTrace');
return const Text('Could not load games.');
}),
},
loading: () => const CenterLoadingIndicator(),
);
}
@@ -347,12 +350,13 @@ class Location extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Row(children: [
profile.country != null
? CachedNetworkImage(
imageUrl: lichessFlagSrc(profile.country!),
errorWidget: (_, __, ___) => kEmptyWidget,
)
: kEmptyWidget,
if (profile.country != null)
CachedNetworkImage(
imageUrl: lichessFlagSrc(profile.country!),
errorWidget: (_, __, ___) => kEmptyWidget,
)
else
kEmptyWidget,
const SizedBox(width: 10),
Text(profile.location ?? ''),
]);
@@ -364,8 +368,8 @@ String lichessFlagSrc(String country) {
}
String _printDuration(Duration duration) {
String days = duration.inDays.toString();
String hours = duration.inHours.remainder(24).toString();
String minutes = duration.inMinutes.remainder(60).toString();
final days = duration.inDays.toString();
final hours = duration.inHours.remainder(24).toString();
final minutes = duration.inMinutes.remainder(60).toString();
return "$days days, $hours hours and $minutes minutes";
}
+1 -1
View File
@@ -136,7 +136,7 @@ Future<T?> _showMaterialBottomSheet<T>(
),
),
);
}).toList(),
}),
],
),
),
+1 -1
View File
@@ -25,7 +25,7 @@ final currentBottomTabProvider =
/// The scaffold lays out the tab bar at the bottom and the content between or
/// behind the tab bar.
class BottomNavScaffold extends ConsumerWidget {
const BottomNavScaffold({Key? key}) : super(key: key);
const BottomNavScaffold({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
+2 -2
View File
@@ -15,8 +15,8 @@ class CountdownClock extends ConsumerStatefulWidget {
final Duration duration;
final bool active;
const CountdownClock({required this.duration, required this.active, Key? key})
: super(key: key);
const CountdownClock(
{required this.duration, required this.active, super.key});
@override
ConsumerState<CountdownClock> createState() => _CountdownClockState();
+1 -1
View File
@@ -23,7 +23,7 @@ class ListTileChoice<T extends Enum> extends StatelessWidget {
final void Function(T choice) onSelectedItemChanged;
@override
Widget build(context) {
Widget build(BuildContext context) {
return PlatformCard(
child: Column(
children: ListTile.divideTiles(
+3 -3
View File
@@ -16,7 +16,7 @@ class PlatformWidget extends StatelessWidget {
final WidgetBuilder iosBuilder;
@override
Widget build(context) {
Widget build(BuildContext context) {
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return androidBuilder(context);
@@ -46,7 +46,7 @@ class ConsumerPlatformWidget extends StatelessWidget {
final ConsumerWidgetBuilder iosBuilder;
@override
Widget build(context) {
Widget build(BuildContext context) {
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return androidBuilder(context, ref);
@@ -71,7 +71,7 @@ class PlatformCard extends StatelessWidget {
final bool semanticContainer;
@override
Widget build(context) {
Widget build(BuildContext context) {
final MediaQueryData mediaQueryData = MediaQuery.of(context);
return MediaQuery(
data: mediaQueryData.copyWith(
+1 -2
View File
@@ -15,8 +15,7 @@ class Player extends StatelessWidget {
this.rating,
required this.active,
required this.clock,
Key? key})
: super(key: key);
super.key});
@override
Widget build(BuildContext context) {
+3 -10
View File
@@ -269,13 +269,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.3.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
flutter_localizations:
dependency: "direct main"
description: flutter
@@ -403,10 +396,10 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.7.0"
lints:
dependency: transitive
lint:
dependency: "direct dev"
description:
name: lints
name: lint
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
+3 -4
View File
@@ -15,13 +15,13 @@ environment:
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
cupertino_icons: ^1.0.2
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: ^0.17.0
flutter_riverpod: ^2.1.1
cupertino_icons: ^1.0.2
freezed_annotation: ^2.2.0
json_annotation: ^4.7.0
http: ^0.13.5
@@ -50,12 +50,11 @@ dependencies:
loading_overlay: ^0.3.0
dev_dependencies:
build_runner: ^2.3.2
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
build_runner: ^2.3.2
freezed: ^2.2.1
lint: ^2.0.1
mocktail: ^0.3.0
# TODO Remove this after next flutter update
+11 -11
View File
@@ -139,28 +139,28 @@ void main() {
final apiClient = ApiClient(mockLogger, FakeClient());
expect(
() async => await apiClient
.stream(Uri.parse('http://api.test/will/return/401')),
() async =>
apiClient.stream(Uri.parse('http://api.test/will/return/401')),
throwsA(isA<UnauthorizedError>()));
expect(
() async => await apiClient
.stream(Uri.parse('http://api.test/will/return/403')),
() async =>
apiClient.stream(Uri.parse('http://api.test/will/return/403')),
throwsA(isA<ForbiddenError>()));
expect(
() async => await apiClient
.stream(Uri.parse('http://api.test/will/return/404')),
() async =>
apiClient.stream(Uri.parse('http://api.test/will/return/404')),
throwsA(isA<NotFoundError>()));
expect(
() async => await apiClient
.stream(Uri.parse('http://api.test/will/return/500')),
() async =>
apiClient.stream(Uri.parse('http://api.test/will/return/500')),
throwsA(isA<ApiRequestError>()));
expect(
() async => await apiClient
.stream(Uri.parse('http://api.test/will/return/503')),
() async =>
apiClient.stream(Uri.parse('http://api.test/will/return/503')),
throwsA(isA<ApiRequestError>()));
});
@@ -168,7 +168,7 @@ void main() {
final apiClient = ApiClient(mockLogger, FakeClient());
expect(
() async => await apiClient
() async => apiClient
.stream(Uri.parse('http://api.test/will/throw/socket/exception')),
throwsA(isA<GenericError>()));
});
@@ -30,7 +30,8 @@ void main() {
when(() =>
mockApiClient.stream(Uri.parse('$kLichessHost/api/stream/event')))
.thenAnswer((_) => mockHttpStreamFromIterable([
'''{
'''
{
"type": "gameStart",
"game": {
"gameId": "rCRw1AuO",
@@ -59,7 +60,8 @@ void main() {
"board": true
}
}
}'''
}
'''
]));
expect(
@@ -208,7 +208,8 @@ void main() {
that: sameRequest(http.Request(
'GET', Uri.parse('$kLichessHost/api/stream/event'))))))
.thenAnswer((_) => mockHttpStreamFromIterable([
'''{
'''
{
"type": "gameStart",
"game": {
"gameId": "$gameIdTest",
@@ -236,7 +237,8 @@ void main() {
"board": true
}
}
}'''
}
'''
]));
when(() => mockClient.send(any(
@@ -291,85 +293,91 @@ void main() {
}
final maiaResponses = {
'maia1': '''{
"id": "maia1",
"username": "maia1",
"createdAt": 1290415680000,
"seenAt": 1290415680000,
"perfs": {
"blitz": {
"games": 2340,
"rating": 1541,
"rd": 30,
"prog": 10
},
"rapid": {
"games": 2340,
"rating": 1477,
"rd": 30,
"prog": 10
},
"classical": {
"games": 2340,
"rating": 1421,
"rd": 30,
"prog": 10
}
'maia1': '''
{
"id": "maia1",
"username": "maia1",
"createdAt": 1290415680000,
"seenAt": 1290415680000,
"perfs": {
"blitz": {
"games": 2340,
"rating": 1541,
"rd": 30,
"prog": 10
},
"rapid": {
"games": 2340,
"rating": 1477,
"rd": 30,
"prog": 10
},
"classical": {
"games": 2340,
"rating": 1421,
"rd": 30,
"prog": 10
}
}''',
'maia5': '''{
"id": "maia5",
"username": "maia5",
"createdAt": 1290415680000,
"seenAt": 1290415680000,
"perfs": {
"blitz": {
"games": 2340,
"rating": 1643,
"rd": 30,
"prog": 10,
"prov": false
},
"rapid": {
"games": 2340,
"rating": 1577,
"rd": 30,
"prog": 10
},
"classical": {
"games": 2340,
"rating": 1591,
"rd": 30,
"prog": 10
}
}
}
''',
'maia5': '''
{
"id": "maia5",
"username": "maia5",
"createdAt": 1290415680000,
"seenAt": 1290415680000,
"perfs": {
"blitz": {
"games": 2340,
"rating": 1643,
"rd": 30,
"prog": 10,
"prov": false
},
"rapid": {
"games": 2340,
"rating": 1577,
"rd": 30,
"prog": 10
},
"classical": {
"games": 2340,
"rating": 1591,
"rd": 30,
"prog": 10
}
}''',
'maia9': '''{
"id": "maia9",
"username": "maia9",
"createdAt": 1290415680000,
"seenAt": 1290415680000,
"perfs": {
"blitz": {
"games": 2340,
"rating": 1681,
"rd": 30,
"prog": 10
},
"rapid": {
"games": 2340,
"rating": 1677,
"rd": 30,
"prog": 10
},
"classical": {
"games": 2340,
"rating": 1618,
"rd": 30,
"prog": 10
}
}
}
''',
'maia9': '''
{
"id": "maia9",
"username": "maia9",
"createdAt": 1290415680000,
"seenAt": 1290415680000,
"perfs": {
"blitz": {
"games": 2340,
"rating": 1681,
"rd": 30,
"prog": 10
},
"rapid": {
"games": 2340,
"rating": 1677,
"rd": 30,
"prog": 10
},
"classical": {
"games": 2340,
"rating": 1618,
"rd": 30,
"prog": 10
}
}''',
}
}
''',
};
const maiaStatusResponses = '''