More lint and eslint configuration.

This commit is contained in:
Rachel Fenichel 2016-05-25 12:53:42 -07:00
parent 8597c94a49
commit 4841f136f1
15 changed files with 105 additions and 56 deletions

10
.eslintignore Normal file
View file

@ -0,0 +1,10 @@
*_compressed*.js
*_uncompressed*.js
/msg/*
/core/css.js
/tests/jsunit/*
/tests/generators/*
/generators/*
/demos/*
/accessible/*
/appengine/*

28
.eslintrc Normal file
View file

@ -0,0 +1,28 @@
{
"rules": {
"curly": ["error", "multi-line"],
"eol-last": ["error"],
"indent": ["error", 2, {"SwitchCase": 1}], # Blockly/Google use 2-space indents
"linebreak-style": ["error", "unix"],
"max-len": ["error", 120, 4],
"no-trailing-spaces": ["error", { "skipBlankLines": true }],
"no-unused-vars": ["error", {"args": "after-used", "varsIgnorePattern": "^_"}],
"no-use-before-define": ["error"],
"quotes": ["off"], # Blockly mixes single and double quotes
"semi": ["error", "always"],
"space-before-function-paren": ["error", "never"], # Blockly doesn't have space before function paren
"strict": ["off"], # Blockly uses 'use strict' in files
"no-cond-assign": ["off"], # Blockly often uses cond-assignment in loops
"no-redeclare": ["off"], # Closure style allows redeclarations
"valid-jsdoc": ["error", {"requireReturn": false}],
"no-console": ["off"]
},
"env": {
"browser": true
},
"globals": {
"Blockly": true, # Blockly global
"goog": true # goog closure libraries/includes
},
"extends": "eslint:recommended"
}

View file

@ -499,16 +499,19 @@ Blockly.Blocks['text_getSubstring'] = {
var menu = new Blockly.FieldDropdown(this['WHERE_OPTIONS_' + n], var menu = new Blockly.FieldDropdown(this['WHERE_OPTIONS_' + n],
function(value) { function(value) {
var newAt = (value == 'FROM_START') || (value == 'FROM_END'); var newAt = (value == 'FROM_START') || (value == 'FROM_END');
// The 'isAt' variable is available due to this function being a closure. // The 'isAt' variable is available due to this function being a
// closure.
if (newAt != isAt) { if (newAt != isAt) {
var block = this.sourceBlock_; var block = this.sourceBlock_;
block.updateAt_(n, newAt); block.updateAt_(n, newAt);
// This menu has been destroyed and replaced. Update the replacement. // This menu has been destroyed and replaced.
// Update the replacement.
block.setFieldValue(value, 'WHERE' + n); block.setFieldValue(value, 'WHERE' + n);
return null; return null;
} }
return undefined; return undefined;
}); });
this.getInput('AT' + n) this.getInput('AT' + n)
.appendField(menu, 'WHERE' + n); .appendField(menu, 'WHERE' + n);
if (n == 1) { if (n == 1) {

View file

@ -535,7 +535,7 @@ Blockly.BlockSvg.prototype.renderDraw_ = function(iconWidth, inputRows) {
var cursorY = this.renderDrawRight_(steps, highlightSteps, inlineSteps, var cursorY = this.renderDrawRight_(steps, highlightSteps, inlineSteps,
highlightInlineSteps, connectionsXY, inputRows, iconWidth); highlightInlineSteps, connectionsXY, inputRows, iconWidth);
this.renderDrawBottom_(steps, highlightSteps, connectionsXY, cursorY); this.renderDrawBottom_(steps, highlightSteps, connectionsXY, cursorY);
this.renderDrawLeft_(steps, highlightSteps, connectionsXY, cursorY); this.renderDrawLeft_(steps, highlightSteps, connectionsXY);
var pathString = steps.join(' ') + '\n' + inlineSteps.join(' '); var pathString = steps.join(' ') + '\n' + inlineSteps.join(' ');
this.svgPath_.setAttribute('d', pathString); this.svgPath_.setAttribute('d', pathString);
@ -560,6 +560,7 @@ Blockly.BlockSvg.prototype.renderDraw_ = function(iconWidth, inputRows) {
*/ */
Blockly.BlockSvg.prototype.renderDrawTop_ = Blockly.BlockSvg.prototype.renderDrawTop_ =
function(steps, highlightSteps, connectionsXY, rightEdge) { function(steps, highlightSteps, connectionsXY, rightEdge) {
/* eslint-disable indent */
// Position the cursor at the top-left starting point. // Position the cursor at the top-left starting point.
if (this.squareTopLeftCorner_) { if (this.squareTopLeftCorner_) {
steps.push('m 0,0'); steps.push('m 0,0');
@ -596,7 +597,7 @@ Blockly.BlockSvg.prototype.renderDrawTop_ =
steps.push('H', rightEdge); steps.push('H', rightEdge);
highlightSteps.push('H', rightEdge - 0.5); highlightSteps.push('H', rightEdge - 0.5);
this.width = rightEdge; this.width = rightEdge;
}; }; /* eslint-enable indent */
/** /**
* Render the right edge of the block. * Render the right edge of the block.
@ -872,6 +873,7 @@ Blockly.BlockSvg.prototype.renderDrawRight_ = function(steps, highlightSteps,
*/ */
Blockly.BlockSvg.prototype.renderDrawBottom_ = Blockly.BlockSvg.prototype.renderDrawBottom_ =
function(steps, highlightSteps, connectionsXY, cursorY) { function(steps, highlightSteps, connectionsXY, cursorY) {
/* eslint-disable indent */
this.height += cursorY + 1; // Add one for the shadow. this.height += cursorY + 1; // Add one for the shadow.
if (this.nextConnection) { if (this.nextConnection) {
steps.push('H', (Blockly.BlockSvg.NOTCH_WIDTH + (this.RTL ? 0.5 : - 0.5)) + steps.push('H', (Blockly.BlockSvg.NOTCH_WIDTH + (this.RTL ? 0.5 : - 0.5)) +
@ -911,18 +913,18 @@ Blockly.BlockSvg.prototype.renderDrawBottom_ =
'0.5,' + (cursorY - Blockly.BlockSvg.CORNER_RADIUS)); '0.5,' + (cursorY - Blockly.BlockSvg.CORNER_RADIUS));
} }
} }
}; }; /* eslint-enable indent */
/** /**
* Render the left edge of the block. * Render the left edge of the block.
* @param {!Array.<string>} steps Path of block outline. * @param {!Array.<string>} steps Path of block outline.
* @param {!Array.<string>} highlightSteps Path of block highlights. * @param {!Array.<string>} highlightSteps Path of block highlights.
* @param {!Object} connectionsXY Location of block. * @param {!Object} connectionsXY Location of block.
* @param {number} cursorY Height of block.
* @private * @private
*/ */
Blockly.BlockSvg.prototype.renderDrawLeft_ = Blockly.BlockSvg.prototype.renderDrawLeft_ =
function(steps, highlightSteps, connectionsXY, cursorY) { function(steps, highlightSteps, connectionsXY) {
/* eslint-disable indent */
if (this.outputConnection) { if (this.outputConnection) {
// Create output connection. // Create output connection.
this.outputConnection.moveTo(connectionsXY.x, connectionsXY.y); this.outputConnection.moveTo(connectionsXY.x, connectionsXY.y);
@ -952,4 +954,4 @@ Blockly.BlockSvg.prototype.renderDrawLeft_ =
} }
} }
steps.push('z'); steps.push('z');
}; }; /* eslint-enable indent */

View file

@ -1461,6 +1461,7 @@ Blockly.BlockSvg.prototype.setColour = function(colour) {
*/ */
Blockly.BlockSvg.prototype.setPreviousStatement = Blockly.BlockSvg.prototype.setPreviousStatement =
function(newBoolean, opt_check) { function(newBoolean, opt_check) {
/* eslint-disable indent */
Blockly.BlockSvg.superClass_.setPreviousStatement.call(this, newBoolean, Blockly.BlockSvg.superClass_.setPreviousStatement.call(this, newBoolean,
opt_check); opt_check);
@ -1468,7 +1469,7 @@ Blockly.BlockSvg.prototype.setPreviousStatement =
this.render(); this.render();
this.bumpNeighbours_(); this.bumpNeighbours_();
} }
}; }; /* eslint-enable indent */
/** /**
* Set whether another block can chain onto the bottom of this block. * Set whether another block can chain onto the bottom of this block.

View file

@ -111,6 +111,7 @@ Blockly.ConnectionDB.prototype.findConnection = function(conn) {
*/ */
Blockly.ConnectionDB.prototype.findPositionForConnection_ = Blockly.ConnectionDB.prototype.findPositionForConnection_ =
function(connection) { function(connection) {
/* eslint-disable indent */
if (!this.length) { if (!this.length) {
return 0; return 0;
} }
@ -128,7 +129,7 @@ Blockly.ConnectionDB.prototype.findPositionForConnection_ =
} }
} }
return pointerMin; return pointerMin;
}; }; /* eslint-enable indent */
/** /**
* Remove a connection from the database. Must already exist in DB. * Remove a connection from the database. Must already exist in DB.

View file

@ -426,6 +426,7 @@ Blockly.Flyout.prototype.setBackgroundPathVertical_ = function(width, height) {
*/ */
Blockly.Flyout.prototype.setBackgroundPathHorizontal_ = Blockly.Flyout.prototype.setBackgroundPathHorizontal_ =
function(width, height) { function(width, height) {
/* eslint-disable indent */
var atTop = this.toolboxPosition_ == Blockly.TOOLBOX_AT_TOP; var atTop = this.toolboxPosition_ == Blockly.TOOLBOX_AT_TOP;
// Start at top left. // Start at top left.
var path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)]; var path = ['M 0,' + (atTop ? 0 : this.CORNER_RADIUS)];
@ -458,7 +459,7 @@ Blockly.Flyout.prototype.setBackgroundPathHorizontal_ =
path.push('z'); path.push('z');
} }
this.svgBackground_.setAttribute('d', path.join(' ')); this.svgBackground_.setAttribute('d', path.join(' '));
}; }; /* eslint-enable indent */
/** /**
* Scroll the flyout to the top. * Scroll the flyout to the top.
@ -568,12 +569,13 @@ Blockly.Flyout.prototype.show = function(xmlList) {
// IE 11 is an incompetant browser that fails to fire mouseout events. // IE 11 is an incompetant browser that fails to fire mouseout events.
// When the mouse is over the background, deselect all blocks. // When the mouse is over the background, deselect all blocks.
var deselectAll = function(e) { var deselectAll = function() {
var topBlocks = this.workspace_.getTopBlocks(false); var topBlocks = this.workspace_.getTopBlocks(false);
for (var i = 0, block; block = topBlocks[i]; i++) { for (var i = 0, block; block = topBlocks[i]; i++) {
block.removeSelect(); block.removeSelect();
} }
}; };
this.listeners_.push(Blockly.bindEvent_(this.svgBackground_, 'mouseover', this.listeners_.push(Blockly.bindEvent_(this.svgBackground_, 'mouseover',
this, deselectAll)); this, deselectAll));

View file

@ -134,7 +134,7 @@ Blockly.Options.prototype.parentWorkspace = null;
* If set, sets the translation of the workspace to match the scrollbars. * If set, sets the translation of the workspace to match the scrollbars.
* No-op if unset. * No-op if unset.
*/ */
Blockly.Options.prototype.setMetrics = function(translation) { return; }; Blockly.Options.prototype.setMetrics = function() { return; };
/** /**
* Return an object with the metrics required to size the workspace, or null * Return an object with the metrics required to size the workspace, or null

View file

@ -164,10 +164,7 @@ Blockly.RenderedConnection.prototype.closest = function(maxLimit, dx, dy) {
Blockly.RenderedConnection.prototype.highlight = function() { Blockly.RenderedConnection.prototype.highlight = function() {
var steps; var steps;
if (this.type == Blockly.INPUT_VALUE || this.type == Blockly.OUTPUT_VALUE) { if (this.type == Blockly.INPUT_VALUE || this.type == Blockly.OUTPUT_VALUE) {
var tabWidth = this.sourceBlock_.RTL ? -Blockly.BlockSvg.TAB_WIDTH :
Blockly.BlockSvg.TAB_WIDTH;
steps = 'm 0,0 ' + Blockly.BlockSvg.TAB_PATH_DOWN + ' v 5'; steps = 'm 0,0 ' + Blockly.BlockSvg.TAB_PATH_DOWN + ' v 5';
} else { } else {
steps = 'm -20,0 h 5 ' + Blockly.BlockSvg.NOTCH_PATH_LEFT + ' h 5'; steps = 'm -20,0 h 5 ' + Blockly.BlockSvg.NOTCH_PATH_LEFT + ' h 5';
} }

View file

@ -583,6 +583,9 @@ Blockly.Toolbox.TreeNode.prototype.onDoubleClick_ = function(e) {
/** /**
* A blank separator node in the tree. * A blank separator node in the tree.
* @param {Object=} config The configuration for the tree. See
* goog.ui.tree.TreeControl.DefaultConfig. If not specified, a default config
* will be used.
* @constructor * @constructor
* @extends {Blockly.Toolbox.TreeNode} * @extends {Blockly.Toolbox.TreeNode}
*/ */

View file

@ -290,7 +290,7 @@ Blockly.WorkspaceSvg.prototype.addFlyout_ = function() {
parentWorkspace: this, parentWorkspace: this,
RTL: this.RTL, RTL: this.RTL,
horizontalLayout: this.horizontalLayout, horizontalLayout: this.horizontalLayout,
toolboxPosition: this.options.toolboxPosition, toolboxPosition: this.options.toolboxPosition
}; };
/** @type {Blockly.Flyout} */ /** @type {Blockly.Flyout} */
this.flyout_ = new Blockly.Flyout(workspaceOptions); this.flyout_ = new Blockly.Flyout(workspaceOptions);
@ -820,18 +820,7 @@ Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) {
for (var i = 0; i < topBlocks.length; i++) { for (var i = 0; i < topBlocks.length; i++) {
addDeletableBlocks(topBlocks[i]); addDeletableBlocks(topBlocks[i]);
} }
var deleteOption = {
text: deleteList.length == 1 ? Blockly.Msg.DELETE_BLOCK :
Blockly.Msg.DELETE_X_BLOCKS.replace('%1', String(deleteList.length)),
enabled: deleteList.length > 0,
callback: function() {
if (deleteList.length < 2 ||
window.confirm(Blockly.Msg.DELETE_ALL_BLOCKS.replace('%1',
String(deleteList.length)))) {
deleteNext();
}
}
};
function deleteNext() { function deleteNext() {
Blockly.Events.setGroup(eventGroup); Blockly.Events.setGroup(eventGroup);
var block = deleteList.shift(); var block = deleteList.shift();
@ -845,6 +834,19 @@ Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) {
} }
Blockly.Events.setGroup(false); Blockly.Events.setGroup(false);
} }
var deleteOption = {
text: deleteList.length == 1 ? Blockly.Msg.DELETE_BLOCK :
Blockly.Msg.DELETE_X_BLOCKS.replace('%1', String(deleteList.length)),
enabled: deleteList.length > 0,
callback: function() {
if (deleteList.length < 2 ||
window.confirm(Blockly.Msg.DELETE_ALL_BLOCKS.replace('%1',
String(deleteList.length)))) {
deleteNext();
}
}
};
menuOptions.push(deleteOption); menuOptions.push(deleteOption);
Blockly.ContextMenu.show(e, menuOptions, this.RTL); Blockly.ContextMenu.show(e, menuOptions, this.RTL);