Skip to content

Commit

Permalink
main: lints
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeHats committed Dec 9, 2023
1 parent 85b8004 commit a993390
Show file tree
Hide file tree
Showing 112 changed files with 406 additions and 426 deletions.
12 changes: 10 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
"plugin:react-hooks/recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module"
"sourceType": "module",
"project": true,
"tsconfigRootDir": "."
},
"rules": {
"@typescript-eslint/no-unused-vars": [
Expand All @@ -31,6 +34,11 @@
],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"no-constant-condition": ["error", { "checkLoops": false }],
"prefer-const": ["error", { "destructuring": "all" }],
"no-relative-import-paths/no-relative-import-paths": ["error"],
Expand Down
4 changes: 2 additions & 2 deletions src/bees/AnimatedSpriteStackSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ export type AnimatedSpriteStackGeometry = SchemaType<
typeof animatedSpriteStackGeometrySchema
>;

export type SpriteStackManifest = {
export interface SpriteStackManifest {
geometry: URL;
baseTexture: Promise<BaseTexture>;
resolution: number;
framesPerSecond: number;
originX: number;
originY: number;
angleOffset: number;
};
}

export class AnimatedSpriteStackSheet {
static async load(
Expand Down
4 changes: 2 additions & 2 deletions src/bees/C.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Vector2 } from "@/lib/geom/Vector2";

export type SpriteOpts = {
export interface SpriteOpts {
pixelScale?: number;
opacity?: number;
};
}

export class C {
constructor(public readonly ctx: CanvasRenderingContext2D) {}
Expand Down
4 changes: 2 additions & 2 deletions src/bees/Sprite.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { C, SpriteOpts } from "@/bees/C";
import { loadImage } from "@/lib/load";

export type SpriteManifest = {
export interface SpriteManifest {
src: URL;
scale: number;
originX: number;
originY: number;
};
}

export class Sprite {
static async load(manifest: SpriteManifest) {
Expand Down
8 changes: 4 additions & 4 deletions src/bees/SpriteStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { C, SpriteOpts } from "@/bees/C";
import { loadImage } from "@/lib/load";
import { mapRange, normalizeAngle } from "@/lib/utils";

export type SpriteStackData = {
export interface SpriteStackData {
width: number;
height: number;
frames: number;
Expand All @@ -11,17 +11,17 @@ export type SpriteStackData = {
cols: number;
regions: number[];
trims: number[];
};
}

export type SpriteStackManifest = {
export interface SpriteStackManifest {
geometry: Promise<{ default: SpriteStackData }>;
url: URL;
scale: number;
frameRate: number;
originX: number;
originY: number;
angleOffset: number;
};
}

export class SpriteStack {
static async load(manifest: SpriteStackManifest) {
Expand Down
4 changes: 2 additions & 2 deletions src/bees/TriCoord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export class TriCoord {
}

/** Returns the tris that intersect the rectangle specified in cartesian co-ordinates */
static intersectingAABB(aabb: AABB, scale = 1): Array<TriCoord> {
const results: Array<TriCoord> = [];
static intersectingAABB(aabb: AABB, scale = 1): TriCoord[] {
const results: TriCoord[] = [];

// For consistency, we treat the triangles as exclusive of their border, and the rect as inclusive
const x = aabb.origin.x / scale;
Expand Down
2 changes: 1 addition & 1 deletion src/bees/bees-main2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const application = new Application({

document.body.appendChild(application.view);

assets.loadAll().then(() => {
void assets.loadAll().then(() => {
times(20, makeBee);
});

Expand Down
2 changes: 1 addition & 1 deletion src/blob-tree/BlobTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class BlobTreeNode {

export class BlobTree {
private nodesById = new Map<string, BlobTreeNode>();
private childrenById = new Map<string, Array<string>>();
private childrenById = new Map<string, string[]>();
private parentById = new Map<string, string>();

constructor() {}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/ButtonMapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import EventEmitter, { Unsubscribe } from "@/lib/EventEmitter";
import { KeyCode } from "@/lib/KeyCode";
import { entries } from "@/lib/utils";

type ActionInfo = {
interface ActionInfo {
downEvent: EventEmitter;
upEvent: EventEmitter;
isDown: boolean;
};
}

export class ButtonMapping<Actions extends string> {
private readonly keyCodeToAction: ReadonlyMap<KeyCode, Actions>;
private readonly actionInfo: ReadonlyMap<Actions, ActionInfo>;

constructor(actionMappings: Record<Actions, Array<KeyCode>>) {
constructor(actionMappings: Record<Actions, KeyCode[]>) {
const keyCodeToAction = new Map<KeyCode, Actions>();
const actionInfo = new Map<Actions, ActionInfo>();

Expand Down
25 changes: 11 additions & 14 deletions src/lib/DebugDraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ import AABB from "@/lib/geom/AABB";
import { Line2 } from "@/lib/geom/Line2";
import { Vector2, Vector2Ish } from "@/lib/geom/Vector2";

export type StrokeOptions = {
export interface StrokeOptions {
strokeWidth?: number;
stroke?: string;
strokeCap?: "butt" | "round" | "square";
strokeDash?: number[];
strokeDashOffset?: number;
strokeJoin?: "bevel" | "round" | "miter";
};
}

export type FillOptions = {
export interface FillOptions {
fill?: string;
};
}

export type DebugOptions = {
export interface DebugOptions {
color?: string;
label?: string;
};
}

export type StrokeAndFillOptions = StrokeOptions & FillOptions;

Expand Down Expand Up @@ -291,7 +291,7 @@ export class DebugDraw {
}

public polygon(
polygon: ReadonlyArray<Vector2>,
polygon: readonly Vector2[],
options: StrokeAndFillOptions = {},
) {
this.beginPath();
Expand All @@ -302,10 +302,7 @@ export class DebugDraw {
this.strokeAndFill(options);
}

public polyLine(
points: ReadonlyArray<Vector2>,
options: StrokeOptions = {},
) {
public polyLine(points: readonly Vector2[], options: StrokeOptions = {}) {
this.beginPath();
this.moveTo(points[0]);
for (let i = 1; i < points.length; i++) {
Expand All @@ -315,7 +312,7 @@ export class DebugDraw {
}

public debugPolygon(
polygon: ReadonlyArray<Vector2>,
polygon: readonly Vector2[],
{
color = DebugDraw.DEFAULT_DEBUG_COLOR,
label = undefined,
Expand All @@ -326,7 +323,7 @@ export class DebugDraw {
}

public debugPolyLine(
polyLine: ReadonlyArray<Vector2>,
polyLine: readonly Vector2[],
{
color = DebugDraw.DEFAULT_DEBUG_COLOR,
label = undefined,
Expand Down Expand Up @@ -385,7 +382,7 @@ export class DebugDraw {
this.debugLabel(
opts.debug.label,
aabb.origin,
opts.debug.color || DebugDraw.DEFAULT_DEBUG_COLOR,
opts.debug.color ?? DebugDraw.DEFAULT_DEBUG_COLOR,
);
}
this.ctx.beginPath();
Expand Down
10 changes: 5 additions & 5 deletions src/lib/DebugDraw3d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class DebugDraw3d {
);
}

projectArray(points: ReadonlyArray<Vector3Ish>): Array<Vector2> {
projectArray(points: readonly Vector3Ish[]): Vector2[] {
return points.map((point) => this.project(point));
}

Expand Down Expand Up @@ -152,25 +152,25 @@ export class DebugDraw3d {
}

public polygon(
polygon: ReadonlyArray<Vector3Ish>,
polygon: readonly Vector3Ish[],
options?: StrokeAndFillOptions,
) {
this.dbg.polygon(this.projectArray(polygon), options);
}

public polyLine(points: ReadonlyArray<Vector3Ish>, options: StrokeOptions) {
public polyLine(points: readonly Vector3Ish[], options: StrokeOptions) {
this.dbg.polyLine(this.projectArray(points), options);
}

public debugPolygon(
polygon: ReadonlyArray<Vector3Ish>,
polygon: readonly Vector3Ish[],
options?: DebugOptions,
) {
this.dbg.debugPolygon(this.projectArray(polygon), options);
}

public debugPolyLine(
polyLine: ReadonlyArray<Vector3Ish>,
polyLine: readonly Vector3Ish[],
options?: DebugOptions,
) {
this.dbg.debugPolyLine(this.projectArray(polyLine), options);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/DebugSvg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function DebugLabel({
);
}

type DebugOptions = { color?: string; label?: string };
interface DebugOptions { color?: string; label?: string }

export function DebugSvgPath({
color,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/DragCover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

type MouseEventHandler = (event: MouseEvent) => void;

type DragCoverOptions = {
interface DragCoverOptions {
down?: MouseEventHandler;
move?: MouseEventHandler;
up?: MouseEventHandler;
debug?: boolean;
cursor?: string;
};
}

const dragCoverStyle = {
position: "fixed",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/EventEmitter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { unstable_batchedUpdates } from "react-dom";

export type Unsubscribe = () => void;

type Listener<Args extends Array<unknown>> = (...args: Args) => void;
type Listener<Args extends unknown[]> = (...args: Args) => void;

export default class EventEmitter<Args extends Array<unknown> = []> {
export default class EventEmitter<Args extends unknown[] = []> {
private handlers = new Set<Listener<Args>>();

listen(listener: Listener<Args>) {
Expand Down
Loading

0 comments on commit a993390

Please sign in to comment.