From 1052f7548b68f056ba33fba1ea8354d49e6dc7c2 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Thu, 28 May 2020 17:44:16 -0700 Subject: [PATCH] Enable unusedPrivateMembers check (#3924) * Add unusedPrivateMembers check --- core/block_svg.js | 7 ---- core/comment.js | 2 +- core/connection.js | 1 + core/field_angle.js | 2 +- core/field_colour.js | 2 +- core/field_dropdown.js | 4 +-- core/field_textinput.js | 10 +++++- core/field_variable.js | 7 ---- core/flyout_base.js | 41 +++++++++++++++++++++--- core/flyout_dragger.js | 2 +- core/flyout_horizontal.js | 14 +++----- core/flyout_vertical.js | 12 ++----- core/icon.js | 8 +++++ core/menuitem.js | 2 ++ core/mutator.js | 2 +- core/toolbox.js | 7 ---- core/warning.js | 12 +------ core/workspace.js | 11 ------- core/workspace_drag_surface_svg.js | 10 ------ demos/custom-fields/pitch/field_pitch.js | 2 +- scripts/gulpfiles/build_tasks.js | 2 +- tests/mocha/workspace_test.js | 10 ------ 22 files changed, 74 insertions(+), 96 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index 19a58bc9b..9cb76f0a6 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -130,13 +130,6 @@ Blockly.BlockSvg.prototype.height = 0; */ Blockly.BlockSvg.prototype.width = 0; -/** - * Original location of block being dragged. - * @type {Blockly.utils.Coordinate} - * @private - */ -Blockly.BlockSvg.prototype.dragStartXY_ = null; - /** * Map from IDs for warnings text to PIDs of functions to apply them. * Used to be able to maintain multiple warnings. diff --git a/core/comment.js b/core/comment.js index e3b076f49..54c102b08 100644 --- a/core/comment.js +++ b/core/comment.js @@ -86,7 +86,7 @@ Blockly.utils.object.inherits(Blockly.Comment, Blockly.Icon); /** * Draw the comment icon. * @param {!Element} group The icon group. - * @private + * @protected */ Blockly.Comment.prototype.drawIcon_ = function(group) { // Circle. diff --git a/core/connection.js b/core/connection.js index a144e1b8c..0d1757c38 100644 --- a/core/connection.js +++ b/core/connection.js @@ -619,6 +619,7 @@ Blockly.Connection.prototype.checkType = function(otherConnection) { * @return {boolean} True if the connections share a type. * @private * @deprecated October 2019, use connection.checkType instead. + * @suppress {unusedPrivateMembers} */ Blockly.Connection.prototype.checkType_ = function(otherConnection) { console.warn('Deprecated call to Blockly.Connection.prototype.checkType_, ' + diff --git a/core/field_angle.js b/core/field_angle.js index 4dbe1b19c..70153495a 100644 --- a/core/field_angle.js +++ b/core/field_angle.js @@ -247,7 +247,7 @@ Blockly.FieldAngle.prototype.render_ = function() { * Create and show the angle field's editor. * @param {Event=} opt_e Optional mouse event that triggered the field to open, * or undefined if triggered programmatically. - * @private + * @protected */ Blockly.FieldAngle.prototype.showEditor_ = function(opt_e) { // Mobile browsers have issues with in-line textareas (focus & keyboards). diff --git a/core/field_colour.js b/core/field_colour.js index 562bdaeec..50068d15a 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -311,7 +311,7 @@ Blockly.FieldColour.prototype.setColumns = function(columns) { /** * Create and show the colour field's editor. - * @private + * @protected */ Blockly.FieldColour.prototype.showEditor_ = function() { this.picker_ = this.dropdownCreate_(); diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 4874964da..bdbe27f9e 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -272,7 +272,7 @@ Blockly.FieldDropdown.prototype.createSVGArrow_ = function() { * Create a dropdown menu under the text. * @param {Event=} opt_e Optional mouse event that triggered the field to open, * or undefined if triggered programmatically. - * @private + * @protected */ Blockly.FieldDropdown.prototype.showEditor_ = function(opt_e) { this.menu_ = this.dropdownCreate_(); @@ -552,7 +552,7 @@ Blockly.FieldDropdown.prototype.applyColour = function() { /** * Draws the border with the correct width. - * @private + * @protected */ Blockly.FieldDropdown.prototype.render_ = function() { // Hide both elements. diff --git a/core/field_textinput.js b/core/field_textinput.js index 2343a2232..7b1c388c8 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -80,6 +80,13 @@ Blockly.FieldTextInput = function(opt_value, opt_validator, opt_config) { * @type {?boolean} */ this.fullBlockClickTarget_ = false; + + /** + * The workspace that this field belongs to. + * @type {?Blockly.WorkspaceSvg} + * @protected + */ + this.workspace_ = null; }; Blockly.utils.object.inherits(Blockly.FieldTextInput, Blockly.Field); @@ -275,7 +282,8 @@ Blockly.FieldTextInput.prototype.setSpellcheck = function(check) { */ Blockly.FieldTextInput.prototype.showEditor_ = function(_opt_e, opt_quietInput) { - this.workspace_ = this.sourceBlock_.workspace; + this.workspace_ = + (/** @type {!Blockly.BlockSvg} */ (this.sourceBlock_)).workspace; var quietInput = opt_quietInput || false; if (!quietInput && (Blockly.utils.userAgent.MOBILE || Blockly.utils.userAgent.ANDROID || diff --git a/core/field_variable.js b/core/field_variable.js index 7d7801384..df4cd526a 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -98,13 +98,6 @@ Blockly.FieldVariable.fromJson = function(options) { varName, undefined, undefined, undefined, options); }; -/** - * The workspace that this variable field belongs to. - * @type {?Blockly.Workspace} - * @private - */ -Blockly.FieldVariable.prototype.workspace_ = null; - /** * Serializable fields are saved by the XML renderer, non-serializable fields * are not. Editable fields should also be serializable. diff --git a/core/flyout_base.js b/core/flyout_base.js index d2405984a..06d51188d 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -64,6 +64,13 @@ Blockly.Flyout = function(workspaceOptions) { */ this.RTL = !!workspaceOptions.RTL; + /** + * Whether the flyout should be laid out horizontally or not. + * @type {boolean} + * @package + */ + this.horizontalLayout = false; + /** * Position of the toolbox and flyout relative to the workspace. * @type {number} @@ -256,7 +263,7 @@ Blockly.Flyout.prototype.init = function(targetWorkspace) { * @package */ this.scrollbar = new Blockly.Scrollbar(this.workspace_, - this.horizontalLayout_, false, 'blocklyFlyoutScrollbar'); + this.horizontalLayout, false, 'blocklyFlyoutScrollbar'); this.hide(); @@ -473,8 +480,9 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { // Parse the Array or NodeList passed in into an Array of // Blockly.utils.toolbox.Toolbox. var parsedContent = Blockly.utils.toolbox.convertToolboxToJSON(flyoutDef); - var flyoutInfo = /** @type {{contents:Array., gaps:Array.}} */ - (this.createFlyoutInfo_(parsedContent)); + var flyoutInfo = + /** @type {{contents:!Array., gaps:!Array.}} */ ( + this.createFlyoutInfo_(parsedContent)); this.setVisible(true); @@ -492,7 +500,7 @@ Blockly.Flyout.prototype.show = function(flyoutDef) { this.listeners_.push(Blockly.bindEventWithChecks_(this.svgBackground_, 'mouseover', this, deselectAll)); - if (this.horizontalLayout_) { + if (this.horizontalLayout) { this.height_ = 0; } else { this.width_ = 0; @@ -522,7 +530,7 @@ Blockly.Flyout.prototype.createFlyoutInfo_ = function(parsedContent) { var contents = []; var gaps = []; this.permanentlyDisabled_.length = 0; - var defaultGap = this.horizontalLayout_ ? this.GAP_X : this.GAP_Y; + var defaultGap = this.horizontalLayout ? this.GAP_X : this.GAP_Y; for (var i = 0, contentInfo; (contentInfo = parsedContent[i]); i++) { switch (contentInfo.kind.toUpperCase()) { case 'BLOCK': @@ -994,3 +1002,26 @@ Blockly.Flyout.prototype.getMetrics_; * @protected */ Blockly.Flyout.prototype.setMetrics_; + +/** + * Lay out the blocks in the flyout. + * @param {!Array.} contents The blocks and buttons to lay out. + * @param {!Array.} gaps The visible gaps between blocks. + * @protected + */ +Blockly.Flyout.prototype.layout_; + +/** + * Scroll the flyout. + * @param {!Event} e Mouse wheel scroll event. + * @protected + */ +Blockly.Flyout.prototype.wheel_; + +/** + * Compute height of flyout. Position mat under each block. + * For RTL: Lay out the blocks right-aligned. + * @return {void} + * @protected + */ +Blockly.Flyout.prototype.reflowInternal_; diff --git a/core/flyout_dragger.js b/core/flyout_dragger.js index 4709bd37d..f49243b7f 100644 --- a/core/flyout_dragger.js +++ b/core/flyout_dragger.js @@ -45,7 +45,7 @@ Blockly.FlyoutDragger = function(flyout) { * @type {boolean} * @private */ - this.horizontalLayout_ = flyout.horizontalLayout_; + this.horizontalLayout_ = flyout.horizontalLayout; }; Blockly.utils.object.inherits(Blockly.FlyoutDragger, Blockly.WorkspaceDragger); diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index b7a5725bb..7f648ec65 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -32,12 +32,8 @@ goog.requireType('Blockly.utils.Metrics'); */ Blockly.HorizontalFlyout = function(workspaceOptions) { Blockly.HorizontalFlyout.superClass_.constructor.call(this, workspaceOptions); - /** - * Flyout should be laid out horizontally. - * @type {boolean} - * @private - */ - this.horizontalLayout_ = true; + + this.horizontalLayout = true; }; Blockly.utils.object.inherits(Blockly.HorizontalFlyout, Blockly.Flyout); @@ -227,7 +223,7 @@ Blockly.HorizontalFlyout.prototype.scrollToStart = function() { /** * Scroll the flyout. * @param {!Event} e Mouse wheel scroll event. - * @private + * @protected */ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { var scrollDelta = Blockly.utils.getScrollDeltaPixels(e); @@ -255,7 +251,7 @@ Blockly.HorizontalFlyout.prototype.wheel_ = function(e) { * Lay out the blocks in the flyout. * @param {!Array.} contents The blocks and buttons to lay out. * @param {!Array.} gaps The visible gaps between blocks. - * @private + * @protected */ Blockly.HorizontalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; @@ -352,7 +348,7 @@ Blockly.HorizontalFlyout.prototype.getClientRect = function() { /** * Compute height of flyout. Position mat under each block. * For RTL: Lay out the blocks right-aligned. - * @private + * @protected */ Blockly.HorizontalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.targetWorkspace.scale; diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index cdafba161..139277cc2 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -33,12 +33,6 @@ goog.requireType('Blockly.utils.Metrics'); */ Blockly.VerticalFlyout = function(workspaceOptions) { Blockly.VerticalFlyout.superClass_.constructor.call(this, workspaceOptions); - /** - * Flyout should be laid out vertically. - * @type {boolean} - * @private - */ - this.horizontalLayout_ = false; }; Blockly.utils.object.inherits(Blockly.VerticalFlyout, Blockly.Flyout); @@ -215,7 +209,7 @@ Blockly.VerticalFlyout.prototype.scrollToStart = function() { /** * Scroll the flyout. * @param {!Event} e Mouse wheel scroll event. - * @private + * @protected */ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { var scrollDelta = Blockly.utils.getScrollDeltaPixels(e); @@ -242,7 +236,7 @@ Blockly.VerticalFlyout.prototype.wheel_ = function(e) { * Lay out the blocks in the flyout. * @param {!Array.} contents The blocks and buttons to lay out. * @param {!Array.} gaps The visible gaps between blocks. - * @private + * @protected */ Blockly.VerticalFlyout.prototype.layout_ = function(contents, gaps) { this.workspace_.scale = this.targetWorkspace.scale; @@ -331,7 +325,7 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { /** * Compute width of flyout. Position mat under each block. * For RTL: Lay out the blocks and buttons to be right-aligned. - * @private + * @protected */ Blockly.VerticalFlyout.prototype.reflowInternal_ = function() { this.workspace_.scale = this.targetWorkspace.scale; diff --git a/core/icon.js b/core/icon.js index 7123dbc6a..0a180ce69 100644 --- a/core/icon.js +++ b/core/icon.js @@ -22,6 +22,7 @@ goog.require('Blockly.utils.Size'); * Class for an icon. * @param {Blockly.BlockSvg} block The block associated with this icon. * @constructor + * @abstract */ Blockly.Icon = function(block) { /** @@ -181,3 +182,10 @@ Blockly.Icon.prototype.getCorrectedSize = function() { return new Blockly.utils.Size( Blockly.Icon.prototype.SIZE, Blockly.Icon.prototype.SIZE - 2); }; + +/** + * Draw the icon. + * @param {!Element} group The icon group. + * @protected + */ +Blockly.Icon.prototype.drawIcon_; diff --git a/core/menuitem.js b/core/menuitem.js index ab93aec33..c9ba07981 100644 --- a/core/menuitem.js +++ b/core/menuitem.js @@ -112,6 +112,8 @@ Blockly.MenuItem.prototype.createDom = function() { element.className = 'blocklyMenuItem goog-menuitem ' + (this.enabled_ ? '' : 'blocklyMenuItemDisabled goog-menuitem-disabled ') + (this.checked_ ? 'blocklyMenuItemSelected goog-option-selected ' : '') + + (this.highlight_ ? + 'blocklyMenuItemHighlight goog-menuitem-highlight ' : '') + (this.rightToLeft_ ? 'blocklyMenuItemRtl goog-menuitem-rtl ' : ''); var content = document.createElement('div'); diff --git a/core/mutator.js b/core/mutator.js index 352648495..2017d9bc1 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -76,7 +76,7 @@ Blockly.Mutator.prototype.getWorkspace = function() { /** * Draw the mutator icon. * @param {!Element} group The icon group. - * @private + * @protected */ Blockly.Mutator.prototype.drawIcon_ = function(group) { // Square with rounded corners. diff --git a/core/toolbox.js b/core/toolbox.js index 63a34d8a5..790be801d 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -127,13 +127,6 @@ Blockly.Toolbox = function(workspace) { */ this.height = 0; - /** - * The SVG group currently selected. - * @type {SVGGElement} - * @private - */ - this.selectedOption_ = null; - /** * The TreeNode most recently selected. * @type {Blockly.tree.BaseNode} diff --git a/core/warning.js b/core/warning.js index 7a5364c5b..915873706 100644 --- a/core/warning.js +++ b/core/warning.js @@ -42,7 +42,7 @@ Blockly.Warning.prototype.collapseHidden = false; /** * Draw the warning icon. * @param {!Element} group The icon group. - * @private + * @protected */ Blockly.Warning.prototype.drawIcon_ = function(group) { // Triangle with rounded corners. @@ -154,16 +154,6 @@ Blockly.Warning.prototype.disposeBubble = function() { this.paragraphElement_ = null; }; -/** - * Bring the warning to the top of the stack when clicked on. - * @param {!Event} _e Mouse up event. - * @private - */ - -Blockly.Warning.prototype.bodyFocus_ = function(_e) { - this.bubble_.promote(); -}; - /** * Set this warning's text. * @param {string} text Warning text (or '' to delete). This supports diff --git a/core/workspace.js b/core/workspace.js index 364aa1222..f07bcea3c 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -409,17 +409,6 @@ Blockly.Workspace.prototype.deleteVariableById = function(id) { this.variableMap_.deleteVariableById(id); }; -/** - * Deletes a variable and all of its uses from this workspace without asking - * the user for confirmation. - * @param {!Blockly.VariableModel} variable Variable to delete. - * @param {!Array.} uses An array of uses of the variable. - * @private - */ -Blockly.Workspace.prototype.deleteVariableInternal_ = function(variable, uses) { - this.variableMap_.deleteVariableInternal(variable, uses); -}; - /** * Check whether a variable exists with the given name. The check is * case-insensitive. diff --git a/core/workspace_drag_surface_svg.js b/core/workspace_drag_surface_svg.js index 0a224fc87..3ee7454be 100644 --- a/core/workspace_drag_surface_svg.js +++ b/core/workspace_drag_surface_svg.js @@ -39,16 +39,6 @@ Blockly.WorkspaceDragSurfaceSvg = function(container) { */ Blockly.WorkspaceDragSurfaceSvg.prototype.SVG_ = null; -/** - * SVG group inside the drag surface that holds blocks while a drag is in - * progress. Blocks are moved here by the workspace at start of a drag and moved - * back into the main SVG at the end of a drag. - * - * @type {Element} - * @private - */ -Blockly.WorkspaceDragSurfaceSvg.prototype.dragGroup_ = null; - /** * Containing HTML element; parent of the workspace and the drag surface. * @type {Element} diff --git a/demos/custom-fields/pitch/field_pitch.js b/demos/custom-fields/pitch/field_pitch.js index b66dca6a8..5b8ef5e1a 100644 --- a/demos/custom-fields/pitch/field_pitch.js +++ b/demos/custom-fields/pitch/field_pitch.js @@ -63,7 +63,7 @@ CustomFields.FieldPitch.NOTES = 'C3 D3 E3 F3 G3 A3 B3 C4 D4 E4 F4 G4 A4'.split(/ /** * Show the inline free-text editor on top of the text and the note picker. - * @private + * @protected */ CustomFields.FieldPitch.prototype.showEditor_ = function() { CustomFields.FieldPitch.superClass_.showEditor_.call(this); diff --git a/scripts/gulpfiles/build_tasks.js b/scripts/gulpfiles/build_tasks.js index 11fdcb2fc..ee20b4b3d 100644 --- a/scripts/gulpfiles/build_tasks.js +++ b/scripts/gulpfiles/build_tasks.js @@ -94,7 +94,7 @@ var JSCOMP_ERROR = [ 'underscore', 'unknownDefines', 'unusedLocalVariables', - // 'unusedPrivateMembers', + 'unusedPrivateMembers', 'useOfGoogBase', 'uselessCode', 'untranspilableFeatures', diff --git a/tests/mocha/workspace_test.js b/tests/mocha/workspace_test.js index db6a2e280..0ac317799 100644 --- a/tests/mocha/workspace_test.js +++ b/tests/mocha/workspace_test.js @@ -99,16 +99,6 @@ function testAWorkspace() { createVarBlocksNoEvents(this.workspace, ['id1', 'id1', 'id2']); }); - test('deleteVariableInternal_(id1)', function() { - var uses = this.workspace.getVariableUsesById(this.var1.getId()); - this.workspace.deleteVariableInternal_(this.var1, uses); - - var variable = this.workspace.getVariableById('id1'); - chai.assert.isNull(variable); - assertVariableValues(this.workspace, 'name2', 'type2', 'id2'); - assertBlockVarModelName(this.workspace, 0, 'name2'); - }); - test('deleteVariableById(id2) one usage', function() { // Deleting variable one usage should not trigger confirm dialog. var stub =