Skip to content

Commit

Permalink
Enable lints requiring typechecking
Browse files Browse the repository at this point in the history
  • Loading branch information
valadaptive committed Jun 18, 2024
1 parent 807f0fe commit 88c01db
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = {
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended'
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking'
],
env: {
es6: true,
Expand Down
4 changes: 2 additions & 2 deletions src/audio/audio-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export default class AudioEngine {

// In case the audio context was suspended due to a lack of user interaction
if (this.ctx.state === 'suspended') {
this.ctx.resume();
void this.ctx.resume();
}

if (this.microphoneRequestState.state === 'NotRequested') {
this.requestMicrophone();
void this.requestMicrophone();
}

if (this.microphoneRequestState.state !== 'Granted') {
Expand Down
2 changes: 1 addition & 1 deletion src/audio/decode-adpcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let __deltaTable: number[] | null = null;
const getDeltaTable = () => {
if (__deltaTable) return __deltaTable;

const deltaTable = new Array(STEP_TABLE.length * INDEX_TABLE.length);
const deltaTable = new Array<number>(STEP_TABLE.length * INDEX_TABLE.length);

for (let stepIndex = 0; stepIndex < STEP_TABLE.length; stepIndex++) {
const step = STEP_TABLE[stepIndex];
Expand Down
2 changes: 1 addition & 1 deletion src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class BlockInput<Type extends string = string, Value extends BlockInputVa
);
});
}
throw new Error(`Unhandled input type: ${valueType}`);
throw new Error(`Unhandled input type: ${String(valueType)}`);
}

validate(value: unknown): value is BlockInputValueShapeFor<Value> {
Expand Down
2 changes: 1 addition & 1 deletion src/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ export const sound_play = new ProtoBlock({
const soundName = toString(ctx.evaluateFast(SOUND_MENU));
const sound = ctx.target.sprite.getSoundByName(soundName);
if (!sound) return;
ctx.target.audio.play(sound);
void ctx.target.audio.play(sound);
},
colorCategory: 'sound',
});
Expand Down
6 changes: 5 additions & 1 deletion src/html/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,19 @@ export default function h<Tag extends keyof HTMLElementTagNameMap>(
for (const prop in props) {
if (!Object.prototype.hasOwnProperty.call(props, prop)) continue;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
const value = props[prop as keyof typeof props] as any;
if (prop.startsWith('$')) {
if (typeof value === 'function') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
element.addEventListener(prop.slice(2), value);
} else {
// eslint-disable-next-line @stylistic/max-len
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
element.addEventListener(prop.slice(2), value.listener, value.options);
}
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
element[prop as keyof HTMLElementTagNameMap[Tag]] = value;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/html/internal-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const defineInternalElement = <Elem extends HTMLElement>(constructorFn: n
customElements.define(tagName, constructorFn);
return {
tagName,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @stylistic/max-len
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument
h: ((...args: any[]) => h(tagName, ...args)) as any,
create: () => document.createElement(tagName) as Elem,
};
Expand Down
2 changes: 1 addition & 1 deletion src/html/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class InternalStageElement extends HTMLElement {
}

createMonitorView(): MonitorElement {
const elem = internalMonitor.h({className: 'monitor'}) as MonitorElement;
const elem = internalMonitor.h({className: 'monitor'});
elem.style.position = 'absolute';
this.monitorContainer.append(elem);
return elem;
Expand Down
4 changes: 2 additions & 2 deletions src/interpreter/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,12 @@ export default class Thread {

// We handle promises by parking the thread and resuming it when the promise resolves. We then pass
// the resolved value of the promise back into the generator function.
value.then(resolved => {
void value.then(resolved => {
// If the thread has been stopped or restarted, we're working with stale state and shouldn't do
// anything.
if (this.generation !== generation || this.status !== ThreadStatus.PARKED) return;
// On the next iteration of step(), this.resolvedValue will be passed back into the generator.
this.resolvedValue = resolved;
this.resolvedValue = resolved as string | number | boolean | void;
this.resume();
});
} else if (value === PARK_THREAD) {
Expand Down
2 changes: 1 addition & 1 deletion src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export abstract class Loader {

async loadAsset(filename: string, contentType: string): Promise<Blob> {
if (this.signal?.aborted) {
throw new Error(this.signal.reason ?? 'The operation was aborted');
throw new Error(this.signal.reason ? String(this.signal.reason) : 'The operation was aborted');
}
const assetKey = `${filename}_${contentType}`;
const cachedAsset = this.assetCache.get(assetKey);
Expand Down
4 changes: 2 additions & 2 deletions src/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class ListMonitor extends BaseMonitor<(string | number | boolean)[]> {
}

get value() {
return this._value as (string | number | boolean)[];
return this._value;
}

setValue(value: (string | number | boolean)[]) {
Expand Down Expand Up @@ -196,7 +196,7 @@ export const listMonitorContents = new ProtoBlock({
execute: function* ({LIST}, ctx) {
// TODO: remove this once there's some strict return type validation and blocks can return arbitrary types.
// This is fine for now because this block will never be executed outside "update monitor" threads.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return
return ctx.lookupOrCreateList(LIST.value) as any;
},
monitorLabel: ({LIST}) => LIST.value,
Expand Down
12 changes: 6 additions & 6 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,9 @@ const parseCustomBlockPrototype = (
throw new Error(`Invalid mutation: ${JSON.stringify(mutation)}`);
}

const argumentids = JSON.parse(mutation.argumentids);
const argumentnames = JSON.parse(mutation.argumentnames);
const argumentdefaults = JSON.parse(mutation.argumentdefaults);
const argumentids = JSON.parse(mutation.argumentids) as unknown;
const argumentnames = JSON.parse(mutation.argumentnames) as unknown;
const argumentdefaults = JSON.parse(mutation.argumentdefaults) as unknown;

if (!validateJson(arrayStringSchema, argumentids)) {
throw new Error(`Invalid argumentids: ${JSON.stringify(mutation.argumentids)}`);
Expand Down Expand Up @@ -586,7 +586,7 @@ const parseCustomBlockDefinition = (
allBlocks.procedures_definition as unknown as ProtoBlock,
EMPTY_MAP,
);
return Object.assign(customBlockDefinition as unknown as CustomBlockStub, {jsonBlock, blockId});
return Object.assign(customBlockDefinition as CustomBlockStub, {jsonBlock, blockId});
};

const parseScript = (
Expand Down Expand Up @@ -816,7 +816,7 @@ const parseMonitor = (
param = jsonMonitor.params[inputName];
}
if (!input.validate(param)) {
throw new Error(`Monitor input ${inputName} has invalid value ${param}`);
throw new Error(`Monitor input ${inputName} has invalid value ${String(param)}`);
}
inputValues[inputName] = param;
}
Expand Down Expand Up @@ -846,7 +846,7 @@ const parseMonitor = (
inputValues,
target,
{
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
mode: mode as any,
visible: jsonMonitor.visible,
position: jsonMonitor.x !== undefined && jsonMonitor.y !== undefined ?
Expand Down
6 changes: 4 additions & 2 deletions src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,11 @@ export default class Project extends TypedEventTarget<CreateMonitorEvent | Quest
// If variable field, check if the variable names match. Otherwise, do normal comparison. Special-casing
// this is a bit ugly, but I want to phase out VariableField and just use variable names everywhere so
// we can remove this code then.
const inputsMatch = proto .inputs[key] === VariableField ?
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const inputsMatch = proto.inputs[key] === VariableField ?
(innerBlock.inputValues[key] as BlockInputValueShapeFor<typeof VariableField>).value ===
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line @stylistic/max-len
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
(inputValues[key] as any).value :
innerBlock.inputValues[key] === inputValues[key];
if (!inputsMatch) {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/shader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export default class Shader {
this.attribLocations = {};
this.uniformLocations = {};

const numAttribs = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
const numAttribs = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES) as number;
for (let i = 0; i < numAttribs; i++) {
const activeAttrib = gl.getActiveAttrib(program, i)!;
this.attribLocations[activeAttrib.name] = gl.getAttribLocation(program, activeAttrib.name);
}

const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS) as number;
for (let i = 0; i < numUniforms; i++) {
const activeUniform = gl.getActiveUniform(program, i)!;
this.uniformLocations[activeUniform.name] = gl.getUniformLocation(program, activeUniform.name)!;
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/silhouette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default class Silhouette {

constructor(image: HTMLImageElement | ImageData, premultipliedAlpha: boolean) {
this.sampleTexel = premultipliedAlpha ?
this.sampleTexelPremultiplied :
this.sampleTexelStraight;
this.sampleTexelPremultiplied.bind(this) :
this.sampleTexelStraight.bind(this);
this.update(image);
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/svg-skin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class SVGSkin implements Skin {
this.costume = costume;
// Make sure drawToCanvas always draws something the first time it's called
this.canvas.width = this.canvas.height = 0;
this.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
this.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE) as number;
const texture = gl.createTexture();
if (!texture) {
throw new Error('Failed to create texture');
Expand Down
5 changes: 3 additions & 2 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const validateJson = <S extends Schema>(schema: S, json: unknown): json i
return false;
};

/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return */
export const validateJsonOrError = <S>(
schema: S,
json: unknown,
Expand Down Expand Up @@ -198,11 +198,12 @@ export const validateJsonOrError = <S>(
}
const obj: any = {};
for (const key of Object.keys(json)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
obj[key] = validateJsonOrError<unknown>(schema2.items, json[key as keyof typeof json], `${path}[${JSON.stringify(key)}]`);
}
return obj;
}

throw new Error(`Unhandled schema type ${(schema2 as any)}`);
};
/* eslint-enable @typescript-eslint/no-explicit-any */
/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return */

0 comments on commit 88c01db

Please sign in to comment.