From f14a1c8034eb0e5e16ae89951841090110a4a532 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 8 Nov 2021 16:41:52 -0800 Subject: [PATCH] chore: fix more lint (#5676) * chore: fix assorted lint * chore: clang-format * chore: clang-format --- blocks/logic.js | 1 - blocks/procedures.js | 1 - blocks/text.js | 5 +- blocks/variables.js | 8 +-- blocks/variables_dynamic.js | 8 +-- core/block.js | 3 +- core/block_svg.js | 7 +-- core/connection.js | 4 +- core/connection_checker.js | 3 +- core/css.js | 2 +- core/dropdowndiv.js | 5 +- core/extensions.js | 2 +- core/field.js | 4 +- core/field_multilineinput.js | 6 +- core/insertion_marker_manager.js | 5 +- core/interfaces/i_registrable_field.js | 2 +- core/keyboard_nav/ast_node.js | 3 +- core/mutator.js | 3 +- core/procedures.js | 7 +++ core/rendered_connection.js | 2 +- core/renderers/common/constants.js | 26 ++++++--- core/renderers/common/marker_svg.js | 4 +- core/renderers/zelos/constants.js | 76 ++++++++++++++++++-------- core/serialization/workspaces.js | 6 +- core/theme/classic.js | 4 +- core/theme/zelos.js | 4 +- core/utils.js | 2 +- core/variable_map.js | 12 ++-- core/variables_dynamic.js | 18 +++--- tests/playgrounds/screenshot.js | 11 ++-- 30 files changed, 146 insertions(+), 98 deletions(-) diff --git a/blocks/logic.js b/blocks/logic.js index 191e4db94..d8e8955c4 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -515,7 +515,6 @@ Blockly.Extensions.registerMutator('controls_if_mutator', * @package */ Blockly.Constants.Logic.CONTROLS_IF_TOOLTIP_EXTENSION = function() { - this.setTooltip(function() { if (!this.elseifCount_ && !this.elseCount_) { return Blockly.Msg['CONTROLS_IF_TOOLTIP_1']; diff --git a/blocks/procedures.js b/blocks/procedures.js index fbe939a0c..b7fcae229 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -75,7 +75,6 @@ Blockly.Blocks['procedures_defnoreturn'] = { * @this {Blockly.Block} */ updateParams_: function() { - // Merge the arguments into a human-readable list. let paramString = ''; if (this.arguments_.length) { diff --git a/blocks/text.js b/blocks/text.js index ca2bc991a..da5e5f68b 100644 --- a/blocks/text.js +++ b/blocks/text.js @@ -63,7 +63,8 @@ Blockly.defineBlocksWithJsonArray([ "width": 12, "height": 17, "alt": '\u00B6', - },{ + }, + { "type": "field_multilinetext", "name": "TEXT", "text": "", @@ -200,7 +201,7 @@ Blockly.defineBlocksWithJsonArray([ "message0": "%{BKY_TEXT_CHARAT_TITLE}", // "in text %1 %2" "args0": [ { - "type":"input_value", + "type": "input_value", "name": "VALUE", "check": "String", }, diff --git a/blocks/variables.js b/blocks/variables.js index e5846b881..92a9b7915 100644 --- a/blocks/variables.js +++ b/blocks/variables.js @@ -82,14 +82,14 @@ Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN = { */ customContextMenu: function(options) { if (!this.isInFlyout) { - let opposite_type; + let oppositeType; let contextMenuMsg; // Getter blocks have the option to create a setter block, and vice versa. if (this.type === 'variables_get') { - opposite_type = 'variables_set'; + oppositeType = 'variables_set'; contextMenuMsg = Blockly.Msg['VARIABLES_GET_CREATE_SET']; } else { - opposite_type = 'variables_get'; + oppositeType = 'variables_get'; contextMenuMsg = Blockly.Msg['VARIABLES_SET_CREATE_GET']; } @@ -100,7 +100,7 @@ Blockly.Constants.Variables.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MIXIN = { xmlField.setAttribute('name', 'VAR'); xmlField.appendChild(Blockly.utils.xml.createTextNode(name)); const xmlBlock = Blockly.utils.xml.createElement('block'); - xmlBlock.setAttribute('type', opposite_type); + xmlBlock.setAttribute('type', oppositeType); xmlBlock.appendChild(xmlField); option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock); options.push(option); diff --git a/blocks/variables_dynamic.js b/blocks/variables_dynamic.js index 3fad3a315..a115d2437 100644 --- a/blocks/variables_dynamic.js +++ b/blocks/variables_dynamic.js @@ -80,16 +80,16 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI customContextMenu: function(options) { // Getter blocks have the option to create a setter block, and vice versa. if (!this.isInFlyout) { - let opposite_type; + let oppositeType; let contextMenuMsg; const id = this.getFieldValue('VAR'); const variableModel = this.workspace.getVariableById(id); const varType = variableModel.type; if (this.type === 'variables_get_dynamic') { - opposite_type = 'variables_set_dynamic'; + oppositeType = 'variables_set_dynamic'; contextMenuMsg = Blockly.Msg['VARIABLES_GET_CREATE_SET']; } else { - opposite_type = 'variables_get_dynamic'; + oppositeType = 'variables_get_dynamic'; contextMenuMsg = Blockly.Msg['VARIABLES_SET_CREATE_GET']; } @@ -101,7 +101,7 @@ Blockly.Constants.VariablesDynamic.CUSTOM_CONTEXT_MENU_VARIABLE_GETTER_SETTER_MI xmlField.setAttribute('variabletype', varType); xmlField.appendChild(Blockly.utils.xml.createTextNode(name)); const xmlBlock = Blockly.utils.xml.createElement('block'); - xmlBlock.setAttribute('type', opposite_type); + xmlBlock.setAttribute('type', oppositeType); xmlBlock.appendChild(xmlField); option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock); options.push(option); diff --git a/core/block.js b/core/block.js index 1b4fc04d9..4f467e0e2 100644 --- a/core/block.js +++ b/core/block.js @@ -243,7 +243,6 @@ const Block = function(workspace, prototypeName, opt_id) { if (eventUtils.isEnabled()) { eventUtils.fire(new (eventUtils.get(eventUtils.BLOCK_CREATE))(this)); } - } finally { if (!existingGroup) { eventUtils.setGroup(false); @@ -1669,7 +1668,7 @@ Block.prototype.mixin = function(mixinObj, opt_disableCheck) { } if (!opt_disableCheck) { const overwrites = []; - for (let key in mixinObj) { + for (const key in mixinObj) { if (this[key] !== undefined) { overwrites.push(key); } diff --git a/core/block_svg.js b/core/block_svg.js index f6567786f..88f507d44 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -397,10 +397,9 @@ BlockSvg.prototype.setParent = function(newParent) { const newXY = this.getRelativeToSurfaceXY(); // Move the connections to match the child's new position. this.moveConnections(newXY.x - oldXY.x, newXY.y - oldXY.y); - } - // If we are losing a parent, we want to move our DOM element to the - // root of the workspace. - else if (oldParent) { + } else if (oldParent) { + // If we are losing a parent, we want to move our DOM element to the + // root of the workspace. this.workspace.getCanvas().appendChild(svgRoot); this.translate(oldXY.x, oldXY.y); } diff --git a/core/connection.js b/core/connection.js index d15c365d2..bd8fef43b 100644 --- a/core/connection.js +++ b/core/connection.js @@ -414,7 +414,9 @@ Connection.prototype.disconnect = function() { if (otherConnection.targetConnection !== this) { throw Error('Target connection not connected to source connection.'); } - let parentBlock, childBlock, parentConnection; + let parentBlock; + let childBlock; + let parentConnection; if (this.isSuperior()) { // Superior block. parentBlock = this.sourceBlock_; diff --git a/core/connection_checker.js b/core/connection_checker.js index 93cd92d7b..8fcc9aa42 100644 --- a/core/connection_checker.js +++ b/core/connection_checker.js @@ -140,7 +140,8 @@ ConnectionChecker.prototype.doSafetyChecks = function(a, b) { if (!a || !b) { return Connection.REASON_TARGET_NULL; } - let blockA, blockB; + let blockA; + let blockB; if (a.isSuperior()) { blockA = a.getSourceBlock(); blockB = b.getSourceBlock(); diff --git a/core/css.js b/core/css.js index aef41e4c4..7cea9284f 100644 --- a/core/css.js +++ b/core/css.js @@ -71,7 +71,7 @@ const inject = function(hasCss, pathToMedia) { } // Strip off any trailing slash (either Unix or Windows). const mediaPath = pathToMedia.replace(/[\\/]$/, ''); - let cssContent = content.replace(/<<>>/g, mediaPath); + const cssContent = content.replace(/<<>>/g, mediaPath); // Cleanup the collected css content after injecting it to the DOM. content = ''; diff --git a/core/dropdowndiv.js b/core/dropdowndiv.js index 1472bcc08..a22baa944 100644 --- a/core/dropdowndiv.js +++ b/core/dropdowndiv.js @@ -576,14 +576,13 @@ const getPositionTopOfPageMetrics = function(sourceX, boundsInfo, divSize) { */ DropDownDiv.getPositionX = function( sourceX, boundsLeft, boundsRight, divWidth) { - let arrowX, divX; - arrowX = divX = sourceX; - + let divX = sourceX; // Offset the topLeft coord so that the dropdowndiv is centered. divX -= divWidth / 2; // Fit the dropdowndiv within the bounds of the workspace. divX = math.clamp(boundsLeft, divX, boundsRight - divWidth); + let arrowX = sourceX; // Offset the arrow coord so that the arrow is centered. arrowX -= DropDownDiv.ARROW_SIZE / 2; // Convert the arrow position to be relative to the top left of the div. diff --git a/core/extensions.js b/core/extensions.js index c5ba089d9..fa5dd10a8 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -374,7 +374,7 @@ const buildTooltipForDropdown = function(dropdownName, lookupTable) { // of document object, in which case skip the validation. if (typeof document === 'object') { // Relies on document.readyState utils.runAfterPageLoad(function() { - for (let key in lookupTable) { + for (const key in lookupTable) { // Will print warnings if reference is missing. utils.checkMessageReferences(lookupTable[key]); } diff --git a/core/field.js b/core/field.js index cd16397c1..a1cc796f6 100644 --- a/core/field.js +++ b/core/field.js @@ -813,7 +813,9 @@ Field.prototype.getSize = function() { * @package */ Field.prototype.getScaledBBox = function() { - let scaledWidth, scaledHeight, xy; + let scaledWidth; + let scaledHeight; + let xy; if (!this.borderRect_) { // Browsers are inconsistent in what they return for a bounding box. // - Webkit / Blink: fill-box / object bounding box diff --git a/core/field_multilineinput.js b/core/field_multilineinput.js index b75c447f6..2e5bf8a17 100644 --- a/core/field_multilineinput.js +++ b/core/field_multilineinput.js @@ -236,9 +236,9 @@ FieldMultilineInput.prototype.render_ = function() { const span = dom.createSvgElement( Svg.TEXT, { 'class': 'blocklyText blocklyMultilineText', - x: this.getConstants().FIELD_BORDER_RECT_X_PADDING, - y: y + this.getConstants().FIELD_BORDER_RECT_Y_PADDING, - dy: this.getConstants().FIELD_TEXT_BASELINE, + 'x': this.getConstants().FIELD_BORDER_RECT_X_PADDING, + 'y': y + this.getConstants().FIELD_BORDER_RECT_Y_PADDING, + 'dy': this.getConstants().FIELD_TEXT_BASELINE, }, this.textGroup_); span.appendChild(document.createTextNode(lines[i])); diff --git a/core/insertion_marker_manager.js b/core/insertion_marker_manager.js index 7122ed96d..df86ecc8c 100644 --- a/core/insertion_marker_manager.js +++ b/core/insertion_marker_manager.js @@ -670,10 +670,9 @@ InsertionMarkerManager.prototype.hideInsertionMarker_ = function() { // anything in that case. Instead, unplug the following block. if (isFirstInStatementStack || isFirstInOutputStack) { imConn.targetBlock().unplug(false); - } - // Inside of a C-block, first statement connection. - else if ( + } else if ( imConn.type === ConnectionType.NEXT_STATEMENT && imConn !== markerNext) { + // Inside of a C-block, first statement connection. const innerConnection = imConn.targetConnection; innerConnection.getSourceBlock().unplug(false); diff --git a/core/interfaces/i_registrable_field.js b/core/interfaces/i_registrable_field.js index f3b9c47f4..c7b275795 100644 --- a/core/interfaces/i_registrable_field.js +++ b/core/interfaces/i_registrable_field.js @@ -29,7 +29,7 @@ const {Field} = goog.requireType('Blockly.Field'); * }} * @alias Blockly.IRegistrableField */ -let IRegistrableField = {}; +const IRegistrableField = {}; /** * @typedef {function(!Object): Field} diff --git a/core/keyboard_nav/ast_node.js b/core/keyboard_nav/ast_node.js index f41cc18a6..f06c1c434 100644 --- a/core/keyboard_nav/ast_node.js +++ b/core/keyboard_nav/ast_node.js @@ -487,10 +487,9 @@ ASTNode.prototype.getOutAstNodeForBlock_ = function(block) { if (!block) { return null; } - let topBlock; // If the block doesn't have a previous connection then it is the top of the // substack. - topBlock = block.getTopStackBlock(); + const topBlock = block.getTopStackBlock(); const topConnection = topBlock.previousConnection || topBlock.outputConnection; // If the top connection has a parentInput, create an AST node pointing to diff --git a/core/mutator.js b/core/mutator.js index 9fbbb6f07..5e4e9ace6 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -324,7 +324,8 @@ Mutator.prototype.setVisible = function(visible) { // The root block should not be draggable or deletable. this.rootBlock_.setMovable(false); this.rootBlock_.setDeletable(false); - let margin, x; + let margin; + let x; if (flyout) { margin = flyout.CORNER_RADIUS * 2; x = this.rootBlock_.RTL ? flyout.getWidth() + margin : margin; diff --git a/core/procedures.js b/core/procedures.js index 174b7c0dd..8563ae99e 100644 --- a/core/procedures.js +++ b/core/procedures.js @@ -238,6 +238,13 @@ const flyoutCategory = function(workspace) { xmlList[xmlList.length - 1].setAttribute('gap', 24); } + /** + * Add items to xmlList for each listed procedure. + * @param {!Array} procedureList A list of procedures, each of which + * is defined by a three-element list of name, parameter list, and return + * value boolean. + * @param {string} templateName The type of the block to generate. + */ function populateProcedures(procedureList, templateName) { for (let i = 0; i < procedureList.length; i++) { const name = procedureList[i][0]; diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 51c8893fe..87d9f4f97 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -319,7 +319,7 @@ RenderedConnection.prototype.highlight = function() { Svg.PATH, { 'class': 'blocklyHighlightedConnectionPath', 'd': steps, - transform: 'translate(' + x + ',' + y + ')' + + 'transform': 'translate(' + x + ',' + y + ')' + (this.sourceBlock_.RTL ? ' scale(-1 1)' : ''), }, this.sourceBlock_.getSvgRoot()); diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index 7f080b264..fc7d2c41d 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -817,11 +817,16 @@ ConstantProvider.prototype.makePuzzleTab = function() { const width = this.TAB_WIDTH; const height = this.TAB_HEIGHT; - // The main path for the puzzle tab is made out of a few curves (c and s). - // Those curves are defined with relative positions. The 'up' and 'down' - // versions of the paths are the same, but the Y sign flips. Forward and back - // are the signs to use to move the cursor in the direction that the path is - // being drawn. + /** + * Make the main path for the puzzle tab made out of a few curves (c and s). + * Those curves are defined with relative positions. The 'up' and 'down' + * versions of the paths are the same, but the Y sign flips. Forward and back + * are the signs to use to move the cursor in the direction that the path is + * being drawn. + * @param {boolean} up True if the path should be drawn from bottom to top, + * false otherwise. + * @return {string} A path fragment describing a puzzle tab. + */ function makeMainPath(up) { const forward = up ? -1 : 1; const back = -forward; @@ -870,6 +875,13 @@ ConstantProvider.prototype.makeNotch = function() { const height = this.NOTCH_HEIGHT; const innerWidth = 3; const outerWidth = (width - innerWidth) / 2; + + /** + * Make the main path for the notch. + * @param {number} dir Direction multiplier to apply to horizontal offsets + * along the path. Either 1 or -1. + * @return {string} A path fragment describing a notch. + */ function makeMainPath(dir) { return svgPaths.line([ svgPaths.point(dir * outerWidth, height), @@ -1087,8 +1099,8 @@ ConstantProvider.prototype.createDebugFilter = function() { 'id': 'blocklyDebugFilter' + this.randomIdentifier, 'height': '160%', 'width': '180%', - y: '-30%', - x: '-40%', + 'y': '-30%', + 'x': '-40%', }, this.defs_); // Set all gaussian blur pixels to 1 opacity before applying flood diff --git a/core/renderers/common/marker_svg.js b/core/renderers/common/marker_svg.js index f3db22d3a..8d19b9191 100644 --- a/core/renderers/common/marker_svg.js +++ b/core/renderers/common/marker_svg.js @@ -252,10 +252,10 @@ MarkerSvg.prototype.showWithBlockPrevOutput_ = function(curNode) { const markerOffset = this.constants_.CURSOR_BLOCK_PADDING; if (block.previousConnection) { - let connectionShape = this.constants_.shapeFor(block.previousConnection); + const connectionShape = this.constants_.shapeFor(block.previousConnection); this.positionPrevious_(width, markerOffset, markerHeight, connectionShape); } else if (block.outputConnection) { - let connectionShape = this.constants_.shapeFor(block.outputConnection); + const connectionShape = this.constants_.shapeFor(block.outputConnection); this.positionOutput_(width, height, connectionShape); } else { this.positionBlock_(width, markerOffset, markerHeight); diff --git a/core/renderers/zelos/constants.js b/core/renderers/zelos/constants.js index 518f5de4d..582f0a4fa 100644 --- a/core/renderers/zelos/constants.js +++ b/core/renderers/zelos/constants.js @@ -471,11 +471,19 @@ ConstantProvider.prototype.makeStartHat = function() { ConstantProvider.prototype.makeHexagonal = function() { const maxWidth = this.MAX_DYNAMIC_CONNECTION_SHAPE_WIDTH; - // The main path for the hexagonal connection shape is made out of two lines. - // The lines are defined with relative positions and require the block height. - // The 'up' and 'down' versions of the paths are the same, but the Y sign - // flips. The 'left' and 'right' versions of the path are also the same, but - // the X sign flips. + /** + * Make the main path for the hexagonal connection shape out of two lines. + * The lines are defined with relative positions and require the block height. + * The 'up' and 'down' versions of the paths are the same, but the Y sign + * flips. The 'left' and 'right' versions of the path are also the same, but + * the X sign flips. + * @param {number} height The height of the block the connection is on. + * @param {boolean} up True if the path should be drawn from bottom to top, + * false otherwise. + * @param {boolean} right True if the path is for the right side of the + * block. + * @return {string} A path fragment describing a rounded connection. + */ function makeMainPath(height, up, right) { const halfHeight = height / 2; const width = halfHeight > maxWidth ? maxWidth : halfHeight; @@ -527,14 +535,22 @@ ConstantProvider.prototype.makeRounded = function() { const maxWidth = this.MAX_DYNAMIC_CONNECTION_SHAPE_WIDTH; const maxHeight = maxWidth * 2; - // The main path for the rounded connection shape is made out of two arcs and - // a line that joins them. The arcs are defined with relative positions. - // Usually, the height of the block is split between the two arcs. In the case - // where the height of the block exceeds the maximum height, a line is drawn - // in between the two arcs. - // The 'up' and 'down' versions of the paths are the same, but the Y sign - // flips. The 'up' and 'right' versions of the path flip the sweep-flag - // which moves the arc at negative angles. + /** + * Make the main path for the rounded connection shape out of two arcs and + * a line that joins them. The arcs are defined with relative positions. + * Usually, the height of the block is split between the two arcs. In the case + * where the height of the block exceeds the maximum height, a line is drawn + * in between the two arcs. + * The 'up' and 'down' versions of the paths are the same, but the Y sign + * flips. The 'up' and 'right' versions of the path flip the sweep-flag + * which moves the arc at negative angles. + * @param {number} blockHeight The height of the block the connection is on. + * @param {boolean} up True if the path should be drawn from bottom to top, + * false otherwise. + * @param {boolean} right True if the path is for the right side of the + * block. + * @return {string} A path fragment describing a rounded connection. + */ function makeMainPath(blockHeight, up, right) { const remainingHeight = blockHeight > maxHeight ? blockHeight - maxHeight : 0; @@ -589,12 +605,20 @@ ConstantProvider.prototype.makeRounded = function() { ConstantProvider.prototype.makeSquared = function() { const radius = this.CORNER_RADIUS; - // The main path for the squared connection shape is made out of two corners - // and a single line in-between (a and v). These are defined in relative - // positions and require the height of the block. - // The 'left' and 'right' versions of the paths are the same, but the Y sign - // flips. The 'up' and 'down' versions of the path determine where the corner - // point is placed and in-turn the direction of the corners. + /** + * Make the main path for the squared connection shape out of two corners + * and a single line in-between (a and v). These are defined in relative + * positions and require the height of the block. + * The 'left' and 'right' versions of the paths are the same, but the Y sign + * flips. The 'up' and 'down' versions of the path determine where the corner + * point is placed and in turn the direction of the corners. + * @param {number} height The height of the block the connection is on. + * @param {boolean} up True if the path should be drawn from bottom to top, + * false otherwise. + * @param {boolean} right True if the path is for the right side of the + * block. + * @return {string} A path fragment describing a squared connection. + */ function makeMainPath(height, up, right) { const innerHeight = height - radius * 2; return svgPaths.arc( @@ -692,6 +716,12 @@ ConstantProvider.prototype.makeNotch = function() { const halfHeight = height / 2; const quarterHeight = halfHeight / 2; + /** + * Make the main path for the notch. + * @param {number} dir Direction multiplier to apply to horizontal offsets + * along the path. Either 1 or -1. + * @return {string} A path fragment describing a notch. + */ function makeMainPath(dir) { return ( svgPaths.curve( @@ -799,8 +829,8 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { 'id': 'blocklySelectedGlowFilter' + this.randomIdentifier, 'height': '160%', 'width': '180%', - y: '-30%', - x: '-40%', + 'y': '-30%', + 'x': '-40%', }, defs); dom.createSvgElement( @@ -840,8 +870,8 @@ ConstantProvider.prototype.createDom = function(svg, tagName, selector) { 'id': 'blocklyReplacementGlowFilter' + this.randomIdentifier, 'height': '160%', 'width': '180%', - y: '-30%', - x: '-40%', + 'y': '-30%', + 'x': '-40%', }, defs); dom.createSvgElement( diff --git a/core/serialization/workspaces.js b/core/serialization/workspaces.js index 3a6b8ca8c..0719fe85e 100644 --- a/core/serialization/workspaces.js +++ b/core/serialization/workspaces.js @@ -60,10 +60,8 @@ const load = function(state, workspace, {recordUndo = false} = {}) { return; } - const deserializers = - Object.entries(serializerMap).sort(([, {priority: priorityA}], [ - , {priority: priorityB} - ]) => priorityB - priorityA); + const deserializers = Object.entries(serializerMap) + .sort((a, b) => b[1].priority - a[1].priority); const prevRecordUndo = eventUtils.getRecordUndo(); eventUtils.setRecordUndo(recordUndo); diff --git a/core/theme/classic.js b/core/theme/classic.js index 648ec5fb8..a3fabb6eb 100644 --- a/core/theme/classic.js +++ b/core/theme/classic.js @@ -20,7 +20,7 @@ goog.module('Blockly.Themes.Classic'); const {Theme} = goog.require('Blockly.Theme'); -let defaultBlockStyles = { +const defaultBlockStyles = { 'colour_blocks': {'colourPrimary': '20'}, 'list_blocks': {'colourPrimary': '260'}, 'logic_blocks': {'colourPrimary': '210'}, @@ -33,7 +33,7 @@ let defaultBlockStyles = { 'hat_blocks': {'colourPrimary': '330', 'hat': 'cap'}, }; -let categoryStyles = { +const categoryStyles = { 'colour_category': {'colour': '20'}, 'list_category': {'colour': '260'}, 'logic_category': {'colour': '210'}, diff --git a/core/theme/zelos.js b/core/theme/zelos.js index 32f791be3..532e48cf4 100644 --- a/core/theme/zelos.js +++ b/core/theme/zelos.js @@ -18,7 +18,7 @@ goog.module('Blockly.Themes.Zelos'); const {Theme} = goog.require('Blockly.Theme'); -let defaultBlockStyles = { +const defaultBlockStyles = { 'colour_blocks': { 'colourPrimary': '#CF63CF', 'colourSecondary': '#C94FC9', @@ -72,7 +72,7 @@ let defaultBlockStyles = { }, }; -let categoryStyles = { +const categoryStyles = { 'colour_category': {'colour': '#CF63CF'}, 'list_category': {'colour': '#9966FF'}, 'logic_category': {'colour': '#4C97FF'}, diff --git a/core/utils.js b/core/utils.js index 5fdf5de1d..f0a9752d4 100644 --- a/core/utils.js +++ b/core/utils.js @@ -482,7 +482,7 @@ const is3dSupported = function() { // Add it to the body to get the computed style. document.body.insertBefore(el, null); - for (let t in transforms) { + for (const t in transforms) { if (el.style[t] !== undefined) { el.style[t] = 'translate3d(1px,1px,1px)'; const computedStyle = global.globalThis['getComputedStyle'](el); diff --git a/core/variable_map.js b/core/variable_map.js index b19882ad9..ddec0d7e8 100644 --- a/core/variable_map.js +++ b/core/variable_map.js @@ -339,9 +339,9 @@ VariableMap.prototype.getVariableById = function(id) { */ VariableMap.prototype.getVariablesOfType = function(type) { type = type || ''; - const variable_list = this.variableMap_[type]; - if (variable_list) { - return variable_list.slice(); + const variableList = this.variableMap_[type]; + if (variableList) { + return variableList.slice(); } return []; }; @@ -379,11 +379,11 @@ VariableMap.prototype.getVariableTypes = function(ws) { * @return {!Array} List of variable models. */ VariableMap.prototype.getAllVariables = function() { - let all_variables = []; + let allVariables = []; for (const key in this.variableMap_) { - all_variables = all_variables.concat(this.variableMap_[key]); + allVariables = allVariables.concat(this.variableMap_[key]); } - return all_variables; + return allVariables; }; /** diff --git a/core/variables_dynamic.js b/core/variables_dynamic.js index a4a3a9ebb..96fdac099 100644 --- a/core/variables_dynamic.js +++ b/core/variables_dynamic.js @@ -26,23 +26,23 @@ const {VariableModel} = goog.require('Blockly.VariableModel'); const {Workspace} = goog.requireType('Blockly.Workspace'); -const onCreateVariableButtonClick_String = function(button) { +const stringButtonClickHandler = function(button) { Variables.createVariableButtonHandler( button.getTargetWorkspace(), undefined, 'String'); }; -exports.onCreateVariableButtonClick_String = onCreateVariableButtonClick_String; +exports.onCreateVariableButtonClick_String = stringButtonClickHandler; -const onCreateVariableButtonClick_Number = function(button) { +const numberButtonClickHandler = function(button) { Variables.createVariableButtonHandler( button.getTargetWorkspace(), undefined, 'Number'); }; -exports.onCreateVariableButtonClick_Number = onCreateVariableButtonClick_Number; +exports.onCreateVariableButtonClick_Number = numberButtonClickHandler; -const onCreateVariableButtonClick_Colour = function(button) { +const colourButtonClickHandler = function(button) { Variables.createVariableButtonHandler( button.getTargetWorkspace(), undefined, 'Colour'); }; -exports.onCreateVariableButtonClick_Colour = onCreateVariableButtonClick_Colour; +exports.onCreateVariableButtonClick_Colour = colourButtonClickHandler; /** * Construct the elements (blocks and button) required by the flyout for the @@ -67,11 +67,11 @@ const flyoutCategory = function(workspace) { xmlList.push(button); workspace.registerButtonCallback( - 'CREATE_VARIABLE_STRING', onCreateVariableButtonClick_String); + 'CREATE_VARIABLE_STRING', stringButtonClickHandler); workspace.registerButtonCallback( - 'CREATE_VARIABLE_NUMBER', onCreateVariableButtonClick_Number); + 'CREATE_VARIABLE_NUMBER', numberButtonClickHandler); workspace.registerButtonCallback( - 'CREATE_VARIABLE_COLOUR', onCreateVariableButtonClick_Colour); + 'CREATE_VARIABLE_COLOUR', colourButtonClickHandler); const blockList = flyoutCategoryBlocks(workspace); diff --git a/tests/playgrounds/screenshot.js b/tests/playgrounds/screenshot.js index 5e292fe81..a1ee9a204 100644 --- a/tests/playgrounds/screenshot.js +++ b/tests/playgrounds/screenshot.js @@ -45,7 +45,6 @@ function svgToPng_(data, width, height, callback) { * @param {string=} customCss Custom CSS to append to the SVG. */ function workspaceToSvg_(workspace, callback, customCss) { - // Go through all text areas and set their value. const textAreas = document.getElementsByTagName("textarea"); for (let i = 0; i < textAreas.length; i++) { @@ -62,7 +61,7 @@ function workspaceToSvg_(workspace, callback, customCss) { const clone = blockCanvas.cloneNode(true); clone.removeAttribute('transform'); - const svg = document.createElementNS('http://www.w3.org/2000/svg','svg'); + const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); svg.appendChild(clone); svg.setAttribute('viewBox', @@ -76,9 +75,11 @@ function workspaceToSvg_(workspace, callback, customCss) { svg.setAttribute("style", 'background-color: transparent'); const css = [].slice.call(document.head.querySelectorAll('style')) - .filter(function(el) { return /\.blocklySvg/.test(el.innerText) || - (el.id.indexOf('blockly-') === 0); }).map(function(el) { - return el.innerText; }).join('\n'); + .filter( + (el) => /\.blocklySvg/.test(el.innerText) || + (el.id.indexOf('blockly-') === 0)) + .map((el) => el.innerText) + .join('\n'); const style = document.createElement('style'); style.innerHTML = css + '\n' + customCss; svg.insertBefore(style, svg.firstChild);