Re-enable the max-len ESLint rule. (#5265)

This commit is contained in:
Logan Smyth
2017-02-04 08:07:15 -08:00
committed by Henry Zhu
parent 4d411ef83e
commit b845f2b69d
63 changed files with 317 additions and 223 deletions

View File

@@ -1,12 +1,7 @@
/* eslint indent: 0 */
/* eslint max-len: 0 */
import type NodePath from "./index";
// This file contains Babels metainterpreter that can evaluate static code.
/* eslint eqeqeq: 0 */
const VALID_CALLEES = ["String", "Number", "Math"];
const INVALID_METHODS = ["random"];
@@ -316,7 +311,7 @@ export function evaluate(): { confident: boolean; value: any } {
case ">": return left > right;
case "<=": return left <= right;
case ">=": return left >= right;
case "==": return left == right;
case "==": return left == right; // eslint-disable-line eqeqeq
case "!=": return left != right;
case "===": return left === right;
case "!==": return left !== right;
@@ -335,7 +330,10 @@ export function evaluate(): { confident: boolean; value: any } {
let func;
// Number(1);
if (callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) && VALID_CALLEES.indexOf(callee.node.name) >= 0) {
if (
callee.isIdentifier() && !path.scope.getBinding(callee.node.name, true) &&
VALID_CALLEES.indexOf(callee.node.name) >= 0
) {
func = global[node.callee.name];
}
@@ -344,7 +342,11 @@ export function evaluate(): { confident: boolean; value: any } {
const property = callee.get("property");
// Math.min(1, 2)
if (object.isIdentifier() && property.isIdentifier() && VALID_CALLEES.indexOf(object.node.name) >= 0 && INVALID_METHODS.indexOf(property.node.name) < 0) {
if (
object.isIdentifier() && property.isIdentifier() &&
VALID_CALLEES.indexOf(object.node.name) >= 0 &&
INVALID_METHODS.indexOf(property.node.name) < 0
) {
context = global[object.node.name];
func = context[property.node.name];
}

View File

@@ -1,5 +1,3 @@
/* eslint max-len: 0 */
import type Hub from "../hub";
import type TraversalContext from "../context";
import * as virtualTypes from "./lib/virtual-types";

View File

@@ -153,7 +153,8 @@ export default class PathHoister {
const attachTo = this.getAttachmentPath();
if (!attachTo) return;
// don't bother hoisting to the same function as this will cause multiple branches to be evaluated more than once leading to a bad optimisation
// don't bother hoisting to the same function as this will cause multiple branches to be
// evaluated more than once leading to a bad optimisation
if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
// generate declaration and insert it to our point

View File

@@ -6,28 +6,29 @@
export const hooks = [
function (self, parent) {
let removeParent = false;
const removeParent =
// while (NODE);
// removing the test of a while/switch, we can either just remove it entirely *or* turn the
// `test` into `true` unlikely that the latter will ever be what's wanted so we just remove
// the loop to avoid infinite recursion
(self.key === "test" && (parent.isWhile() || parent.isSwitchCase())) ||
// while (NODE);
// removing the test of a while/switch, we can either just remove it entirely *or* turn the `test` into `true`
// unlikely that the latter will ever be what's wanted so we just remove the loop to avoid infinite recursion
removeParent = removeParent || (self.key === "test" && (parent.isWhile() || parent.isSwitchCase()));
// export NODE;
// just remove a declaration for an export as this is no longer valid
(self.key === "declaration" && parent.isExportDeclaration()) ||
// export NODE;
// just remove a declaration for an export as this is no longer valid
removeParent = removeParent || (self.key === "declaration" && parent.isExportDeclaration());
// label: NODE
// stray labeled statement with no body
(self.key === "body" && parent.isLabeledStatement()) ||
// label: NODE
// stray labeled statement with no body
removeParent = removeParent || (self.key === "body" && parent.isLabeledStatement());
// let NODE;
// remove an entire declaration if there are no declarators left
(self.listKey === "declarations" && parent.isVariableDeclaration() &&
parent.node.declarations.length === 1) ||
// let NODE;
// remove an entire declaration if there are no declarators left
removeParent = removeParent || (self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1);
// NODE;
// remove the entire expression statement if there's no expression
removeParent = removeParent || (self.key === "expression" && parent.isExpressionStatement());
// NODE;
// remove the entire expression statement if there's no expression
(self.key === "expression" && parent.isExpressionStatement());
if (removeParent) {
parent.remove();

View File

@@ -1,4 +1,3 @@
/* eslint max-len: 0 */
// This file contains methods that modify the path/node in some ways.
import { path as pathCache } from "../cache";
@@ -17,7 +16,10 @@ export function insertBefore(nodes) {
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
return this.parentPath.insertBefore(nodes);
} else if (this.isNodeType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
} else if (
this.isNodeType("Expression") ||
(this.parentPath.isForStatement() && this.key === "init")
) {
if (this.node) nodes.push(this.node);
this.replaceExpressionWithStatements(nodes);
} else {
@@ -28,7 +30,8 @@ export function insertBefore(nodes) {
if (this.node) nodes.push(this.node);
this._replaceWith(t.blockStatement(nodes));
} else {
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
throw new Error("We don't know what to do with this node type. " +
"We were previously a Statement but we can't fit in here?");
}
}
@@ -88,7 +91,8 @@ export function _containerInsertAfter(nodes) {
export function _maybePopFromStatements(nodes) {
const last = nodes[nodes.length - 1];
const isIdentifier = t.isIdentifier(last) || (t.isExpressionStatement(last) && t.isIdentifier(last.expression));
const isIdentifier = t.isIdentifier(last) ||
(t.isExpressionStatement(last) && t.isIdentifier(last.expression));
if (isIdentifier && !this.isCompletionRecord()) {
nodes.pop();
@@ -107,7 +111,10 @@ export function insertAfter(nodes) {
if (this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement()) {
return this.parentPath.insertAfter(nodes);
} else if (this.isNodeType("Expression") || (this.parentPath.isForStatement() && this.key === "init")) {
} else if (
this.isNodeType("Expression") ||
(this.parentPath.isForStatement() && this.key === "init")
) {
if (this.node) {
const temp = this.scope.generateDeclaredUidIdentifier();
nodes.unshift(t.expressionStatement(t.assignmentExpression("=", temp, this.node)));
@@ -122,7 +129,8 @@ export function insertAfter(nodes) {
if (this.node) nodes.unshift(this.node);
this._replaceWith(t.blockStatement(nodes));
} else {
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
throw new Error("We don't know what to do with this node type. " +
"We were previously a Statement but we can't fit in here?");
}
}

View File

@@ -1,4 +1,3 @@
/* eslint max-len: 0 */
// This file contains methods responsible for replacing a node with another.
import codeFrame from "babel-code-frame";
@@ -114,22 +113,30 @@ export function replaceWith(replacement) {
}
if (Array.isArray(replacement)) {
throw new Error("Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`");
throw new Error(
"Don't use `path.replaceWith()` with an array of nodes, use `path.replaceWithMultiple()`");
}
if (typeof replacement === "string") {
throw new Error("Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`");
throw new Error(
"Don't use `path.replaceWith()` with a source string, use `path.replaceWithSourceString()`");
}
if (this.isNodeType("Statement") && t.isExpression(replacement)) {
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) {
if (
!this.canHaveVariableDeclarationOrExpression() &&
!this.canSwapBetweenExpressionAndStatement(replacement)
) {
// replacing a statement with an expression so wrap it in an expression statement
replacement = t.expressionStatement(replacement);
}
}
if (this.isNodeType("Expression") && t.isStatement(replacement)) {
if (!this.canHaveVariableDeclarationOrExpression() && !this.canSwapBetweenExpressionAndStatement(replacement)) {
if (
!this.canHaveVariableDeclarationOrExpression() &&
!this.canSwapBetweenExpressionAndStatement(replacement)
) {
// replacing an expression with a statement so let's explode it
return this.replaceExpressionWithStatements([replacement]);
}