Skip to content

Commit

Permalink
chore: esling upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
Zielak committed Nov 5, 2023
1 parent adb33d2 commit 5f2fcd3
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 16 deletions.
11 changes: 10 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,20 @@ module.exports = {
},
},
{
files: ["*.test.ts", "*.test.tsx"],
files: ["**/__test__/**/*.ts", "*.test.ts", "*.test.tsx"],
extends: ["plugin:jest/recommended"],
rules: {
"no-empty": "warn",
"@typescript-eslint/ban-ts-comment": "warn",
"@typescript-eslint/no-unsafe-declaration-merging": "off",
"@typescript-eslint/explicit-function-return-type": "off",
},
},
{
files: ["examples/**/*.ts"],
extends: ["plugin:jest/recommended"],
rules: {
"@typescript-eslint/explicit-function-return-type": "off",
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/HomepageFeatures/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const FeatureList: FeatureItem[] = [
},
]

function Feature({ title, Svg, description }: FeatureItem) {
function Feature({ title, Svg, description }: FeatureItem): JSX.Element {
return (
<div className={clsx("col col--6")}>
<div className="text--center">
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from "react"

import styles from "./index.module.css"

function HomepageHeader() {
function HomepageHeader(): JSX.Element {
const { siteConfig } = useDocusaurusContext()
return (
<header className={clsx("hero hero--primary", styles.heroBanner)}>
Expand Down
2 changes: 1 addition & 1 deletion examples/server-ts/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { WebSocketTransport } from "@colyseus/ws-transport"
import express from "express"

import { exitHandler } from "./exitHandler"
import WarGame from "./game/room"
import { WarGame } from "./game/room"

const { key, cert } = certs()

Expand Down
2 changes: 1 addition & 1 deletion examples/server-ts/src/game/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PickCard } from "./actions"
import { JustPlayGoal } from "./bot"
import { WarState } from "./state"

export default defineRoom<WarState>("WarGame", {
export const WarGame = defineRoom<WarState>("WarGame", {
stateConstructor: WarState,
variantDefaults: {
anteRatio: 0.5,
Expand Down
12 changes: 8 additions & 4 deletions packages/server/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { logs } from "@cardsgame/utils"
import type { Room } from "./room/base.js"
import type { State } from "./state/state.js"

export interface Command<S extends State = State> {
export interface ICommand<S extends State = State> {
execute(state: S, room: Room<S>): Promise<void>
undo(state: S, room: Room<S>): Promise<void>
}

export class Command<S extends State> {
export abstract class Command<S extends State = State> implements ICommand<S> {
/**
* @ignore
*/
Expand All @@ -29,6 +29,10 @@ export class Command<S extends State> {
this._name = name || this.constructor.name
}

execute(state: S, room: Room<S, Record<string, unknown>>): Promise<void> {
throw new Error("Method not implemented.")
}

/**
* Undoes every remembered extra sub command.
* `Command` may gather new sub commands only while executing.
Expand Down Expand Up @@ -60,8 +64,8 @@ export class Command<S extends State> {
*/
protected async subExecute(
state: S,
room: Room<any>,
command: Command
room: Room<S>,
command: Command<S>
): Promise<void> {
this._subCommands.push(command)
await command.execute(state, room)
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/conditions/allMethods.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import { State } from "../state/state.js"

import { ConditionAssertions } from "./assertions.js"
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/conditions/conditions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import { applyMixins, logs } from "@cardsgame/utils"

import type { State } from "../state/state.js"
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/entities/classicCard.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import { def } from "@cardsgame/utils"

import { canBeChild } from "../annotations/canBeChild.js"
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/entities/container.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import { def } from "@cardsgame/utils"

import { canBeChild } from "../annotations/canBeChild.js"
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/entities/deck.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import { def } from "@cardsgame/utils"
import { Schema } from "@colyseus/schema"

Expand Down
1 change: 1 addition & 0 deletions packages/server/src/entities/grid.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import { def } from "@cardsgame/utils"

import { canBeChild } from "../annotations/canBeChild.js"
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/entities/hand.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import { def } from "@cardsgame/utils"

import { canBeChild } from "../annotations/canBeChild.js"
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/entities/line.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import { def } from "@cardsgame/utils"

import { canBeChild } from "../annotations/canBeChild.js"
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/entities/pile.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import { def } from "@cardsgame/utils"

import { canBeChild } from "../annotations/canBeChild.js"
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/entities/selection.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import { def, logs } from "@cardsgame/utils"

import { canBeChild } from "../annotations/canBeChild.js"
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/entities/spread.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import { def } from "@cardsgame/utils"

import { canBeChild } from "../annotations/canBeChild.js"
Expand Down
1 change: 1 addition & 0 deletions packages/server/src/state/state.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import { ArraySchema, MapSchema } from "@colyseus/schema"

import { containsChildren } from "../annotations/containsChildren.js"
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

// eslint-disable-next-line @typescript-eslint/ban-types
interface AnyClass extends Function {
new (...args: any[]): any
}
Expand Down
8 changes: 4 additions & 4 deletions packages/utils/src/__test__/strings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ describe("trim", () => {
})

test(`returns empty string given non string value`, () => {
// @ts-ignore
// @ts-expect-error testing for invalid input
expect(trim([])).toBe("")
// @ts-ignore
// @ts-expect-error testing for invalid input
expect(trim({})).toBe("")
// @ts-ignore
// @ts-expect-error testing for invalid input
expect(trim(15)).toBe("")
// @ts-ignore
// @ts-expect-error testing for invalid input
expect(trim(function () {})).toBe("")
})
})
Expand Down
16 changes: 13 additions & 3 deletions packages/utils/src/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ if (logLevel < LogLevels.verbose) {

export const logs = logsPreExport

export interface Logs {
export interface ILogs {
error: (...any) => void
warn: (...any) => void
info: (...any) => void
Expand All @@ -239,7 +239,7 @@ type LogsOptions = {
browserStyle?: string
serverStyle?: Chalk.Chalk
}
export class Logs {
export class Logs implements ILogs {
constructor(
name: string,
private readonly enabled = false,
Expand All @@ -251,14 +251,24 @@ export class Logs {
this.setupServerLogs(name, options.serverStyle)
}
}
error: (...any: any[]) => void
warn: (...any: any[]) => void
info: (...any: any[]) => void
notice: (...any: any[]) => void
log: (...any: any[]) => void
verbose: (...any: any[]) => void
debug: (...any: any[]) => void
group: (...any: any[]) => void
groupCollapsed: (...any: any[]) => void
groupEnd: (...any: any[]) => void

setupServerLogs(name: string, style: Chalk.Chalk = Chalk.dim): void {
let indentLevel = 0
const getIndent = (): string => {
return Array(indentLevel).fill("│ ").join("")
}

const nameAndFirst = (first: string) => `${name} ${first}`
const nameAndFirst = (first: string): string => `${name} ${first}`

this["error"] =
this.enabled && logLevel >= LogLevels.error
Expand Down

0 comments on commit 5f2fcd3

Please sign in to comment.