From ba2bf7dd01636d2e12e9e6effbc9cbc794fe0280 Mon Sep 17 00:00:00 2001 From: Bertie690 Date: Thu, 24 Apr 2025 20:15:22 -0400 Subject: [PATCH] Added and enforced `no-fallthrough` --- biome.jsonc | 11 +++++++---- eslint.config.js | 17 ++++++++++------- package-lock.json | 20 +++++++++++++++++++- package.json | 3 ++- public/locales | 2 +- src/data/pokemon-species.ts | 1 + src/data/weather.ts | 1 + src/system/settings/settings.ts | 1 + src/ui-inputs.ts | 4 +++- tsconfig.json | 2 +- 10 files changed, 46 insertions(+), 16 deletions(-) diff --git a/biome.jsonc b/biome.jsonc index 9d0e6a9b5ff..caed6720d2f 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -38,6 +38,9 @@ "src/data/balance/tms.ts" ] }, + + // While it'd be nice to enable consistent sorting, this stuff screws with circular import resolution order + // TODO: Remove if we ever get down to 0 circular imports "organizeImports": { "enabled": false }, "linter": { "ignore": [ @@ -55,13 +58,13 @@ }, "style": { "noVar": "error", - "useEnumInitializers": "off", + "useEnumInitializers": "off", // have fun explicitly numbering all 1000+ species, moves, etc. lol "useBlockStatements": "error", "useConst": "error", "useImportType": "error", "noNonNullAssertion": "off", // TODO: Turn this on ASAP and fix all non-null assertions "noParameterAssign": "off", - "useExponentiationOperator": "off", + "useExponentiationOperator": "off", // Too typo-prone and easy to mixup with standard multiplication "useDefaultParameterLast": "off", // TODO: Fix spots in the codebase where this flag would be triggered, and then enable "useSingleVarDeclarator": "off", "useNodejsImportProtocol": "off", @@ -70,10 +73,10 @@ }, "suspicious": { "noDoubleEquals": "error", - "noExplicitAny": "off", + "noExplicitAny": "off", // TODO: Refactor and make this an error after save data refactored "noAssignInExpressions": "off", "noPrototypeBuiltins": "off", - "noFallthroughSwitchClause": "off", + "noFallthroughSwitchClause": "off", // Handled by ESLint due to not supporting simple "falls through" commenst "noImplicitAnyLet": "info", // TODO: Refactor and make this an error "noRedeclare": "off", // TODO: Refactor and make this an error "noGlobalIsNan": "off", diff --git a/eslint.config.js b/eslint.config.js index a97e3902411..2003082cbc1 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,9 +1,10 @@ -import tseslint from "@typescript-eslint/eslint-plugin"; +/** @ts-check */ +import tseslint from "typescript-eslint"; import stylisticTs from "@stylistic/eslint-plugin-ts"; import parser from "@typescript-eslint/parser"; import importX from "eslint-plugin-import-x"; -export default [ +export default tseslint.config( { name: "eslint-config", files: ["src/**/*.{ts,tsx,js,jsx}", "test/**/*.{ts,tsx,js,jsx}"], @@ -14,12 +15,14 @@ export default [ plugins: { "import-x": importX, "@stylistic/ts": stylisticTs, - "@typescript-eslint": tseslint, + "@typescript-eslint": tseslint.plugin, }, rules: { - "prefer-const": "error", // Enforces the use of `const` for variables that are never reassigned + // Prevent fallthrough on switch without an explicit "falls through" comment. + // Note: Move to biome if/when they add "falls through" comments + "no-fallthrough": ["error", { commentPattern: "falls through" }], "no-undef": "off", // Disables the rule that disallows the use of undeclared variables (TypeScript handles this) - "no-extra-semi": ["error"], // Disallows unnecessary semicolons for TypeScript-specific syntax + "no-extra-semi": "error", // Disallows unnecessary semicolons for TypeScript-specific syntax "import-x/extensions": ["error", "never", { json: "always" }], // Enforces no extension for imports unless json }, }, @@ -33,11 +36,11 @@ export default [ }, }, plugins: { - "@typescript-eslint": tseslint, + "@typescript-eslint": tseslint.plugin, }, rules: { "@typescript-eslint/no-floating-promises": "error", // Require Promise-like statements to be handled appropriately. - https://typescript-eslint.io/rules/no-floating-promises/ "@typescript-eslint/no-misused-promises": "error", // Disallow Promises in places not designed to handle them. - https://typescript-eslint.io/rules/no-misused-promises/ }, }, -]; +); diff --git a/package-lock.json b/package-lock.json index 07fed79969e..591e56b0ed9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,8 @@ "json-stable-stringify": "^1.2.0", "jszip": "^3.10.1", "phaser": "^3.88.2", - "phaser3-rex-plugins": "^1.80.15" + "phaser3-rex-plugins": "^1.80.15", + "save-dev": "^0.0.1-security" }, "devDependencies": { "@biomejs/biome": "1.9.4", @@ -5226,6 +5227,18 @@ "moo-color": "^1.0.2" } }, + "node_modules/jiti": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.4.2.tgz", + "integrity": "sha512-rg9zJN+G4n2nfJl5MW3BMygZX56zKPNVEYYqq7adpmMh4Jn2QNEwhvQlFy6jPVdcod7txZtKHWnyZiA3a0zP7A==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "bin": { + "jiti": "lib/jiti-cli.mjs" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -6671,6 +6684,11 @@ "dev": true, "license": "MIT" }, + "node_modules/save-dev": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/save-dev/-/save-dev-0.0.1-security.tgz", + "integrity": "sha512-k6knZTDNK8PKKbIqnvxiOveJinuw2LcQjqDoaorZWP9M5AR2EPsnpDeSbeoZZ0pHr5ze1uoaKdK8NBGQrJ34Uw==" + }, "node_modules/saxes": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", diff --git a/package.json b/package.json index 4758e6c5182..63ead765085 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,8 @@ "json-stable-stringify": "^1.2.0", "jszip": "^3.10.1", "phaser": "^3.88.2", - "phaser3-rex-plugins": "^1.80.15" + "phaser3-rex-plugins": "^1.80.15", + "save-dev": "^0.0.1-security" }, "engines": { "node": ">=22.0.0" diff --git a/public/locales b/public/locales index 18c1963ef30..e98f0eb9c20 160000 --- a/public/locales +++ b/public/locales @@ -1 +1 @@ -Subproject commit 18c1963ef309612a5a7fef76f9879709a7202189 +Subproject commit e98f0eb9c2022bc78b53f0444424c636498e725a diff --git a/src/data/pokemon-species.ts b/src/data/pokemon-species.ts index 2fff2b562c0..1ab118d8d43 100644 --- a/src/data/pokemon-species.ts +++ b/src/data/pokemon-species.ts @@ -488,6 +488,7 @@ export abstract class PokemonSpeciesForm { if (formSpriteKey.startsWith("behemoth")) { formSpriteKey = "crowned"; } + break; default: ret += `-${formSpriteKey}`; break; diff --git a/src/data/weather.ts b/src/data/weather.ts index 81559304661..be9107798df 100644 --- a/src/data/weather.ts +++ b/src/data/weather.ts @@ -369,6 +369,7 @@ export function getRandomWeatherType(arena: Arena): WeatherType { if (hasSun) { weatherPool.push({ weatherType: WeatherType.SUNNY, weight: 2 }); } + break; case Biome.VOLCANO: weatherPool = [ { diff --git a/src/system/settings/settings.ts b/src/system/settings/settings.ts index 31faf2b6283..8bbba267bd6 100644 --- a/src/system/settings/settings.ts +++ b/src/system/settings/settings.ts @@ -804,6 +804,7 @@ export function setSetting(setting: string, value: number): boolean { break; case SettingKeys.Candy_Upgrade_Display: globalScene.candyUpgradeDisplay = value; + break; case SettingKeys.Money_Format: switch (Setting[index].options[value].value) { case "Normal": diff --git a/src/ui-inputs.ts b/src/ui-inputs.ts index bf4f51e5af7..5a3871cd1f0 100644 --- a/src/ui-inputs.ts +++ b/src/ui-inputs.ts @@ -176,11 +176,13 @@ export class UiInputs { return; } switch (globalScene.ui?.getMode()) { - case UiMode.MESSAGE: + case UiMode.MESSAGE: { const messageHandler = globalScene.ui.getHandler(); if (!messageHandler.pendingPrompt || messageHandler.isTextAnimationInProgress()) { return; } + // falls through + } case UiMode.TITLE: case UiMode.COMMAND: case UiMode.MODIFIER_SELECT: diff --git a/tsconfig.json b/tsconfig.json index 30e208745b9..6af3e9ce650 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "esModuleInterop": true, "strictNullChecks": true, "sourceMap": false, - "strict": false, + "strict": false, // TODO: Enable this eventually "rootDir": ".", "baseUrl": "./src", "paths": {