From ad1831ebfa308aab442bf2e37bad722273e8aa74 Mon Sep 17 00:00:00 2001 From: seotts Date: Mon, 9 Nov 2020 16:25:51 -0500 Subject: [PATCH 1/7] =?UTF-8?q?Don=E2=80=99t=20call=20hasOwnProperty=20dir?= =?UTF-8?q?ectly=20on=20object?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RenderWebGL.js | 10 +++++----- src/ShaderManager.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/RenderWebGL.js b/src/RenderWebGL.js index 0e9033f2a..404d815bd 100644 --- a/src/RenderWebGL.js +++ b/src/RenderWebGL.js @@ -472,7 +472,7 @@ class RenderWebGL extends EventEmitter { * @returns {int} The ID of the new Drawable. */ createDrawable (group) { - if (!group || !this._layerGroups.hasOwnProperty(group)) { + if (!group || !Object.prototype.hasOwnProperty.call(this._layerGroups, group)) { log.warn('Cannot create a drawable without a known layer group'); return; } @@ -542,7 +542,7 @@ class RenderWebGL extends EventEmitter { * @param {string} group Group name that the drawable belongs to */ destroyDrawable (drawableID, group) { - if (!group || !this._layerGroups.hasOwnProperty(group)) { + if (!group || !Object.prototype.hasOwnProperty.call(this._layerGroups, group)) { log.warn('Cannot destroy drawable without known layer group.'); return; } @@ -596,7 +596,7 @@ class RenderWebGL extends EventEmitter { * @return {?number} New order if changed, or null. */ setDrawableOrder (drawableID, order, group, optIsRelative, optMin) { - if (!group || !this._layerGroups.hasOwnProperty(group)) { + if (!group || !Object.prototype.hasOwnProperty.call(this._layerGroups, group)) { log.warn('Cannot set the order of a drawable without a known layer group.'); return; } @@ -1124,7 +1124,7 @@ class RenderWebGL extends EventEmitter { let hit = RenderConstants.ID_NONE; for (const hitID in hits) { - if (hits.hasOwnProperty(hitID) && (hits[hitID] > hits[hit])) { + if (Object.prototype.hasOwnProperty.call(hits, hitID) && (hits[hitID] > hits[hit])) { hit = hitID; } } @@ -1873,7 +1873,7 @@ class RenderWebGL extends EventEmitter { const uniforms = {}; let effectBits = drawable.enabledEffects; - effectBits &= opts.hasOwnProperty('effectMask') ? opts.effectMask : effectBits; + effectBits &= Object.prototype.hasOwnProperty.call(opts, 'effectMask') ? opts.effectMask : effectBits; const newShader = this._shaderManager.getShader(drawMode, effectBits); // Manually perform region check. Do not create functions inside a diff --git a/src/ShaderManager.js b/src/ShaderManager.js index 37c24346d..40822356a 100644 --- a/src/ShaderManager.js +++ b/src/ShaderManager.js @@ -16,7 +16,7 @@ class ShaderManager { */ this._shaderCache = {}; for (const modeName in ShaderManager.DRAW_MODE) { - if (ShaderManager.DRAW_MODE.hasOwnProperty(modeName)) { + if (Object.prototype.hasOwnProperty.call(ShaderManager.DRAW_MODE, modeName)) { this._shaderCache[modeName] = []; } } From 65fca3e3c7c11358a49baff47b56b2c973f258c5 Mon Sep 17 00:00:00 2001 From: seotts Date: Mon, 9 Nov 2020 16:35:05 -0500 Subject: [PATCH 2/7] fix lint errors in playground --- src/playground/playground.js | 10 +++++----- src/playground/queryPlayground.js | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/playground/playground.js b/src/playground/playground.js index 0b288f149..4cc8c42bb 100644 --- a/src/playground/playground.js +++ b/src/playground/playground.js @@ -37,7 +37,7 @@ image.src = 'https://cdn.assets.scratch.mit.edu/internalapi/asset/7e24c99c1b853e // SVG (cat 1-a) const xhr = new XMLHttpRequest(); -xhr.addEventListener('load', function () { +xhr.addEventListener('load', () => { const skinId = renderer.createSVGSkin(xhr.responseText); if (wantedSkin === WantedSkinType.vector) { renderer.updateDrawableProperties(drawableID2, { @@ -56,10 +56,10 @@ if (wantedSkin === WantedSkinType.pen) { }); canvas.addEventListener('click', event => { - let rect = canvas.getBoundingClientRect(); + const rect = canvas.getBoundingClientRect(); - let x = event.clientX - rect.left; - let y = event.clientY - rect.top; + const x = event.clientX - rect.left; + const y = event.clientY - rect.top; renderer.penLine(penSkinID, { color4f: [Math.random(), Math.random(), Math.random(), 1], @@ -184,7 +184,7 @@ canvas.addEventListener('mousemove', event => { canvas.addEventListener('click', event => { const mousePos = getMousePosition(event, canvas); const pickID = renderer.pick(mousePos.x, mousePos.y); - console.log('You clicked on ' + (pickID < 0 ? 'nothing' : 'ID# ' + pickID)); + console.log(`You clicked on ${(pickID < 0 ? 'nothing' : `ID#${pickID}`)}`); if (pickID >= 0) { console.dir(renderer.extractDrawable(pickID, mousePos.x, mousePos.y)); } diff --git a/src/playground/queryPlayground.js b/src/playground/queryPlayground.js index 7befdf7a1..0d124bd0a 100644 --- a/src/playground/queryPlayground.js +++ b/src/playground/queryPlayground.js @@ -92,9 +92,9 @@ renderCanvas.addEventListener('click', event => { } }); -const rgb2fillStyle = (rgb) => { - return `rgb(${rgb[0]},${rgb[1]},${rgb[2]})`; -}; +const rgb2fillStyle = rgb => ( + `rgb(${rgb[0]},${rgb[1]},${rgb[2]})` +); const makeCursorImage = () => { const canvas = document.createElement('canvas'); From 261dfb7536d476498640216213aaea99339e3e5a Mon Sep 17 00:00:00 2001 From: seotts Date: Mon, 9 Nov 2020 16:35:46 -0500 Subject: [PATCH 3/7] update eslint, babel-eslint, and eslint-config-scratch --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9947b18dd..7f7771fb8 100644 --- a/package.json +++ b/package.json @@ -25,14 +25,14 @@ }, "devDependencies": { "babel-core": "^6.23.1", - "babel-eslint": "^8.2.1", + "babel-eslint": "^10.1.0", "babel-loader": "^7.1.4", "babel-polyfill": "^6.22.0", "babel-preset-env": "^1.6.1", "copy-webpack-plugin": "^4.5.1", "docdash": "^0.4.0", - "eslint": "^4.6.1", - "eslint-config-scratch": "^5.0.0", + "eslint": "^7.13.0", + "eslint-config-scratch": "^6.1.0", "gh-pages": "^1.0.0", "jsdoc": "^3.6.0", "json": "^9.0.4", From aa704383b4849f73a7f7ca819df38e4a8a4929b0 Mon Sep 17 00:00:00 2001 From: seotts Date: Mon, 9 Nov 2020 16:41:55 -0500 Subject: [PATCH 4/7] Remove built-in global variables in comments --- test/helper/page-util.js | 2 +- test/integration/pick-tests.js | 2 +- test/integration/scratch-tests.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/helper/page-util.js b/test/helper/page-util.js index 25f5b007e..36277a7e5 100644 --- a/test/helper/page-util.js +++ b/test/helper/page-util.js @@ -1,4 +1,4 @@ -/* global window, VirtualMachine, ScratchStorage, ScratchSVGRenderer */ +/* global VirtualMachine, ScratchStorage, ScratchSVGRenderer */ /* eslint-env browser */ // Wait for all SVG skins to be loaded. diff --git a/test/integration/pick-tests.js b/test/integration/pick-tests.js index 00a2a08bd..345f035b3 100644 --- a/test/integration/pick-tests.js +++ b/test/integration/pick-tests.js @@ -1,4 +1,4 @@ -/* global vm, render, Promise */ +/* global vm, render */ const {chromium} = require('playwright-chromium'); const test = require('tap').test; const path = require('path'); diff --git a/test/integration/scratch-tests.js b/test/integration/scratch-tests.js index 57b7e07f1..3d1e7255e 100644 --- a/test/integration/scratch-tests.js +++ b/test/integration/scratch-tests.js @@ -1,4 +1,4 @@ -/* global vm, Promise */ +/* global vm */ const {chromium} = require('playwright-chromium'); const test = require('tap').test; const path = require('path'); From c855e8d143a07ff2f7a9c8cbd001c06439c4501c Mon Sep 17 00:00:00 2001 From: seotts Date: Mon, 9 Nov 2020 17:00:32 -0500 Subject: [PATCH 5/7] use eslint-scratch-config version 6.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7f7771fb8..41d2712b7 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "copy-webpack-plugin": "^4.5.1", "docdash": "^0.4.0", "eslint": "^7.13.0", - "eslint-config-scratch": "^6.1.0", + "eslint-config-scratch": "^6.0.0", "gh-pages": "^1.0.0", "jsdoc": "^3.6.0", "json": "^9.0.4", From 1e5ce914a2d2682de71a164dc0ead3cc4cfc704b Mon Sep 17 00:00:00 2001 From: seotts Date: Mon, 9 Nov 2020 17:01:02 -0500 Subject: [PATCH 6/7] replace .apply() with spread --- src/RenderWebGL.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RenderWebGL.js b/src/RenderWebGL.js index 404d815bd..81cf9d380 100644 --- a/src/RenderWebGL.js +++ b/src/RenderWebGL.js @@ -650,7 +650,7 @@ class RenderWebGL extends EventEmitter { twgl.bindFramebufferInfo(gl, null); gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); - gl.clearColor.apply(gl, this._backgroundColor4f); + gl.clearColor(...this._backgroundColor4f); gl.clear(gl.COLOR_BUFFER_BIT); this._drawThese(this._drawList, ShaderManager.DRAW_MODE.default, this._projection); @@ -1379,7 +1379,7 @@ class RenderWebGL extends EventEmitter { gl.viewport(0, 0, bounds.width, bounds.height); const projection = twgl.m4.ortho(bounds.left, bounds.right, bounds.top, bounds.bottom, -1, 1); - gl.clearColor.apply(gl, this._backgroundColor4f); + gl.clearColor(...this._backgroundColor4f); gl.clear(gl.COLOR_BUFFER_BIT); this._drawThese(this._drawList, ShaderManager.DRAW_MODE.default, projection); From 00710f33471fe5138e3023a86805d93c76d519bf Mon Sep 17 00:00:00 2001 From: Sarah Otts Date: Tue, 10 Nov 2020 09:28:26 -0500 Subject: [PATCH 7/7] Fix spacing in 'You clicked on' console log --- src/playground/playground.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/playground/playground.js b/src/playground/playground.js index 4cc8c42bb..7cac6dc56 100644 --- a/src/playground/playground.js +++ b/src/playground/playground.js @@ -184,7 +184,7 @@ canvas.addEventListener('mousemove', event => { canvas.addEventListener('click', event => { const mousePos = getMousePosition(event, canvas); const pickID = renderer.pick(mousePos.x, mousePos.y); - console.log(`You clicked on ${(pickID < 0 ? 'nothing' : `ID#${pickID}`)}`); + console.log(`You clicked on ${(pickID < 0 ? 'nothing' : `ID# ${pickID}`)}`); if (pickID >= 0) { console.dir(renderer.extractDrawable(pickID, mousePos.x, mousePos.y)); }