From face6ff6af50dd3d655239c8e5c00b069c2ca744 Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Sat, 6 Jun 2015 09:14:24 -0400 Subject: [PATCH] add lint config from babel, lint --- eslint/babel-eslint-parser/.eslintrc | 26 +++++++++++++++++ .../babel-eslint-parser/acorn-to-esprima.js | 8 ++---- eslint/babel-eslint-parser/index.js | 25 ++++++++--------- .../babel-eslint-parser/test/babel-eslint.js | 10 +++---- .../test/non-regression.js | 28 +++++++++---------- 5 files changed, 59 insertions(+), 38 deletions(-) create mode 100644 eslint/babel-eslint-parser/.eslintrc diff --git a/eslint/babel-eslint-parser/.eslintrc b/eslint/babel-eslint-parser/.eslintrc new file mode 100644 index 0000000000..b4c0ddaa6f --- /dev/null +++ b/eslint/babel-eslint-parser/.eslintrc @@ -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 + } +} \ No newline at end of file diff --git a/eslint/babel-eslint-parser/acorn-to-esprima.js b/eslint/babel-eslint-parser/acorn-to-esprima.js index 81b79aa82f..479e4f97d5 100644 --- a/eslint/babel-eslint-parser/acorn-to-esprima.js +++ b/eslint/babel-eslint-parser/acorn-to-esprima.js @@ -73,10 +73,6 @@ exports.toTokens = function (tokens) { return tokens.map(exports.toToken); }; -function isCompatTag(tagName) { - return tagName && /^[a-z]|\-/.test(tagName); -} - function convertTemplateType(tokens) { var startingToken = 0; var currentToken = 0; @@ -124,7 +120,7 @@ function convertTemplateType(tokens) { start: tokens[start].loc.start, end: tokens[end].loc.end } - } + }; // put new token in place of old tokens tokens.splice(start, end - start + 1, templateToken); @@ -174,7 +170,7 @@ function convertTemplateType(tokens) { var astTransformVisitor = { noScope: true, - exit: function (node, parent) { + exit: function (node) { /* parent */ if (this.isSpreadProperty()) { node.type = "Property"; node.kind = "init"; diff --git a/eslint/babel-eslint-parser/index.js b/eslint/babel-eslint-parser/index.js index 074a0720a5..7f0f48a961 100644 --- a/eslint/babel-eslint-parser/index.js +++ b/eslint/babel-eslint-parser/index.js @@ -1,5 +1,4 @@ var acornToEsprima = require("./acorn-to-esprima"); -var traverse = require("babel-core").traverse; var assign = require("lodash.assign"); var pick = require("lodash.pick"); var Module = require("module"); @@ -54,7 +53,7 @@ function monkeypatch() { // monkeypatch escope/referencer var referencerLoc; try { - var referencerLoc = Module._resolveFilename("./referencer", escopeMod); + referencerLoc = Module._resolveFilename("./referencer", escopeMod); } catch (err) { throw new ReferenceError("couldn't resolve escope/referencer"); } @@ -64,7 +63,7 @@ function monkeypatch() { // reference Definition var definitionLoc; try { - var definitionLoc = Module._resolveFilename("./definition", referencerMod); + definitionLoc = Module._resolveFilename("./definition", referencerMod); } catch (err) { throw new ReferenceError("couldn't resolve escope/definition"); } @@ -146,8 +145,8 @@ function monkeypatch() { } else if (propertyType.type === "typeAnnotation") { visitTypeAnnotation.call(this, node.typeAnnotation); } else if (propertyType.type === "typeParameters") { - for (var j = 0; j < node.typeParameters.params.length; j++) { - checkIdentifierOrVisit.call(this, node.typeParameters.params[j]); + for (var l = 0; l < node.typeParameters.params.length; l++) { + checkIdentifierOrVisit.call(this, node.typeParameters.params[l]); } } else if (propertyType.type === "id") { if (node.id.type === "Identifier") { @@ -184,13 +183,13 @@ function monkeypatch() { } } if (node.typeParameters) { - for (var i = 0; i < node.typeParameters.params.length; i++) { - checkIdentifierOrVisit.call(this, node.typeParameters.params[i]); + for (var j = 0; j < node.typeParameters.params.length; j++) { + checkIdentifierOrVisit.call(this, node.typeParameters.params[j]); } } if (node.superTypeParameters) { - for (var i = 0; i < node.superTypeParameters.params.length; i++) { - checkIdentifierOrVisit.call(this, node.superTypeParameters.params[i]); + for (var k = 0; k < node.superTypeParameters.params.length; k++) { + checkIdentifierOrVisit.call(this, node.superTypeParameters.params[k]); } } visitClass.call(this, node); @@ -220,8 +219,8 @@ function monkeypatch() { } } if (node.typeParameters) { - for (var i = 0; i < node.typeParameters.params.length; i++) { - checkIdentifierOrVisit.call(this, node.typeParameters.params[i]); + for (var j = 0; j < node.typeParameters.params.length; j++) { + checkIdentifierOrVisit.call(this, node.typeParameters.params[j]); } } visitFunction.call(this, node); @@ -264,7 +263,7 @@ function monkeypatch() { checkIdentifierOrVisit.call(this, node.typeParameters.params[i]); } } - } + }; referencer.prototype.ComprehensionBlock = function(node) { var left = node.left; @@ -282,7 +281,7 @@ function monkeypatch() { if (node.right) { this.visit(node.right); } - } + }; } exports.attachComments = function (ast, comments, tokens) { diff --git a/eslint/babel-eslint-parser/test/babel-eslint.js b/eslint/babel-eslint-parser/test/babel-eslint.js index 64260de815..09e3229e58 100644 --- a/eslint/babel-eslint-parser/test/babel-eslint.js +++ b/eslint/babel-eslint-parser/test/babel-eslint.js @@ -195,19 +195,19 @@ describe("acorn-to-esprima", function () { }); it("default import", function () { - parseAndAssertSame('import foo from "foo";'); + parseAndAssertSame("import foo from 'foo';"); }); it("import specifier", function () { - parseAndAssertSame('import { foo } from "foo";'); + parseAndAssertSame("import { foo } from 'foo';"); }); it("import specifier with name", function () { - parseAndAssertSame('import { foo as bar } from "foo";'); + parseAndAssertSame("import { foo as bar } from 'foo';"); }); it("import bare", function () { - parseAndAssertSame('import "foo";'); + parseAndAssertSame("import 'foo';"); }); it("export default class declaration", function () { @@ -227,7 +227,7 @@ describe("acorn-to-esprima", function () { }); it("export all", function () { - parseAndAssertSame('export * from "foo";'); + parseAndAssertSame("export * from 'foo';"); }); it("export named", function () { diff --git a/eslint/babel-eslint-parser/test/non-regression.js b/eslint/babel-eslint-parser/test/non-regression.js index c21096f930..0bafac9e01 100644 --- a/eslint/babel-eslint-parser/test/non-regression.js +++ b/eslint/babel-eslint-parser/test/non-regression.js @@ -420,7 +420,7 @@ describe("verify", function () { { "no-unused-vars": 1, "no-undef": 1 }, [] ); - }) + }); it("10", function () { verifyAndAssertMessages( @@ -672,7 +672,7 @@ describe("verify", function () { verifyAndAssertMessages( [ "import type Foo from 'foo';", - 'var {x}: {x: Foo; } = { x: "hello" }; x;' + "var {x}: {x: Foo; } = { x: 'hello' }; x;" ].join("\n"), { "no-unused-vars": 1, "no-undef": 1 }, [] @@ -683,7 +683,7 @@ describe("verify", function () { verifyAndAssertMessages( [ "import type Foo from 'foo';", - 'var [x]: Array = [ "hello" ]; x;' + "var [x]: Array = [ 'hello' ]; x;" ].join("\n"), { "no-unused-vars": 1, "no-undef": 1 }, [] @@ -764,8 +764,8 @@ describe("verify", function () { it("38", function () { verifyAndAssertMessages( [ - 'import type {foo, bar} from "baz";', - 'foo; bar;' + "import type {foo, bar} from 'baz';", + "foo; bar;" ].join("\n"), { "no-unused-vars": 1, "no-undef": 1 }, [] @@ -775,8 +775,8 @@ describe("verify", function () { it("39", function () { verifyAndAssertMessages( [ - 'import type {foo as bar} from "baz";', - 'bar;' + "import type {foo as bar} from 'baz';", + "bar;" ].join("\n"), { "no-unused-vars": 1, "no-undef": 1 }, [] @@ -786,8 +786,8 @@ describe("verify", function () { it("40", function () { verifyAndAssertMessages( [ - 'import type from "foo";', - 'type;' + "import type from 'foo';", + "type;" ].join("\n"), { "no-unused-vars": 1, "no-undef": 1 }, [] @@ -797,8 +797,8 @@ describe("verify", function () { it("41", function () { verifyAndAssertMessages( [ - 'import type, {foo} from "bar";', - 'type; foo;' + "import type, {foo} from 'bar';", + "type; foo;" ].join("\n"), { "no-unused-vars": 1, "no-undef": 1 }, [] @@ -808,8 +808,8 @@ describe("verify", function () { it("42", function () { verifyAndAssertMessages( [ - 'import type * as namespace from "bar";', - 'namespace;' + "import type * as namespace from 'bar';", + "namespace;" ].join("\n"), { "no-unused-vars": 1, "no-undef": 1 }, [] @@ -1088,6 +1088,6 @@ describe("verify", function () { "var unused;", { "no-unused-vars": 1 }, [ "1:4 unused is defined but never used no-unused-vars" ] - ) + ); }); });