style: fix the other lint complaints

This commit is contained in:
Christopher Willis-Ford 2023-12-15 17:40:25 -08:00
parent 8dbcc1fc8f
commit 7d5a780638
10 changed files with 36 additions and 12 deletions

View file

@ -50,6 +50,8 @@ class CentralDispatch extends SharedDispatch {
throw new Error(`Cannot use 'callSync' on remote provider for service ${service}.`);
}
// TODO: verify correct `this` after switching from apply to spread
// eslint-disable-next-line prefer-spread
return provider[method].apply(provider, args);
}
throw new Error(`Provider not found for service: ${service}`);

View file

@ -82,6 +82,8 @@ class SharedDispatch {
return this._remoteTransferCall(provider, service, method, transfer, ...args);
}
// TODO: verify correct `this` after switching from apply to spread
// eslint-disable-next-line prefer-spread
const result = provider[method].apply(provider, args);
return Promise.resolve(result);
}

View file

@ -232,6 +232,8 @@ class BlockUtility {
this.sequencer.runtime.ioDevices[device] &&
this.sequencer.runtime.ioDevices[device][func]) {
const devObject = this.sequencer.runtime.ioDevices[device];
// TODO: verify correct `this` after switching from apply to spread
// eslint-disable-next-line prefer-spread
return devObject[func].apply(devObject, args);
}
}

View file

@ -2211,9 +2211,9 @@ class Runtime extends EventEmitter {
*/
_updateGlows (optExtraThreads) {
const searchThreads = [];
searchThreads.push.apply(searchThreads, this.threads);
searchThreads.push(...this.threads);
if (optExtraThreads) {
searchThreads.push.apply(searchThreads, optExtraThreads);
searchThreads.push(...optExtraThreads);
}
// Set of scripts that request a glow this frame.
const requestedGlowsThisFrame = [];

View file

@ -167,7 +167,6 @@ class Scratch3VideoSensingBlocks {
if (stage) {
stage.videoTransparency = transparency;
}
return transparency;
}
/**
@ -191,7 +190,6 @@ class Scratch3VideoSensingBlocks {
if (stage) {
stage.videoState = state;
}
return state;
}
/**

View file

@ -100,9 +100,13 @@ const canvasPool = (function () {
*/
const fetchBitmapCanvas_ = function (costume, runtime, rotationCenter) {
if (!costume || !costume.asset) { // TODO: We can probably remove this check...
// TODO: reject with an Error (breaking API change!)
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject('Costume load failed. Assets were missing.');
}
if (!runtime.v2BitmapAdapter) {
// TODO: reject with an Error (breaking API change!)
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject('No V2 Bitmap adapter present.');
}
@ -125,6 +129,8 @@ const fetchBitmapCanvas_ = function (costume, runtime, rotationCenter) {
image.onerror = null;
};
image.onerror = function () {
// TODO: reject with an Error (breaking API change!)
// eslint-disable-next-line prefer-promise-reject-errors
reject('Costume load failed. Asset could not be read.');
image.onload = null;
image.onerror = null;
@ -194,6 +200,8 @@ const loadBitmap_ = function (costume, runtime, _rotationCenter) {
// somewhere and act on that error (like logging).
//
// Return a rejection to stop executing updateCostumeAsset.
// TODO: reject with an Error (breaking API change!)
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject('No V2 Bitmap adapter present.');
}

View file

@ -55,7 +55,7 @@ class TaskQueue {
if (this._maxTotalCost < Infinity) {
const currentTotalCost = this._pendingTaskRecords.reduce((t, r) => t + r.cost, 0);
if (currentTotalCost + cost > this._maxTotalCost) {
return Promise.reject('Maximum total cost exceeded');
return Promise.reject(new Error('Maximum total cost exceeded'));
}
}
const newRecord = {

View file

@ -502,6 +502,8 @@ class VirtualMachine extends EventEmitter {
const sb3 = require('./serialization/sb3');
return sb3.deserialize(projectJSON, runtime, zip);
}
// TODO: reject with an Error (possible breaking API change!)
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject('Unable to verify Scratch Project version.');
};
return deserializePromise()
@ -606,6 +608,8 @@ class VirtualMachine extends EventEmitter {
if (projectVersion === 3) {
return this._addSprite3(validatedInput[0], validatedInput[1]);
}
// TODO: reject with an Error (possible breaking API change!)
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject(`${errorPrefix} Unable to verify sprite version.`);
})
.then(() => this.runtime.emitProjectChanged())
@ -614,6 +618,8 @@ class VirtualMachine extends EventEmitter {
if (Object.prototype.hasOwnProperty.call(error, 'validationError')) {
return Promise.reject(JSON.stringify(error));
}
// TODO: reject with an Error (possible breaking API change!)
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject(`${errorPrefix} ${error}`);
});
}
@ -672,6 +678,8 @@ class VirtualMachine extends EventEmitter {
});
}
// If the target cannot be found by id, return a rejected promise
// TODO: reject with an Error (possible breaking API change!)
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject();
}
@ -686,6 +694,8 @@ class VirtualMachine extends EventEmitter {
* @returns {?Promise} - a promise that resolves when the costume has been added
*/
addCostumeFromLibrary (md5ext, costumeObject) {
// TODO: reject with an Error (possible breaking API change!)
// eslint-disable-next-line prefer-promise-reject-errors
if (!this.editingTarget) return Promise.reject();
return this.addCostume(md5ext, costumeObject, this.editingTarget.id, 2 /* optVersion */);
}

View file

@ -6,6 +6,8 @@ const path = require('path');
const oldRequire = Module.prototype.require;
Module.prototype.require = function (target) {
if (target.indexOf('/') === -1) {
// we really do just want to forward the arguments here
// eslint-disable-next-line prefer-rest-params
return oldRequire.apply(this, arguments);
}

View file

@ -290,8 +290,8 @@ test('wait', t => {
t.equal(yields, 1, 'Second call after timeElapsed does not yield');
t.equal(waitTime, mockUtil.stackFrame.duration);
t.ok(timeElapsed >= (waitTime - thresholdSmall),
'Wait block ended too early: ${timeElapsed} < ${waitTime} - ${thresholdSmall}');
`Wait block ended too early: ${timeElapsed} < ${waitTime} - ${thresholdSmall}`);
t.ok(timeElapsed <= (waitTime + thresholdLarge),
'Wait block ended too late: ${timeElapsed} > ${waitTime} + ${thresholdLarge}');
`Wait block ended too late: ${timeElapsed} > ${waitTime} + ${thresholdLarge}`);
t.end();
});