Skip to content

Commit

Permalink
style: fix the other lint complaints
Browse files Browse the repository at this point in the history
  • Loading branch information
cwillisf committed Dec 16, 2023
1 parent 8dbcc1f commit 7d5a780
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/dispatch/central-dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
2 changes: 2 additions & 0 deletions src/dispatch/shared-dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/engine/block-utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/engine/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
2 changes: 0 additions & 2 deletions src/extensions/scratch3_video_sensing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ class Scratch3VideoSensingBlocks {
if (stage) {
stage.videoTransparency = transparency;
}
return transparency;
}

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

/**
Expand Down
18 changes: 13 additions & 5 deletions src/import/load-costume.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const loadVector_ = function (costume, runtime, rotationCenter, optVersion) {
// scratch-svg-renderer fixes syntax that causes loading issues,
// and if optVersion is 2, fixes "quirks" associated with Scratch 2 SVGs,
const fixedSvgString = serializeSvgToString(loadSvgString(svgString, true /* fromVersion2 */));

// If the string changed, put back into storage
if (svgString !== fixedSvgString) {
svgString = fixedSvgString;
Expand Down Expand Up @@ -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.');
}

Expand All @@ -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;
Expand Down Expand Up @@ -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.');
}

Expand Down Expand Up @@ -261,14 +269,14 @@ const handleCostumeLoadError = function (costume, runtime) {

const AssetType = runtime.storage.AssetType;
const isVector = costume.dataFormat === AssetType.ImageVector.runtimeFormat;

// Use default asset if original fails to load
costume.assetId = isVector ?
runtime.storage.defaultAssetId.ImageVector :
runtime.storage.defaultAssetId.ImageBitmap;
costume.asset = runtime.storage.get(costume.assetId);
costume.md5 = `${costume.assetId}.${costume.asset.dataFormat}`;

const defaultCostumePromise = (isVector) ?
loadVector_(costume, runtime) : loadBitmap_(costume, runtime);

Expand All @@ -280,7 +288,7 @@ const handleCostumeLoadError = function (costume, runtime) {
// Should be null if we got here because the costume was missing
loadedCostume.broken.asset = oldAsset;
loadedCostume.broken.dataFormat = oldDataFormat;

loadedCostume.broken.rotationCenterX = oldRotationX;
loadedCostume.broken.rotationCenterY = oldRotationY;
loadedCostume.broken.bitmapResolution = oldBitmapResolution;
Expand Down Expand Up @@ -322,7 +330,7 @@ const loadCostumeFromAsset = function (costume, runtime, optVersion) {
.catch(error => {
log.warn(`Error loading vector image: ${error}`);
return handleCostumeLoadError(costume, runtime);

});
}
return loadBitmap_(costume, runtime, rotationCenter, optVersion)
Expand Down
2 changes: 1 addition & 1 deletion src/util/task-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
10 changes: 10 additions & 0 deletions src/virtual-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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())
Expand All @@ -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}`);
});
}
Expand Down Expand Up @@ -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();
}

Expand All @@ -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 */);
}
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/dispatch-test-worker-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions test/unit/blocks_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit 7d5a780

Please sign in to comment.