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: "4"
- node_js: "5" - node_js: "5"
- node_js: "6" - node_js: "6"
script: npm run test-ci

View File

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

View File

@ -17,4 +17,4 @@ exports.convertComments = function (comments) {
comment.range = [comment.start, comment.end]; 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 = { var astTransformVisitor = {
noScope: true, noScope: true,
enter: function (path) { enter: function (path) {
@ -33,27 +45,11 @@ var astTransformVisitor = {
} }
if (node.trailingComments) { if (node.trailingComments) {
for (var i = 0; i < node.trailingComments.length; i++) { changeComments(node.trailingComments);
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];
}
} }
if (node.leadingComments) { if (node.leadingComments) {
for (var i = 0; i < node.leadingComments.length; i++) { changeComments(node.leadingComments);
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];
}
} }
// make '_paths' non-enumerable (babel-eslint #200) // make '_paths' non-enumerable (babel-eslint #200)

View File

@ -388,7 +388,7 @@ exports.parse = function (code, options) {
} }
return exports.parseNoPatch(code, options); return exports.parseNoPatch(code, options);
} };
exports.parseNoPatch = function (code, options) { exports.parseNoPatch = function (code, options) {
var opts = { var opts = {
@ -397,20 +397,20 @@ exports.parseNoPatch = function (code, options) {
allowReturnOutsideFunction: true, allowReturnOutsideFunction: true,
allowSuperOutsideMethod: true, allowSuperOutsideMethod: true,
plugins: [ plugins: [
"flow", "flow",
"jsx", "jsx",
"asyncFunctions", "asyncFunctions",
"asyncGenerators", "asyncGenerators",
"classConstructorCall", "classConstructorCall",
"classProperties", "classProperties",
"decorators", "decorators",
"doExpressions", "doExpressions",
"exponentiationOperator", "exponentiationOperator",
"exportExtensions", "exportExtensions",
"functionBind", "functionBind",
"functionSent", "functionSent",
"objectRestSpread", "objectRestSpread",
"trailingFunctionCommas" "trailingFunctionCommas"
] ]
}; };
@ -458,4 +458,4 @@ exports.parseNoPatch = function (code, options) {
babylonToEspree.attachComments(ast, ast.comments, ast.tokens); babylonToEspree.attachComments(ast, ast.comments, ast.tokens);
return ast; return ast;
} };

View File

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

View File

@ -36,20 +36,20 @@ function lookup(obj, keypath, backwardsDepth) {
if (!keypath) { return obj; } if (!keypath) { return obj; }
return keypath.split(".").slice(0, -1 * backwardsDepth) 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) { function parseAndAssertSame(code) {
var esAST = espree.parse(code, { var esAST = espree.parse(code, {
ecmaFeatures: { ecmaFeatures: {
// enable JSX parsing // enable JSX parsing
jsx: true, jsx: true,
// enable return in global scope // enable return in global scope
globalReturn: true, globalReturn: true,
// enable implied strict mode (if ecmaVersion >= 5) // enable implied strict mode (if ecmaVersion >= 5)
impliedStrict: true, impliedStrict: true,
// allow experimental object rest/spread // allow experimental object rest/spread
experimentalObjectRestSpread: true experimentalObjectRestSpread: true
}, },
tokens: true, tokens: true,
loc: true, loc: true,
@ -62,7 +62,7 @@ function parseAndAssertSame(code) {
var babylonAST = babelEslint.parse(code); var babylonAST = babelEslint.parse(code);
try { try {
assertImplementsAST(esAST, babylonAST); assertImplementsAST(esAST, babylonAST);
} catch(err) { } catch (err) {
var traversal = err.message.slice(3, err.message.indexOf(":")); var traversal = err.message.slice(3, err.message.indexOf(":"));
if (esAST.tokens) { if (esAST.tokens) {
delete esAST.tokens; delete esAST.tokens;
@ -145,10 +145,10 @@ describe("babylon-to-esprima", function () {
it("template with destructuring #31", function () { it("template with destructuring #31", function () {
parseAndAssertSame([ parseAndAssertSame([
"module.exports = {", "module.exports = {",
"render() {", "render() {",
"var {name} = this.props;", "var {name} = this.props;",
"return Math.max(null, `Name: ${name}, Name: ${name}`);", "return Math.max(null, `Name: ${name}, Name: ${name}`);",
"}", "}",
"};" "};"
].join("\n")); ].join("\n"));
}); });
@ -199,19 +199,19 @@ describe("babylon-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 () {
@ -231,7 +231,7 @@ describe("babylon-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 () {
@ -272,11 +272,11 @@ describe("babylon-to-esprima", function () {
it("block comments #124", function () { it("block comments #124", function () {
parseAndAssertSame([ parseAndAssertSame([
"React.createClass({", "React.createClass({",
"render() {", "render() {",
"// return (", "// return (",
"// <div />", "// <div />",
"// ); // <-- this is the line that is reported", "// ); // <-- this is the line that is reported",
"}", "}",
"});" "});"
].join("\n")); ].join("\n"));
}); });
@ -308,24 +308,24 @@ describe("babylon-to-esprima", function () {
it("jsdoc", function () { it("jsdoc", function () {
parseAndAssertSame([ parseAndAssertSame([
"/**", "/**",
"* @param {object} options", "* @param {object} options",
"* @return {number}", "* @return {number}",
"*/", "*/",
"const test = function({ a, b, c }) {", "const test = function({ a, b, c }) {",
"return a + b + c;", "return a + b + c;",
"};", "};",
"module.exports = test;" "module.exports = test;"
].join("\n")); ].join("\n"));
}) });
it("empty block with comment", function () { it("empty block with comment", function () {
parseAndAssertSame([ parseAndAssertSame([
"function a () {", "function a () {",
"try {", "try {",
"b();", "b();",
"} catch (e) {", "} catch (e) {",
"// asdf", "// asdf",
"}", "}",
"}" "}"
].join("\n")); ].join("\n"));
}); });
@ -334,7 +334,7 @@ describe("babylon-to-esprima", function () {
it("MethodDefinition", function () { it("MethodDefinition", function () {
parseAndAssertSame([ parseAndAssertSame([
"export default class A {", "export default class A {",
"a() {}", "a() {}",
"}" "}"
].join("\n")); ].join("\n"));
}); });
@ -348,8 +348,8 @@ describe("babylon-to-esprima", function () {
it("ClassMethod", function () { it("ClassMethod", function () {
parseAndAssertSame([ parseAndAssertSame([
"class A {", "class A {",
"constructor() {", "constructor() {",
"}", "}",
"}" "}"
].join("\n")); ].join("\n"));
}); });
@ -357,8 +357,8 @@ describe("babylon-to-esprima", function () {
it("ClassMethod multiple params", function () { it("ClassMethod multiple params", function () {
parseAndAssertSame([ parseAndAssertSame([
"class A {", "class A {",
"constructor(a, b, c) {", "constructor(a, b, c) {",
"}", "}",
"}" "}"
].join("\n")); ].join("\n"));
}); });
@ -385,8 +385,8 @@ describe("babylon-to-esprima", function () {
it("ObjectMethod", function () { it("ObjectMethod", function () {
parseAndAssertSame([ parseAndAssertSame([
"var a = {", "var a = {",
"b(c) {", "b(c) {",
"}", "}",
"}" "}"
].join("\n")); ].join("\n"));
}); });
@ -394,7 +394,7 @@ describe("babylon-to-esprima", function () {
it("do not allow import export everywhere", function() { it("do not allow import export everywhere", function() {
assert.throws(function () { assert.throws(function () {
parseAndAssertSame("function F() { import a from \"a\"; }"); 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 () { it("return outside function", function () {
@ -415,31 +415,31 @@ describe("babylon-to-esprima", function () {
parseAndAssertSame("class A { get x ( ) { ; } }"); parseAndAssertSame("class A { get x ( ) { ; } }");
parseAndAssertSame([ parseAndAssertSame([
"class A {", "class A {",
"get x(", "get x(",
")", ")",
"{", "{",
";", ";",
"}", "}",
"}" "}"
].join("\n")); ].join("\n"));
parseAndAssertSame("class A { set x (a) { ; } }"); parseAndAssertSame("class A { set x (a) { ; } }");
parseAndAssertSame([ parseAndAssertSame([
"class A {", "class A {",
"set x(a", "set x(a",
")", ")",
"{", "{",
";", ";",
"}", "}",
"}" "}"
].join("\n")); ].join("\n"));
parseAndAssertSame([ parseAndAssertSame([
"var B = {", "var B = {",
"get x () {", "get x () {",
"return this.ecks;", "return this.ecks;",
"},", "},",
"set x (ecks) {", "set x (ecks) {",
"this.ecks = ecks;", "this.ecks = ecks;",
"}", "}",
"};" "};"
].join("\n")); ].join("\n"));
}); });

View File

@ -1,4 +1,4 @@
"use strict";; "use strict";
/* /*
The empty statement is intentional. As of now, ESLint won't enforce 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 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) { if (overrideConfig) {
for (var key in overrideConfig) { for (var key in overrideConfig) {
config[key] = overrideConfig[key] config[key] = overrideConfig[key];
} }
} }
@ -161,11 +161,11 @@ describe("verify", function () {
it("comment with padded-blocks (issue #33)", function () { it("comment with padded-blocks (issue #33)", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"if (a){", "if (a){",
"// i'm a comment!", "// i'm a comment!",
"let b = c", "let b = c",
"}" "}"
].join("\n"), ].join("\n"),
{ "padded-blocks": [1, "never"] }, { "padded-blocks": [1, "never"] },
[] []
); );
@ -174,8 +174,8 @@ describe("verify", function () {
describe("flow", function () { describe("flow", function () {
it("check regular function", function () { it("check regular function", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"function a(b, c) { b += 1; c += 1; return b + c; } a;", "function a(b, c) { b += 1; c += 1; return b + c; } a;",
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -199,14 +199,14 @@ describe("verify", function () {
it("multiple nullable type annotations and return #108", function () { it("multiple nullable type annotations and return #108", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import type Foo from 'foo';", "import type Foo from 'foo';",
"import type Foo2 from 'foo';", "import type Foo2 from 'foo';",
"import type Foo3 from 'foo';", "import type Foo3 from 'foo';",
"function log(foo: ?Foo, foo2: ?Foo2): ?Foo3 {", "function log(foo: ?Foo, foo2: ?Foo2): ?Foo3 {",
"console.log(foo, foo2);", "console.log(foo, foo2);",
"}", "}",
"log(1, 2);" "log(1, 2);"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -214,11 +214,11 @@ describe("verify", function () {
it("type parameters", function () { it("type parameters", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import type Foo from 'foo';", "import type Foo from 'foo';",
"import type Foo2 from 'foo';", "import type Foo2 from 'foo';",
"function log<T1, T2>(a: T1, b: T2) { return a + b; }", "function log<T1, T2>(a: T1, b: T2) { return a + b; }",
"log<Foo, Foo2>(1, 2);" "log<Foo, Foo2>(1, 2);"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -226,12 +226,12 @@ describe("verify", function () {
it("nested type annotations", function () { it("nested type annotations", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import type Foo from 'foo';", "import type Foo from 'foo';",
"function foo(callback: () => Foo) {", "function foo(callback: () => Foo) {",
"return callback();", "return callback();",
"}", "}",
"foo();" "foo();"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -239,10 +239,10 @@ describe("verify", function () {
it("type in var declaration", function () { it("type in var declaration", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import type Foo from 'foo';", "import type Foo from 'foo';",
"var x: Foo = 1;", "var x: Foo = 1;",
"x;" "x;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -250,10 +250,10 @@ describe("verify", function () {
it("object type annotation", function () { it("object type annotation", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import type Foo from 'foo';", "import type Foo from 'foo';",
"var a: {numVal: Foo};", "var a: {numVal: Foo};",
"a;" "a;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -261,13 +261,13 @@ describe("verify", function () {
it("object property types", function () { it("object property types", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import type Foo from 'foo';", "import type Foo from 'foo';",
"import type Foo2 from 'foo';", "import type Foo2 from 'foo';",
"var a = {", "var a = {",
"circle: (null : ?{ setNativeProps(props: Foo): Foo2 })", "circle: (null : ?{ setNativeProps(props: Foo): Foo2 })",
"};", "};",
"a;" "a;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -275,16 +275,16 @@ describe("verify", function () {
it("namespaced types", function () { it("namespaced types", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"var React = require('react-native');", "var React = require('react-native');",
"var b = {", "var b = {",
"openExternalExample: (null: ?React.Component)", "openExternalExample: (null: ?React.Component)",
"};", "};",
"var c = {", "var c = {",
"render(): React.Component {}", "render(): React.Component {}",
"};", "};",
"b;", "b;",
"c;" "c;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -292,9 +292,9 @@ describe("verify", function () {
it("ArrayTypeAnnotation", function () { it("ArrayTypeAnnotation", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import type Foo from 'foo';", "import type Foo from 'foo';",
"var x: Foo[]; x;" "var x: Foo[]; x;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -302,9 +302,9 @@ describe("verify", function () {
it("ClassImplements", function () { it("ClassImplements", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import type Bar from 'foo';", "import type Bar from 'foo';",
"export default class Foo implements Bar {}" "export default class Foo implements Bar {}"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -312,9 +312,9 @@ describe("verify", function () {
it("type alias creates declaration + usage", function () { it("type alias creates declaration + usage", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"type Foo = any;", "type Foo = any;",
"var x : Foo = 1; x;" "var x : Foo = 1; x;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -322,11 +322,11 @@ describe("verify", function () {
it("type alias with type parameters", function () { it("type alias with type parameters", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import type Bar from 'foo';", "import type Bar from 'foo';",
"import type Foo3 from 'foo';", "import type Foo3 from 'foo';",
"type Foo<T> = Bar<T, Foo3>", "type Foo<T> = Bar<T, Foo3>",
"var x : Foo = 1; x;" "var x : Foo = 1; x;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -334,9 +334,9 @@ describe("verify", function () {
it("export type alias", function () { it("export type alias", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import type Foo2 from 'foo';", "import type Foo2 from 'foo';",
"export type Foo = Foo2;" "export type Foo = Foo2;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -344,8 +344,8 @@ describe("verify", function () {
it("polymorphpic types #109", function () { it("polymorphpic types #109", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"export default function groupByEveryN<T>(array: Array<T>, n: number): Array<Array<?T>> { n; }" "export default function groupByEveryN<T>(array: Array<T>, n: number): Array<Array<?T>> { n; }"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -353,10 +353,10 @@ describe("verify", function () {
it("types definition from import", function () { it("types definition from import", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import type Promise from 'bluebird';", "import type Promise from 'bluebird';",
"type Operation = () => Promise;", "type Operation = () => Promise;",
"x: Operation;" "x: Operation;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -364,12 +364,12 @@ describe("verify", function () {
it("polymorphpic/generic types for class #123", function () { it("polymorphpic/generic types for class #123", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"class Box<T> {", "class Box<T> {",
"value: T;", "value: T;",
"}", "}",
"var box = new Box();", "var box = new Box();",
"console.log(box.value);" "console.log(box.value);"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -377,10 +377,10 @@ describe("verify", function () {
it("polymorphpic/generic types for function #123", function () { it("polymorphpic/generic types for function #123", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"export function identity<T>(value) {", "export function identity<T>(value) {",
"var a: T = value; a;", "var a: T = value; a;",
"}" "}"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -388,9 +388,9 @@ describe("verify", function () {
it("polymorphpic/generic types for type alias #123", function () { it("polymorphpic/generic types for type alias #123", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import Bar from './Bar';", "import Bar from './Bar';",
"type Foo<T> = Bar<T>; var x: Foo = 1; console.log(x);" "type Foo<T> = Bar<T>; var x: Foo = 1; console.log(x);"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[] []
); );
@ -398,9 +398,9 @@ describe("verify", function () {
it("polymorphpic/generic types - outside of fn scope #123", function () { it("polymorphpic/generic types - outside of fn scope #123", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"export function foo<T>(value) { value; };", "export function foo<T>(value) { value; };",
"var b: T = 1; b;" "var b: T = 1; b;"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[ "1:21 'T' is defined but never used. no-unused-vars", [ "1:21 'T' is defined but never used. no-unused-vars",
"2:8 'T' is not defined. no-undef" ] "2:8 'T' is not defined. no-undef" ]
@ -409,9 +409,9 @@ describe("verify", function () {
it("polymorphpic/generic types - extending unknown #123", function () { it("polymorphpic/generic types - extending unknown #123", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import Bar from 'bar';", "import Bar from 'bar';",
"export class Foo extends Bar<T> {}", "export class Foo extends Bar<T> {}",
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[ "2:30 'T' is not defined. no-undef" ] [ "2:30 'T' is not defined. no-undef" ]
); );
@ -419,12 +419,12 @@ describe("verify", function () {
it("support declarations #132", function () { it("support declarations #132", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"declare class A { static () : number }", "declare class A { static () : number }",
"declare module B { declare var x: number; }", "declare module B { declare var x: number; }",
"declare function foo<T>(): void;", "declare function foo<T>(): void;",
"declare var bar", "declare var bar",
"A; B; foo(); bar;" "A; B; foo(); bar;"
].join("\n"), ].join("\n"),
{ "no-undef": 1, "no-unused-vars": 1 }, { "no-undef": 1, "no-unused-vars": 1 },
[] []
); );
@ -1002,12 +1002,12 @@ describe("verify", function () {
it("class definition: gaearon/redux#24", function () { it("class definition: gaearon/redux#24", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"export default function root(stores) {", "export default function root(stores) {",
"return DecoratedComponent => class ReduxRootDecorator {", "return DecoratedComponent => class ReduxRootDecorator {",
"a() { DecoratedComponent; stores; }", "a() { DecoratedComponent; stores; }",
"};", "};",
"}", "}",
].join("\n"), ].join("\n"),
{ "no-undef": 1, "no-unused-vars": 1 }, { "no-undef": 1, "no-unused-vars": 1 },
[] []
); );
@ -1032,10 +1032,10 @@ describe("verify", function () {
it("template with destructuring #31", function () { it("template with destructuring #31", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"module.exports = {", "module.exports = {",
"render() {", "render() {",
"var {name} = this.props;", "var {name} = this.props;",
"return Math.max(null, `Name: ${name}, Name: ${name}`);", "return Math.max(null, `Name: ${name}, Name: ${name}`);",
"}", "}",
"};"].join("\n"), "};"].join("\n"),
{ "comma-spacing": 1 }, { "comma-spacing": 1 },
[] []
@ -1064,12 +1064,12 @@ describe("verify", function () {
"import classMethodDeclarationA from 'decorator';", "import classMethodDeclarationA from 'decorator';",
"import decoratorParameter from 'decorator';", "import decoratorParameter from 'decorator';",
"export class TextareaAutosize {", "export class TextareaAutosize {",
"@classMethodDeclarationA((parameter) => parameter)", "@classMethodDeclarationA((parameter) => parameter)",
"@classMethodDeclarationA(decoratorParameter)", "@classMethodDeclarationA(decoratorParameter)",
"@classMethodDeclarationA", "@classMethodDeclarationA",
"methodDeclaration(e) {", "methodDeclaration(e) {",
"e();", "e();",
"}", "}",
"}" "}"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1 }, { "no-unused-vars": 1 },
@ -1083,14 +1083,14 @@ describe("verify", function () {
"import classMethodDeclarationA from 'decorator';", "import classMethodDeclarationA from 'decorator';",
"import decoratorParameter from 'decorator';", "import decoratorParameter from 'decorator';",
"export class TextareaAutosize {", "export class TextareaAutosize {",
"@classMethodDeclarationA((parameter) => parameter)", "@classMethodDeclarationA((parameter) => parameter)",
"@classMethodDeclarationA(decoratorParameter)", "@classMethodDeclarationA(decoratorParameter)",
"@classMethodDeclarationA", "@classMethodDeclarationA",
"get bar() { }", "get bar() { }",
"@classMethodDeclarationA((parameter) => parameter)", "@classMethodDeclarationA((parameter) => parameter)",
"@classMethodDeclarationA(decoratorParameter)", "@classMethodDeclarationA(decoratorParameter)",
"@classMethodDeclarationA", "@classMethodDeclarationA",
"set bar(val) { val; }", "set bar(val) { val; }",
"}" "}"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1 }, { "no-unused-vars": 1 },
@ -1104,12 +1104,12 @@ describe("verify", function () {
"import classMethodDeclarationA from 'decorator';", "import classMethodDeclarationA from 'decorator';",
"import decoratorParameter from 'decorator';", "import decoratorParameter from 'decorator';",
"var obj = {", "var obj = {",
"@classMethodDeclarationA((parameter) => parameter)", "@classMethodDeclarationA((parameter) => parameter)",
"@classMethodDeclarationA(decoratorParameter)", "@classMethodDeclarationA(decoratorParameter)",
"@classMethodDeclarationA", "@classMethodDeclarationA",
"methodDeclaration(e) {", "methodDeclaration(e) {",
"e();", "e();",
"}", "}",
"};", "};",
"obj;" "obj;"
].join("\n"), ].join("\n"),
@ -1124,14 +1124,14 @@ describe("verify", function () {
"import classMethodDeclarationA from 'decorator';", "import classMethodDeclarationA from 'decorator';",
"import decoratorParameter from 'decorator';", "import decoratorParameter from 'decorator';",
"var obj = {", "var obj = {",
"@classMethodDeclarationA((parameter) => parameter)", "@classMethodDeclarationA((parameter) => parameter)",
"@classMethodDeclarationA(decoratorParameter)", "@classMethodDeclarationA(decoratorParameter)",
"@classMethodDeclarationA", "@classMethodDeclarationA",
"get bar() { },", "get bar() { },",
"@classMethodDeclarationA((parameter) => parameter)", "@classMethodDeclarationA((parameter) => parameter)",
"@classMethodDeclarationA(decoratorParameter)", "@classMethodDeclarationA(decoratorParameter)",
"@classMethodDeclarationA", "@classMethodDeclarationA",
"set bar(val) { val; }", "set bar(val) { val; }",
"};", "};",
"obj;" "obj;"
].join("\n"), ].join("\n"),
@ -1202,13 +1202,13 @@ describe("verify", function () {
it("don't warn no-unused-vars with spread #142", function () { it("don't warn no-unused-vars with spread #142", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"export default function test(data) {", "export default function test(data) {",
"return {", "return {",
"foo: 'bar',", "foo: 'bar',",
"...data", "...data",
"};", "};",
"}", "}",
].join("\n"), ].join("\n"),
{ "no-undef": 1, "no-unused-vars": 1 }, { "no-undef": 1, "no-unused-vars": 1 },
[] []
); );
@ -1218,8 +1218,8 @@ describe("verify", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
[ [
"var a = [", "var a = [",
"1,", "1,",
"2, // a trailing comment makes this line fail comma-dangle (always-multiline)", "2, // a trailing comment makes this line fail comma-dangle (always-multiline)",
"];", "];",
].join("\n"), ].join("\n"),
{ "comma-dangle": [2, "always-multiline"] }, { "comma-dangle": [2, "always-multiline"] },
@ -1229,9 +1229,9 @@ describe("verify", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
[ [
"switch (a) {", "switch (a) {",
"// A comment here makes the above line fail brace-style", "// A comment here makes the above line fail brace-style",
"case 1:", "case 1:",
"console.log(a);", "console.log(a);",
"}" "}"
].join("\n"), ].join("\n"),
{ "brace-style": 2 }, { "brace-style": 2 },
@ -1241,8 +1241,8 @@ describe("verify", function () {
it("ternary and parens #149", function () { it("ternary and parens #149", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"true ? (true) : false;" "true ? (true) : false;"
].join("\n"), ].join("\n"),
{ "space-infix-ops": 1 }, { "space-infix-ops": 1 },
[] []
); );
@ -1252,67 +1252,67 @@ describe("verify", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
[ [
"React.createClass({", "React.createClass({",
"render() {", "render() {",
"// return (", "// return (",
"// <div />", "// <div />",
"// ); // <-- this is the line that is reported", "// ); // <-- this is the line that is reported",
"}", "}",
"});" "});"
].join("\n"), ].join("\n"),
{ "space-in-parens": 1 }, { "space-in-parens": 1 },
[ ] [ ]
) );
}); });
it("block comment space-in-parens #124", function () { it("block comment space-in-parens #124", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
[ [
"React.createClass({", "React.createClass({",
"render() {", "render() {",
"/*", "/*",
"return (", "return (",
" <div />", " <div />",
"); // <-- this is the line that is reported", "); // <-- this is the line that is reported",
"*/", "*/",
"}", "}",
"});" "});"
].join("\n"), ].join("\n"),
{ "space-in-parens": 1 }, { "space-in-parens": 1 },
[ ] [ ]
) );
}); });
it("no no-undef error with rest #11", function () { it("no no-undef error with rest #11", function () {
verifyAndAssertMessages("const [a, ...rest] = ['1', '2', '3']; a; rest;", verifyAndAssertMessages("const [a, ...rest] = ['1', '2', '3']; a; rest;",
{ "no-undef": 1, "no-unused-vars": 1 }, { "no-undef": 1, "no-unused-vars": 1 },
[ ] [ ]
) );
}); });
it("async function with space-before-function-paren #168", function () { it("async function with space-before-function-paren #168", function () {
verifyAndAssertMessages("it('handles updates', async function() {});", verifyAndAssertMessages("it('handles updates', async function() {});",
{ "space-before-function-paren": [1, "never"] }, { "space-before-function-paren": [1, "never"] },
[ ] [ ]
) );
}); });
it("default param flow type no-unused-vars #184", function () { it("default param flow type no-unused-vars #184", function () {
verifyAndAssertMessages( verifyAndAssertMessages(
[ [
"type ResolveOptionType = {", "type ResolveOptionType = {",
"depth?: number,", "depth?: number,",
"identifier?: string", "identifier?: string",
"};", "};",
"", "",
"export default function resolve(", "export default function resolve(",
"options: ResolveOptionType = {}", "options: ResolveOptionType = {}",
"): Object {", "): Object {",
"options;", "options;",
"}", "}",
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-undef": 1 }, { "no-unused-vars": 1, "no-undef": 1 },
[ ] [ ]
) );
}); });
it("no-use-before-define #192", function () { it("no-use-before-define #192", function () {
@ -1322,8 +1322,8 @@ describe("verify", function () {
"var x = 1;" "var x = 1;"
].join("\n"), ].join("\n"),
{ "no-use-before-define": 1 }, { "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 () { it("jsx and stringliteral #216", function () {
@ -1331,31 +1331,31 @@ describe("verify", function () {
"<div className=''></div>", "<div className=''></div>",
{}, {},
[] []
) );
}); });
it("getter/setter #218", function () { it("getter/setter #218", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"class Person {", "class Person {",
" set a (v) { }", " set a (v) { }",
"}" "}"
].join("\n"), ].join("\n"),
{ "space-before-function-paren": 1, "keyword-spacing": [1, {"before": true}], "indent": 1 }, { "space-before-function-paren": 1, "keyword-spacing": [1, {"before": true}], "indent": 1 },
[] []
) );
}); });
it("getter/setter #220", function () { it("getter/setter #220", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"var B = {", "var B = {",
"get x () {", "get x () {",
"return this.ecks;", "return this.ecks;",
"},", "},",
"set x (ecks) {", "set x (ecks) {",
"this.ecks = ecks;", "this.ecks = ecks;",
"}", "}",
"};" "};"
].join("\n"), ].join("\n"),
{ "no-dupe-keys": 1 }, { "no-dupe-keys": 1 },
[] []
); );
@ -1363,12 +1363,12 @@ describe("verify", function () {
it("fixes issues with flow types and ObjectPattern", function () { it("fixes issues with flow types and ObjectPattern", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import type Foo from 'bar';", "import type Foo from 'bar';",
"export default class Foobar {", "export default class Foobar {",
" foo({ bar }: Foo) { bar; }", " foo({ bar }: Foo) { bar; }",
" bar({ foo }: Foo) { foo; }", " bar({ foo }: Foo) { foo; }",
"}" "}"
].join("\n"), ].join("\n"),
{ "no-unused-vars": 1, "no-shadow": 1 }, { "no-unused-vars": 1, "no-shadow": 1 },
[] []
); );
@ -1376,22 +1376,22 @@ describe("verify", function () {
it("correctly detects redeclares if in script mode #217", function () { it("correctly detects redeclares if in script mode #217", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"var a = 321;", "var a = 321;",
"var a = 123;", "var a = 123;",
].join("\n"), ].join("\n"),
{ "no-redeclare": 1 }, { "no-redeclare": 1 },
[ "2:5 'a' is already defined no-redeclare" ], [ "2:5 'a' is already defined. no-redeclare" ],
"script" "script"
); );
}); });
it("correctly detects redeclares if in module mode #217", function () { it("correctly detects redeclares if in module mode #217", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"var a = 321;", "var a = 321;",
"var a = 123;", "var a = 123;",
].join("\n"), ].join("\n"),
{ "no-redeclare": 1 }, { "no-redeclare": 1 },
[ "2:5 'a' is already defined no-redeclare" ], [ "2:5 'a' is already defined. no-redeclare" ],
"module" "module"
); );
}); });
@ -1437,10 +1437,10 @@ describe("verify", function () {
it("allowImportExportEverywhere option (#327)", function () { it("allowImportExportEverywhere option (#327)", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"if (true) { import Foo from 'foo'; }", "if (true) { import Foo from 'foo'; }",
"function foo() { import Bar from 'bar'; }", "function foo() { import Bar from 'bar'; }",
"switch (a) { case 1: import FooBar from 'foobar'; }" "switch (a) { case 1: import FooBar from 'foobar'; }"
].join("\n"), ].join("\n"),
{}, {},
[], [],
"module", "module",
@ -1478,11 +1478,11 @@ describe("verify", function () {
it("decorator does not create TypeError #229", function () { it("decorator does not create TypeError #229", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"class A {", "class A {",
" @test", " @test",
" f() {}", " f() {}",
"}" "}"
].join("\n"), ].join("\n"),
{ "no-undef": 1 }, { "no-undef": 1 },
[ "2:4 'test' is not defined. no-undef" ] [ "2:4 'test' is not defined. no-undef" ]
); );
@ -1490,9 +1490,9 @@ describe("verify", function () {
it("Flow definition does not trigger warnings #223", function () { it("Flow definition does not trigger warnings #223", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"import { Map as $Map } from 'immutable';", "import { Map as $Map } from 'immutable';",
"function myFunction($state: $Map, { a, b, c } : { a: ?Object, b: ?Object, c: $Map }) {}" "function myFunction($state: $Map, { a, b, c } : { a: ?Object, b: ?Object, c: $Map }) {}"
].join("\n"), ].join("\n"),
{ "no-dupe-args": 1, "no-redeclare": 1, "no-shadow": 1 }, { "no-dupe-args": 1, "no-redeclare": 1, "no-shadow": 1 },
[] []
); );
@ -1500,16 +1500,16 @@ describe("verify", function () {
it("newline-before-return with comments #289", function () { it("newline-before-return with comments #289", function () {
verifyAndAssertMessages([ verifyAndAssertMessages([
"function a() {", "function a() {",
"if (b) {", "if (b) {",
"/* eslint-disable no-console */", "/* eslint-disable no-console */",
"console.log('test');", "console.log('test');",
"/* eslint-enable no-console */", "/* eslint-enable no-console */",
"}", "}",
"", "",
"return hasGlobal;", "return hasGlobal;",
"}" "}"
].join("\n"), ].join("\n"),
{ "newline-before-return": 1 }, { "newline-before-return": 1 },
[] []
); );