diff options
author | Rich Trott <rtrott@gmail.com> | 2016-07-07 15:44:32 -0700 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2016-07-11 13:47:20 -0700 |
commit | e8a7003e940928e2d1684c12881dd2a39af2d7cc (patch) | |
tree | 92264eb4c317b287366e7774f6d4e15000856e06 /tools/eslint/lib/ast-utils.js | |
parent | fcae5e2d9187b4a9c16cbce843c10e2087990946 (diff) | |
download | android-node-v8-e8a7003e940928e2d1684c12881dd2a39af2d7cc.tar.gz android-node-v8-e8a7003e940928e2d1684c12881dd2a39af2d7cc.tar.bz2 android-node-v8-e8a7003e940928e2d1684c12881dd2a39af2d7cc.zip |
tools: update ESLint, fix unused vars bug
Update ESLint to 3.0.0. This includes an enhancement to `no-unused-vars`
such that it finds a few instances in our code base that it did not find
previously (fixed in previous commits readying this for landing).
PR-URL: https://github.com/nodejs/node/pull/7601
Reviewed-By: Michaƫl Zasso <mic.besace@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Diffstat (limited to 'tools/eslint/lib/ast-utils.js')
-rw-r--r-- | tools/eslint/lib/ast-utils.js | 101 |
1 files changed, 96 insertions, 5 deletions
diff --git a/tools/eslint/lib/ast-utils.js b/tools/eslint/lib/ast-utils.js index e008beeb2a..c8d6dcb491 100644 --- a/tools/eslint/lib/ast-utils.js +++ b/tools/eslint/lib/ast-utils.js @@ -57,7 +57,7 @@ function isModifyingReference(reference, index, references) { function isES5Constructor(node) { return ( node.id && - node.id.name[0] === node.id.name[0].toLocaleUpperCase() + node.id.name[0] !== node.id.name[0].toLocaleLowerCase() ); } @@ -176,14 +176,14 @@ function hasJSDocThisTag(node, sourceCode) { /** * Determines if a node is surrounded by parentheses. - * @param {RuleContext} context The context object passed to the rule + * @param {SourceCode} sourceCode The ESLint source code object * @param {ASTNode} node The node to be checked. * @returns {boolean} True if the node is parenthesised. * @private */ -function isParenthesised(context, node) { - var previousToken = context.getTokenBefore(node), - nextToken = context.getTokenAfter(node); +function isParenthesised(sourceCode, node) { + var previousToken = sourceCode.getTokenBefore(node), + nextToken = sourceCode.getTokenAfter(node); return Boolean(previousToken && nextToken) && previousToken.value === "(" && previousToken.range[1] <= node.range[0] && @@ -460,5 +460,96 @@ module.exports = { /* istanbul ignore next */ return true; + }, + + /** + * Get the precedence level based on the node type + * @param {ASTNode} node node to evaluate + * @returns {int} precedence level + * @private + */ + getPrecedence: function(node) { + switch (node.type) { + case "SequenceExpression": + return 0; + + case "AssignmentExpression": + case "ArrowFunctionExpression": + case "YieldExpression": + return 1; + + case "ConditionalExpression": + return 3; + + case "LogicalExpression": + switch (node.operator) { + case "||": + return 4; + case "&&": + return 5; + + // no default + } + + /* falls through */ + + case "BinaryExpression": + + switch (node.operator) { + case "|": + return 6; + case "^": + return 7; + case "&": + return 8; + case "==": + case "!=": + case "===": + case "!==": + return 9; + case "<": + case "<=": + case ">": + case ">=": + case "in": + case "instanceof": + return 10; + case "<<": + case ">>": + case ">>>": + return 11; + case "+": + case "-": + return 12; + case "*": + case "/": + case "%": + return 13; + + // no default + } + + /* falls through */ + + case "UnaryExpression": + return 14; + + case "UpdateExpression": + return 15; + + case "CallExpression": + + // IIFE is allowed to have parens in any position (#655) + if (node.callee.type === "FunctionExpression") { + return -1; + } + return 16; + + case "NewExpression": + return 17; + + // no default + } + return 18; } }; |