From 4f5ec32d5734d55b989d1bf97a174fa57bb2a803 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Sat, 8 Jan 2022 15:46:15 +0100 Subject: [PATCH] :sparkles: (all) improve linter settings --- engine/.eslintrc.js | 10 +++++----- engine/src/engine.ts | 3 --- engine/src/map.ts | 4 ++-- engine/src/player-data.ts | 2 ++ viewer/.eslintrc.js | 13 +++++++------ viewer/src/components/Charts.vue | 1 + viewer/src/components/Game.vue | 2 +- viewer/src/data/log.ts | 19 ++++++++++--------- 8 files changed, 28 insertions(+), 26 deletions(-) diff --git a/engine/.eslintrc.js b/engine/.eslintrc.js index 0ee21a10..1697dfed 100644 --- a/engine/.eslintrc.js +++ b/engine/.eslintrc.js @@ -16,17 +16,17 @@ module.exports = { rules: { "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", - "@typescript-eslint/no-non-null-assertion": "off", - "@typescript-eslint/consistent-type-assertions": "off", + "@typescript-eslint/no-non-null-assertion": "error", + "@typescript-eslint/consistent-type-assertions": "error", "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-empty-function": "off", + "@typescript-eslint/no-empty-function": "error", "@typescript-eslint/no-unused-vars": "off", "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/no-use-before-define": "off", "@typescript-eslint/no-namespace": "off", "no-inner-declarations": "off", - "no-return-assign": "off", - "no-fallthrough": "off", + "no-return-assign": "error", + "no-fallthrough": "error", "no-invalid-this": "error", eqeqeq: ["error", "always"], }, diff --git a/engine/src/engine.ts b/engine/src/engine.ts index 5cd887ae..6763627c 100644 --- a/engine/src/engine.ts +++ b/engine/src/engine.ts @@ -299,9 +299,6 @@ export default class Engine { } this.sanitizeOptions(); this.loadMoves(moves); - if (replay) { - this.options = options; // is this necessary? - } } /** Fix old options passed. To remove when legacy data is no more in database */ diff --git a/engine/src/map.ts b/engine/src/map.ts index 29dfb6b6..83555385 100644 --- a/engine/src/map.ts +++ b/engine/src/map.ts @@ -357,10 +357,10 @@ export default class SpaceMap { const relative = CubeCoordinates.parse(reverseSuffixes[suffix]); - let center = this.placement!.sectors!.find((conf) => conf.sector.replace(/[AB]/, "") === sector).center!; + let center = this.placement.sectors.find((conf) => conf.sector.replace(/[AB]/, "") === sector).center; if (!center) { - const index = this.placement!.sectors!.findIndex((conf) => conf.sector.replace(/[AB]/, "") === sector); + const index = this.placement.sectors.findIndex((conf) => conf.sector.replace(/[AB]/, "") === sector); center = (this.placement.sectors.length === 7 ? smallCenters : bigCenters)[index]; } diff --git a/engine/src/player-data.ts b/engine/src/player-data.ts index 5f83c710..3477202c 100644 --- a/engine/src/player-data.ts +++ b/engine/src/player-data.ts @@ -486,8 +486,10 @@ export default class PlayerData extends EventEmitter { switch (area) { case PowerArea.Area3: power += this.power.area3; + // eslint-disable-next-line no-fallthrough case PowerArea.Area2: power += this.power.area2; + // eslint-disable-next-line no-fallthrough case PowerArea.Area1: power += this.power.area1; } diff --git a/viewer/.eslintrc.js b/viewer/.eslintrc.js index 56f68310..6a78e66c 100644 --- a/viewer/.eslintrc.js +++ b/viewer/.eslintrc.js @@ -11,15 +11,16 @@ module.exports = { "no-console": process.env.NODE_ENV === "production" ? "warn" : "off", "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off", semi: ["error", "always"], - "@typescript-eslint/no-non-null-assertion": "off", - "@typescript-eslint/consistent-type-assertions": "off", + "@typescript-eslint/no-non-null-assertion": "error", + "@typescript-eslint/consistent-type-assertions": "error", "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-empty-function": "off", "@typescript-eslint/no-unused-vars": "off", - "no-return-assign": "off", - "no-lone-blocks": "off", - "no-unmodified-loop-condition": "off", - "no-useless-return": "off", + "no-return-assign": "error", + "no-lone-blocks": "error", + "no-unmodified-loop-condition": "error", + "no-useless-return": "error", + "no-invalid-this": "error", quotes: "off", }, }; diff --git a/viewer/src/components/Charts.vue b/viewer/src/components/Charts.vue index b77ff754..9b656205 100644 --- a/viewer/src/components/Charts.vue +++ b/viewer/src/components/Charts.vue @@ -94,6 +94,7 @@ type Table = { title: string; header: any[]; items: any[] }; components: { PlayerCircle, BuildingImage, SpecialAction }, }) export default class Charts extends Vue { + // eslint-disable-next-line no-invalid-this private chartStyle: ChartStyleDisplay = this.chartStyles[0]; private chartFamily: ChartFamily = vpChartFamily; private chartKind: ChartKind = barChartKind; diff --git a/viewer/src/components/Game.vue b/viewer/src/components/Game.vue index 618280b6..2b3ca941 100644 --- a/viewer/src/components/Game.vue +++ b/viewer/src/components/Game.vue @@ -155,7 +155,7 @@ import { orderedPlayers } from "../data/player"; } this.handleData(Engine.fromData(JSON.parse(JSON.stringify(this.engine)))); - return; + } }); diff --git a/viewer/src/data/log.ts b/viewer/src/data/log.ts index c5c80076..7ec86e6b 100644 --- a/viewer/src/data/log.ts +++ b/viewer/src/data/log.ts @@ -198,15 +198,16 @@ export function makeHistory( const bumpLog = () => { advancedLogIndex += 1; - nextLogEntry = advancedLog[advancedLogIndex]; + const entry = advancedLog[advancedLogIndex]; if (advancedLogIndex == 0) { ret.push(makeEntry(data, state, recent.index > 0 && onlyRecent ? "moves-skipped" : Phase.SetupInit)); - } else if (nextLogEntry?.round) { - state.round = nextLogEntry.round; + } else if (entry?.round) { + state.round = entry.round; newPhase(Phase.RoundStart, 0); - } else if (nextLogEntry?.phase) { - newPhase(nextLogEntry?.phase, state.turn); + } else if (entry?.phase) { + newPhase(entry?.phase, state.turn); } + return entry; }; const newEntry = (move: ParsedMove = null, entry: LogEntry = nextLogEntry): HistoryEntry => { @@ -214,7 +215,7 @@ export function makeHistory( return makeEntry(data, state, newPhase, move, entry.player, entry.changes); }; - bumpLog(); + nextLogEntry = bumpLog(); recent.allMoves.forEach((parsedMove, i) => { if (onlyRecent && i == recent.index) { @@ -233,19 +234,19 @@ export function makeHistory( if (nextLogEntry.player === undefined || !!nextLogEntry.changes) { addEntry(newEntry()); } - bumpLog(); + nextLogEntry = bumpLog(); } const entry = newEntry(replaceMove(data, parsedMove), {} as LogEntry); if (nextLogEntry && nextLogEntry.move === i) { entry.changes = makeChanges(data, nextLogEntry.changes); - bumpLog(); + nextLogEntry = bumpLog(); } addEntry(entry); while (nextLogEntry && nextLogEntry.move === undefined) { if (nextLogEntry.player === undefined || !!nextLogEntry.changes) { addEntry(newEntry()); } - bumpLog(); + nextLogEntry = bumpLog(); } });