add lint config from babel, lint

This commit is contained in:
Henry Zhu 2015-06-06 09:14:24 -04:00
parent c38ea387e5
commit face6ff6af
5 changed files with 59 additions and 38 deletions

View File

@ -0,0 +1,26 @@
{
"rules": {
"strict": 0,
"no-underscore-dangle": 0,
"curly": 0,
"no-multi-spaces": 0,
"key-spacing": 0,
"no-return-assign": 0,
"consistent-return": 0,
"no-shadow": 0,
"comma-dangle": 0,
"no-use-before-define": 0,
"no-empty": 0,
"new-parens": 0,
"no-cond-assign": 0,
"no-fallthrough": 0,
"new-cap": 0,
"no-loop-func": 0,
"no-unreachable": 0,
"no-process-exit": 0
},
"env": {
"node": true,
"mocha": true
}
}

View File

@ -73,10 +73,6 @@ exports.toTokens = function (tokens) {
return tokens.map(exports.toToken); return tokens.map(exports.toToken);
}; };
function isCompatTag(tagName) {
return tagName && /^[a-z]|\-/.test(tagName);
}
function convertTemplateType(tokens) { function convertTemplateType(tokens) {
var startingToken = 0; var startingToken = 0;
var currentToken = 0; var currentToken = 0;
@ -124,7 +120,7 @@ function convertTemplateType(tokens) {
start: tokens[start].loc.start, start: tokens[start].loc.start,
end: tokens[end].loc.end end: tokens[end].loc.end
} }
} };
// put new token in place of old tokens // put new token in place of old tokens
tokens.splice(start, end - start + 1, templateToken); tokens.splice(start, end - start + 1, templateToken);
@ -174,7 +170,7 @@ function convertTemplateType(tokens) {
var astTransformVisitor = { var astTransformVisitor = {
noScope: true, noScope: true,
exit: function (node, parent) { exit: function (node) { /* parent */
if (this.isSpreadProperty()) { if (this.isSpreadProperty()) {
node.type = "Property"; node.type = "Property";
node.kind = "init"; node.kind = "init";

View File

@ -1,5 +1,4 @@
var acornToEsprima = require("./acorn-to-esprima"); var acornToEsprima = require("./acorn-to-esprima");
var traverse = require("babel-core").traverse;
var assign = require("lodash.assign"); var assign = require("lodash.assign");
var pick = require("lodash.pick"); var pick = require("lodash.pick");
var Module = require("module"); var Module = require("module");
@ -54,7 +53,7 @@ function monkeypatch() {
// monkeypatch escope/referencer // monkeypatch escope/referencer
var referencerLoc; var referencerLoc;
try { try {
var referencerLoc = Module._resolveFilename("./referencer", escopeMod); referencerLoc = Module._resolveFilename("./referencer", escopeMod);
} catch (err) { } catch (err) {
throw new ReferenceError("couldn't resolve escope/referencer"); throw new ReferenceError("couldn't resolve escope/referencer");
} }
@ -64,7 +63,7 @@ function monkeypatch() {
// reference Definition // reference Definition
var definitionLoc; var definitionLoc;
try { try {
var definitionLoc = Module._resolveFilename("./definition", referencerMod); definitionLoc = Module._resolveFilename("./definition", referencerMod);
} catch (err) { } catch (err) {
throw new ReferenceError("couldn't resolve escope/definition"); throw new ReferenceError("couldn't resolve escope/definition");
} }
@ -146,8 +145,8 @@ function monkeypatch() {
} else if (propertyType.type === "typeAnnotation") { } else if (propertyType.type === "typeAnnotation") {
visitTypeAnnotation.call(this, node.typeAnnotation); visitTypeAnnotation.call(this, node.typeAnnotation);
} else if (propertyType.type === "typeParameters") { } else if (propertyType.type === "typeParameters") {
for (var j = 0; j < node.typeParameters.params.length; j++) { for (var l = 0; l < node.typeParameters.params.length; l++) {
checkIdentifierOrVisit.call(this, node.typeParameters.params[j]); checkIdentifierOrVisit.call(this, node.typeParameters.params[l]);
} }
} else if (propertyType.type === "id") { } else if (propertyType.type === "id") {
if (node.id.type === "Identifier") { if (node.id.type === "Identifier") {
@ -184,13 +183,13 @@ function monkeypatch() {
} }
} }
if (node.typeParameters) { if (node.typeParameters) {
for (var i = 0; i < node.typeParameters.params.length; i++) { for (var j = 0; j < node.typeParameters.params.length; j++) {
checkIdentifierOrVisit.call(this, node.typeParameters.params[i]); checkIdentifierOrVisit.call(this, node.typeParameters.params[j]);
} }
} }
if (node.superTypeParameters) { if (node.superTypeParameters) {
for (var i = 0; i < node.superTypeParameters.params.length; i++) { for (var k = 0; k < node.superTypeParameters.params.length; k++) {
checkIdentifierOrVisit.call(this, node.superTypeParameters.params[i]); checkIdentifierOrVisit.call(this, node.superTypeParameters.params[k]);
} }
} }
visitClass.call(this, node); visitClass.call(this, node);
@ -220,8 +219,8 @@ function monkeypatch() {
} }
} }
if (node.typeParameters) { if (node.typeParameters) {
for (var i = 0; i < node.typeParameters.params.length; i++) { for (var j = 0; j < node.typeParameters.params.length; j++) {
checkIdentifierOrVisit.call(this, node.typeParameters.params[i]); checkIdentifierOrVisit.call(this, node.typeParameters.params[j]);
} }
} }
visitFunction.call(this, node); visitFunction.call(this, node);
@ -264,7 +263,7 @@ function monkeypatch() {
checkIdentifierOrVisit.call(this, node.typeParameters.params[i]); checkIdentifierOrVisit.call(this, node.typeParameters.params[i]);
} }
} }
} };
referencer.prototype.ComprehensionBlock = function(node) { referencer.prototype.ComprehensionBlock = function(node) {
var left = node.left; var left = node.left;
@ -282,7 +281,7 @@ function monkeypatch() {
if (node.right) { if (node.right) {
this.visit(node.right); this.visit(node.right);
} }
} };
} }
exports.attachComments = function (ast, comments, tokens) { exports.attachComments = function (ast, comments, tokens) {

View File

@ -195,19 +195,19 @@ describe("acorn-to-esprima", function () {
}); });
it("default import", function () { it("default import", function () {
parseAndAssertSame('import foo from "foo";'); parseAndAssertSame("import foo from 'foo';");
}); });
it("import specifier", function () { it("import specifier", function () {
parseAndAssertSame('import { foo } from "foo";'); parseAndAssertSame("import { foo } from 'foo';");
}); });
it("import specifier with name", function () { it("import specifier with name", function () {
parseAndAssertSame('import { foo as bar } from "foo";'); parseAndAssertSame("import { foo as bar } from 'foo';");
}); });
it("import bare", function () { it("import bare", function () {
parseAndAssertSame('import "foo";'); parseAndAssertSame("import 'foo';");
}); });
it("export default class declaration", function () { it("export default class declaration", function () {
@ -227,7 +227,7 @@ describe("acorn-to-esprima", function () {
}); });
it("export all", function () { it("export all", function () {
parseAndAssertSame('export * from "foo";'); parseAndAssertSame("export * from 'foo';");
}); });
it("export named", function () { it("export named", function () {

View File

@ -420,7 +420,7 @@ describe("verify", function () {
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
}) });
it("10", function () { it("10", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
@ -672,7 +672,7 @@ describe("verify", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
[ [
"import type Foo from 'foo';", "import type Foo from 'foo';",
'var {x}: {x: Foo; } = { x: "hello" }; x;' "var {x}: {x: Foo; } = { x: 'hello' }; x;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
@ -683,7 +683,7 @@ describe("verify", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
[ [
"import type Foo from 'foo';", "import type Foo from 'foo';",
'var [x]: Array<Foo> = [ "hello" ]; x;' "var [x]: Array<Foo> = [ 'hello' ]; x;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
@ -764,8 +764,8 @@ describe("verify", function () {
it("38", function () { it("38", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
[ [
'import type {foo, bar} from "baz";', "import type {foo, bar} from 'baz';",
'foo; bar;' "foo; bar;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
@ -775,8 +775,8 @@ describe("verify", function () {
it("39", function () { it("39", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
[ [
'import type {foo as bar} from "baz";', "import type {foo as bar} from 'baz';",
'bar;' "bar;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
@ -786,8 +786,8 @@ describe("verify", function () {
it("40", function () { it("40", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
[ [
'import type from "foo";', "import type from 'foo';",
'type;' "type;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
@ -797,8 +797,8 @@ describe("verify", function () {
it("41", function () { it("41", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
[ [
'import type, {foo} from "bar";', "import type, {foo} from 'bar';",
'type; foo;' "type; foo;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
@ -808,8 +808,8 @@ describe("verify", function () {
it("42", function () { it("42", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
[ [
'import type * as namespace from "bar";', "import type * as namespace from 'bar';",
'namespace;' "namespace;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
@ -1088,6 +1088,6 @@ describe("verify", function () {
"var unused;", "var unused;",
{ "no-unused-vars": 1 }, { "no-unused-vars": 1 },
[ "1:4 unused is defined but never used no-unused-vars" ] [ "1:4 unused is defined but never used no-unused-vars" ]
) );
}); });
}); });