Merge pull request babel/babel-eslint#354 from babel/eslint-config-babel

Use eslint-config-babel
This commit is contained in:
Henry Zhu 2016-08-03 09:34:51 -04:00
parent 481329a47e
commit 2b812b087c
12 changed files with 334 additions and 345 deletions

View File

@ -0,0 +1 @@
test/fixtures

View File

@ -1,28 +0,0 @@
{
"root": true,
"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,
"quotes": [1, "double", "avoid-escape"]
},
"env": {
"node": true,
"mocha": true
}
}

View File

@ -0,0 +1,16 @@
module.exports = {
root: true,
extends: "babel",
parserOptions: {
ecmaVersion: 7,
sourceType: "module"
},
rules: {
"no-var": 0,
"max-len": 0
},
env: {
node: true,
mocha: true
}
};

View File

@ -7,3 +7,5 @@ matrix:
- node_js: "4"
- node_js: "5"
- node_js: "6"
script: npm run test-ci

View File

@ -90,4 +90,4 @@ module.exports = function (tokens, tt) {
}
startingToken++;
}
}
};

View File

@ -17,4 +17,4 @@ exports.convertComments = function (comments) {
comment.range = [comment.start, comment.end];
}
}
}
};

View File

@ -17,6 +17,18 @@ function changeToLiteral(node) {
}
}
function changeComments(nodeComments) {
for (var i = 0; i < nodeComments.length; i++) {
var comment = nodeComments[i];
if (comment.type === "CommentLine") {
comment.type = "Line";
} else if (comment.type === "CommentBlock") {
comment.type = "Block";
}
comment.range = [comment.start, comment.end];
}
}
var astTransformVisitor = {
noScope: true,
enter: function (path) {
@ -33,27 +45,11 @@ var astTransformVisitor = {
}
if (node.trailingComments) {
for (var i = 0; i < node.trailingComments.length; i++) {
var comment = node.trailingComments[i];
if (comment.type === "CommentLine") {
comment.type = "Line";
} else if (comment.type === "CommentBlock") {
comment.type = "Block";
}
comment.range = [comment.start, comment.end];
}
changeComments(node.trailingComments);
}
if (node.leadingComments) {
for (var i = 0; i < node.leadingComments.length; i++) {
var comment = node.leadingComments[i];
if (comment.type === "CommentLine") {
comment.type = "Line";
} else if (comment.type === "CommentBlock") {
comment.type = "Block";
}
comment.range = [comment.start, comment.end];
}
changeComments(node.leadingComments);
}
// make '_paths' non-enumerable (babel-eslint #200)

View File

@ -388,7 +388,7 @@ exports.parse = function (code, options) {
}
return exports.parseNoPatch(code, options);
}
};
exports.parseNoPatch = function (code, options) {
var opts = {
@ -458,4 +458,4 @@ exports.parseNoPatch = function (code, options) {
babylonToEspree.attachComments(ast, ast.comments, ast.tokens);
return ast;
}
};

View File

@ -22,6 +22,7 @@
"bootstrap": "git submodule update --init && cd eslint && npm install",
"eslint": "cd eslint && mocha -c tests/lib/rules/*.js -r ../eslint-tester.js",
"test": "mocha",
"test-ci" "npm test && npm run lint",
"lint": "eslint index.js babylon-to-espree test",
"fix": "eslint index.js babylon-to-espree test --fix",
"preversion": "npm test",
@ -38,6 +39,7 @@
"homepage": "https://github.com/babel/babel-eslint",
"devDependencies": {
"eslint": "^3.0.0",
"eslint-config-babel": "^1.0.1",
"espree": "^3.0.0",
"mocha": "^3.0.0"
}

View File

@ -36,7 +36,7 @@ function lookup(obj, keypath, backwardsDepth) {
if (!keypath) { return obj; }
return keypath.split(".").slice(0, -1 * backwardsDepth)
.reduce(function (base, segment) { return base && base[segment], obj });
.reduce(function (base, segment) { return base && base[segment], obj; });
}
function parseAndAssertSame(code) {
@ -199,19 +199,19 @@ describe("babylon-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 () {
@ -231,7 +231,7 @@ describe("babylon-to-esprima", function () {
});
it("export all", function () {
parseAndAssertSame('export * from "foo";');
parseAndAssertSame("export * from \"foo\";");
});
it("export named", function () {
@ -316,7 +316,7 @@ describe("babylon-to-esprima", function () {
"};",
"module.exports = test;"
].join("\n"));
})
});
it("empty block with comment", function () {
parseAndAssertSame([
@ -394,7 +394,7 @@ describe("babylon-to-esprima", function () {
it("do not allow import export everywhere", function() {
assert.throws(function () {
parseAndAssertSame("function F() { import a from \"a\"; }");
}, /SyntaxError: 'import' and 'export' may only appear at the top level/)
}, /SyntaxError: 'import' and 'export' may only appear at the top level/);
});
it("return outside function", function () {

View File

@ -1,4 +1,4 @@
"use strict";;
"use strict";
/*
The empty statement is intentional. As of now, ESLint won't enforce
string: [2, "global"] on a program with an empty body. A test for that without

View File

@ -23,7 +23,7 @@ function verifyAndAssertMessages(code, rules, expectedMessages, sourceType, over
if (overrideConfig) {
for (var key in overrideConfig) {
config[key] = overrideConfig[key]
config[key] = overrideConfig[key];
}
}
@ -1261,7 +1261,7 @@ describe("verify", function () {
].join("\n"),
{ "space-in-parens": 1 },
[ ]
)
);
});
it("block comment space-in-parens #124", function () {
@ -1279,21 +1279,21 @@ describe("verify", function () {
].join("\n"),
{ "space-in-parens": 1 },
[ ]
)
);
});
it("no no-undef error with rest #11", function () {
verifyAndAssertMessages("const [a, ...rest] = ['1', '2', '3']; a; rest;",
{ "no-undef": 1, "no-unused-vars": 1 },
[ ]
)
);
});
it("async function with space-before-function-paren #168", function () {
verifyAndAssertMessages("it('handles updates', async function() {});",
{ "space-before-function-paren": [1, "never"] },
[ ]
)
);
});
it("default param flow type no-unused-vars #184", function () {
@ -1312,7 +1312,7 @@ describe("verify", function () {
].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 },
[ ]
)
);
});
it("no-use-before-define #192", function () {
@ -1322,8 +1322,8 @@ describe("verify", function () {
"var x = 1;"
].join("\n"),
{ "no-use-before-define": 1 },
[ "1:13 'x' was used before it was defined no-use-before-define" ]
)
[ "1:13 'x' was used before it was defined. no-use-before-define" ]
);
});
it("jsx and stringliteral #216", function () {
@ -1331,7 +1331,7 @@ describe("verify", function () {
"<div className=''></div>",
{},
[]
)
);
});
it("getter/setter #218", function () {
@ -1342,7 +1342,7 @@ describe("verify", function () {
].join("\n"),
{ "space-before-function-paren": 1, "keyword-spacing": [1, {"before": true}], "indent": 1 },
[]
)
);
});
it("getter/setter #220", function () {
@ -1380,7 +1380,7 @@ describe("verify", function () {
"var a = 123;",
].join("\n"),
{ "no-redeclare": 1 },
[ "2:5 'a' is already defined no-redeclare" ],
[ "2:5 'a' is already defined. no-redeclare" ],
"script"
);
});
@ -1391,7 +1391,7 @@ describe("verify", function () {
"var a = 123;",
].join("\n"),
{ "no-redeclare": 1 },
[ "2:5 'a' is already defined no-redeclare" ],
[ "2:5 'a' is already defined. no-redeclare" ],
"module"
);
});