Skip to content

Commit

Permalink
Added some lints
Browse files Browse the repository at this point in the history
  • Loading branch information
alexobviously committed Jun 23, 2024
1 parent 45113e9 commit c985a7f
Show file tree
Hide file tree
Showing 30 changed files with 125 additions and 106 deletions.
17 changes: 11 additions & 6 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ include: package:lints/recommended.yaml

linter:
rules:
- camel_case_types
- prefer_single_quotes
- unawaited_futures
- cancel_subscriptions
- require_trailing_commas
- always_declare_return_types
always_declare_return_types: true
camel_case_types: true
cancel_subscriptions: true
constant_identifier_names: true
noop_primitive_operations: true
prefer_const_constructors: true
# prefer_final_locals: true # todo: there are like 500 of these lol
prefer_single_quotes: true
require_trailing_commas: true
unawaited_futures: true
unnecessary_to_list_in_spreads: true
2 changes: 1 addition & 1 deletion example/json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void main(List<String> args) {
final variant = Variant(
name: 'Example',
description: 'An example variant for JSON serialisation',
boardSize: BoardSize(3, 5),
boardSize: const BoardSize(3, 5),
startPosition: 'nkn/ppp/3/PPP/NKN w - - 0 1',
castlingOptions: CastlingOptions.none,
enPassant: false,
Expand Down
24 changes: 16 additions & 8 deletions lib/src/actions/actions/checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ class ActionCheckRoyalsAlive extends Action {
return kingsAlive[Bishop.black]
? []
: [
EffectSetGameResult(
const EffectSetGameResult(
WonGameRoyalDead(winner: Bishop.white),
),
];
}
return kingsAlive[Bishop.black]
? [EffectSetGameResult(WonGameRoyalDead(winner: Bishop.black))]
? [
const EffectSetGameResult(
WonGameRoyalDead(winner: Bishop.black),
),
]
: (allowDraw
? [EffectSetGameResult(DrawnGameBothRoyalsDead())]
: [EffectInvalidateMove()]);
? [const EffectSetGameResult(DrawnGameBothRoyalsDead())]
: [const EffectInvalidateMove()]);
},
);
}
Expand All @@ -56,7 +60,9 @@ class CheckRoyalsAliveAdapter
@override
Map<String, dynamic> export(ActionCheckRoyalsAlive e) {
if (e.condition != null || e.precondition != null) {
throw BishopException('Unsupported export of condition or precondition');
throw const BishopException(
'Unsupported export of condition or precondition',
);
}
return {
if (e.event != ActionEvent.afterMove) 'event': e.event.export(),
Expand Down Expand Up @@ -99,8 +105,8 @@ class ActionCheckPieceCount extends Action {
if (white && black) return [];
if (draw || (!white && !black)) {
return drawsInvalidate
? [EffectInvalidateMove()]
: [EffectSetGameResult(DrawnGameElimination())];
? [const EffectInvalidateMove()]
: [const EffectSetGameResult(DrawnGameElimination())];
}
return [
EffectSetGameResult(
Expand Down Expand Up @@ -132,7 +138,9 @@ class CheckPieceCountAdapter extends BishopTypeAdapter<ActionCheckPieceCount> {
@override
Map<String, dynamic>? export(ActionCheckPieceCount e) {
if (e.condition != null || e.precondition != null) {
throw BishopException('Unsupported export of condition or precondition');
throw const BishopException(
'Unsupported export of condition or precondition',
);
}
return {
'pieceType': e.pieceType,
Expand Down
8 changes: 6 additions & 2 deletions lib/src/actions/actions/hands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class AddToHandAdapter extends BishopTypeAdapter<ActionAddToHand> {
@override
Map<String, dynamic> export(ActionAddToHand e) {
if (e.condition != null || e.precondition != null) {
throw BishopException('Unsupported export of condition or precondition');
throw const BishopException(
'Unsupported export of condition or precondition',
);
}
return {
'piece': e.piece,
Expand All @@ -88,7 +90,9 @@ class RemoveFromHandAdapter extends BishopTypeAdapter<ActionRemoveFromHand> {
@override
Map<String, dynamic> export(ActionRemoveFromHand e) {
if (e.condition != null || e.precondition != null) {
throw BishopException('Unsupported export of condition or precondition');
throw const BishopException(
'Unsupported export of condition or precondition',
);
}
return {
'piece': e.piece,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/actions/actions/immortality.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ImmortalityAdapter extends BishopTypeAdapter<ActionImmortality> {
@override
Map<String, dynamic>? export(ActionImmortality e) {
if (e.condition != null) {
throw BishopException('Unsupported export of condition');
throw const BishopException('Unsupported export of condition');
}
return {
if (e.event != ActionEvent.afterMove) 'event': e.event.export(),
Expand Down
4 changes: 3 additions & 1 deletion lib/src/actions/actions/region.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class ExitRegionEndingAdapter
@override
Map<String, dynamic> export(ActionExitRegionEnding e) {
if (e.condition != null || e.precondition != null) {
throw BishopException('Unsupported export of condition or precondition');
throw const BishopException(
'Unsupported export of condition or precondition',
);
}
return {
'region': e.region.toJson(),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/actions/actions/transfer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TransferOwnershipAdapter
@override
Map<String, dynamic>? export(ActionTransferOwnership e) {
if (e.condition != null) {
throw BishopException('Unsupported export of condition');
throw const BishopException('Unsupported export of condition');
}
return {
if (!e.capture) 'capture': e.capture,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Engine {
}) async {
if (game.gameOver) {
print(game.drawn ? 'Draw' : 'Checkmate');
return EngineResult();
return const EngineResult();
}
int endTime = DateTime.now().millisecondsSinceEpoch + timeLimit;
int endBuffer = endTime + timeBuffer;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/game/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Game {
if (!variant.canPass(state: state, colour: colour)) {
return null;
}
PassMove m = PassMove();
PassMove m = const PassMove();
if (legal) {
bool valid = makeMove(m, false);
if (lostBy(colour, ignoreSoftResults: true) || kingAttacked(colour)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/src/game/game_endings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension GameEndings on Game {
final elimCond = variant.gameEndConditions[state.turn].elimination;
if (elimCond.isNotNone) {
if (eliminated) {
if (elimCond.isDraw) return DrawnGameElimination();
if (elimCond.isDraw) return const DrawnGameElimination();
return WonGameElimination(
winner: elimCond.isWin ? state.turn : state.turn.opponent,
);
Expand All @@ -37,12 +37,12 @@ extension GameEndings on Game {
final stalemateCond = variant.gameEndConditions[state.turn].stalemate;
if (stalemateCond.isNotNone && stalemate) {
return stalemateCond.isDraw
? DrawnGameStalemate()
? const DrawnGameStalemate()
: WonGameStalemate(
winner: stalemateCond.isWin ? state.turn : state.turn.opponent,
);
}
if (insufficientMaterial) return DrawnGameInsufficientMaterial();
if (insufficientMaterial) return const DrawnGameInsufficientMaterial();
if (repetition) return DrawnGameRepetition(repeats: hashHits);
if (halfMoveRule) return DrawnGameLength(halfMoves: state.halfMoves);
return null;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/piece_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class PieceType {
PieceType withRoyal() =>
copyWith(royal: true, promoOptions: PiecePromoOptions.none);

factory PieceType.empty() => PieceType(
factory PieceType.empty() => const PieceType(
moves: [],
promoOptions: PiecePromoOptions.none,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/regions/area.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Area implements Region {
(x) => List.generate(height, (y) => Direction(x + xStart, y + yStart)),
).expand((e) => e).toList();
if (omitCentre) {
dirs.remove(Direction(0, 0));
dirs.remove(const Direction(0, 0));
}
return Area(directions: dirs);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/src/serialisation/serialisation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ class BishopSerialisation {
static List<BishopTypeAdapter>? _baseAdapters;

static List<BishopTypeAdapter> get basePromoAdapters => [
NoPromotionAdapter(),
const NoPromotionAdapter(),
RegionPromotionAdapter(),
StandardPromotionAdapter(),
OptionalPromotionAdapter(),
];

static List<BishopTypeAdapter> get baseDropAdapters => [
RegionDropAdapter(),
StandardDropAdapter(),
UnrestrictedDropAdapter(),
const StandardDropAdapter(),
const UnrestrictedDropAdapter(),
];

static List<BishopTypeAdapter> get basePassAdapters => [
NoPassAdapter(),
StandardPassAdapter(),
const NoPassAdapter(),
const StandardPassAdapter(),
];

static List<BishopTypeAdapter> get baseStartPosAdapters => [
Expand All @@ -65,7 +65,7 @@ class BishopSerialisation {
FirstMovePairAdapter(),
FirstMoveSetAdapter(),
RanksFirstMoveAdapter(),
InitialFirstMoveAdapter(),
const InitialFirstMoveAdapter(),
];

static List<BishopTypeAdapter> get baseStateTransformAdapters => [
Expand Down
2 changes: 1 addition & 1 deletion lib/src/variant/options/material_conditions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extension ConvertMaterialConditions on MaterialConditions<String> {
List<int> pieceIndices(List<String> symbols) =>
symbols.map((p) => pieceIndex(p)).where((p) => p >= 0).toList();
if (!enabled) {
return MaterialConditions(enabled: false);
return const MaterialConditions(enabled: false);
} else {
return MaterialConditions(
enabled: true,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/variant/variants/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CommonVariants {
)
.withRegion(
'hill',
RectRegion(
const RectRegion(
startFile: Bishop.fileD,
endFile: Bishop.fileE,
startRank: Bishop.rank4,
Expand Down Expand Up @@ -128,6 +128,6 @@ class CommonVariants {
materialConditions: MaterialConditions.none,
enPassant: false,
gameEndConditions:
GameEndConditions(stalemate: EndType.lose).symmetric(),
const GameEndConditions(stalemate: EndType.lose).symmetric(),
);
}
2 changes: 1 addition & 1 deletion lib/src/variant/variants/fairy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FairyVariants {
/// https://en.wikipedia.org/wiki/Wolf_chess
static Variant wolf() => Variant(
name: 'Wolf Chess',
boardSize: BoardSize(8, 10),
boardSize: const BoardSize(8, 10),
startPosition: 'qwfrbbnk/pssppssp/1pp2pp1/8/8'
'/8/8/1PP2PP1/PSSPPSSP/KNBBRFWQ w - - 0 1',
pieceTypes: {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/variant/variants/large.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abstract class LargeVariants {
final standard = Variant.standard();
return standard.copyWith(
name: 'Capablanca Chess',
boardSize: BoardSize(10, 8),
boardSize: const BoardSize(10, 8),
startPosition: 'rnabqkbcnr/pppppppppp/10/10/10/10/PPPPPPPPPP'
'/RNABQKBCNR w KQkq - 0 1',
castlingOptions: CastlingOptions.capablanca,
Expand All @@ -22,7 +22,7 @@ abstract class LargeVariants {
final standard = Variant.standard();
return standard.copyWith(
name: 'Grand Chess',
boardSize: BoardSize(10, 10),
boardSize: const BoardSize(10, 10),
startPosition: 'r8r/1nbqkcabn1/pppppppppp/10/10/10/10/PPPPPPPPPP'
'/1NBQKCABN1/R8R w - - 0 1',
castlingOptions: CastlingOptions.none,
Expand Down Expand Up @@ -65,15 +65,15 @@ abstract class LargeVariants {
final standard = Variant.standard();
return standard.copyWith(
name: 'Shako',
boardSize: BoardSize(10, 10),
boardSize: const BoardSize(10, 10),
startPosition: 'c8c/ernbqkbnre/pppppppppp/10/10/10/10/PPPPPPPPPP'
'/ERNBQKBNRE/C8C w KQkq - 0 1',
pieceTypes: {
...standard.pieceTypes,
'E': PieceType.fromBetza('FA'),
'C': Xiangqi.cannon(),
},
castlingOptions: CastlingOptions(
castlingOptions: const CastlingOptions(
enabled: true,
kTarget: Bishop.fileH,
qTarget: Bishop.fileD,
Expand All @@ -88,7 +88,7 @@ abstract class LargeVariants {
/// https://www.chessvariants.com/contests/10/tencubedchess.html
static Variant tenCubed() => Variant(
name: 'TenCubed',
boardSize: BoardSize(10, 10),
boardSize: const BoardSize(10, 10),
startPosition: '2cwamwc2/1rnbqkbnr1/pppppppppp/10/10/10/10'
'/PPPPPPPPPP/1RNBQKBNR1/2CWAMWC2 w - - 0 1',
pieceTypes: {
Expand Down
8 changes: 4 additions & 4 deletions lib/src/variant/variants/misc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MiscVariants {
// https://www.chessvariants.com/diffobjective.dir/utchess.html#domination
// todo: make this serialisable, break action down
static Variant domination({int scoreLimit = 15}) {
final region = RectRegion(
final region = const RectRegion(
startFile: Bishop.fileD,
endFile: Bishop.fileE,
startRank: Bishop.rank4,
Expand Down Expand Up @@ -109,15 +109,15 @@ class MiscVariants {
}

static Variant dart() {
final dropRegion = RectRegion(
final dropRegion = const RectRegion(
startFile: Bishop.fileB,
endFile: Bishop.fileE,
startRank: Bishop.rank2,
endRank: Bishop.rank5,
);
return Variant(
name: 'Dart',
boardSize: BoardSize(6, 6),
boardSize: const BoardSize(6, 6),
startPosition: 'knrppp/nbp3/rp3P/p3PR/3PBN/PPPRNK[XXXxxx] w - - 0 1',
enPassant: false,
handOptions: HandOptions(
Expand Down Expand Up @@ -153,7 +153,7 @@ class MiscVariants {
...Variant.standard().pieceTypes,
'P': PieceType.fromBetza('mlfFcflW', noSanSymbol: true).promotable(),
},
promotionOptions: RegionPromotion(whiteId: 'wp', blackId: 'bp'),
promotionOptions: const RegionPromotion(whiteId: 'wp', blackId: 'bp'),
regions: {
'wp': RectRegion.lrbt(0, 0, 4, 7) + RectRegion.lrbt(0, 3, 7, 7),
'bp': RectRegion.lrbt(7, 7, 0, 3) + RectRegion.lrbt(4, 7, 0, 0),
Expand Down
Loading

0 comments on commit c985a7f

Please sign in to comment.