style: fix hasOwnProperty lint complaints

This commit is contained in:
Christopher Willis-Ford 2023-12-15 17:25:23 -08:00
parent b1cc55e680
commit 8dbcc1fc8f
29 changed files with 207 additions and 180 deletions
src/engine

View file

@ -231,7 +231,7 @@ class Blocks {
}
for (const id in this._blocks) {
if (!this._blocks.hasOwnProperty(id)) continue;
if (!Object.prototype.hasOwnProperty.call(this._blocks, id)) continue;
const block = this._blocks[id];
if (block.opcode === 'procedures_definition') {
const internal = this._getCustomBlockInternal(block);
@ -267,7 +267,7 @@ class Blocks {
}
for (const id in this._blocks) {
if (!this._blocks.hasOwnProperty(id)) continue;
if (!Object.prototype.hasOwnProperty.call(this._blocks, id)) continue;
const block = this._blocks[id];
if (block.opcode === 'procedures_prototype' &&
block.mutation.proccode === name) {
@ -357,7 +357,7 @@ class Blocks {
case 'delete':
// Don't accept delete events for missing blocks,
// or shadow blocks being obscured.
if (!this._blocks.hasOwnProperty(e.blockId) ||
if (!Object.prototype.hasOwnProperty.call(this._blocks, e.blockId) ||
this._blocks[e.blockId].shadow) {
return;
}
@ -397,7 +397,7 @@ class Blocks {
}
break;
case 'var_rename':
if (editingTarget && editingTarget.variables.hasOwnProperty(e.varId)) {
if (editingTarget && Object.prototype.hasOwnProperty.call(editingTarget.variables, e.varId)) {
// This is a local variable, rename on the current target
editingTarget.renameVariable(e.varId, e.newName);
// Update all the blocks on the current target that use
@ -416,7 +416,7 @@ class Blocks {
this.emitProjectChanged();
break;
case 'var_delete': {
const target = (editingTarget && editingTarget.variables.hasOwnProperty(e.varId)) ?
const target = (editingTarget && Object.prototype.hasOwnProperty.call(editingTarget.variables, e.varId)) ?
editingTarget : stage;
target.deleteVariable(e.varId);
this.emitProjectChanged();
@ -445,20 +445,21 @@ class Blocks {
case 'comment_change':
if (this.runtime.getEditingTarget()) {
const currTarget = this.runtime.getEditingTarget();
if (!currTarget.comments.hasOwnProperty(e.commentId)) {
if (!Object.prototype.hasOwnProperty.call(currTarget.comments, e.commentId)) {
log.warn(`Cannot change comment with id ${e.commentId} because it does not exist.`);
return;
}
const comment = currTarget.comments[e.commentId];
const change = e.newContents_;
if (change.hasOwnProperty('minimized')) {
if (Object.prototype.hasOwnProperty.call(change, 'minimized')) {
comment.minimized = change.minimized;
}
if (change.hasOwnProperty('width') && change.hasOwnProperty('height')){
if (Object.prototype.hasOwnProperty.call(change, 'width') &&
Object.prototype.hasOwnProperty.call(change, 'height')) {
comment.width = change.width;
comment.height = change.height;
}
if (change.hasOwnProperty('text')) {
if (Object.prototype.hasOwnProperty.call(change, 'text')) {
comment.text = change.text;
}
this.emitProjectChanged();
@ -467,7 +468,7 @@ class Blocks {
case 'comment_move':
if (this.runtime.getEditingTarget()) {
const currTarget = this.runtime.getEditingTarget();
if (currTarget && !currTarget.comments.hasOwnProperty(e.commentId)) {
if (currTarget && !Object.prototype.hasOwnProperty.call(currTarget.comments, e.commentId)) {
log.warn(`Cannot change comment with id ${e.commentId} because it does not exist.`);
return;
}
@ -482,7 +483,7 @@ class Blocks {
case 'comment_delete':
if (this.runtime.getEditingTarget()) {
const currTarget = this.runtime.getEditingTarget();
if (!currTarget.comments.hasOwnProperty(e.commentId)) {
if (!Object.prototype.hasOwnProperty.call(currTarget.comments, e.commentId)) {
// If we're in this state, we have probably received
// a delete event from a workspace that we switched from
// (e.g. a delete event for a comment on sprite a's workspace
@ -536,7 +537,7 @@ class Blocks {
createBlock (block) {
// Does the block already exist?
// Could happen, e.g., for an unobscured shadow.
if (this._blocks.hasOwnProperty(block.id)) {
if (Object.prototype.hasOwnProperty.call(this._blocks, block.id)) {
return;
}
// Create new block.
@ -650,7 +651,7 @@ class Blocks {
}
const isSpriteSpecific = isSpriteLocalVariable ||
(this.runtime.monitorBlockInfo.hasOwnProperty(block.opcode) &&
(Object.prototype.hasOwnProperty.call(this.runtime.monitorBlockInfo, block.opcode) &&
this.runtime.monitorBlockInfo[block.opcode].isSpriteSpecific);
if (isSpriteSpecific) {
// If creating a new sprite specific monitor, the only possible target is
@ -692,7 +693,7 @@ class Blocks {
* @param {!object} e Blockly move event to be processed
*/
moveBlock (e) {
if (!this._blocks.hasOwnProperty(e.id)) {
if (!Object.prototype.hasOwnProperty.call(this._blocks, e.id)) {
return;
}
@ -740,7 +741,7 @@ class Blocks {
// Moved to the new parent's input.
// Don't obscure the shadow block.
let oldShadow = null;
if (this._blocks[e.newParent].inputs.hasOwnProperty(e.newInput)) {
if (Object.prototype.hasOwnProperty.call(this._blocks[e.newParent].inputs, e.newInput)) {
oldShadow = this._blocks[e.newParent].inputs[e.newInput].shadow;
}
@ -990,7 +991,7 @@ class Blocks {
*/
_getCostumeField (blockId) {
const block = this.getBlock(blockId);
if (block && block.fields.hasOwnProperty('COSTUME')) {
if (block && Object.prototype.hasOwnProperty.call(block.fields, 'COSTUME')) {
return block.fields.COSTUME;
}
return null;
@ -1005,7 +1006,7 @@ class Blocks {
*/
_getSoundField (blockId) {
const block = this.getBlock(blockId);
if (block && block.fields.hasOwnProperty('SOUND_MENU')) {
if (block && Object.prototype.hasOwnProperty.call(block.fields, 'SOUND_MENU')) {
return block.fields.SOUND_MENU;
}
return null;
@ -1020,7 +1021,7 @@ class Blocks {
*/
_getBackdropField (blockId) {
const block = this.getBlock(blockId);
if (block && block.fields.hasOwnProperty('BACKDROP')) {
if (block && Object.prototype.hasOwnProperty.call(block.fields, 'BACKDROP')) {
return block.fields.BACKDROP;
}
return null;
@ -1042,7 +1043,7 @@ class Blocks {
'DISTANCETOMENU', 'TOUCHINGOBJECTMENU', 'CLONE_OPTION'];
for (let i = 0; i < spriteMenuNames.length; i++) {
const menuName = spriteMenuNames[i];
if (block.fields.hasOwnProperty(menuName)) {
if (Object.prototype.hasOwnProperty.call(block.fields, menuName)) {
return block.fields[menuName];
}
}
@ -1085,7 +1086,7 @@ class Blocks {
const commentId = block.comment;
if (commentId) {
if (comments) {
if (comments.hasOwnProperty(commentId)) {
if (Object.prototype.hasOwnProperty.call(comments, commentId)) {
xmlString += comments[commentId].toXML();
} else {
log.warn(`Could not find comment with id: ${commentId} in provided comment descriptions.`);
@ -1100,7 +1101,7 @@ class Blocks {
}
// Add any inputs on this block.
for (const input in block.inputs) {
if (!block.inputs.hasOwnProperty(input)) continue;
if (!Object.prototype.hasOwnProperty.call(block.inputs, input)) continue;
const blockInput = block.inputs[input];
// Only encode a value tag if the value input is occupied.
if (blockInput.block || blockInput.shadow) {
@ -1117,7 +1118,7 @@ class Blocks {
}
// Add any fields on this block.
for (const field in block.fields) {
if (!block.fields.hasOwnProperty(field)) continue;
if (!Object.prototype.hasOwnProperty.call(block.fields, field)) continue;
const blockField = block.fields[field];
xmlString += `<field name="${blockField.name}"`;
const fieldId = blockField.id;