reneable eslint and fix assorted linting errors

This commit is contained in:
Sebastian McKenzie 2015-05-25 00:42:59 +01:00
parent 3139482358
commit ec74eb41cf
36 changed files with 92 additions and 86 deletions

View File

@ -10,11 +10,15 @@
"no-return-assign": 0,
"consistent-return": 0,
"no-shadow": 0,
"no-comma-dangle": 0,
"comma-dangle": 0,
"no-use-before-define": 0,
"no-empty": 0,
"new-parens": 0,
"no-cond-assign": 0
"no-cond-assign": 0,
"no-fallthrough": 0,
"new-cap": 0,
"no-loop-func": 0,
"no-unreachable": 0
},
"env": {
"node": true

View File

@ -22,6 +22,9 @@ watch-core: clean-core
clean-core:
rm -rf lib
lint:
eslint src/babel
build:
mkdir -p dist
make build-core
@ -61,7 +64,7 @@ test-cov:
test-parser:
node test/acorn/run.js
test-travis: bootstrap build test
test-travis: bootstrap lint build test
test-browser:
mkdir -p dist
@ -73,7 +76,7 @@ test-browser:
test -n "`which open`" && open test/browser.html
publish:
publish: lint
git pull --rebase
make test

View File

@ -67,8 +67,8 @@
"babel": "5.3.1",
"browserify": "^9.0.8",
"chai": "^2.2.0",
"eslint": "^0.18.0",
"babel-eslint": "^2.0.0",
"eslint": "^0.21.2",
"babel-eslint": "^3.1.8",
"esvalid": "^1.1.0",
"istanbul": "^0.3.5",
"matcha": "^0.6.0",

View File

@ -1,3 +1,5 @@
/* eslint no-new-func: 0 */
require("./node");
var transform = module.exports = require("../transformation");

View File

@ -1,5 +1,5 @@
// required to safely use babel/register within a browserify codebase
export default function () {};
export default function () {}
import "../../polyfill";

View File

@ -164,4 +164,4 @@ export default function (opts = {}) {
delete opts.only;
extend(transformOpts, opts);
};
}

View File

@ -107,9 +107,9 @@ export function ImportDeclaration(node, print) {
if (node.specifiers.length) {
this.push("{");
this.space()
this.space();
print.join(node.specifiers, { separator: ", " });
this.space()
this.space();
this.push("}");
}

View File

@ -1,3 +1,5 @@
/* eslint quotes: 0 */
import each from "lodash/collection/each";
import * as t from "../../types";

View File

@ -252,21 +252,23 @@ class CodeGenerator {
if (opts.indent) this.indent();
var printOpts = {
statement: opts.statement,
addNewlines: opts.addNewlines,
after: () => {
if (opts.iterator) {
opts.iterator(node, i);
}
if (opts.separator && i < len - 1) {
this.push(opts.separator);
}
}
};
for (var i = 0; i < nodes.length; i++) {
var node = nodes[i];
print(node, {
statement: opts.statement,
addNewlines: opts.addNewlines,
after: () => {
if (opts.iterator) {
opts.iterator(node, i);
}
if (opts.separator && i < len - 1) {
this.push(opts.separator);
}
}
});
print(node, printOpts);
}
if (opts.indent) this.dedent();
@ -318,7 +320,7 @@ class CodeGenerator {
nodes.push(node.argument);
}
for (var node of (nodes: Array)) {
for (let node of (nodes: Array)) {
comments = comments.concat(this._getComments(key, node));
}

View File

@ -85,4 +85,4 @@ export default function (lines: number, lineNumber: number, colNumber: number, o
params.before = params.before.replace(/^./, ">");
}
}).join("\n");
};
}

View File

@ -6,4 +6,4 @@ export default function (ast, comments, tokens) {
} else {
throw new Error("Not a valid ast?");
}
};
}

View File

@ -1,3 +1,3 @@
export default function () {
return Object.create(null);
};
}

View File

@ -83,4 +83,4 @@ export default function (whitelist, outputType = "global") {
}
return generator(tree).code;
};
}

View File

@ -56,4 +56,4 @@ export default function (loc, opts = {}) {
}
return opts;
};
}

View File

@ -3,7 +3,7 @@ import * as optionParsers from "./option-parsers";
import moduleFormatters from "../modules";
import PluginManager from "./plugin-manager";
import shebangRegex from "shebang-regex";
import TraversalPath from "../../traversal/path";
import NodePath from "../../traversal/path";
import Transformer from "../transformer";
import isFunction from "lodash/lang/isFunction";
import isAbsolute from "path-is-absolute";
@ -195,7 +195,7 @@ export default class File {
// build internal transformers
for (var key in this.pipeline.transformers) {
var transformer = this.pipeline.transformers[key];
var pass = transformers[key] = transformer.buildPass(file);
let pass = transformers[key] = transformer.buildPass(file);
if (pass.canTransform()) {
stack.push(pass);
@ -228,7 +228,7 @@ export default class File {
this.uncollapsedTransformerStack = stack = stack.concat(secondaryStack);
// build dependency graph
for (var pass of (stack: Array)) {
for (let pass of (stack: Array)) {
for (var dep of (pass.transformer.dependencies: Array)) {
this.transformerDependencies[dep] = pass.key;
}
@ -410,7 +410,7 @@ export default class File {
outputMapGenerator.applySourceMap(inputMapConsumer);
var mergedMap = outputMapGenerator.toJSON();
mergedMap.sources = inputMap.sources
mergedMap.sources = inputMap.sources;
mergedMap.file = inputMap.file;
return mergedMap;
}
@ -467,7 +467,7 @@ export default class File {
}
_addAst(ast) {
this.path = TraversalPath.get(null, ast, ast, "program", this).setContext(null, this);
this.path = NodePath.get(null, ast, ast, "program", this).setContext(null, this);
this.scope = this.path.scope;
this.ast = ast;
}

View File

@ -44,4 +44,4 @@ export default function (opts) {
};
return exports;
};
}

View File

@ -42,4 +42,4 @@ export default function (exports, opts) {
return nodes;
};
};
}

View File

@ -202,4 +202,4 @@ export default function (exports, opts) {
addDisplayName(left.name, right);
}
};
};
}

View File

@ -68,4 +68,4 @@ export default function (node, nodes, file, scope, allowedSingleIdent) {
uid: uid,
ref: ref
};
};
}

View File

@ -6,4 +6,4 @@ export default function (node) {
if (!t.isAssignmentPattern(node.params[i])) lastNonDefault = i + 1;
}
return lastNonDefault;
};
}

View File

@ -55,4 +55,4 @@ export default function (node, callId, scope) {
return call;
}
};
}

View File

@ -130,7 +130,7 @@ export default class ReplaceSupers {
* Description
*/
traverseLevel(path: TraversalPath, topLevel: boolean) {
traverseLevel(path: NodePath, topLevel: boolean) {
var state = { self: this, topLevel: topLevel };
path.traverse(visitor, state);
}
@ -192,7 +192,7 @@ export default class ReplaceSupers {
* Description
*/
looseHandle(path: TraversalPath, getThisReference: Function) {
looseHandle(path: NodePath, getThisReference: Function) {
var node = path.node;
if (path.isSuper()) {
return this.getLooseSuperProperty(node, path.parent);
@ -234,7 +234,7 @@ export default class ReplaceSupers {
* Description
*/
specHandle(path: TraversalPath, getThisReference: Function) {
specHandle(path: NodePath, getThisReference: Function) {
var methodNode = this.methodNode;
var property;
var computed;
@ -274,7 +274,7 @@ export default class ReplaceSupers {
property = node.property;
computed = node.computed;
} else if (t.isUpdateExpression(node) && isMemberExpressionSuper(node.argument)) {
var binary = t.binaryExpression(node.operator[0], node.argument, t.literal(1))
var binary = t.binaryExpression(node.operator[0], node.argument, t.literal(1));
if (node.prefix) {
// ++super.foo; -> super.foo += 1;
return this.specHandleAssignmentExpression(null, path, binary, getThisReference);

View File

@ -86,7 +86,7 @@ var metadataVisitor = {
var declar = this.get("declaration");
if (declar.isStatement()) {
var bindings = declar.getBindingIdentifiers()
var bindings = declar.getBindingIdentifiers();
for (var name in bindings) {
var binding = bindings[name];
formatter._addExport(name, binding);

View File

@ -10,4 +10,4 @@ export default function (Parent) {
util.inherits(Constructor, Parent);
return Constructor;
};
}

View File

@ -258,7 +258,7 @@ class BlockScoping {
* Description
*/
constructor(loopPath?: TraversalPath, blockPath: TraversalPath, parent: Object, scope: Scope, file: File) {
constructor(loopPath?: NodePath, blockPath: NodePath, parent: Object, scope: Scope, file: File) {
this.parent = parent;
this.scope = scope;
this.file = file;

View File

@ -104,7 +104,7 @@ class ClassTransformer {
* Description
*/
constructor(path: TraversalPath, file: File) {
constructor(path: NodePath, file: File) {
this.parent = path.parent;
this.scope = path.scope;
this.node = path.node;
@ -262,7 +262,7 @@ class ClassTransformer {
var map = defineMap.push(mutatorMap, node, kind, this.file);
if (enumerable) {
map.enumerable = t.literal(true)
map.enumerable = t.literal(true);
}
if (map.decorators) {
@ -375,7 +375,7 @@ class ClassTransformer {
}
var lastNonNullIndex = 0;
for (var i = 0; i < args.length; i++) {
for (let i = 0; i < args.length; i++) {
if (args[i] !== nullNode) lastNonNullIndex = i;
}
args = args.slice(0, lastNonNullIndex + 1);
@ -450,7 +450,7 @@ class ClassTransformer {
* Description
*/
verifyConstructor(path: TraversalPath) {
verifyConstructor(path: NodePath) {
var state = {
hasBareSuper: false,
bareSuper: null,
@ -471,7 +471,7 @@ class ClassTransformer {
* Push a method to its respective mutatorMap.
*/
pushMethod(node: { type: "MethodDefinition" }, path?: TraversalPath, allowedIllegal?) {
pushMethod(node: { type: "MethodDefinition" }, path?: NodePath, allowedIllegal?) {
if (!allowedIllegal && t.isLiteral(t.toComputedKey(node), { value: PROPERTY_COLLISION_METHOD_NAME })) {
throw this.file.errorWithNode(node, messages.get("illegalMethodName", PROPERTY_COLLISION_METHOD_NAME));
}
@ -519,7 +519,6 @@ class ClassTransformer {
this.pushToMap(node, true, "initializer");
var initializers;
var body;
var target;
if (node.static) {
initializers = this.staticInitializersId = this.staticInitializersId || this.scope.generateUidIdentifier("staticInitializers");
@ -558,7 +557,7 @@ class ClassTransformer {
* Replace the constructor body of our class.
*/
pushConstructor(method: { type: "MethodDefinition" }, path: TraversalPath) {
pushConstructor(method: { type: "MethodDefinition" }, path: NodePath) {
// https://github.com/babel/babel/issues/1077
var fnPath = path.get("value");
if (fnPath.scope.hasOwnBinding(this.classRef.name)) {

View File

@ -204,7 +204,7 @@ class TailCallTransformer {
}
if (this.needsArguments || this.setsArguments) {
for (var path of (this.argumentsPaths: Array)) {
for (let path of (this.argumentsPaths: Array)) {
path.replaceWith(this.argumentsId);
}
@ -356,14 +356,14 @@ class TailCallTransformer {
var elems = args.elements;
for (let i = 0; i < elems.length && i < params.length; i++) {
let param = params[i];
var elem = elems[i] || (elems[i] = t.identifier("undefined"));
let elem = elems[i] || (elems[i] = t.identifier("undefined"));
if (!param._isDefaultPlaceholder) {
elems[i] = t.assignmentExpression("=", param, elem);
}
}
if (!this.needsArguments) {
for (var elem of (elems: Array)) {
for (let elem of (elems: Array)) {
body.push(t.expressionStatement(elem));
}
}

View File

@ -10,8 +10,8 @@ export var metadata = {
export function ObjectExpression(node, parent, scope, file) {
var hasDecorators = false;
for (var i = 0; i < node.properties.length; i++) {
var prop = node.properties[i];
for (let i = 0; i < node.properties.length; i++) {
let prop = node.properties[i];
if (prop.decorators) {
hasDecorators = true;
break;
@ -21,8 +21,8 @@ export function ObjectExpression(node, parent, scope, file) {
var mutatorMap = {};
for (var i = 0; i < node.properties.length; i++) {
var prop = node.properties[i];
for (let i = 0; i < node.properties.length; i++) {
let prop = node.properties[i];
if (prop.decorators) memoiseDecorators(prop.decorators, scope);

View File

@ -24,7 +24,7 @@ export function ExportDefaultDeclaration(node, parent, scope) {
if (t.isClassDeclaration(declar)) {
// export default class Foo {};
var nodes = [getDeclar(node), node];
let nodes = [getDeclar(node), node];
node.declaration = declar.id;
return nodes;
} else if (t.isClassExpression(declar)) {
@ -34,14 +34,14 @@ export function ExportDefaultDeclaration(node, parent, scope) {
t.variableDeclarator(temp, declar)
]);
var nodes = [getDeclar(node), node];
let nodes = [getDeclar(node), node];
node.declaration = temp;
return nodes;
} else if (t.isFunctionDeclaration(declar)) {
// export default function Foo() {}
node._blockHoist = 2;
var nodes = [getDeclar(node), node];
let nodes = [getDeclar(node), node];
node.declaration = declar.id;
return nodes;
}
@ -57,7 +57,8 @@ export function ExportNamedDeclaration(node, parent, scope) {
if (t.isClassDeclaration(declar)) {
// export class Foo {}
node.specifiers = [buildExportSpecifier(declar.id)];
var nodes = [getDeclar(node), node];
let nodes = [getDeclar(node), node];
node.declaration = null;
return nodes;
} else if (t.isFunctionDeclaration(declar)) {
@ -65,7 +66,7 @@ export function ExportNamedDeclaration(node, parent, scope) {
node.specifiers = [buildExportSpecifier(declar.id)];
node._blockHoist = 2;
var nodes = [getDeclar(node), node];
let nodes = [getDeclar(node), node];
node.declaration = null;
return nodes;
} else if (t.isVariableDeclaration(declar)) {

View File

@ -5,6 +5,6 @@ export var metadata = {
group: "builtin-setup"
};
export function DebuggerStatement(node) {
this.remove();
export function DebuggerStatement(node) {
this.remove();
}

View File

@ -24,7 +24,7 @@ export var Program = {
}
directive._blockHoist = Infinity;
}
}
};
export function ThisExpression() {
if (!this.findParent((node) => !node.shadow && THIS_BREAK_KEYS.indexOf(node.type) >= 0)) {

View File

@ -4,7 +4,7 @@ function statementList(key, path, file) {
var paths = path.get(key);
for (var i = 0; i < paths.length; i++) {
var path = paths[i];
let path = paths[i];
var func = path.node;
if (!t.isFunctionDeclaration(func)) continue;

View File

@ -46,17 +46,17 @@ traverse.node = function (node, opts, scope, state, parentPath) {
const CLEAR_KEYS = [
"trailingComments", "leadingComments", "extendedRange",
"_scopeInfo" ,"_paths",
"_scopeInfo", "_paths",
"tokens", "range", "start", "end", "loc", "raw"
];
function clearNode(node) {
for (var i = 0; i < CLEAR_KEYS.length; i++) {
var key = CLEAR_KEYS[i];
let key = CLEAR_KEYS[i];
if (node[key] != null) node[key] = null;
}
for (var key in node) {
for (let key in node) {
var val = node[key];
if (Array.isArray(val)) {
delete val._paths;

View File

@ -1,4 +1,4 @@
import * as virtualTypes from "./path/virtual-types";
import * as virtualTypes from "./path/lib/virtual-types";
import * as messages from "../messages";
import * as t from "../types";
import clone from "lodash/lang/clone";
@ -29,7 +29,7 @@ export function explode(visitor) {
if (!wrapper) continue;
// wrap all the functions
var fns = visitor[nodeType];
let fns = visitor[nodeType];
for (let type in fns) {
fns[type] = wrapCheck(wrapper, fns[type]);
}
@ -55,7 +55,7 @@ export function explode(visitor) {
for (let nodeType in visitor) {
if (shouldIgnoreKey(nodeType)) continue;
var fns = visitor[nodeType];
let fns = visitor[nodeType];
var aliases = t.FLIPPED_ALIAS_KEYS[nodeType];
if (!aliases) continue;

View File

@ -72,6 +72,7 @@ export function isReferenced(node: Object, parent: Object): boolean {
// no: import { NODE as foo } from "foo";
// no: import { foo as NODE } from "foo";
// no: import NODE from "bar";
case "ImportSpecifier":
return false;
@ -106,14 +107,6 @@ export function isReferenced(node: Object, parent: Object): boolean {
case "ObjectPattern":
case "ArrayPattern":
return false;
// no: import NODE from "bar";
case "ImportSpecifier":
return false;
// no: import * as NODE from "foo";
case "ImportNamespaceSpecifier":
return false;
}
return true;

View File

@ -112,12 +112,12 @@ export function shouldIgnore(filename, ignore, only) {
filename = slash(filename);
if (only.length) {
for (var pattern of (only: Array)) {
for (let pattern of (only: Array)) {
if (pattern.test(filename)) return false;
}
return true;
} else if (ignore.length) {
for (var pattern of (ignore: Array)) {
for (let pattern of (ignore: Array)) {
if (pattern.test(filename)) return true;
}
}