From 7f7445ad7a4bfca020ca6c771383f206b19ff694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=93=E3=81=8B=E3=82=8A?= <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:25:23 +0900 Subject: [PATCH] =?UTF-8?q?refactor(misskey-games):=20Misskey=20Games?= =?UTF-8?q?=E7=B3=BB=E3=83=91=E3=83=83=E3=82=B1=E3=83=BC=E3=82=B8=E3=81=AE?= =?UTF-8?q?lint=E4=BF=AE=E6=AD=A3=EF=BC=8BLint=20CI=E6=95=B4=E5=82=99=20(#?= =?UTF-8?q?14612)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore(lint): Fix linting in misskey-reversi (cherry picked from commit 894934a1a7743472b2d051e2690007ae373efd76) * chore(lint): Fix linting in misskey-bubble-game (cherry picked from commit 1ba9c37a8d5e4ae6a98494026b87f6f6439790c7) * enhance(gh): add lint ci for misskey games packages * enhance(gh): fix lint ci * fix * revert some changes that nothing to do with lint rules * fix * lint fixes * refactor: strict type def * lint fixes * :art: * :art: --------- Co-authored-by: 4censord --- .github/workflows/lint.yml | 6 ++++ packages/misskey-bubble-game/build.js | 32 +++++++++---------- packages/misskey-bubble-game/eslint.config.js | 1 + packages/misskey-bubble-game/src/game.ts | 30 +++++++++++------ packages/misskey-reversi/build.js | 32 +++++++++---------- packages/misskey-reversi/eslint.config.js | 1 + packages/misskey-reversi/src/game.ts | 11 +++++-- 7 files changed, 68 insertions(+), 45 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3064b0f6f4..07d9af12f7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,6 +12,8 @@ on: - packages/frontend-embed/** - packages/sw/** - packages/misskey-js/** + - packages/misskey-bubble-game/** + - packages/misskey-reversi/** - packages/shared/eslint.config.js - .github/workflows/lint.yml pull_request: @@ -22,6 +24,8 @@ on: - packages/frontend-embed/** - packages/sw/** - packages/misskey-js/** + - packages/misskey-bubble-game/** + - packages/misskey-reversi/** - packages/shared/eslint.config.js - .github/workflows/lint.yml jobs: @@ -53,6 +57,8 @@ jobs: - frontend-embed - sw - misskey-js + - misskey-bubble-game + - misskey-reversi env: eslint-cache-version: v1 eslint-cache-path: ${{ github.workspace }}/node_modules/.cache/eslint-${{ matrix.workspace }} diff --git a/packages/misskey-bubble-game/build.js b/packages/misskey-bubble-game/build.js index e626c97a59..a80b71646f 100644 --- a/packages/misskey-bubble-game/build.js +++ b/packages/misskey-bubble-game/build.js @@ -1,32 +1,32 @@ -import * as esbuild from "esbuild"; -import { build } from "esbuild"; -import { globSync } from "glob"; -import { execa } from "execa"; -import fs from "node:fs"; -import { fileURLToPath } from "node:url"; -import { dirname } from "node:path"; +import fs from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import { dirname } from 'node:path'; +import * as esbuild from 'esbuild'; +import { build } from 'esbuild'; +import { globSync } from 'glob'; +import { execa } from 'execa'; const _filename = fileURLToPath(import.meta.url); const _dirname = dirname(_filename); const _package = JSON.parse(fs.readFileSync(_dirname + '/package.json', 'utf-8')); -const entryPoints = globSync("./src/**/**.{ts,tsx}"); +const entryPoints = globSync('./src/**/**.{ts,tsx}'); /** @type {import('esbuild').BuildOptions} */ const options = { entryPoints, minify: process.env.NODE_ENV === 'production', - outdir: "./built", - target: "es2022", - platform: "browser", - format: "esm", + outdir: './built', + target: 'es2022', + platform: 'browser', + format: 'esm', sourcemap: 'linked', }; // built配下をすべて削除する fs.rmSync('./built', { recursive: true, force: true }); -if (process.argv.map(arg => arg.toLowerCase()).includes("--watch")) { +if (process.argv.map(arg => arg.toLowerCase()).includes('--watch')) { await watchSrc(); } else { await buildSrc(); @@ -36,7 +36,7 @@ async function buildSrc() { console.log(`[${_package.name}] start building...`); await build(options) - .then(it => { + .then(() => { console.log(`[${_package.name}] build succeeded.`); }) .catch((err) => { @@ -65,7 +65,7 @@ function buildDts() { { stdout: process.stdout, stderr: process.stderr, - } + }, ); } @@ -86,7 +86,7 @@ async function watchSrc() { }, }]; - console.log(`[${_package.name}] start watching...`) + console.log(`[${_package.name}] start watching...`); const context = await esbuild.context({ ...options, plugins }); await context.watch(); diff --git a/packages/misskey-bubble-game/eslint.config.js b/packages/misskey-bubble-game/eslint.config.js index 86c21a22a3..bce383b1a6 100644 --- a/packages/misskey-bubble-game/eslint.config.js +++ b/packages/misskey-bubble-game/eslint.config.js @@ -1,6 +1,7 @@ import tsParser from '@typescript-eslint/parser'; import sharedConfig from '../shared/eslint.config.js'; +// eslint-disable-next-line import/no-default-export export default [ ...sharedConfig, { diff --git a/packages/misskey-bubble-game/src/game.ts b/packages/misskey-bubble-game/src/game.ts index 3bce4b1dcf..7f230e39cb 100644 --- a/packages/misskey-bubble-game/src/game.ts +++ b/packages/misskey-bubble-game/src/game.ts @@ -199,13 +199,12 @@ export class DropAndFusionGame extends EventEmitter<{ }; if (mono.shape === 'circle') { return Matter.Bodies.circle(x, y, mono.sizeX / 2, options); - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition } else if (mono.shape === 'rectangle') { return Matter.Bodies.rectangle(x, y, mono.sizeX, mono.sizeY, options); - } else if (mono.shape === 'custom') { - return Matter.Bodies.fromVertices(x, y, mono.vertices!.map(i => i.map(j => ({ - x: (j.x / mono.verticesSize!) * mono.sizeX, - y: (j.y / mono.verticesSize!) * mono.sizeY, + } else if (mono.shape === 'custom' && mono.vertices != null && mono.verticesSize != null) { //eslint-disable-line @typescript-eslint/no-unnecessary-condition + return Matter.Bodies.fromVertices(x, y, mono.vertices.map(i => i.map(j => ({ + x: (j.x / mono.verticesSize!) * mono.sizeX, //eslint-disable-line @typescript-eslint/no-non-null-assertion + y: (j.y / mono.verticesSize!) * mono.sizeY, //eslint-disable-line @typescript-eslint/no-non-null-assertion }))), options); } else { throw new Error('unrecognized shape'); @@ -227,7 +226,12 @@ export class DropAndFusionGame extends EventEmitter<{ this.gameOverReadyBodyIds = this.gameOverReadyBodyIds.filter(x => x !== bodyA.id && x !== bodyB.id); Matter.Composite.remove(this.engine.world, [bodyA, bodyB]); - const currentMono = this.monoDefinitions.find(y => y.id === bodyA.label)!; + const currentMono = this.monoDefinitions.find(y => y.id === bodyA.label); + + if (currentMono == null) { + throw new Error('Current Mono Not Found'); + } + const nextMono = this.monoDefinitions.find(x => x.level === currentMono.level + 1) ?? null; if (nextMono) { @@ -362,14 +366,18 @@ export class DropAndFusionGame extends EventEmitter<{ } public getActiveMonos() { - return this.engine.world.bodies.map(x => this.monoDefinitions.find((mono) => mono.id === x.label)!).filter(x => x !== undefined); + return this.engine.world.bodies + .map(x => this.monoDefinitions.find((mono) => mono.id === x.label)) + .filter(x => x !== undefined); } public drop(_x: number) { if (this.isGameOver) return; if (this.frame - this.latestDroppedAt < this.DROP_COOLTIME) return; - const head = this.stock.shift()!; + const head = this.stock.shift(); + if (!head) return; + this.stock.push({ id: this.rng().toString(), mono: this.monoDefinitions.filter(x => x.dropCandidate)[Math.floor(this.rng() * this.monoDefinitions.filter(x => x.dropCandidate).length)], @@ -411,13 +419,15 @@ export class DropAndFusionGame extends EventEmitter<{ }); if (this.holding) { - const head = this.stock.shift()!; + const head = this.stock.shift(); + if (!head) return; this.stock.unshift(this.holding); this.holding = head; this.emit('changeHolding', this.holding); this.emit('changeStock', this.stock); } else { - const head = this.stock.shift()!; + const head = this.stock.shift(); + if (!head) return; this.holding = head; this.stock.push({ id: this.rng().toString(), diff --git a/packages/misskey-reversi/build.js b/packages/misskey-reversi/build.js index e626c97a59..a80b71646f 100644 --- a/packages/misskey-reversi/build.js +++ b/packages/misskey-reversi/build.js @@ -1,32 +1,32 @@ -import * as esbuild from "esbuild"; -import { build } from "esbuild"; -import { globSync } from "glob"; -import { execa } from "execa"; -import fs from "node:fs"; -import { fileURLToPath } from "node:url"; -import { dirname } from "node:path"; +import fs from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import { dirname } from 'node:path'; +import * as esbuild from 'esbuild'; +import { build } from 'esbuild'; +import { globSync } from 'glob'; +import { execa } from 'execa'; const _filename = fileURLToPath(import.meta.url); const _dirname = dirname(_filename); const _package = JSON.parse(fs.readFileSync(_dirname + '/package.json', 'utf-8')); -const entryPoints = globSync("./src/**/**.{ts,tsx}"); +const entryPoints = globSync('./src/**/**.{ts,tsx}'); /** @type {import('esbuild').BuildOptions} */ const options = { entryPoints, minify: process.env.NODE_ENV === 'production', - outdir: "./built", - target: "es2022", - platform: "browser", - format: "esm", + outdir: './built', + target: 'es2022', + platform: 'browser', + format: 'esm', sourcemap: 'linked', }; // built配下をすべて削除する fs.rmSync('./built', { recursive: true, force: true }); -if (process.argv.map(arg => arg.toLowerCase()).includes("--watch")) { +if (process.argv.map(arg => arg.toLowerCase()).includes('--watch')) { await watchSrc(); } else { await buildSrc(); @@ -36,7 +36,7 @@ async function buildSrc() { console.log(`[${_package.name}] start building...`); await build(options) - .then(it => { + .then(() => { console.log(`[${_package.name}] build succeeded.`); }) .catch((err) => { @@ -65,7 +65,7 @@ function buildDts() { { stdout: process.stdout, stderr: process.stderr, - } + }, ); } @@ -86,7 +86,7 @@ async function watchSrc() { }, }]; - console.log(`[${_package.name}] start watching...`) + console.log(`[${_package.name}] start watching...`); const context = await esbuild.context({ ...options, plugins }); await context.watch(); diff --git a/packages/misskey-reversi/eslint.config.js b/packages/misskey-reversi/eslint.config.js index 3f81df7145..8453d9b8e7 100644 --- a/packages/misskey-reversi/eslint.config.js +++ b/packages/misskey-reversi/eslint.config.js @@ -1,6 +1,7 @@ import tsParser from '@typescript-eslint/parser'; import sharedConfig from '../shared/eslint.config.js'; +// eslint-disable-next-line import/no-default-export export default [ ...sharedConfig, { diff --git a/packages/misskey-reversi/src/game.ts b/packages/misskey-reversi/src/game.ts index 4afca9898c..35cc44feb4 100644 --- a/packages/misskey-reversi/src/game.ts +++ b/packages/misskey-reversi/src/game.ts @@ -53,9 +53,13 @@ export class Game { //#region Options this.opts = opts; + + /* eslint-disable @typescript-eslint/no-unnecessary-condition */ if (this.opts.isLlotheo == null) this.opts.isLlotheo = false; if (this.opts.canPutEverywhere == null) this.opts.canPutEverywhere = false; if (this.opts.loopedBoard == null) this.opts.loopedBoard = false; + /* eslint-enable */ + //#endregion //#region Parse map data @@ -123,12 +127,13 @@ export class Game { // ターン計算 this.turn = this.canPutSomewhere(!this.prevColor) ? !this.prevColor : - this.canPutSomewhere(this.prevColor!) ? this.prevColor : + this.canPutSomewhere(this.prevColor!) ? this.prevColor : //eslint-disable-line @typescript-eslint/no-non-null-assertion null; } public undo() { - const undo = this.logs.pop()!; + const undo = this.logs.pop(); + if (undo == null) return; this.prevColor = undo.color; this.prevPos = undo.pos; this.board[undo.pos] = null; @@ -183,7 +188,7 @@ export class Game { const found: number[] = []; // 挟めるかもしれない相手の石を入れておく配列 let [x, y] = this.posToXy(initPos); - while (true) { + while (true) { // eslint-disable-line @typescript-eslint/no-unnecessary-condition [x, y] = nextPos(x, y); // 座標が指し示す位置がボード外に出たとき