diff --git a/.eslintrc.cjs b/.eslintrc.cjs deleted file mode 100644 index 47298aee..00000000 --- a/.eslintrc.cjs +++ /dev/null @@ -1,76 +0,0 @@ -module.exports = { - env: { - node: true, - }, - extends: [ - 'eslint:recommended', - 'airbnb-base', - 'plugin:@typescript-eslint/recommended', - 'plugin:import/errors', - 'plugin:import/warnings', - 'plugin:import/typescript', - ], - parserOptions: { - parser: '@typescript-eslint/parser', - project: ['./tsconfig.json'] - }, - plugins: ['@typescript-eslint', 'import'], - rules: { - 'arrow-body-style': 'off', - 'class-methods-use-this': 'off', - 'no-plusplus': 'off', - 'no-useless-constructor': 'off', - 'no-restricted-syntax': 0, - 'no-shadow': 0, - 'no-use-before-define': ['error', { functions: false }], - 'no-console': 0, - 'no-param-reassign': 0, - 'no-underscore-dangle': 0, - 'consistent-return': 0, - 'no-use-before-define': 0, - camelcase: 0, - 'lines-between-class-members': ["error", "always", {exceptAfterSingleLine: true}], - 'no-void': ['error', { allowAsStatement: true }], - '@typescript-eslint/consistent-type-imports': 'error', - '@typescript-eslint/no-useless-constructor': 'warn', - '@typescript-eslint/no-var-requires': 0, - '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: "^_"}], - '@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }], - '@typescript-eslint/no-use-before-define': ['error', { functions: false }], - '@typescript-eslint/no-unsafe-declaration-merging': 0, - '@typescript-eslint/ban-ts-comment': ['error', { - 'ts-expect-error': 'allow-with-description', - 'ts-ignore': true, - 'ts-nocheck': true, - 'ts-check': false, - minimumDescriptionLength: 3, - }], - 'import/extensions': ["error", 'never'], - 'import/prefer-default-export': 0, - 'import/no-extraneous-dependencies': ['error', { devDependencies: ['**/*.test.ts', '**/*.spec.ts', '**/testUtils.ts', '**/cli/*.ts'] }], - 'import/order': ['error', { - groups: [ - 'builtin', - 'external', - 'internal', - 'parent', - 'sibling', - 'index', - ], - alphabetize: { - order: 'asc', - caseInsensitive: true, - }, - }], - 'import/namespace': ['error', { allowComputed: true }], - }, - settings: { - 'import/parsers': { - '@typescript-eslint/parser': ['.ts', '.js'], - }, - 'import/resolver': { - typescript: {}, - }, - }, - ignorePatterns: ['.eslintrc.cjs'] -}; diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4c358852..43ad61c6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,8 +13,8 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Use Bun + - uses: actions/checkout@v4 + - name: Setup Bun uses: oven-sh/setup-bun@v2 - name: bun install run: bun install diff --git a/.gitignore b/.gitignore index 3f75876f..2c811f81 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea/ node_modules/ .tg-token -.env \ No newline at end of file +.env +.DS_Store \ No newline at end of file diff --git a/biome.json b/biome.json new file mode 100644 index 00000000..03f77ffd --- /dev/null +++ b/biome.json @@ -0,0 +1,42 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "vcs": { + "enabled": false, + "clientKind": "git", + "useIgnoreFile": false + }, + "files": { + "ignoreUnknown": false, + "ignore": ["*.test.ts"] + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "indentWidth": 2 + }, + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "complexity": { + "noForEach": "off", + "noStaticOnlyClass": "off", + "noThisInStatic": "off" + }, + "suspicious": { + "noUnsafeDeclarationMerging": "off" + }, + "style": { + "noParameterAssign": "off" + } + } + }, + "javascript": { + "formatter": { + "quoteStyle": "single" + } + } +} diff --git a/bun.lockb b/bun.lockb index e63a1d19..d912d323 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 9331a63d..119bcf76 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,11 @@ "type": "module", "scripts": { "start": "NODE_ENV=production bun src/fwo.ts", - "dev": "NODE_ENV=development bun src/cli/dev.ts", + "dev": "bun src/cli/dev.ts", "test": "bun src/cli/test.ts -i", "reset-harks": "bun src/cli/resetHarks.ts", - "lint": "eslint --fix src/ --ext .js,.ts", + "lint": "biome lint", + "format": "biome format", "types": "tsc --noEmit" }, "repository": { @@ -42,16 +43,8 @@ "zod": "^3.23.8" }, "devDependencies": { + "@biomejs/biome": "1.9.4", "@types/lodash": "^4.17.10", - "@typescript-eslint/eslint-plugin": "^8.9.0", - "@typescript-eslint/parser": "^8.9.0", - "casual": "^1.6.2", - "eslint": "^8.57.1", - "eslint-config-airbnb-base": "^15.0.0", - "eslint-import-resolver-typescript": "^3.6.3", - "eslint-plugin-import": "^2.31.0", - "eslint-plugin-jest": "^28.8.3", - "execa": "^9.4.0", - "tsconfig-paths": "^4.2.0" + "casual": "^1.6.2" } } diff --git a/src/api/inventory.ts b/src/api/inventory.ts index b851d339..0e7c2ce4 100644 --- a/src/api/inventory.ts +++ b/src/api/inventory.ts @@ -1,4 +1,4 @@ -import { InventoryDocument, InventoryModel } from "@/models/inventory"; +import { type InventoryDocument, InventoryModel } from "@/models/inventory"; function dbErr(e) { throw new Error(`Fail in inventory: ${e}`); diff --git a/src/arena/CharacterService.ts b/src/arena/CharacterService.ts index e2b29d2a..9ccd6127 100644 --- a/src/arena/CharacterService.ts +++ b/src/arena/CharacterService.ts @@ -8,7 +8,7 @@ import type { HarksLvl } from '@/data/harks'; import type { Char } from '@/models/character'; import { assignWithSum } from '@/utils/assignWithSum'; import { floatNumber } from '@/utils/floatNumber'; -import { Character, CharacterClass } from '@/schemas/character'; +import type { Character, CharacterClass } from '@/schemas/character'; /** * Конструктор персонажа diff --git a/src/arena/ClanService/ClanService.ts b/src/arena/ClanService/ClanService.ts index a9d5830c..5d756baf 100644 --- a/src/arena/ClanService/ClanService.ts +++ b/src/arena/ClanService/ClanService.ts @@ -80,9 +80,7 @@ export class ClanService { if (char) { return char.leaveClan(); } - return CharacterService.getCharacterById(player.id).then((char) => - char?.leaveClan() - ); + return CharacterService.getCharacterById(player.id).then((char) => char?.leaveClan()); }); await Promise.all(promises); diff --git a/src/arena/Constuructors/AffectableAction.ts b/src/arena/Constuructors/AffectableAction.ts index cc7bb221..d5fe14be 100644 --- a/src/arena/Constuructors/AffectableAction.ts +++ b/src/arena/Constuructors/AffectableAction.ts @@ -58,7 +58,7 @@ export abstract class AffectableAction extends BaseAction { return false; } - private addAffects(affects: void | SuccessArgs | SuccessArgs[]) { + private addAffects(affects: undefined | SuccessArgs | SuccessArgs[]) { if (!affects) { return; } diff --git a/src/arena/Constuructors/MagicConstructor.ts b/src/arena/Constuructors/MagicConstructor.ts index f9c578db..2a3636ad 100644 --- a/src/arena/Constuructors/MagicConstructor.ts +++ b/src/arena/Constuructors/MagicConstructor.ts @@ -104,7 +104,7 @@ export abstract class Magic extends AffectableAction { this.status.exp = this.getEffectExp(this.status.effect || 0, this.baseExp); } - getEffectExp(effect: number, baseExp = 0) { + getEffectExp(_effect: number, baseExp = 0) { return Math.round(baseExp * this.params.initiator.proc); } @@ -138,26 +138,24 @@ export abstract class Magic extends AffectableAction { * Проверка прошла ли магия * @return */ - checkChance(): true | void { + checkChance(): true | undefined { // Если шанс > random = true if (MiscService.rndm('1d100') <= this.getChance()) { // Магия прошла, проверяем что скажут боги if (this.godCheck()) { // Боги фейлят шанс throw new CastError('GOD_FAIL'); - } else { - // Магия прошла - return true; } - } else { - // Магия провалилась, проверяем что скажут боги - if (this.godCheck()) { - // Боги помогают - return true; - } - // Магия остается фейловой - throw new CastError('CHANCE_FAIL'); + // Магия прошла + return true; + } + // Магия провалилась, проверяем что скажут боги + if (this.godCheck()) { + // Боги помогают + return true; } + // Магия остается фейловой + throw new CastError('CHANCE_FAIL'); } /** diff --git a/src/arena/Constuructors/ProtectConstructor.ts b/src/arena/Constuructors/ProtectConstructor.ts index 51ccfd58..cbeeedbf 100644 --- a/src/arena/Constuructors/ProtectConstructor.ts +++ b/src/arena/Constuructors/ProtectConstructor.ts @@ -72,7 +72,7 @@ export abstract class ProtectConstructor extends AffectableAction implements Aff }); } - preAffect: Affect['preAffect'] = ({ params, status }) => { + preAffect: Affect['preAffect'] = ({ params, status }): undefined => { this.reset(); const { initiator, target, game } = params; diff --git a/src/arena/Constuructors/interfaces/Affect.ts b/src/arena/Constuructors/interfaces/Affect.ts index 12b350b1..e56ff02c 100644 --- a/src/arena/Constuructors/interfaces/Affect.ts +++ b/src/arena/Constuructors/interfaces/Affect.ts @@ -1,7 +1,7 @@ import type { BaseActionContext } from '@/arena/Constuructors/BaseAction'; import type { SuccessArgs } from '@/arena/Constuructors/types'; -type AffectResult = SuccessArgs | SuccessArgs[] | void; +type AffectResult = SuccessArgs | SuccessArgs[] | undefined; export type AffectFn = (context: BaseActionContext) => AffectResult diff --git a/src/arena/Constuructors/utils/index.ts b/src/arena/Constuructors/utils/index.ts index e3ef2015..f0a85a8a 100644 --- a/src/arena/Constuructors/utils/index.ts +++ b/src/arena/Constuructors/utils/index.ts @@ -1,4 +1,4 @@ -import { Player } from '@/arena/PlayersService'; +import type { Player } from '@/arena/PlayersService'; import type { FailArgs, SuccessArgs } from '../types'; type Result = SuccessArgs | FailArgs; diff --git a/src/arena/GameService.ts b/src/arena/GameService.ts index a84b8600..da9902f7 100644 --- a/src/arena/GameService.ts +++ b/src/arena/GameService.ts @@ -139,7 +139,8 @@ export default class GameService { preKick(id: string, reason: KickReason): void { const player = this.players.getById(id); if (!player) { - return console.log('GC debug:: preKick', id, 'no player'); + console.log('GC debug:: preKick', id, 'no player'); + return; } player.preKick(reason); } @@ -408,29 +409,13 @@ export default class GameService { * Очистка массива длительных магий от умерших */ cleanLongMagics(): void { - /** - * Очищаем массив длительных магий для мертвецов -{ - frostTouch: [ - { - initiator: '5ea330784e5f0354f04edcec', - target: '5e05ee58bdf83c6a5ff3f8dd', - duration: 0, - round: 1, - proc: 1 - } - ] -} - */ - // eslint-disable-next-line @typescript-eslint/no-this-alias - const _this = this; _.forEach(this.longActions, (longMagicType, k) => { - _this.longActions[k] = _.filter(longMagicType, (act) => { - const p = _this.players.getById(act.target); + this.longActions[k] = _.filter(longMagicType, (act) => { + const p = this.players.getById(act.target); return p?.alive; }); }); - this.longActions = _this.longActions; + this.longActions = this.longActions; } /** diff --git a/src/arena/LogService/utils/format-action.ts b/src/arena/LogService/utils/format-action.ts index 2a07c9de..1da0d693 100644 --- a/src/arena/LogService/utils/format-action.ts +++ b/src/arena/LogService/utils/format-action.ts @@ -1,22 +1,11 @@ import type { SuccessArgs } from '@/arena/Constuructors/types'; import { getWeaponAction } from '@/arena/MiscService'; -import { floatNumber } from '@/utils/floatNumber'; export function formatAction(msgObj: SuccessArgs): string { if (msgObj.msg) { return msgObj.msg(msgObj); } - const calculateEffect = () => { - if (msgObj.expArr.length) { - return msgObj.expArr.reduce((effect, { val }) => { - return floatNumber(effect + (val || 0)); - }, msgObj.effect); - } - - return msgObj.effect; - }; - switch (msgObj.actionType) { case 'heal': return `Игрок *${msgObj.target.nick}* был вылечен 🤲 на *💖${msgObj.effect}*`; diff --git a/src/arena/MatchMakingService.ts b/src/arena/MatchMakingService.ts index e1ef51a5..5cab2da3 100644 --- a/src/arena/MatchMakingService.ts +++ b/src/arena/MatchMakingService.ts @@ -1,4 +1,4 @@ -import { EventEmitter } from 'events'; +import { EventEmitter } from 'node:events'; import _ from 'lodash'; import config from './config'; import QueueConstructor from './Constuructors/QueueConstrucror'; diff --git a/src/arena/MonsterService.js b/src/arena/MonsterService.js index cf88041f..c37ca156 100644 --- a/src/arena/MonsterService.js +++ b/src/arena/MonsterService.js @@ -6,8 +6,8 @@ */ const Monster = (data) => { - this.name = data && data.name ? data.name : this.generateName(); - this.class = data && data.class ? data.class : this.generateClass(); + this.name = data?.name ? data.name : this.generateName(); + this.class = data?.class ? data.class : this.generateClass(); }; Monster.prototype = { diff --git a/src/arena/PlayersService/PlayerWeapon.ts b/src/arena/PlayersService/PlayerWeapon.ts index 19f2e84f..562d9cef 100644 --- a/src/arena/PlayersService/PlayerWeapon.ts +++ b/src/arena/PlayersService/PlayerWeapon.ts @@ -10,7 +10,7 @@ export class PlayerWeapon { get item() { if (!this.inventory) { - return; + return undefined; } return arena.items[this.inventory.code]; diff --git a/src/arena/RoundService.ts b/src/arena/RoundService.ts index 84d005f3..5f4069e4 100644 --- a/src/arena/RoundService.ts +++ b/src/arena/RoundService.ts @@ -1,4 +1,4 @@ -import RoundEmitter from 'events'; +import RoundEmitter from 'node:events'; import config from '@/arena/config'; export enum RoundStatus { diff --git a/src/arena/StatsService.ts b/src/arena/StatsService.ts index 38086f9f..67788ccf 100644 --- a/src/arena/StatsService.ts +++ b/src/arena/StatsService.ts @@ -33,7 +33,7 @@ export default class StatsService { } private setDefaultVal(atr: keyof Stats) { - if (typeof this.inRound[atr] === undefined && !isMinMax(atr)) { + if (typeof this.inRound[atr] === 'undefined' && !isMinMax(atr)) { console.error('mode atr error', atr); this.inRound[atr] = 0; } diff --git a/src/arena/actions/attack.ts b/src/arena/actions/attack.ts index 8c2bb3c6..046381f1 100644 --- a/src/arena/actions/attack.ts +++ b/src/arena/actions/attack.ts @@ -31,7 +31,7 @@ class Attack extends PhysConstructor implements Affect { target.stats.down('hp', this.status.effect); } - preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }) => { + preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }): undefined => { if (target.flags.isHited) { throw new CastError(this.getSuccessResult({ initiator: target, target: initiator, game })); } diff --git a/src/arena/engineService.ts b/src/arena/engineService.ts index 5fc27c66..ab6b94c6 100644 --- a/src/arena/engineService.ts +++ b/src/arena/engineService.ts @@ -58,7 +58,7 @@ function runStage(ar: Stages, gameObj: Game) { /** * @param gameObj Объект игры */ -export function engine(gameObj: Game): Game | void { +export function engine(gameObj: Game): Game | undefined { try { return runStage(STAGES, gameObj); } catch (e) { diff --git a/src/arena/magics/eclipse.ts b/src/arena/magics/eclipse.ts index ffdb4d1b..f33d1203 100644 --- a/src/arena/magics/eclipse.ts +++ b/src/arena/magics/eclipse.ts @@ -31,7 +31,7 @@ class Eclipse extends CommonMagic implements Affect { game.flags.global.isEclipsed = true; } - preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }) => { + preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }): undefined => { if (game.flags.global.isEclipsed) { throw new CastError(this.getSuccessResult({ initiator: target, target: initiator, game })); } diff --git a/src/arena/magics/fireBall.ts b/src/arena/magics/fireBall.ts index 92fda2ac..0832fc3b 100644 --- a/src/arena/magics/fireBall.ts +++ b/src/arena/magics/fireBall.ts @@ -2,7 +2,7 @@ import { times } from 'lodash'; import { AoeDmgMagic } from '../Constuructors/AoeDmgMagicConstructor'; import type GameService from '../GameService'; import { dice } from '../MiscService'; -import { type Player } from '../PlayersService'; +import type { Player } from '../PlayersService'; class FireBall extends AoeDmgMagic { bounces = 4; diff --git a/src/arena/magics/glitch.ts b/src/arena/magics/glitch.ts index 7bf7400b..5e8bf6c8 100644 --- a/src/arena/magics/glitch.ts +++ b/src/arena/magics/glitch.ts @@ -29,7 +29,7 @@ class Glitch extends CommonMagic implements Affect { target.flags.isGlitched = true; } - preAffect: Affect['preAffect'] = ({ params }) => { + preAffect: Affect['preAffect'] = ({ params }): undefined => { if (params.initiator.flags.isGlitched) { params.target = params.game.players.randomAlive; } diff --git a/src/arena/magics/magicWall.ts b/src/arena/magics/magicWall.ts index 1408a83c..7dc38f37 100644 --- a/src/arena/magics/magicWall.ts +++ b/src/arena/magics/magicWall.ts @@ -57,7 +57,7 @@ class MagicWallBuff extends LongMagic { target.flags.isBehindWall.push({ initiator: initiator.id, val: this.status.effect }); } - preAffect: Affect['preAffect'] = (context) => { + preAffect: Affect['preAffect'] = (context): undefined => { const { initiator, target, game } = context.params; if (initiator.flags.isBehindWall.length) { diff --git a/src/arena/magics/paralysis.ts b/src/arena/magics/paralysis.ts index bf1e3da6..8f3dd215 100644 --- a/src/arena/magics/paralysis.ts +++ b/src/arena/magics/paralysis.ts @@ -30,7 +30,7 @@ class Paralysis extends CommonMagic implements Affect { target.flags.isParalysed = true; } - preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }) => { + preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }): undefined => { if (target.flags.isParalysed) { throw new CastError(this.getSuccessResult({ initiator: target, target: initiator, game })); } diff --git a/src/arena/magics/silence.ts b/src/arena/magics/silence.ts index d1fdfb3d..8c06f722 100644 --- a/src/arena/magics/silence.ts +++ b/src/arena/magics/silence.ts @@ -33,7 +33,7 @@ class Silence extends CommonMagic implements Affect { }); } - preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }) => { + preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }): undefined => { const { isSilenced } = initiator.flags; if (isSilenced.some((e) => e.initiator !== this.name)) { // если кастер находится под безмолвием/бунтом богов diff --git a/src/arena/magics/sleep.ts b/src/arena/magics/sleep.ts index d248a71a..cc8bc536 100644 --- a/src/arena/magics/sleep.ts +++ b/src/arena/magics/sleep.ts @@ -35,7 +35,7 @@ class Sleep extends LongMagic implements Affect { target.flags.isSleeping = true; } - preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }) => { + preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }): undefined => { if (initiator.flags.isSleeping) { throw new CastError(this.getSuccessResult({ initiator: target, target: initiator, game })); } diff --git a/src/arena/passiveSkills/staticProtect.ts b/src/arena/passiveSkills/staticProtect.ts index 44ca1339..f76c59b2 100644 --- a/src/arena/passiveSkills/staticProtect.ts +++ b/src/arena/passiveSkills/staticProtect.ts @@ -28,7 +28,7 @@ class StaticProtect extends PassiveSkillConstructor implements Affect { return Math.round((1 - Math.exp(-2 * ratio)) * 100); } - preAffect: Affect['preAffect'] = (context) => { + preAffect: Affect['preAffect'] = (context): undefined => { this.applyContext(context); const { initiator, target, game } = context.params; diff --git a/src/arena/skills/disarm.ts b/src/arena/skills/disarm.ts index b3430599..50ccf638 100644 --- a/src/arena/skills/disarm.ts +++ b/src/arena/skills/disarm.ts @@ -40,7 +40,7 @@ class Disarm extends Skill implements Affect { } } - preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }) => { + preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }): undefined => { if (initiator.flags.isDisarmed) { throw new CastError(this.getSuccessResult({ initiator: target, target: initiator, game })); } diff --git a/src/arena/skills/dodge.ts b/src/arena/skills/dodge.ts index 0457fc5d..06c2ec6a 100644 --- a/src/arena/skills/dodge.ts +++ b/src/arena/skills/dodge.ts @@ -43,7 +43,7 @@ class Dodge extends Skill implements Affect { initiator.flags.isDodging = this.effect[initiatorSkillLvl - 1] * initiator.stats.val('dex'); } - preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }) => { + preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }): undefined => { const isDodgeable = initiator.weapon.isOfType(dodgeableWeaponTypes); if (target.flags.isDodging && isDodgeable) { diff --git a/src/arena/skills/parry.ts b/src/arena/skills/parry.ts index af291d6c..161f3cbe 100644 --- a/src/arena/skills/parry.ts +++ b/src/arena/skills/parry.ts @@ -40,7 +40,7 @@ class Parry extends Skill implements Affect { initiator.flags.isParry = initiator.stats.val('dex') * effect; } - preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }) => { + preAffect: Affect['preAffect'] = ({ params: { initiator, target, game } }): undefined => { const isParryable = initiator.weapon.isOfType(parryableWeaponTypes); if (target.flags.isParry && isParryable) { diff --git a/src/cli/resetHarks.ts b/src/cli/resetHarks.ts index 4e12d1a2..5df6bdfc 100644 --- a/src/cli/resetHarks.ts +++ b/src/cli/resetHarks.ts @@ -7,12 +7,12 @@ const main = async () => { await connect(); await CharModel.bulkWrite( - times(10).map((lvl) => profsList.map((prof) => ({ + times(10).flatMap((lvl) => profsList.map((prof) => ({ updateMany: { filter: { lvl, prof }, update: { $set: { free: lvl * 10, harks: profsData[prof].hark } }, }, - }))).flat(), + }))), ); process.exit(0); diff --git a/src/fwo.ts b/src/fwo.ts index f9dd189d..2b47aa6f 100644 --- a/src/fwo.ts +++ b/src/fwo.ts @@ -1,4 +1,3 @@ -import * as http from 'http'; import type { Context, Scenes } from 'telegraf'; import { Telegraf, session, diff --git a/src/models/character.ts b/src/models/character.ts index 6f469af5..d8865bd5 100644 --- a/src/models/character.ts +++ b/src/models/character.ts @@ -1,4 +1,4 @@ -import mongoose, { Schema, Model, Types } from 'mongoose'; +import mongoose, { Schema, type Model, type Types } from 'mongoose'; import type { Profs, Harks } from '../data'; import type { Clan } from './clan'; import type { InventoryDocument } from './inventory'; diff --git a/src/models/clan.ts b/src/models/clan.ts index 3f9e0484..016cd806 100644 --- a/src/models/clan.ts +++ b/src/models/clan.ts @@ -1,4 +1,4 @@ -import mongoose, { Schema, Model, Types } from 'mongoose'; +import mongoose, { Schema, type Model, type Types } from 'mongoose'; import type { Char } from './character'; export interface Clan { diff --git a/src/models/game.ts b/src/models/game.ts index 2d67aa49..e1951b92 100644 --- a/src/models/game.ts +++ b/src/models/game.ts @@ -1,4 +1,4 @@ -import mongoose, { Schema, Model, Types } from 'mongoose'; +import mongoose, { Schema, type Model, type Types } from 'mongoose'; export interface Game { _id: Types.ObjectId diff --git a/src/models/index.ts b/src/models/index.ts index 22b1055b..2717ff41 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -1,4 +1,4 @@ -import mongoose, { ConnectOptions } from 'mongoose'; +import mongoose, { type ConnectOptions } from 'mongoose'; // MONGO - полный mongo uri: // "mongodb://user:password@db:27017/fwo?retryWrites=true&w=majority&authSource=admin diff --git a/src/models/inventory.ts b/src/models/inventory.ts index e817c90e..ba6cbe1b 100644 --- a/src/models/inventory.ts +++ b/src/models/inventory.ts @@ -1,10 +1,10 @@ import _ from "lodash"; -import mongoose, { Schema, Model, Query, Types } from "mongoose"; +import mongoose, { Schema, type Model, type Query, type Types } from "mongoose"; import arena from "../arena"; import config from "../arena/config"; -import { Collections, Profs } from "../data"; -import { CharModel, Char } from "./character"; -import { Item } from "./item"; +import { Collections, type Profs } from "../data"; +import { CharModel, type Char } from "./character"; +import type { Item } from "./item"; /** * getDefaultItem @@ -72,7 +72,7 @@ export class InventoryDocument { this: InventoryModel, charId: string, itemId: string, - ): Promise { + ): Promise { const char = await CharModel.findById(charId); _.pull(char?.inventory as unknown as string[], itemId); await char?.save(); @@ -92,7 +92,7 @@ export class InventoryDocument { static async firstCreate( this: InventoryModel, charObj: Char, - ): Promise { + ): Promise { const defItemCode = getDefaultItem(charObj.prof); if (!defItemCode) return; diff --git a/src/models/item.ts b/src/models/item.ts index aba8010d..ca2472f7 100644 --- a/src/models/item.ts +++ b/src/models/item.ts @@ -1,8 +1,8 @@ -import fs from 'fs'; +import fs from 'node:fs'; import _ from 'lodash'; -import mongoose, { Schema, Model, Types } from 'mongoose'; +import mongoose, { Schema, type Model, type Types } from 'mongoose'; import arena from '../arena'; -import config, { ParseAttr } from '../arena/config'; +import config, { type ParseAttr } from '../arena/config'; import type { Harks } from '../data'; const parseAttr = (p: string) => { diff --git a/src/scenes/create/create.ts b/src/scenes/create/create.ts index 9ff3a847..deb0b52f 100644 --- a/src/scenes/create/create.ts +++ b/src/scenes/create/create.ts @@ -21,18 +21,20 @@ async function validNickname(nickname: string) { const trimNickname = nickname.trim(); if (trimNickname.length > 16) { throw new Error('Слишком длинный. Попробуй короче'); - } else if (trimNickname.length < 3) { + } + if (trimNickname.length < 3) { throw new Error('Напрягись, ещё пару символов!'); - } else if (/[^a-zA-Zа-яА-ЯёЁ0-9-]/.test(trimNickname)) { + } + if (/[^a-zA-Zа-яА-ЯёЁ0-9-]/.test(trimNickname)) { throw new Error('Можно использовать только буквы, числа и "-"'); } const resp = await loginHelper.checkNick(trimNickname); if (resp) { throw new Error('Кто-то придумал это до тебя!'); - } else { - return trimNickname; } + + return trimNickname; } export const create = new Scenes.BaseScene('create'); diff --git a/src/scenes/createClan.ts b/src/scenes/createClan.ts index f3d622bf..754af8de 100644 --- a/src/scenes/createClan.ts +++ b/src/scenes/createClan.ts @@ -12,9 +12,11 @@ async function valid(name: string) { const trimName = name.trim(); if (trimName.length > 16) { throw new Error('Слишком длинное название. Попробуй короче'); - } else if (trimName.length < 3) { + } + if (trimName.length < 3) { throw new Error('Напрягись, ещё пару символов!'); - } else if (trimName.charAt(0) === '/') { + } + if (trimName.charAt(0) === '/') { throw new Error('Запрещено начинать клан с "/" '); } diff --git a/src/scenes/inventory.ts b/src/scenes/inventory.ts index a58e7dcc..2b629e4d 100644 --- a/src/scenes/inventory.ts +++ b/src/scenes/inventory.ts @@ -2,7 +2,7 @@ import { Scenes, Markup } from "telegraf"; import arena from "../arena"; import ItemService from "../arena/ItemService"; import type { BotContext } from "../fwo"; -import { InventoryDocument, InventoryModel } from "@/models/inventory"; +import { type InventoryDocument, InventoryModel } from "@/models/inventory"; export const inventoryScene = new Scenes.BaseScene("inventory"); diff --git a/src/scenes/shop/keyboards.ts b/src/scenes/shop/keyboards.ts index 145a45cf..2fac89ec 100644 --- a/src/scenes/shop/keyboards.ts +++ b/src/scenes/shop/keyboards.ts @@ -4,7 +4,7 @@ import type { Convenience } from 'telegraf/types'; import arena from '../../arena'; import type Char from '../../arena/CharacterService'; import { stores } from '../../arena/MiscService'; -import { Collections, Profs } from '../../data'; +import { Collections, type Profs } from '../../data'; import type { Item } from '../../models/item'; const storeKeys = Object.keys(stores); diff --git a/src/scenes/skills.ts b/src/scenes/skills.ts index 743a8251..166ea7b1 100644 --- a/src/scenes/skills.ts +++ b/src/scenes/skills.ts @@ -1,6 +1,6 @@ import { Scenes, Markup } from 'telegraf'; import ValidationError from '../arena/errors/ValidationError'; -import SkillService, { SkillsNames } from '../arena/SkillService'; +import SkillService, { type SkillsNames } from '../arena/SkillService'; import type { BotContext } from '../fwo'; export const skillsScene = new Scenes.BaseScene('skills'); diff --git a/src/server/index.ts b/src/server/index.ts index e66af19d..7583cd65 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -1,6 +1,4 @@ import { Hono } from 'hono'; -import { hc } from 'hono/client'; -import { cors } from 'hono/cors'; import { logger } from 'hono/logger'; import { character } from './character'; import { inventory } from './inventory'; diff --git a/src/utils/floatNumber.ts b/src/utils/floatNumber.ts index 9d5380c2..bc33b6c9 100644 --- a/src/utils/floatNumber.ts +++ b/src/utils/floatNumber.ts @@ -1 +1 @@ -export const floatNumber = (str: string | number): number => +parseFloat(str.toString()).toFixed(2); +export const floatNumber = (str: string | number): number => +Number.parseFloat(str.toString()).toFixed(2); diff --git a/tsconfig.json b/tsconfig.json index fe1c0ac6..89ba3829 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -77,6 +77,8 @@ /* Advanced Options */ // "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */ + "noUnusedLocals": true, + "noUnusedParameters": true }, "include": ["src"], }