fix: Add eslint config and fix warnings
This commit is contained in:
parent
d58a84a7b1
commit
d5ef78427c
10 changed files with 1330 additions and 41 deletions
34
.eslintignore
Normal file
34
.eslintignore
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
# lockfile
|
||||||
|
pnpm-lock.yaml
|
||||||
|
|
||||||
|
# CI
|
||||||
|
.pnpm-store
|
||||||
|
.drone.yml
|
||||||
|
|
||||||
|
# Config
|
||||||
|
.eslintrc.js
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
27
.eslintrc.js
Normal file
27
.eslintrc.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
module.exports = {
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"es2021": true
|
||||||
|
},
|
||||||
|
"extends": [
|
||||||
|
"eslint:recommended",
|
||||||
|
"plugin:react/recommended",
|
||||||
|
"plugin:@typescript-eslint/recommended",
|
||||||
|
"plugin:react/jsx-runtime",
|
||||||
|
],
|
||||||
|
"parser": "@typescript-eslint/parser",
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaFeatures": {
|
||||||
|
"jsx": true,
|
||||||
|
},
|
||||||
|
"ecmaVersion": "latest",
|
||||||
|
"sourceType": "module",
|
||||||
|
},
|
||||||
|
"plugins": [
|
||||||
|
"react",
|
||||||
|
"@typescript-eslint",
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"@typescript-eslint/no-non-null-assertion": "off",
|
||||||
|
},
|
||||||
|
}
|
|
@ -7,7 +7,8 @@
|
||||||
"build": "tsc && vite build",
|
"build": "tsc && vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"format:check": "prettier --check ."
|
"format:check": "prettier --check .",
|
||||||
|
"lint": "eslint ."
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource/noto-sans-symbols-2": "^4.5.9",
|
"@fontsource/noto-sans-symbols-2": "^4.5.9",
|
||||||
|
@ -16,9 +17,14 @@
|
||||||
"react-draggable": "^4.4.5"
|
"react-draggable": "^4.4.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/node": "^18.0.3",
|
||||||
"@types/react": "^18.0.0",
|
"@types/react": "^18.0.0",
|
||||||
"@types/react-dom": "^18.0.0",
|
"@types/react-dom": "^18.0.0",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^5.30.5",
|
||||||
|
"@typescript-eslint/parser": "^5.30.5",
|
||||||
"@vitejs/plugin-react": "^1.3.0",
|
"@vitejs/plugin-react": "^1.3.0",
|
||||||
|
"eslint": "^8.19.0",
|
||||||
|
"eslint-plugin-react": "^7.30.1",
|
||||||
"prettier": "^2.7.1",
|
"prettier": "^2.7.1",
|
||||||
"ts-node": "^10.8.2",
|
"ts-node": "^10.8.2",
|
||||||
"typescript": "^4.6.3",
|
"typescript": "^4.6.3",
|
||||||
|
|
1231
pnpm-lock.yaml
1231
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
|
@ -1,12 +1,7 @@
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import Board from './components/Board';
|
import Board from './components/Board';
|
||||||
import {
|
import {
|
||||||
LEGAL_MOVE_TEST_FEN,
|
|
||||||
parseFEN,
|
parseFEN,
|
||||||
PAWN_BUG_TEST_FEN,
|
|
||||||
POSITION_2,
|
|
||||||
POSITION_4,
|
|
||||||
POSITION_5,
|
|
||||||
START_FEN,
|
START_FEN,
|
||||||
} from './utils/board';
|
} from './utils/board';
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
import { FC, Fragment, useCallback, useEffect, useMemo, useState } from 'react';
|
import { FC, Fragment, useCallback, useMemo, useState } from 'react';
|
||||||
import { encodeFEN, eq, GameState, isChecked } from '../utils/board';
|
import { encodeFEN, eq, GameState, isChecked } from '../utils/board';
|
||||||
import {
|
import {
|
||||||
filterMoves,
|
filterMoves,
|
||||||
generateLegalMoves,
|
generateLegalMoves,
|
||||||
generatePseudolegalMoves,
|
|
||||||
makeMove,
|
makeMove,
|
||||||
Move,
|
Move,
|
||||||
} from '../utils/move';
|
} from '../utils/move';
|
||||||
import { BoardPiece, getType, otherSide, Side } from '../utils/piece';
|
import { getType, otherSide } from '../utils/piece';
|
||||||
import styles from './Board.module.css';
|
import styles from './Board.module.css';
|
||||||
import Piece from './Piece';
|
import Piece from './Piece';
|
||||||
|
|
||||||
|
@ -45,7 +44,7 @@ const Board: FC<Props> = (props) => {
|
||||||
const [enPassantTarget, setEnPassantTarget] = useState(
|
const [enPassantTarget, setEnPassantTarget] = useState(
|
||||||
props.state.enPassantTarget
|
props.state.enPassantTarget
|
||||||
);
|
);
|
||||||
const [halfmoveClock, setHalfmoveClock] = useState(
|
const [halfmoveClock] = useState(
|
||||||
props.state.halfmoveClock
|
props.state.halfmoveClock
|
||||||
);
|
);
|
||||||
const [fullmoveNumber, setFullmoveNumber] = useState(
|
const [fullmoveNumber, setFullmoveNumber] = useState(
|
||||||
|
|
|
@ -5,8 +5,11 @@ import './index.css';
|
||||||
import '@fontsource/noto-sans-symbols-2';
|
import '@fontsource/noto-sans-symbols-2';
|
||||||
import { runAllPerfts, runPerft } from './test/perft';
|
import { runAllPerfts, runPerft } from './test/perft';
|
||||||
|
|
||||||
(window as any).runPerfts = runAllPerfts;
|
/* eslint @typescript-eslint/no-explicit-any: off */
|
||||||
(window as any).runPerft = runPerft;
|
{
|
||||||
|
(window as any).runPerfts = runAllPerfts;
|
||||||
|
(window as any).runPerft = runPerft;
|
||||||
|
}
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
import {
|
import {
|
||||||
generateLegalMoves,
|
|
||||||
generatePseudolegalMoves,
|
generatePseudolegalMoves,
|
||||||
isValidMove,
|
|
||||||
toAlgebraic,
|
|
||||||
} from './move';
|
} from './move';
|
||||||
import {
|
import {
|
||||||
BoardPiece,
|
BoardPiece,
|
||||||
otherSide,
|
|
||||||
pieceFromChar,
|
pieceFromChar,
|
||||||
Side,
|
Side,
|
||||||
toAlgebraicChar,
|
toAlgebraicChar,
|
||||||
|
@ -107,16 +103,19 @@ export const POSITION_5 =
|
||||||
export const POSITION_6 =
|
export const POSITION_6 =
|
||||||
'r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - - 0 10';
|
'r4rk1/1pp1qppp/p1np1n2/2b1p1B1/2B1P1b1/P1NP1N2/1PP1QPPP/R4RK1 w - - 0 10';
|
||||||
|
|
||||||
(window as any).START_FEN = START_FEN;
|
/* eslint @typescript-eslint/no-explicit-any: off */
|
||||||
(window as any).TEST_FEN = TEST_FEN;
|
{
|
||||||
(window as any).PAWN_BUG_TEST_FEN = PAWN_BUG_TEST_FEN;
|
(window as any).START_FEN = START_FEN;
|
||||||
(window as any).KNIGHT_TEST_FEN = KNIGHT_TEST_FEN;
|
(window as any).TEST_FEN = TEST_FEN;
|
||||||
(window as any).LEGAL_MOVE_TEST_FEN = LEGAL_MOVE_TEST_FEN;
|
(window as any).PAWN_BUG_TEST_FEN = PAWN_BUG_TEST_FEN;
|
||||||
(window as any).POSITION_2 = POSITION_2;
|
(window as any).KNIGHT_TEST_FEN = KNIGHT_TEST_FEN;
|
||||||
(window as any).POSITION_3 = POSITION_3;
|
(window as any).LEGAL_MOVE_TEST_FEN = LEGAL_MOVE_TEST_FEN;
|
||||||
(window as any).POSITION_4 = POSITION_4;
|
(window as any).POSITION_2 = POSITION_2;
|
||||||
(window as any).POSITION_5 = POSITION_5;
|
(window as any).POSITION_3 = POSITION_3;
|
||||||
(window as any).POSITION_6 = POSITION_6;
|
(window as any).POSITION_4 = POSITION_4;
|
||||||
|
(window as any).POSITION_5 = POSITION_5;
|
||||||
|
(window as any).POSITION_6 = POSITION_6;
|
||||||
|
}
|
||||||
|
|
||||||
export interface GameState {
|
export interface GameState {
|
||||||
board: Board;
|
board: Board;
|
||||||
|
@ -197,16 +196,16 @@ export function encodeFEN(state: GameState): string {
|
||||||
function parseFENPieces(fen: string): BoardPiece[][] {
|
function parseFENPieces(fen: string): BoardPiece[][] {
|
||||||
const board = Array(8)
|
const board = Array(8)
|
||||||
.fill(0)
|
.fill(0)
|
||||||
.map((_) => Array(8).fill(null));
|
.map(() => Array(8).fill(null));
|
||||||
let rankIdx = 7;
|
let rankIdx = 7;
|
||||||
for (const rank of fen.split('/')) {
|
for (const rank of fen.split('/')) {
|
||||||
let file = 0;
|
let file = 0;
|
||||||
for (const c of rank) {
|
for (const c of rank) {
|
||||||
let skip = parseInt(c);
|
const skip = parseInt(c);
|
||||||
if (!isNaN(skip)) {
|
if (!isNaN(skip)) {
|
||||||
file += skip;
|
file += skip;
|
||||||
} else {
|
} else {
|
||||||
let piece = pieceFromChar(c);
|
const piece = pieceFromChar(c);
|
||||||
board[rankIdx][file] = piece;
|
board[rankIdx][file] = piece;
|
||||||
file++;
|
file++;
|
||||||
}
|
}
|
||||||
|
@ -226,14 +225,15 @@ function encodeFENBoard(board: Board): string {
|
||||||
let emptyCount = 0;
|
let emptyCount = 0;
|
||||||
let result = '';
|
let result = '';
|
||||||
while (file < 8) {
|
while (file < 8) {
|
||||||
if (row[file] === null) {
|
const piece = row[file];
|
||||||
|
if (piece === null) {
|
||||||
emptyCount++;
|
emptyCount++;
|
||||||
} else {
|
} else {
|
||||||
if (emptyCount > 0) {
|
if (emptyCount > 0) {
|
||||||
result += emptyCount.toString();
|
result += emptyCount.toString();
|
||||||
emptyCount = 0;
|
emptyCount = 0;
|
||||||
}
|
}
|
||||||
result += toAlgebraicChar(row[file]!);
|
result += toAlgebraicChar(piece);
|
||||||
}
|
}
|
||||||
file++;
|
file++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import {
|
import {
|
||||||
algebraicCoord,
|
algebraicCoord,
|
||||||
Board,
|
|
||||||
coord,
|
coord,
|
||||||
Coordinate,
|
Coordinate,
|
||||||
coordsBetween,
|
coordsBetween,
|
||||||
|
@ -147,7 +146,7 @@ function addIfCapture(
|
||||||
state: GameState,
|
state: GameState,
|
||||||
moves: Move[],
|
moves: Move[],
|
||||||
move: Move,
|
move: Move,
|
||||||
enPassant: boolean = false
|
enPassant = false
|
||||||
): MoveResult {
|
): MoveResult {
|
||||||
if (
|
if (
|
||||||
move.to.rank < 0 ||
|
move.to.rank < 0 ||
|
||||||
|
@ -275,7 +274,7 @@ function generateLineMoves(
|
||||||
moves: Move[],
|
moves: Move[],
|
||||||
type: PieceType,
|
type: PieceType,
|
||||||
directions: Coordinate[],
|
directions: Coordinate[],
|
||||||
distanceLimit: number = 8
|
distanceLimit = 8
|
||||||
) {
|
) {
|
||||||
const validPiece: Piece = `${state.sideToMove}-${type}`;
|
const validPiece: Piece = `${state.sideToMove}-${type}`;
|
||||||
|
|
||||||
|
@ -411,6 +410,7 @@ export function filterMoves(
|
||||||
}
|
}
|
||||||
|
|
||||||
function dbg<T>(t: T, m?: string): T {
|
function dbg<T>(t: T, m?: string): T {
|
||||||
|
m;
|
||||||
// m ? console.trace(m, t) : console.trace(t);
|
// m ? console.trace(m, t) : console.trace(t);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
@ -422,7 +422,8 @@ export function makeMove(
|
||||||
): GameState {
|
): GameState {
|
||||||
const { board, sideToMove } = state;
|
const { board, sideToMove } = state;
|
||||||
const newBoard = board.map((rank) => rank.slice());
|
const newBoard = board.map((rank) => rank.slice());
|
||||||
const piece = board[move.from.rank][move.from.file]!;
|
const piece = board[move.from.rank][move.from.file];
|
||||||
|
if (!piece) throw new Error();
|
||||||
const newCastling = { ...state.castling };
|
const newCastling = { ...state.castling };
|
||||||
if (getType(piece) === 'king') {
|
if (getType(piece) === 'king') {
|
||||||
newCastling[sideToMove] = {
|
newCastling[sideToMove] = {
|
||||||
|
|
|
@ -5,4 +5,9 @@ import react from '@vitejs/plugin-react';
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
base: '',
|
base: '',
|
||||||
|
server: {
|
||||||
|
hmr: {
|
||||||
|
clientPort: parseInt(process.env.CLIENT_PORT || '3000'),
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue