mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-05-15 16:01:07 -04:00
style: fix hasOwnProperty lint complaints
This commit is contained in:
parent
b1cc55e680
commit
8dbcc1fc8f
29 changed files with 207 additions and 180 deletions
|
@ -57,7 +57,9 @@ test('importing sb2 project with special chars in message names', t => {
|
|||
t.equal(allBroadcastFields[ltPerfectMessageId].length, 1);
|
||||
t.equal(allBroadcastFields[abMessageId].length, 1);
|
||||
const catBlocks = Object.keys(cat.blocks._blocks).map(blockId => cat.blocks._blocks[blockId]);
|
||||
const catMessageBlocks = catBlocks.filter(block => block.fields.hasOwnProperty('BROADCAST_OPTION'));
|
||||
const catMessageBlocks = catBlocks.filter(
|
||||
block => Object.prototype.hasOwnProperty.call(block.fields, 'BROADCAST_OPTION')
|
||||
);
|
||||
t.equal(catMessageBlocks.length, 2);
|
||||
t.equal(catMessageBlocks[0].fields.BROADCAST_OPTION.id, ltPerfectMessageId);
|
||||
t.equal(catMessageBlocks[1].fields.BROADCAST_OPTION.id, abMessageId);
|
||||
|
|
|
@ -57,7 +57,9 @@ test('importing sb3 project with special chars in message names', t => {
|
|||
t.equal(allBroadcastFields[ltPerfectMessageId].length, 1);
|
||||
t.equal(allBroadcastFields[abMessageId].length, 1);
|
||||
const catBlocks = Object.keys(cat.blocks._blocks).map(blockId => cat.blocks._blocks[blockId]);
|
||||
const catMessageBlocks = catBlocks.filter(block => block.fields.hasOwnProperty('BROADCAST_OPTION'));
|
||||
const catMessageBlocks = catBlocks.filter(
|
||||
block => Object.prototype.hasOwnProperty.call(block.fields, 'BROADCAST_OPTION')
|
||||
);
|
||||
t.equal(catMessageBlocks.length, 2);
|
||||
t.equal(catMessageBlocks[0].fields.BROADCAST_OPTION.id, ltPerfectMessageId);
|
||||
t.equal(catMessageBlocks[1].fields.BROADCAST_OPTION.id, abMessageId);
|
||||
|
|
|
@ -55,12 +55,12 @@ test('importing sb2 project with special chars in variable names', t => {
|
|||
// There should be 3 fields, 2 on the stage, and one on the cat
|
||||
t.equal(allVarListFields[abVarId].length, 3);
|
||||
const stageBlocks = Object.keys(stage.blocks._blocks).map(blockId => stage.blocks._blocks[blockId]);
|
||||
const stageListBlocks = stageBlocks.filter(block => block.fields.hasOwnProperty('LIST'));
|
||||
const stageListBlocks = stageBlocks.filter(block => Object.prototype.hasOwnProperty.call(block.fields, 'LIST'));
|
||||
t.equal(stageListBlocks.length, 2);
|
||||
t.equal(stageListBlocks[0].fields.LIST.id, abVarId);
|
||||
t.equal(stageListBlocks[1].fields.LIST.id, abVarId);
|
||||
const catBlocks = Object.keys(cat.blocks._blocks).map(blockId => cat.blocks._blocks[blockId]);
|
||||
const catListBlocks = catBlocks.filter(block => block.fields.hasOwnProperty('LIST'));
|
||||
const catListBlocks = catBlocks.filter(block => Object.prototype.hasOwnProperty.call(block.fields, 'LIST'));
|
||||
t.equal(catListBlocks.length, 1);
|
||||
t.equal(catListBlocks[0].fields.LIST.id, abVarId);
|
||||
|
||||
|
@ -83,10 +83,12 @@ test('importing sb2 project with special chars in variable names', t => {
|
|||
// Find all the references for this variable, and verify they have the correct ID
|
||||
// There should be only two, one on the stage and one on bananas
|
||||
t.equal(allVarListFields[fooVarId].length, 2);
|
||||
const stageVarBlocks = stageBlocks.filter(block => block.fields.hasOwnProperty('VARIABLE'));
|
||||
const stageVarBlocks = stageBlocks.filter(
|
||||
block => Object.prototype.hasOwnProperty.call(block.fields, 'VARIABLE')
|
||||
);
|
||||
t.equal(stageVarBlocks.length, 1);
|
||||
t.equal(stageVarBlocks[0].fields.VARIABLE.id, fooVarId);
|
||||
const catVarBlocks = catBlocks.filter(block => block.fields.hasOwnProperty('VARIABLE'));
|
||||
const catVarBlocks = catBlocks.filter(block => Object.prototype.hasOwnProperty.call(block.fields, 'VARIABLE'));
|
||||
t.equal(catVarBlocks.length, 1);
|
||||
t.equal(catVarBlocks[0].fields.VARIABLE.id, fooVarId);
|
||||
|
||||
|
@ -110,7 +112,9 @@ test('importing sb2 project with special chars in variable names', t => {
|
|||
// There should be one
|
||||
t.equal(allVarListFields[ltPerfectVarId].length, 1);
|
||||
const bananasBlocks = Object.keys(bananas.blocks._blocks).map(blockId => bananas.blocks._blocks[blockId]);
|
||||
const bananasVarBlocks = bananasBlocks.filter(block => block.fields.hasOwnProperty('VARIABLE'));
|
||||
const bananasVarBlocks = bananasBlocks.filter(
|
||||
block => Object.prototype.hasOwnProperty.call(block.fields, 'VARIABLE')
|
||||
);
|
||||
t.equal(bananasVarBlocks.length, 1);
|
||||
t.equal(bananasVarBlocks[0].fields.VARIABLE.id, ltPerfectVarId);
|
||||
|
||||
|
|
|
@ -55,12 +55,12 @@ test('importing sb3 project with special chars in variable names', t => {
|
|||
// There should be 3 fields, 2 on the stage, and one on the cat
|
||||
t.equal(allVarListFields[abVarId].length, 3);
|
||||
const stageBlocks = Object.keys(stage.blocks._blocks).map(blockId => stage.blocks._blocks[blockId]);
|
||||
const stageListBlocks = stageBlocks.filter(block => block.fields.hasOwnProperty('LIST'));
|
||||
const stageListBlocks = stageBlocks.filter(block => Object.prototype.hasOwnProperty.call(block.fields, 'LIST'));
|
||||
t.equal(stageListBlocks.length, 2);
|
||||
t.equal(stageListBlocks[0].fields.LIST.id, abVarId);
|
||||
t.equal(stageListBlocks[1].fields.LIST.id, abVarId);
|
||||
const catBlocks = Object.keys(cat.blocks._blocks).map(blockId => cat.blocks._blocks[blockId]);
|
||||
const catListBlocks = catBlocks.filter(block => block.fields.hasOwnProperty('LIST'));
|
||||
const catListBlocks = catBlocks.filter(block => Object.prototype.hasOwnProperty.call(block.fields, 'LIST'));
|
||||
t.equal(catListBlocks.length, 1);
|
||||
t.equal(catListBlocks[0].fields.LIST.id, abVarId);
|
||||
|
||||
|
@ -83,10 +83,14 @@ test('importing sb3 project with special chars in variable names', t => {
|
|||
// Find all the references for this variable, and verify they have the correct ID
|
||||
// There should be only two, one on the stage and one on bananas
|
||||
t.equal(allVarListFields[fooVarId].length, 2);
|
||||
const stageVarBlocks = stageBlocks.filter(block => block.fields.hasOwnProperty('VARIABLE'));
|
||||
const stageVarBlocks = stageBlocks.filter(
|
||||
block => Object.prototype.hasOwnProperty.call(block.fields, 'VARIABLE')
|
||||
);
|
||||
t.equal(stageVarBlocks.length, 1);
|
||||
t.equal(stageVarBlocks[0].fields.VARIABLE.id, fooVarId);
|
||||
const catVarBlocks = catBlocks.filter(block => block.fields.hasOwnProperty('VARIABLE'));
|
||||
const catVarBlocks = catBlocks.filter(
|
||||
block => Object.prototype.hasOwnProperty.call(block.fields, 'VARIABLE')
|
||||
);
|
||||
t.equal(catVarBlocks.length, 1);
|
||||
t.equal(catVarBlocks[0].fields.VARIABLE.id, fooVarId);
|
||||
|
||||
|
@ -110,7 +114,9 @@ test('importing sb3 project with special chars in variable names', t => {
|
|||
// There should be one
|
||||
t.equal(allVarListFields[ltPerfectVarId].length, 1);
|
||||
const bananasBlocks = Object.keys(bananas.blocks._blocks).map(blockId => bananas.blocks._blocks[blockId]);
|
||||
const bananasVarBlocks = bananasBlocks.filter(block => block.fields.hasOwnProperty('VARIABLE'));
|
||||
const bananasVarBlocks = bananasBlocks.filter(
|
||||
block => Object.prototype.hasOwnProperty.call(block.fields, 'VARIABLE')
|
||||
);
|
||||
t.equal(bananasVarBlocks.length, 1);
|
||||
t.equal(bananasVarBlocks[0].fields.VARIABLE.id, ltPerfectVarId);
|
||||
|
||||
|
|
|
@ -402,10 +402,10 @@ test('duplicateVariables duplicates all variables', t => {
|
|||
|
||||
// Should be able to find original var IDs in both this target's variables and
|
||||
// the duplicate variables since a blocks container was not specified.
|
||||
t.equal(target.variables.hasOwnProperty('var ID 1'), true);
|
||||
t.equal(target.variables.hasOwnProperty('var ID 2'), true);
|
||||
t.equal(duplicateVariables.hasOwnProperty('var ID 1'), true);
|
||||
t.equal(duplicateVariables.hasOwnProperty('var ID 1'), true);
|
||||
t.equal(Object.prototype.hasOwnProperty.call(target.variables, 'var ID 1'), true);
|
||||
t.equal(Object.prototype.hasOwnProperty.call(target.variables, 'var ID 2'), true);
|
||||
t.equal(Object.prototype.hasOwnProperty.call(duplicateVariables, 'var ID 1'), true);
|
||||
t.equal(Object.prototype.hasOwnProperty.call(duplicateVariables, 'var ID 1'), true);
|
||||
|
||||
// Values of the duplicate varaiables should match the value of the original values at the time of duplication
|
||||
t.equal(target.variables['var ID 1'].value, duplicateVariables['var ID 1'].value);
|
||||
|
|
|
@ -142,11 +142,11 @@ const testReporter = function (t, reporter) {
|
|||
t.equal(reporter.json.checkboxInFlyout, true);
|
||||
t.equal(reporter.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_ROUND);
|
||||
t.equal(reporter.json.output, 'String');
|
||||
t.notOk(reporter.json.hasOwnProperty('previousStatement'));
|
||||
t.notOk(reporter.json.hasOwnProperty('nextStatement'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(reporter.json, 'previousStatement'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(reporter.json, 'nextStatement'));
|
||||
t.same(reporter.json.extensions, ['scratch_extension']);
|
||||
t.equal(reporter.json.message0, '%1 %2simple text'); // "%1 %2" from the block icon
|
||||
t.notOk(reporter.json.hasOwnProperty('message1'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(reporter.json, 'message1'));
|
||||
t.same(reporter.json.args0, [
|
||||
// %1 in message0: the block icon
|
||||
{
|
||||
|
@ -160,7 +160,7 @@ const testReporter = function (t, reporter) {
|
|||
type: 'field_vertical_separator'
|
||||
}
|
||||
]);
|
||||
t.notOk(reporter.json.hasOwnProperty('args1'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(reporter.json, 'args1'));
|
||||
t.equal(reporter.xml, '<block type="test_reporter"></block>');
|
||||
};
|
||||
|
||||
|
@ -170,11 +170,11 @@ const testInlineImage = function (t, inlineImage) {
|
|||
t.equal(inlineImage.json.checkboxInFlyout, true);
|
||||
t.equal(inlineImage.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_ROUND);
|
||||
t.equal(inlineImage.json.output, 'String');
|
||||
t.notOk(inlineImage.json.hasOwnProperty('previousStatement'));
|
||||
t.notOk(inlineImage.json.hasOwnProperty('nextStatement'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(inlineImage.json, 'previousStatement'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(inlineImage.json, 'nextStatement'));
|
||||
t.notOk(inlineImage.json.extensions && inlineImage.json.extensions.length); // OK if it's absent or empty
|
||||
t.equal(inlineImage.json.message0, 'text and %1'); // block text followed by inline image
|
||||
t.notOk(inlineImage.json.hasOwnProperty('message1'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(inlineImage.json, 'message1'));
|
||||
t.same(inlineImage.json.args0, [
|
||||
// %1 in message0: the block icon
|
||||
{
|
||||
|
@ -185,7 +185,7 @@ const testInlineImage = function (t, inlineImage) {
|
|||
flip_rtl: false // False by default
|
||||
}
|
||||
]);
|
||||
t.notOk(inlineImage.json.hasOwnProperty('args1'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(inlineImage.json, 'args1'));
|
||||
t.equal(inlineImage.xml, '<block type="test_inlineImage"></block>');
|
||||
};
|
||||
|
||||
|
@ -198,16 +198,16 @@ const testCommand = function (t, command) {
|
|||
t.equal(command.json.type, 'test_command');
|
||||
testCategoryInfo(t, command);
|
||||
t.equal(command.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_SQUARE);
|
||||
t.assert(command.json.hasOwnProperty('previousStatement'));
|
||||
t.assert(command.json.hasOwnProperty('nextStatement'));
|
||||
t.assert(Object.prototype.hasOwnProperty.call(command.json, 'previousStatement'));
|
||||
t.assert(Object.prototype.hasOwnProperty.call(command.json, 'nextStatement'));
|
||||
t.notOk(command.json.extensions && command.json.extensions.length); // OK if it's absent or empty
|
||||
t.equal(command.json.message0, 'text with %1 %2');
|
||||
t.notOk(command.json.hasOwnProperty('message1'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(command.json, 'message1'));
|
||||
t.strictSame(command.json.args0[0], {
|
||||
type: 'input_value',
|
||||
name: 'ARG'
|
||||
});
|
||||
t.notOk(command.json.hasOwnProperty('args1'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(command.json, 'args1'));
|
||||
t.equal(command.xml,
|
||||
'<block type="test_command"><value name="ARG"><shadow type="text"></shadow></value>' +
|
||||
'<value name="ARG_WITH_DEFAULT"><shadow type="text"><field name="TEXT">' +
|
||||
|
@ -218,14 +218,14 @@ const testConditional = function (t, conditional) {
|
|||
t.equal(conditional.json.type, 'test_ifElse');
|
||||
testCategoryInfo(t, conditional);
|
||||
t.equal(conditional.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_SQUARE);
|
||||
t.ok(conditional.json.hasOwnProperty('previousStatement'));
|
||||
t.ok(conditional.json.hasOwnProperty('nextStatement'));
|
||||
t.ok(Object.prototype.hasOwnProperty.call(conditional.json, 'previousStatement'));
|
||||
t.ok(Object.prototype.hasOwnProperty.call(conditional.json, 'nextStatement'));
|
||||
t.notOk(conditional.json.extensions && conditional.json.extensions.length); // OK if it's absent or empty
|
||||
t.equal(conditional.json.message0, 'test if %1 is spiffy and if so then');
|
||||
t.equal(conditional.json.message1, '%1'); // placeholder for substack #1
|
||||
t.equal(conditional.json.message2, 'or elsewise');
|
||||
t.equal(conditional.json.message3, '%1'); // placeholder for substack #2
|
||||
t.notOk(conditional.json.hasOwnProperty('message4'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(conditional.json, 'message4'));
|
||||
t.strictSame(conditional.json.args0[0], {
|
||||
type: 'input_value',
|
||||
name: 'THING',
|
||||
|
@ -235,12 +235,12 @@ const testConditional = function (t, conditional) {
|
|||
type: 'input_statement',
|
||||
name: 'SUBSTACK'
|
||||
});
|
||||
t.notOk(conditional.json.hasOwnProperty(conditional.json.args2));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(conditional.json, conditional.json.args2));
|
||||
t.strictSame(conditional.json.args3[0], {
|
||||
type: 'input_statement',
|
||||
name: 'SUBSTACK2'
|
||||
});
|
||||
t.notOk(conditional.json.hasOwnProperty('args4'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(conditional.json, 'args4'));
|
||||
t.equal(conditional.xml, '<block type="test_ifElse"><value name="THING"></value></block>');
|
||||
};
|
||||
|
||||
|
@ -248,13 +248,13 @@ const testLoop = function (t, loop) {
|
|||
t.equal(loop.json.type, 'test_loop');
|
||||
testCategoryInfo(t, loop);
|
||||
t.equal(loop.json.outputShape, ScratchBlocksConstants.OUTPUT_SHAPE_SQUARE);
|
||||
t.ok(loop.json.hasOwnProperty('previousStatement'));
|
||||
t.notOk(loop.json.hasOwnProperty('nextStatement')); // isTerminal is set on this block
|
||||
t.ok(Object.prototype.hasOwnProperty.call(loop.json, 'previousStatement'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(loop.json, 'nextStatement')); // isTerminal is set on this block
|
||||
t.notOk(loop.json.extensions && loop.json.extensions.length); // OK if it's absent or empty
|
||||
t.equal(loop.json.message0, 'loopty %1 loops');
|
||||
t.equal(loop.json.message1, '%1'); // placeholder for substack
|
||||
t.equal(loop.json.message2, '%1'); // placeholder for loop arrow
|
||||
t.notOk(loop.json.hasOwnProperty('message3'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(loop.json, 'message3'));
|
||||
t.strictSame(loop.json.args0[0], {
|
||||
type: 'input_value',
|
||||
name: 'MANY'
|
||||
|
@ -266,7 +266,7 @@ const testLoop = function (t, loop) {
|
|||
t.equal(loop.json.lastDummyAlign2, 'RIGHT'); // move loop arrow to right side
|
||||
t.equal(loop.json.args2[0].type, 'field_image');
|
||||
t.equal(loop.json.args2[0].flip_rtl, true);
|
||||
t.notOk(loop.json.hasOwnProperty('args3'));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(loop.json, 'args3'));
|
||||
t.equal(loop.xml,
|
||||
'<block type="test_loop"><value name="MANY"><shadow type="math_number"></shadow></value></block>');
|
||||
};
|
||||
|
|
|
@ -40,7 +40,7 @@ test('blocks get new id on duplicate', t => {
|
|||
rt.blocks.createBlock(block);
|
||||
|
||||
return rt.duplicate().then(duplicate => {
|
||||
t.notOk(duplicate.blocks._blocks.hasOwnProperty(block.id));
|
||||
t.notOk(Object.prototype.hasOwnProperty.call(duplicate.blocks._blocks, block.id));
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue