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}.`); 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); return provider[method].apply(provider, args);
} }
throw new Error(`Provider not found for service: ${service}`); 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); 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); const result = provider[method].apply(provider, args);
return Promise.resolve(result); return Promise.resolve(result);
} }

View file

@ -232,6 +232,8 @@ class BlockUtility {
this.sequencer.runtime.ioDevices[device] && this.sequencer.runtime.ioDevices[device] &&
this.sequencer.runtime.ioDevices[device][func]) { this.sequencer.runtime.ioDevices[device][func]) {
const devObject = this.sequencer.runtime.ioDevices[device]; 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); return devObject[func].apply(devObject, args);
} }
} }

View file

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

View file

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

View file

@ -10,7 +10,7 @@ const loadVector_ = function (costume, runtime, rotationCenter, optVersion) {
// scratch-svg-renderer fixes syntax that causes loading issues, // scratch-svg-renderer fixes syntax that causes loading issues,
// and if optVersion is 2, fixes "quirks" associated with Scratch 2 SVGs, // and if optVersion is 2, fixes "quirks" associated with Scratch 2 SVGs,
const fixedSvgString = serializeSvgToString(loadSvgString(svgString, true /* fromVersion2 */)); const fixedSvgString = serializeSvgToString(loadSvgString(svgString, true /* fromVersion2 */));
// If the string changed, put back into storage // If the string changed, put back into storage
if (svgString !== fixedSvgString) { if (svgString !== fixedSvgString) {
svgString = fixedSvgString; svgString = fixedSvgString;
@ -100,9 +100,13 @@ const canvasPool = (function () {
*/ */
const fetchBitmapCanvas_ = function (costume, runtime, rotationCenter) { const fetchBitmapCanvas_ = function (costume, runtime, rotationCenter) {
if (!costume || !costume.asset) { // TODO: We can probably remove this check... 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.'); return Promise.reject('Costume load failed. Assets were missing.');
} }
if (!runtime.v2BitmapAdapter) { 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.'); return Promise.reject('No V2 Bitmap adapter present.');
} }
@ -125,6 +129,8 @@ const fetchBitmapCanvas_ = function (costume, runtime, rotationCenter) {
image.onerror = null; image.onerror = null;
}; };
image.onerror = function () { 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.'); reject('Costume load failed. Asset could not be read.');
image.onload = null; image.onload = null;
image.onerror = null; image.onerror = null;
@ -194,6 +200,8 @@ const loadBitmap_ = function (costume, runtime, _rotationCenter) {
// somewhere and act on that error (like logging). // somewhere and act on that error (like logging).
// //
// Return a rejection to stop executing updateCostumeAsset. // 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.'); return Promise.reject('No V2 Bitmap adapter present.');
} }
@ -261,14 +269,14 @@ const handleCostumeLoadError = function (costume, runtime) {
const AssetType = runtime.storage.AssetType; const AssetType = runtime.storage.AssetType;
const isVector = costume.dataFormat === AssetType.ImageVector.runtimeFormat; const isVector = costume.dataFormat === AssetType.ImageVector.runtimeFormat;
// Use default asset if original fails to load // Use default asset if original fails to load
costume.assetId = isVector ? costume.assetId = isVector ?
runtime.storage.defaultAssetId.ImageVector : runtime.storage.defaultAssetId.ImageVector :
runtime.storage.defaultAssetId.ImageBitmap; runtime.storage.defaultAssetId.ImageBitmap;
costume.asset = runtime.storage.get(costume.assetId); costume.asset = runtime.storage.get(costume.assetId);
costume.md5 = `${costume.assetId}.${costume.asset.dataFormat}`; costume.md5 = `${costume.assetId}.${costume.asset.dataFormat}`;
const defaultCostumePromise = (isVector) ? const defaultCostumePromise = (isVector) ?
loadVector_(costume, runtime) : loadBitmap_(costume, runtime); loadVector_(costume, runtime) : loadBitmap_(costume, runtime);
@ -280,7 +288,7 @@ const handleCostumeLoadError = function (costume, runtime) {
// Should be null if we got here because the costume was missing // Should be null if we got here because the costume was missing
loadedCostume.broken.asset = oldAsset; loadedCostume.broken.asset = oldAsset;
loadedCostume.broken.dataFormat = oldDataFormat; loadedCostume.broken.dataFormat = oldDataFormat;
loadedCostume.broken.rotationCenterX = oldRotationX; loadedCostume.broken.rotationCenterX = oldRotationX;
loadedCostume.broken.rotationCenterY = oldRotationY; loadedCostume.broken.rotationCenterY = oldRotationY;
loadedCostume.broken.bitmapResolution = oldBitmapResolution; loadedCostume.broken.bitmapResolution = oldBitmapResolution;
@ -322,7 +330,7 @@ const loadCostumeFromAsset = function (costume, runtime, optVersion) {
.catch(error => { .catch(error => {
log.warn(`Error loading vector image: ${error}`); log.warn(`Error loading vector image: ${error}`);
return handleCostumeLoadError(costume, runtime); return handleCostumeLoadError(costume, runtime);
}); });
} }
return loadBitmap_(costume, runtime, rotationCenter, optVersion) return loadBitmap_(costume, runtime, rotationCenter, optVersion)

View file

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

View file

@ -502,6 +502,8 @@ class VirtualMachine extends EventEmitter {
const sb3 = require('./serialization/sb3'); const sb3 = require('./serialization/sb3');
return sb3.deserialize(projectJSON, runtime, zip); 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 Promise.reject('Unable to verify Scratch Project version.');
}; };
return deserializePromise() return deserializePromise()
@ -606,6 +608,8 @@ class VirtualMachine extends EventEmitter {
if (projectVersion === 3) { if (projectVersion === 3) {
return this._addSprite3(validatedInput[0], validatedInput[1]); 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.`); return Promise.reject(`${errorPrefix} Unable to verify sprite version.`);
}) })
.then(() => this.runtime.emitProjectChanged()) .then(() => this.runtime.emitProjectChanged())
@ -614,6 +618,8 @@ class VirtualMachine extends EventEmitter {
if (Object.prototype.hasOwnProperty.call(error, 'validationError')) { if (Object.prototype.hasOwnProperty.call(error, 'validationError')) {
return Promise.reject(JSON.stringify(error)); 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}`); 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 // 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(); return Promise.reject();
} }
@ -686,6 +694,8 @@ class VirtualMachine extends EventEmitter {
* @returns {?Promise} - a promise that resolves when the costume has been added * @returns {?Promise} - a promise that resolves when the costume has been added
*/ */
addCostumeFromLibrary (md5ext, costumeObject) { 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(); if (!this.editingTarget) return Promise.reject();
return this.addCostume(md5ext, costumeObject, this.editingTarget.id, 2 /* optVersion */); 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; const oldRequire = Module.prototype.require;
Module.prototype.require = function (target) { Module.prototype.require = function (target) {
if (target.indexOf('/') === -1) { 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); 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(yields, 1, 'Second call after timeElapsed does not yield');
t.equal(waitTime, mockUtil.stackFrame.duration); t.equal(waitTime, mockUtil.stackFrame.duration);
t.ok(timeElapsed >= (waitTime - thresholdSmall), 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), t.ok(timeElapsed <= (waitTime + thresholdLarge),
'Wait block ended too late: ${timeElapsed} > ${waitTime} + ${thresholdLarge}'); `Wait block ended too late: ${timeElapsed} > ${waitTime} + ${thresholdLarge}`);
t.end(); t.end();
}); });