Skip to content

Commit

Permalink
migrate to biome
Browse files Browse the repository at this point in the history
  • Loading branch information
kyvg committed Oct 23, 2024
1 parent 5b271c1 commit 5a333bf
Show file tree
Hide file tree
Showing 50 changed files with 124 additions and 191 deletions.
76 changes: 0 additions & 76 deletions .eslintrc.cjs

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea/
node_modules/
.tg-token
.env
.env
.DS_Store
42 changes: 42 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Binary file modified bun.lockb
Binary file not shown.
17 changes: 5 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion src/api/inventory.ts
Original file line number Diff line number Diff line change
@@ -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}`);
Expand Down
2 changes: 1 addition & 1 deletion src/arena/CharacterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
* Конструктор персонажа
Expand Down
4 changes: 1 addition & 3 deletions src/arena/ClanService/ClanService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/arena/Constuructors/AffectableAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 11 additions & 13 deletions src/arena/Constuructors/MagicConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/arena/Constuructors/ProtectConstructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/arena/Constuructors/interfaces/Affect.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/arena/Constuructors/utils/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
25 changes: 5 additions & 20 deletions src/arena/GameService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

/**
Expand Down
11 changes: 0 additions & 11 deletions src/arena/LogService/utils/format-action.ts
Original file line number Diff line number Diff line change
@@ -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}*`;
Expand Down
2 changes: 1 addition & 1 deletion src/arena/MatchMakingService.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions src/arena/MonsterService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/arena/PlayersService/PlayerWeapon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class PlayerWeapon {

get item() {
if (!this.inventory) {
return;
return undefined;
}

return arena.items[this.inventory.code];
Expand Down
2 changes: 1 addition & 1 deletion src/arena/RoundService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import RoundEmitter from 'events';
import RoundEmitter from 'node:events';
import config from '@/arena/config';

export enum RoundStatus {
Expand Down
2 changes: 1 addition & 1 deletion src/arena/StatsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/arena/actions/attack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}
Expand Down
Loading

0 comments on commit 5a333bf

Please sign in to comment.