tools: update to ESLint 3.2.2 · nodejs/node@e313c02
@@ -9,18 +9,19 @@
99// Requirements
1010//------------------------------------------------------------------------------
111112-var esutils = require("esutils");
12+let esutils = require("esutils");
13131414//------------------------------------------------------------------------------
1515// Helpers
1616//------------------------------------------------------------------------------
171718-var anyFunctionPattern = /^(?:Function(?:Declaration|Expression)|ArrowFunctionExpression)$/;
19-var arrayOrTypedArrayPattern = /Array$/;
20-var arrayMethodPattern = /^(?:every|filter|find|findIndex|forEach|map|some)$/;
21-var bindOrCallOrApplyPattern = /^(?:bind|call|apply)$/;
22-var breakableTypePattern = /^(?:(?:Do)?While|For(?:In|Of)?|Switch)Statement$/;
23-var thisTagPattern = /^[\s\*]*@this/m;
18+let anyFunctionPattern = /^(?:Function(?:Declaration|Expression)|ArrowFunctionExpression)$/;
19+let anyLoopPattern = /^(?:DoWhile|For|ForIn|ForOf|While)Statement$/;
20+let arrayOrTypedArrayPattern = /Array$/;
21+let arrayMethodPattern = /^(?:every|filter|find|findIndex|forEach|map|some)$/;
22+let bindOrCallOrApplyPattern = /^(?:bind|call|apply)$/;
23+let breakableTypePattern = /^(?:(?:Do)?While|For(?:In|Of)?|Switch)Statement$/;
24+let thisTagPattern = /^[\s\*]*@this/m;
24252526/**
2627 * Checks reference if is non initializer and writable.
@@ -31,7 +32,7 @@ var thisTagPattern = /^[\s\*]*@this/m;
3132 * @private
3233 */
3334function isModifyingReference(reference, index, references) {
34-var identifier = reference.identifier,
35+let identifier = reference.identifier,
3536modifyingDifferentIdentifier;
36373738/*
@@ -159,7 +160,7 @@ function isMethodWhichHasThisArg(node) {
159160 * @returns {boolean} Whether or not the node has a `@this` tag in its comments.
160161 */
161162function hasJSDocThisTag(node, sourceCode) {
162-var jsdocComment = sourceCode.getJSDocComment(node);
163+let jsdocComment = sourceCode.getJSDocComment(node);
163164164165if (jsdocComment && thisTagPattern.test(jsdocComment.value)) {
165166return true;
@@ -182,7 +183,7 @@ function hasJSDocThisTag(node, sourceCode) {
182183 * @private
183184 */
184185function isParenthesised(sourceCode, node) {
185-var previousToken = sourceCode.getTokenBefore(node),
186+let previousToken = sourceCode.getTokenBefore(node),
186187nextToken = sourceCode.getTokenAfter(node);
187188188189return Boolean(previousToken && nextToken) &&
@@ -284,7 +285,7 @@ module.exports = {
284285 * @returns {boolean} `true` if the node is an ESLint directive comment
285286 */
286287isDirectiveComment: function(node) {
287-var comment = node.value.trim();
288+let comment = node.value.trim();
288289289290return (
290291node.type === "Line" && comment.indexOf("eslint-") === 0 ||
@@ -317,10 +318,10 @@ module.exports = {
317318 * @returns {escope.Variable|null} A found variable or `null`.
318319 */
319320getVariableByName: function(initScope, name) {
320-var scope = initScope;
321+let scope = initScope;
321322322323while (scope) {
323-var variable = scope.set.get(name);
324+let variable = scope.set.get(name);
324325325326if (variable) {
326327return variable;
@@ -359,7 +360,7 @@ module.exports = {
359360}
360361361362while (node) {
362-var parent = node.parent;
363+let parent = node.parent;
363364364365switch (parent.type) {
365366@@ -378,14 +379,15 @@ module.exports = {
378379// // setup...
379380// return function foo() { ... };
380381// })();
381-case "ReturnStatement":
382-var func = getUpperFunction(parent);
382+case "ReturnStatement": {
383+const func = getUpperFunction(parent);
383384384385if (func === null || !isCallee(func)) {
385386return true;
386387}
387388node = func.parent;
388389break;
390+}
389391390392// e.g.
391393// var obj = { foo() { ... } };
@@ -551,5 +553,37 @@ module.exports = {
551553// no default
552554}
553555return 18;
556+},
557+558+/**
559+ * Checks whether a given node is a loop node or not.
560+ * The following types are loop nodes:
561+ *
562+ * - DoWhileStatement
563+ * - ForInStatement
564+ * - ForOfStatement
565+ * - ForStatement
566+ * - WhileStatement
567+ *
568+ * @param {ASTNode|null} node - A node to check.
569+ * @returns {boolean} `true` if the node is a loop node.
570+ */
571+isLoop: function(node) {
572+return Boolean(node && anyLoopPattern.test(node.type));
573+},
574+575+/**
576+ * Checks whether a given node is a function node or not.
577+ * The following types are function nodes:
578+ *
579+ * - ArrowFunctionExpression
580+ * - FunctionDeclaration
581+ * - FunctionExpression
582+ *
583+ * @param {ASTNode|null} node - A node to check.
584+ * @returns {boolean} `true` if the node is a function node.
585+ */
586+isFunction: function(node) {
587+return Boolean(node && anyFunctionPattern.test(node.type));
554588}
555589};