Merge pull request #670 from rschamp/eslint-config-scratch-4

Update eslint and eslint-config-scratch
This commit is contained in:
Ray Schamp 2017-08-26 13:26:05 -04:00 committed by GitHub
commit f367f2d358
19 changed files with 103 additions and 110 deletions

View file

@ -31,8 +31,8 @@
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"copy-webpack-plugin": "4.0.1",
"eslint": "^3.16.0",
"eslint-config-scratch": "^3.1.0",
"eslint": "^4.5.0",
"eslint-config-scratch": "^4.0.0",
"expose-loader": "0.7.3",
"gh-pages": "^0.12.0",
"got": "5.7.1",

View file

@ -87,7 +87,7 @@ class Scratch3LooksBlocks {
* @return {Array.<!Thread>} Any threads started by this switch.
*/
_setCostumeOrBackdrop (target,
requestedCostume, optZeroIndex) {
requestedCostume, optZeroIndex) {
if (typeof requestedCostume === 'number') {
target.setCostume(optZeroIndex ?
requestedCostume : requestedCostume - 1);

View file

@ -106,22 +106,7 @@ class Scratch3MotionBlocks {
}
glide (args, util) {
if (!util.stackFrame.timer) {
// First time: save data for future use.
util.stackFrame.timer = new Timer();
util.stackFrame.timer.start();
util.stackFrame.duration = Cast.toNumber(args.SECS);
util.stackFrame.startX = util.target.x;
util.stackFrame.startY = util.target.y;
util.stackFrame.endX = Cast.toNumber(args.X);
util.stackFrame.endY = Cast.toNumber(args.Y);
if (util.stackFrame.duration <= 0) {
// Duration too short to glide.
util.target.setXY(util.stackFrame.endX, util.stackFrame.endY);
return;
}
util.yield();
} else {
if (util.stackFrame.timer) {
const timeElapsed = util.stackFrame.timer.timeElapsed();
if (timeElapsed < util.stackFrame.duration * 1000) {
// In progress: move to intermediate position.
@ -137,6 +122,21 @@ class Scratch3MotionBlocks {
// Finished: move to final position.
util.target.setXY(util.stackFrame.endX, util.stackFrame.endY);
}
} else {
// First time: save data for future use.
util.stackFrame.timer = new Timer();
util.stackFrame.timer.start();
util.stackFrame.duration = Cast.toNumber(args.SECS);
util.stackFrame.startX = util.target.x;
util.stackFrame.startY = util.target.y;
util.stackFrame.endX = Cast.toNumber(args.X);
util.stackFrame.endY = Cast.toNumber(args.Y);
if (util.stackFrame.duration <= 0) {
// Duration too short to glide.
util.target.setXY(util.stackFrame.endX, util.stackFrame.endY);
return;
}
util.yield();
}
}

View file

@ -295,7 +295,7 @@ class Scratch3PenBlocks {
penState.penAttributes.color4f[0] = rgb.r / 255.0;
penState.penAttributes.color4f[1] = rgb.g / 255.0;
penState.penAttributes.color4f[2] = rgb.b / 255.0;
if (rgb.hasOwnProperty('a')) { // Will there always be an 'a'?
if (rgb.hasOwnProperty('a')) { // Will there always be an 'a'?
penState.penAttributes.color4f[3] = rgb.a / 255.0;
} else {
penState.penAttributes.color4f[3] = 1;

View file

@ -51,20 +51,20 @@ class Scratch3SoundBlocks {
return {min: 0, max: 100};
}
/** The minimum and maximum tempo values, in bpm.
/** The minimum and maximum tempo values, in bpm.
* @type {{min: number, max: number}}
*/
static get TEMPO_RANGE () {
return {min: 20, max: 500};
}
/** The minimum and maximum values for each sound effect.
/** The minimum and maximum values for each sound effect.
* @type {{effect:{min: number, max: number}}}
*/
static get EFFECT_RANGE () {
return {
pitch: {min: -600, max: 600}, // -5 to 5 octaves
pan: {min: -100, max: 100} // 100% left to 100% right
pitch: {min: -600, max: 600}, // -5 to 5 octaves
pan: {min: -100, max: 100} // 100% left to 100% right
};
}

View file

@ -57,61 +57,61 @@ const domToBlock = function (blockDOM, blocks, isTopBlock, parent) {
// as we won't be using all of them for Scratch.
switch (xmlChild.name.toLowerCase()) {
case 'field':
{
// Add the field to this block.
const fieldName = xmlChild.attribs.name;
// Add id in case it is a variable field
const fieldId = xmlChild.attribs.id;
let fieldData = '';
if (xmlChild.children.length > 0 && xmlChild.children[0].data) {
fieldData = xmlChild.children[0].data;
} else {
// If the child of the field with a data property
// doesn't exist, set the data to an empty string.
fieldData = '';
}
block.fields[fieldName] = {
name: fieldName,
id: fieldId,
value: fieldData
};
break;
{
// Add the field to this block.
const fieldName = xmlChild.attribs.name;
// Add id in case it is a variable field
const fieldId = xmlChild.attribs.id;
let fieldData = '';
if (xmlChild.children.length > 0 && xmlChild.children[0].data) {
fieldData = xmlChild.children[0].data;
} else {
// If the child of the field with a data property
// doesn't exist, set the data to an empty string.
fieldData = '';
}
block.fields[fieldName] = {
name: fieldName,
id: fieldId,
value: fieldData
};
break;
}
case 'value':
case 'statement':
{
// Recursively generate block structure for input block.
domToBlock(childBlockNode, blocks, false, block.id);
if (childShadowNode && childBlockNode !== childShadowNode) {
// Also generate the shadow block.
domToBlock(childShadowNode, blocks, false, block.id);
}
// Link this block's input to the child block.
const inputName = xmlChild.attribs.name;
block.inputs[inputName] = {
name: inputName,
block: childBlockNode.attribs.id,
shadow: childShadowNode ? childShadowNode.attribs.id : null
};
break;
{
// Recursively generate block structure for input block.
domToBlock(childBlockNode, blocks, false, block.id);
if (childShadowNode && childBlockNode !== childShadowNode) {
// Also generate the shadow block.
domToBlock(childShadowNode, blocks, false, block.id);
}
// Link this block's input to the child block.
const inputName = xmlChild.attribs.name;
block.inputs[inputName] = {
name: inputName,
block: childBlockNode.attribs.id,
shadow: childShadowNode ? childShadowNode.attribs.id : null
};
break;
}
case 'next':
{
if (!childBlockNode || !childBlockNode.attribs) {
// Invalid child block.
continue;
}
// Recursively generate block structure for next block.
domToBlock(childBlockNode, blocks, false, block.id);
// Link next block to this block.
block.next = childBlockNode.attribs.id;
break;
{
if (!childBlockNode || !childBlockNode.attribs) {
// Invalid child block.
continue;
}
// Recursively generate block structure for next block.
domToBlock(childBlockNode, blocks, false, block.id);
// Link next block to this block.
block.next = childBlockNode.attribs.id;
break;
}
case 'mutation':
{
block.mutation = mutationAdapter(xmlChild);
break;
}
{
block.mutation = mutationAdapter(xmlChild);
break;
}
}
}
};

View file

@ -52,7 +52,7 @@ class Blocks {
return this._scripts;
}
/**
/**
* Get the next block for a particular block
* @param {?string} id ID of block to get the next block for
* @return {?string} ID of next block in the sequence
@ -458,10 +458,7 @@ class Blocks {
`<${tagName}
id="${block.id}"
type="${block.opcode}"
${block.topLevel ?
`x="${block.x}" y="${block.y}"` :
''
}
${block.topLevel ? `x="${block.x}" y="${block.y}"` : ''}
>`;
// Add any mutation. Must come before inputs.
if (block.mutation) {

View file

@ -66,8 +66,8 @@ const execute = function (sequencer, thread) {
* or after a promise resolves.
* @param {*} resolvedValue Value eventually returned from the primitive.
*/
// @todo move this to callback attached to the thread when we have performance
// metrics (dd)
// @todo move this to callback attached to the thread when we have performance
// metrics (dd)
const handleReport = function (resolvedValue) {
thread.pushReportedValue(resolvedValue);
if (isHat) {
@ -86,12 +86,10 @@ const execute = function (sequencer, thread) {
sequencer.retireThread(thread);
}
}
} else {
} else if (!resolvedValue) {
// Not an edge-activated hat: retire the thread
// if predicate was false.
if (!resolvedValue) {
sequencer.retireThread(thread);
}
sequencer.retireThread(thread);
}
} else {
// In a non-hat, report the value visually if necessary if

View file

@ -3,7 +3,7 @@
* Object representing a Scratch list.
*/
/**
/**
* @param {!string} name Name of the list.
* @param {Array} contents Contents of the list, as an array.
* @constructor

View file

@ -70,7 +70,7 @@ class Sequencer {
this.stepThread(activeThread);
activeThread.warpTimer = null;
if (activeThread.isKilled) {
i--; // if the thread is removed from the list (killed), do not increase index
i--; // if the thread is removed from the list (killed), do not increase index
}
}
if (activeThread.status === Thread.STATUS_RUNNING) {
@ -158,8 +158,8 @@ class Sequencer {
// to be re-executed.
return;
}
// Don't go to the next block for this level of the stack,
// since loops need to be re-executed.
// Don't go to the next block for this level of the stack,
// since loops need to be re-executed.
continue;
} else if (stackFrame.waitingReporter) {
@ -228,11 +228,9 @@ class Sequencer {
const doWarp = definitionBlock.mutation.warp;
if (doWarp) {
thread.peekStackFrame().warpMode = true;
} else {
} else if (isRecursive) {
// In normal-mode threads, yield any time we have a recursive call.
if (isRecursive) {
thread.status = Thread.STATUS_YIELD;
}
thread.status = Thread.STATUS_YIELD;
}
}
}

View file

@ -40,10 +40,10 @@ class Mouse {
*/
postData (data) {
if (data.x) {
this._x = data.x - data.canvasWidth / 2;
this._x = data.x - (data.canvasWidth / 2);
}
if (data.y) {
this._y = data.y - data.canvasHeight / 2;
this._y = data.y - (data.canvasHeight / 2);
}
if (typeof data.isDown !== 'undefined') {
this._isDown = data.isDown;

View file

@ -288,10 +288,10 @@ window.onload = function () {
vm.setTurboMode(turboOn);
});
document.getElementById('compatmode').addEventListener('change',
() => {
const compatibilityMode = document.getElementById('compatmode').checked;
vm.setCompatibilityMode(compatibilityMode);
});
() => {
const compatibilityMode = document.getElementById('compatmode').checked;
vm.setCompatibilityMode(compatibilityMode);
});
const tabBlockExplorer = document.getElementById('tab-blockexplorer');
const tabThreadExplorer = document.getElementById('tab-threadexplorer');
const tabRenderExplorer = document.getElementById('tab-renderexplorer');

View file

@ -60,7 +60,7 @@ const parseScratchObject = function (object, runtime) {
sprite.name = object.name;
}
if (object.hasOwnProperty('blocks')) {
for (let blockId in object.blocks) {
for (const blockId in object.blocks) {
blocks.createBlock(object.blocks[blockId]);
}
// console.log(blocks);
@ -100,7 +100,7 @@ const parseScratchObject = function (object, runtime) {
const target = sprite.createClone();
// Load target properties from JSON.
if (object.hasOwnProperty('variables')) {
for (let j in object.variables) {
for (const j in object.variables) {
const variable = object.variables[j];
const newVariable = new Variable(
variable.id,

View file

@ -95,7 +95,7 @@ class Cast {
* @return {boolean} True if the argument is all white spaces or null / empty.
*/
static isWhiteSpace (val) {
return val === null || typeof val === 'string' && val.trim().length === 0;
return val === null || (typeof val === 'string' && val.trim().length === 0);
}
/**
@ -120,7 +120,7 @@ class Cast {
const s2 = String(v2).toLowerCase();
return s1.localeCompare(s2);
}
// Compare as numbers.
// Compare as numbers.
return n1 - n2;
}

View file

@ -32,9 +32,9 @@ class StringUtil {
const index = text.indexOf(separator);
if (index >= 0) {
return [text.substring(0, index), text.substring(index + 1)];
} else {
return [text, null];
}
return [text, null];
}
}

View file

@ -16,7 +16,7 @@ test('repeat', t => {
// Test harness (mocks `util`)
let i = 0;
const repeat = 10;
var util = {
const util = {
stackFrame: Object.create(null),
startBranch: function () {
i++;
@ -38,7 +38,7 @@ test('repeatUntil', t => {
// Test harness (mocks `util`)
let i = 0;
const repeat = 10;
var util = {
const util = {
stackFrame: Object.create(null),
startBranch: function () {
i++;

View file

@ -28,8 +28,8 @@ test('multiply', t => {
test('divide', t => {
t.strictEqual(blocks.divide({NUM1: '2', NUM2: '2'}), 1);
t.strictEqual(blocks.divide({NUM1: '1', NUM2: '0'}), Infinity); // @todo
t.ok(isNaN(blocks.divide({NUM1: 'foo', NUM2: 'bar'}))); // @todo
t.strictEqual(blocks.divide({NUM1: '1', NUM2: '0'}), Infinity); // @todo
t.ok(isNaN(blocks.divide({NUM1: 'foo', NUM2: 'bar'}))); // @todo
t.end();
});

View file

@ -75,12 +75,12 @@ test('set and clear effects', t => {
const a = new RenderedTarget(s, r);
const renderer = new FakeRenderer();
a.renderer = renderer;
for (var effect in a.effects) {
for (const effect in a.effects) {
a.setEffect(effect, 1);
t.equals(a.effects[effect], 1);
}
a.clearEffects();
for (effect in a.effects) {
for (const effect in a.effects) {
t.equals(a.effects[effect], 0);
}
t.end();

View file

@ -26,7 +26,7 @@ test('time', t => {
test('start / timeElapsed', t => {
const timer = new Timer();
const delay = 100;
const threshold = 1000 / 60; // 60 hz
const threshold = 1000 / 60; // 60 hz
// Start timer
timer.start();