summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorかっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>2024-09-23 21:25:23 +0900
committerGitHub <noreply@github.com>2024-09-23 21:25:23 +0900
commit7f7445ad7a4bfca020ca6c771383f206b19ff694 (patch)
tree3fe75a23e679754e7177a2cc664bcb3d9af9e97a
parentBump version to 2024.9.0-alpha.6 (diff)
downloadmisskey-7f7445ad7a4bfca020ca6c771383f206b19ff694.tar.gz
misskey-7f7445ad7a4bfca020ca6c771383f206b19ff694.tar.bz2
misskey-7f7445ad7a4bfca020ca6c771383f206b19ff694.zip
refactor(misskey-games): Misskey Games系パッケージのlint修正+Lint CI整備 (#14612)
* 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 <mail@4censord.de>
-rw-r--r--.github/workflows/lint.yml6
-rw-r--r--packages/misskey-bubble-game/build.js32
-rw-r--r--packages/misskey-bubble-game/eslint.config.js1
-rw-r--r--packages/misskey-bubble-game/src/game.ts30
-rw-r--r--packages/misskey-reversi/build.js32
-rw-r--r--packages/misskey-reversi/eslint.config.js1
-rw-r--r--packages/misskey-reversi/src/game.ts11
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);
// 座標が指し示す位置がボード外に出たとき