Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Commit a24eddf

Browse files
committed
Use eslint-config-babel
1 parent 2ce1f53 commit a24eddf

File tree

10 files changed

+319
-333
lines changed

10 files changed

+319
-333
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/fixtures

.eslintrc

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
{
22
"root": true,
3+
"extends": "babel",
4+
"parserOptions": {
5+
"ecmaVersion": 7,
6+
"sourceType": "module"
7+
},
38
"rules": {
4-
"strict": 0,
5-
"no-underscore-dangle": 0,
6-
"curly": 0,
7-
"no-multi-spaces": 0,
8-
"key-spacing": 0,
9-
"no-return-assign": 0,
10-
"consistent-return": 0,
11-
"no-shadow": 0,
12-
"comma-dangle": 0,
13-
"no-use-before-define": 0,
14-
"no-empty": 0,
15-
"new-parens": 0,
16-
"no-cond-assign": 0,
17-
"no-fallthrough": 0,
18-
"new-cap": 0,
19-
"no-loop-func": 0,
20-
"no-unreachable": 0,
21-
"no-process-exit": 0,
22-
"quotes": [1, "double", "avoid-escape"]
9+
"no-var": 0,
10+
"max-len": 0
2311
},
2412
"env": {
2513
"node": true,

babylon-to-espree/convertTemplateType.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,4 @@ module.exports = function (tokens, tt) {
9090
}
9191
startingToken++;
9292
}
93-
}
93+
};

babylon-to-espree/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ exports.convertComments = function (comments) {
1717
comment.range = [comment.start, comment.end];
1818
}
1919
}
20-
}
20+
};

babylon-to-espree/toAST.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ function changeToLiteral(node) {
1717
}
1818
}
1919

20+
function changeComments(nodeComments) {
21+
for (var i = 0; i < nodeComments.length; i++) {
22+
var comment = nodeComments[i];
23+
if (comment.type === "CommentLine") {
24+
comment.type = "Line";
25+
} else if (comment.type === "CommentBlock") {
26+
comment.type = "Block";
27+
}
28+
comment.range = [comment.start, comment.end];
29+
}
30+
}
31+
2032
var astTransformVisitor = {
2133
noScope: true,
2234
enter: function (path) {
@@ -33,27 +45,11 @@ var astTransformVisitor = {
3345
}
3446

3547
if (node.trailingComments) {
36-
for (var i = 0; i < node.trailingComments.length; i++) {
37-
var comment = node.trailingComments[i];
38-
if (comment.type === "CommentLine") {
39-
comment.type = "Line";
40-
} else if (comment.type === "CommentBlock") {
41-
comment.type = "Block";
42-
}
43-
comment.range = [comment.start, comment.end];
44-
}
48+
changeComments(node.trailingComments);
4549
}
4650

4751
if (node.leadingComments) {
48-
for (var i = 0; i < node.leadingComments.length; i++) {
49-
var comment = node.leadingComments[i];
50-
if (comment.type === "CommentLine") {
51-
comment.type = "Line";
52-
} else if (comment.type === "CommentBlock") {
53-
comment.type = "Block";
54-
}
55-
comment.range = [comment.start, comment.end];
56-
}
52+
changeComments(node.leadingComments);
5753
}
5854

5955
// make '_paths' non-enumerable (babel-eslint #200)

index.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ exports.parse = function (code, options) {
388388
}
389389

390390
return exports.parseNoPatch(code, options);
391-
}
391+
};
392392

393393
exports.parseNoPatch = function (code, options) {
394394
var opts = {
@@ -397,20 +397,20 @@ exports.parseNoPatch = function (code, options) {
397397
allowReturnOutsideFunction: true,
398398
allowSuperOutsideMethod: true,
399399
plugins: [
400-
"flow",
401-
"jsx",
402-
"asyncFunctions",
403-
"asyncGenerators",
404-
"classConstructorCall",
405-
"classProperties",
406-
"decorators",
407-
"doExpressions",
408-
"exponentiationOperator",
409-
"exportExtensions",
410-
"functionBind",
411-
"functionSent",
412-
"objectRestSpread",
413-
"trailingFunctionCommas"
400+
"flow",
401+
"jsx",
402+
"asyncFunctions",
403+
"asyncGenerators",
404+
"classConstructorCall",
405+
"classProperties",
406+
"decorators",
407+
"doExpressions",
408+
"exponentiationOperator",
409+
"exportExtensions",
410+
"functionBind",
411+
"functionSent",
412+
"objectRestSpread",
413+
"trailingFunctionCommas"
414414
]
415415
};
416416

@@ -458,4 +458,4 @@ exports.parseNoPatch = function (code, options) {
458458
babylonToEspree.attachComments(ast, ast.comments, ast.tokens);
459459

460460
return ast;
461-
}
461+
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"homepage": "https://github.com/babel/babel-eslint",
3939
"devDependencies": {
4040
"eslint": "^3.0.0",
41+
"eslint-config-babel": "^1.0.1",
4142
"espree": "^3.0.0",
4243
"mocha": "^3.0.0"
4344
}

test/babel-eslint.js

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ function lookup(obj, keypath, backwardsDepth) {
3636
if (!keypath) { return obj; }
3737

3838
return keypath.split(".").slice(0, -1 * backwardsDepth)
39-
.reduce(function (base, segment) { return base && base[segment], obj });
39+
.reduce(function (base, segment) { return base && base[segment], obj; });
4040
}
4141

4242
function parseAndAssertSame(code) {
4343
var esAST = espree.parse(code, {
4444
ecmaFeatures: {
4545
// enable JSX parsing
46-
jsx: true,
46+
jsx: true,
4747
// enable return in global scope
48-
globalReturn: true,
48+
globalReturn: true,
4949
// enable implied strict mode (if ecmaVersion >= 5)
50-
impliedStrict: true,
50+
impliedStrict: true,
5151
// allow experimental object rest/spread
52-
experimentalObjectRestSpread: true
52+
experimentalObjectRestSpread: true
5353
},
5454
tokens: true,
5555
loc: true,
@@ -62,7 +62,7 @@ function parseAndAssertSame(code) {
6262
var babylonAST = babelEslint.parse(code);
6363
try {
6464
assertImplementsAST(esAST, babylonAST);
65-
} catch(err) {
65+
} catch (err) {
6666
var traversal = err.message.slice(3, err.message.indexOf(":"));
6767
if (esAST.tokens) {
6868
delete esAST.tokens;
@@ -145,10 +145,10 @@ describe("babylon-to-esprima", function () {
145145
it("template with destructuring #31", function () {
146146
parseAndAssertSame([
147147
"module.exports = {",
148-
"render() {",
149-
"var {name} = this.props;",
150-
"return Math.max(null, `Name: ${name}, Name: ${name}`);",
151-
"}",
148+
"render() {",
149+
"var {name} = this.props;",
150+
"return Math.max(null, `Name: ${name}, Name: ${name}`);",
151+
"}",
152152
"};"
153153
].join("\n"));
154154
});
@@ -199,19 +199,19 @@ describe("babylon-to-esprima", function () {
199199
});
200200

201201
it("default import", function () {
202-
parseAndAssertSame('import foo from "foo";');
202+
parseAndAssertSame("import foo from \"foo\";");
203203
});
204204

205205
it("import specifier", function () {
206-
parseAndAssertSame('import { foo } from "foo";');
206+
parseAndAssertSame("import { foo } from \"foo\";");
207207
});
208208

209209
it("import specifier with name", function () {
210-
parseAndAssertSame('import { foo as bar } from "foo";');
210+
parseAndAssertSame("import { foo as bar } from \"foo\";");
211211
});
212212

213213
it("import bare", function () {
214-
parseAndAssertSame('import "foo";');
214+
parseAndAssertSame("import \"foo\";");
215215
});
216216

217217
it("export default class declaration", function () {
@@ -231,7 +231,7 @@ describe("babylon-to-esprima", function () {
231231
});
232232

233233
it("export all", function () {
234-
parseAndAssertSame('export * from "foo";');
234+
parseAndAssertSame("export * from \"foo\";");
235235
});
236236

237237
it("export named", function () {
@@ -272,11 +272,11 @@ describe("babylon-to-esprima", function () {
272272
it("block comments #124", function () {
273273
parseAndAssertSame([
274274
"React.createClass({",
275-
"render() {",
276-
"// return (",
277-
"// <div />",
278-
"// ); // <-- this is the line that is reported",
279-
"}",
275+
"render() {",
276+
"// return (",
277+
"// <div />",
278+
"// ); // <-- this is the line that is reported",
279+
"}",
280280
"});"
281281
].join("\n"));
282282
});
@@ -308,24 +308,24 @@ describe("babylon-to-esprima", function () {
308308
it("jsdoc", function () {
309309
parseAndAssertSame([
310310
"/**",
311-
"* @param {object} options",
312-
"* @return {number}",
313-
"*/",
311+
"* @param {object} options",
312+
"* @return {number}",
313+
"*/",
314314
"const test = function({ a, b, c }) {",
315-
"return a + b + c;",
315+
"return a + b + c;",
316316
"};",
317317
"module.exports = test;"
318318
].join("\n"));
319-
})
319+
});
320320

321321
it("empty block with comment", function () {
322322
parseAndAssertSame([
323323
"function a () {",
324-
"try {",
325-
"b();",
326-
"} catch (e) {",
327-
"// asdf",
328-
"}",
324+
"try {",
325+
"b();",
326+
"} catch (e) {",
327+
"// asdf",
328+
"}",
329329
"}"
330330
].join("\n"));
331331
});
@@ -334,7 +334,7 @@ describe("babylon-to-esprima", function () {
334334
it("MethodDefinition", function () {
335335
parseAndAssertSame([
336336
"export default class A {",
337-
"a() {}",
337+
"a() {}",
338338
"}"
339339
].join("\n"));
340340
});
@@ -348,17 +348,17 @@ describe("babylon-to-esprima", function () {
348348
it("ClassMethod", function () {
349349
parseAndAssertSame([
350350
"class A {",
351-
"constructor() {",
352-
"}",
351+
"constructor() {",
352+
"}",
353353
"}"
354354
].join("\n"));
355355
});
356356

357357
it("ClassMethod multiple params", function () {
358358
parseAndAssertSame([
359359
"class A {",
360-
"constructor(a, b, c) {",
361-
"}",
360+
"constructor(a, b, c) {",
361+
"}",
362362
"}"
363363
].join("\n"));
364364
});
@@ -385,16 +385,16 @@ describe("babylon-to-esprima", function () {
385385
it("ObjectMethod", function () {
386386
parseAndAssertSame([
387387
"var a = {",
388-
"b(c) {",
389-
"}",
388+
"b(c) {",
389+
"}",
390390
"}"
391391
].join("\n"));
392392
});
393393

394394
it("do not allow import export everywhere", function() {
395395
assert.throws(function () {
396396
parseAndAssertSame("function F() { import a from \"a\"; }");
397-
}, /SyntaxError: 'import' and 'export' may only appear at the top level/)
397+
}, /SyntaxError: 'import' and 'export' may only appear at the top level/);
398398
});
399399

400400
it("return outside function", function () {
@@ -415,31 +415,31 @@ describe("babylon-to-esprima", function () {
415415
parseAndAssertSame("class A { get x ( ) { ; } }");
416416
parseAndAssertSame([
417417
"class A {",
418-
"get x(",
419-
")",
420-
"{",
421-
";",
422-
"}",
418+
"get x(",
419+
")",
420+
"{",
421+
";",
422+
"}",
423423
"}"
424424
].join("\n"));
425425
parseAndAssertSame("class A { set x (a) { ; } }");
426426
parseAndAssertSame([
427427
"class A {",
428-
"set x(a",
429-
")",
430-
"{",
431-
";",
432-
"}",
428+
"set x(a",
429+
")",
430+
"{",
431+
";",
432+
"}",
433433
"}"
434434
].join("\n"));
435435
parseAndAssertSame([
436436
"var B = {",
437-
"get x () {",
438-
"return this.ecks;",
439-
"},",
440-
"set x (ecks) {",
441-
"this.ecks = ecks;",
442-
"}",
437+
"get x () {",
438+
"return this.ecks;",
439+
"},",
440+
"set x (ecks) {",
441+
"this.ecks = ecks;",
442+
"}",
443443
"};"
444444
].join("\n"));
445445
});

test/fixtures/rules/strict/global-with.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"use strict";;
1+
"use strict";
22
/*
33
The empty statement is intentional. As of now, ESLint won't enforce
44
string: [2, "global"] on a program with an empty body. A test for that without

0 commit comments

Comments
 (0)