diff --git a/lib/rules/id-blacklist.js b/lib/rules/id-blacklist.js index d03ee1ec233..ee28c0b5a81 100644 --- a/lib/rules/id-blacklist.js +++ b/lib/rules/id-blacklist.js @@ -67,9 +67,13 @@ module.exports = { * @private */ function report(node) { - context.report({ node, message: "Identifier '{{name}}' is blacklisted.", data: { - name: node.name - } }); + context.report({ + node, + message: "Identifier '{{name}}' is blacklisted.", + data: { + name: node.name + } + }); } return { diff --git a/lib/rules/id-match.js b/lib/rules/id-match.js index 7536e07b109..0420fdc74e4 100644 --- a/lib/rules/id-match.js +++ b/lib/rules/id-match.js @@ -75,10 +75,14 @@ module.exports = { * @private */ function report(node) { - context.report({ node, message: "Identifier '{{name}}' does not match the pattern '{{pattern}}'.", data: { - name: node.name, - pattern - } }); + context.report({ + node, + message: "Identifier '{{name}}' does not match the pattern '{{pattern}}'.", + data: { + name: node.name, + pattern + } + }); } return { diff --git a/lib/rules/no-cond-assign.js b/lib/rules/no-cond-assign.js index 61e5751e4ed..7c031c13f06 100644 --- a/lib/rules/no-cond-assign.js +++ b/lib/rules/no-cond-assign.js @@ -112,9 +112,13 @@ module.exports = { const ancestor = findConditionalAncestor(node); if (ancestor) { - context.report({ node: ancestor, message: "Unexpected assignment within {{type}}.", data: { - type: NODE_DESCRIPTIONS[ancestor.type] || ancestor.type - } }); + context.report({ + node: ancestor, + message: "Unexpected assignment within {{type}}.", + data: { + type: NODE_DESCRIPTIONS[ancestor.type] || ancestor.type + } + }); } } diff --git a/lib/rules/no-inner-declarations.js b/lib/rules/no-inner-declarations.js index e7d1b004e77..28aa5b4b5c3 100644 --- a/lib/rules/no-inner-declarations.js +++ b/lib/rules/no-inner-declarations.js @@ -63,10 +63,14 @@ module.exports = { body.distance === 2); if (!valid) { - context.report({ node, message: "Move {{type}} declaration to {{body}} root.", data: { - type: (node.type === "FunctionDeclaration" ? "function" : "variable"), - body: (body.type === "Program" ? "program" : "function body") - } }); + context.report({ + node, + message: "Move {{type}} declaration to {{body}} root.", + data: { + type: (node.type === "FunctionDeclaration" ? "function" : "variable"), + body: (body.type === "Program" ? "program" : "function body") + } + }); } } diff --git a/lib/rules/no-restricted-properties.js b/lib/rules/no-restricted-properties.js index e3a3d14e51a..44db74f5354 100644 --- a/lib/rules/no-restricted-properties.js +++ b/lib/rules/no-restricted-properties.js @@ -109,20 +109,28 @@ module.exports = { if (matchedObjectProperty) { const message = matchedObjectProperty.message ? ` ${matchedObjectProperty.message}` : ""; - // eslint-disable-next-line eslint-plugin/report-message-format - context.report({ node, message: "'{{objectName}}.{{propertyName}}' is restricted from being used.{{message}}", data: { - objectName, - propertyName, - message - } }); + context.report({ + node, + // eslint-disable-next-line eslint-plugin/report-message-format + message: "'{{objectName}}.{{propertyName}}' is restricted from being used.{{message}}", + data: { + objectName, + propertyName, + message + } + }); } else if (globalMatchedProperty) { const message = globalMatchedProperty.message ? ` ${globalMatchedProperty.message}` : ""; - // eslint-disable-next-line eslint-plugin/report-message-format - context.report({ node, message: "'{{propertyName}}' is restricted from being used.{{message}}", data: { - propertyName, - message - } }); + context.report({ + node, + // eslint-disable-next-line eslint-plugin/report-message-format + message: "'{{propertyName}}' is restricted from being used.{{message}}", + data: { + propertyName, + message + } + }); } } diff --git a/lib/rules/no-tabs.js b/lib/rules/no-tabs.js index 19983c57ba9..0757a69060e 100644 --- a/lib/rules/no-tabs.js +++ b/lib/rules/no-tabs.js @@ -31,10 +31,14 @@ module.exports = { const match = regex.exec(line); if (match) { - context.report({ node, loc: { - line: index + 1, - column: match.index + 1 - }, message: "Unexpected tab character." }); + context.report({ + node, + loc: { + line: index + 1, + column: match.index + 1 + }, + message: "Unexpected tab character." + }); } }); } diff --git a/lib/rules/prefer-reflect.js b/lib/rules/prefer-reflect.js index 49e20989ecb..a47e66c5f53 100644 --- a/lib/rules/prefer-reflect.js +++ b/lib/rules/prefer-reflect.js @@ -83,10 +83,14 @@ module.exports = { * @returns {void} */ function report(node, existing, substitute) { - context.report({ node, message: "Avoid using {{existing}}, instead use {{substitute}}.", data: { - existing, - substitute - } }); + context.report({ + node, + message: "Avoid using {{existing}}, instead use {{substitute}}.", + data: { + existing, + substitute + } + }); } return { diff --git a/lib/rules/valid-jsdoc.js b/lib/rules/valid-jsdoc.js index 331ed7b69b6..ac8ae57c9fc 100644 --- a/lib/rules/valid-jsdoc.js +++ b/lib/rules/valid-jsdoc.js @@ -362,14 +362,22 @@ module.exports = { // TODO(nzakas): Figure out logical things to do with destructured, default, rest params if (param.type === "Identifier") { if (jsdocParams[i] && (name !== jsdocParams[i])) { - context.report({ node: jsdocNode, message: "Expected JSDoc for '{{name}}' but found '{{jsdocName}}'.", data: { - name, - jsdocName: jsdocParams[i] - } }); + context.report({ + node: jsdocNode, + message: "Expected JSDoc for '{{name}}' but found '{{jsdocName}}'.", + data: { + name, + jsdocName: jsdocParams[i] + } + }); } else if (!params[name] && !isOverride) { - context.report({ node: jsdocNode, message: "Missing JSDoc for parameter '{{name}}'.", data: { - name - } }); + context.report({ + node: jsdocNode, + message: "Missing JSDoc for parameter '{{name}}'.", + data: { + name + } + }); } } }); diff --git a/packages/eslint-config-eslint/default.yml b/packages/eslint-config-eslint/default.yml index d97f54cbb4d..410ede81b0f 100644 --- a/packages/eslint-config-eslint/default.yml +++ b/packages/eslint-config-eslint/default.yml @@ -115,7 +115,7 @@ rules: no-whitespace-before-property: "error" no-with: "error" no-var: "error" - object-curly-newline: ["error", { "consistent": true, "multiline": true}] + object-curly-newline: ["error", { "consistent": true, "multiline": true }] object-curly-spacing: ["error", "always"] object-property-newline: ["error", { "allowMultiplePropertiesPerLine": true }] object-shorthand: "error" diff --git a/tests/lib/cli-engine.js b/tests/lib/cli-engine.js index 104118888b9..419df9eef21 100644 --- a/tests/lib/cli-engine.js +++ b/tests/lib/cli-engine.js @@ -34,10 +34,12 @@ describe("CLIEngine", () => { const examplePluginName = "eslint-plugin-example", examplePluginNameWithNamespace = "@eslint/eslint-plugin-example", requireStubs = {}, - examplePlugin = { rules: { - "example-rule": require("../fixtures/rules/custom-rule"), - "make-syntax-error": require("../fixtures/rules/make-syntax-error-rule") - } }, + examplePlugin = { + rules: { + "example-rule": require("../fixtures/rules/custom-rule"), + "make-syntax-error": require("../fixtures/rules/make-syntax-error-rule") + } + }, examplePreprocessorName = "eslint-plugin-processor", originalDir = process.cwd(); let CLIEngine, diff --git a/tests/lib/linter.js b/tests/lib/linter.js index 672088c71f6..ba98b0a1fe0 100644 --- a/tests/lib/linter.js +++ b/tests/lib/linter.js @@ -2914,23 +2914,25 @@ describe("Linter", () => { }; let ok = false; - linter.defineRules({ test(context) { - return { - Program() { - const scope = context.getScope(); - const sourceCode = context.getSourceCode(); - const comments = sourceCode.getAllComments(); + linter.defineRules({ + test(context) { + return { + Program() { + const scope = context.getScope(); + const sourceCode = context.getSourceCode(); + const comments = sourceCode.getAllComments(); - assert.equal(1, comments.length); + assert.equal(1, comments.length); - const foo = getVariable(scope, "foo"); + const foo = getVariable(scope, "foo"); - assert.notOk(foo); + assert.notOk(foo); - ok = true; - } - }; - } }); + ok = true; + } + }; + } + }); linter.verify(code, config, { allowInlineConfig: false }); assert(ok); @@ -3005,23 +3007,25 @@ describe("Linter", () => { }; let ok = false; - linter.defineRules({ test(context) { - return { - Program() { - const scope = context.getScope(); - const sourceCode = context.getSourceCode(); - const comments = sourceCode.getAllComments(); + linter.defineRules({ + test(context) { + return { + Program() { + const scope = context.getScope(); + const sourceCode = context.getSourceCode(); + const comments = sourceCode.getAllComments(); - assert.equal(1, comments.length); + assert.equal(1, comments.length); - const windowVar = getVariable(scope, "window"); + const windowVar = getVariable(scope, "window"); - assert.notOk(windowVar.eslintExplicitGlobal); + assert.notOk(windowVar.eslintExplicitGlobal); - ok = true; - } - }; - } }); + ok = true; + } + }; + } + }); linter.verify(code, config, { allowInlineConfig: false }); assert(ok); @@ -3354,34 +3358,36 @@ describe("Linter", () => { const code = "/* global foo */\n/* global bar, baz */"; let ok = false; - linter.defineRules({ test(context) { - return { - Program() { - const scope = context.getScope(); - const sourceCode = context.getSourceCode(); - const comments = sourceCode.getAllComments(); + linter.defineRules({ + test(context) { + return { + Program() { + const scope = context.getScope(); + const sourceCode = context.getSourceCode(); + const comments = sourceCode.getAllComments(); - assert.equal(2, comments.length); + assert.equal(2, comments.length); - const foo = getVariable(scope, "foo"); + const foo = getVariable(scope, "foo"); - assert.equal(true, foo.eslintExplicitGlobal); - assert.equal(comments[0], foo.eslintExplicitGlobalComment); + assert.equal(true, foo.eslintExplicitGlobal); + assert.equal(comments[0], foo.eslintExplicitGlobalComment); - const bar = getVariable(scope, "bar"); + const bar = getVariable(scope, "bar"); - assert.equal(true, bar.eslintExplicitGlobal); - assert.equal(comments[1], bar.eslintExplicitGlobalComment); + assert.equal(true, bar.eslintExplicitGlobal); + assert.equal(comments[1], bar.eslintExplicitGlobalComment); - const baz = getVariable(scope, "baz"); + const baz = getVariable(scope, "baz"); - assert.equal(true, baz.eslintExplicitGlobal); - assert.equal(comments[1], baz.eslintExplicitGlobalComment); + assert.equal(true, baz.eslintExplicitGlobal); + assert.equal(comments[1], baz.eslintExplicitGlobalComment); - ok = true; - } - }; - } }); + ok = true; + } + }; + } + }); linter.verify(code, { rules: { test: 2 } }); assert(ok); @@ -3430,14 +3436,16 @@ describe("Linter", () => { beforeEach(() => { let ok = false; - linter.defineRules({ test(context) { - return { - Program() { - scope = context.getScope(); - ok = true; - } - }; - } }); + linter.defineRules({ + test(context) { + return { + Program() { + scope = context.getScope(); + ok = true; + } + }; + } + }); linter.verify(code, { rules: { test: 2 }, globals: { e: true, f: false } }); assert(ok); }); @@ -3530,70 +3538,72 @@ describe("Linter", () => { * @returns {void} */ function verify(code, type, expectedNamesList) { - linter.defineRules({ test(context) { - const rule = { - Program: checkEmpty, - EmptyStatement: checkEmpty, - BlockStatement: checkEmpty, - ExpressionStatement: checkEmpty, - LabeledStatement: checkEmpty, - BreakStatement: checkEmpty, - ContinueStatement: checkEmpty, - WithStatement: checkEmpty, - SwitchStatement: checkEmpty, - ReturnStatement: checkEmpty, - ThrowStatement: checkEmpty, - TryStatement: checkEmpty, - WhileStatement: checkEmpty, - DoWhileStatement: checkEmpty, - ForStatement: checkEmpty, - ForInStatement: checkEmpty, - DebuggerStatement: checkEmpty, - ThisExpression: checkEmpty, - ArrayExpression: checkEmpty, - ObjectExpression: checkEmpty, - Property: checkEmpty, - SequenceExpression: checkEmpty, - UnaryExpression: checkEmpty, - BinaryExpression: checkEmpty, - AssignmentExpression: checkEmpty, - UpdateExpression: checkEmpty, - LogicalExpression: checkEmpty, - ConditionalExpression: checkEmpty, - CallExpression: checkEmpty, - NewExpression: checkEmpty, - MemberExpression: checkEmpty, - SwitchCase: checkEmpty, - Identifier: checkEmpty, - Literal: checkEmpty, - ForOfStatement: checkEmpty, - ArrowFunctionExpression: checkEmpty, - YieldExpression: checkEmpty, - TemplateLiteral: checkEmpty, - TaggedTemplateExpression: checkEmpty, - TemplateElement: checkEmpty, - ObjectPattern: checkEmpty, - ArrayPattern: checkEmpty, - RestElement: checkEmpty, - AssignmentPattern: checkEmpty, - ClassBody: checkEmpty, - MethodDefinition: checkEmpty, - MetaProperty: checkEmpty - }; + linter.defineRules({ + test(context) { + const rule = { + Program: checkEmpty, + EmptyStatement: checkEmpty, + BlockStatement: checkEmpty, + ExpressionStatement: checkEmpty, + LabeledStatement: checkEmpty, + BreakStatement: checkEmpty, + ContinueStatement: checkEmpty, + WithStatement: checkEmpty, + SwitchStatement: checkEmpty, + ReturnStatement: checkEmpty, + ThrowStatement: checkEmpty, + TryStatement: checkEmpty, + WhileStatement: checkEmpty, + DoWhileStatement: checkEmpty, + ForStatement: checkEmpty, + ForInStatement: checkEmpty, + DebuggerStatement: checkEmpty, + ThisExpression: checkEmpty, + ArrayExpression: checkEmpty, + ObjectExpression: checkEmpty, + Property: checkEmpty, + SequenceExpression: checkEmpty, + UnaryExpression: checkEmpty, + BinaryExpression: checkEmpty, + AssignmentExpression: checkEmpty, + UpdateExpression: checkEmpty, + LogicalExpression: checkEmpty, + ConditionalExpression: checkEmpty, + CallExpression: checkEmpty, + NewExpression: checkEmpty, + MemberExpression: checkEmpty, + SwitchCase: checkEmpty, + Identifier: checkEmpty, + Literal: checkEmpty, + ForOfStatement: checkEmpty, + ArrowFunctionExpression: checkEmpty, + YieldExpression: checkEmpty, + TemplateLiteral: checkEmpty, + TaggedTemplateExpression: checkEmpty, + TemplateElement: checkEmpty, + ObjectPattern: checkEmpty, + ArrayPattern: checkEmpty, + RestElement: checkEmpty, + AssignmentPattern: checkEmpty, + ClassBody: checkEmpty, + MethodDefinition: checkEmpty, + MetaProperty: checkEmpty + }; - rule[type] = function(node) { - const expectedNames = expectedNamesList.shift(); - const variables = context.getDeclaredVariables(node); + rule[type] = function(node) { + const expectedNames = expectedNamesList.shift(); + const variables = context.getDeclaredVariables(node); - assert(Array.isArray(expectedNames)); - assert(Array.isArray(variables)); - assert.equal(expectedNames.length, variables.length); - for (let i = variables.length - 1; i >= 0; i--) { - assert.equal(expectedNames[i], variables[i].name); - } - }; - return rule; - } }); + assert(Array.isArray(expectedNames)); + assert(Array.isArray(variables)); + assert.equal(expectedNames.length, variables.length); + for (let i = variables.length - 1; i >= 0; i--) { + assert.equal(expectedNames[i], variables[i].name); + } + }; + return rule; + } + }); linter.verify(code, { rules: { test: 2 }, parserOptions: { diff --git a/tests/lib/rules/brace-style.js b/tests/lib/rules/brace-style.js index 6db469124a4..0b93f9c48b2 100644 --- a/tests/lib/rules/brace-style.js +++ b/tests/lib/rules/brace-style.js @@ -315,7 +315,8 @@ ruleTester.run("brace-style", rule, { { code: "if (a) { \nb();\n } else { \nc();\n }", output: "if (a) { \nb();\n }\n else { \nc();\n }", - options: ["stroustrup"], errors: [{ message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }] + options: ["stroustrup"], + errors: [{ message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }] }, { code: "if (foo) {\nbaz();\n} else if (bar) {\nbaz();\n}\nelse {\nqux();\n}", diff --git a/tests/lib/rules/dot-notation.js b/tests/lib/rules/dot-notation.js index 19b0031753f..28edc2528b5 100644 --- a/tests/lib/rules/dot-notation.js +++ b/tests/lib/rules/dot-notation.js @@ -76,7 +76,8 @@ ruleTester.run("dot-notation", rule, { { code: "a['_dangle'];", output: "a._dangle;", - options: [{ allowPattern: "^[a-z]+(_[a-z]+)+$" }], errors: [{ message: "[\"_dangle\"] is better written in dot notation." }] + options: [{ allowPattern: "^[a-z]+(_[a-z]+)+$" }], + errors: [{ message: "[\"_dangle\"] is better written in dot notation." }] }, { code: "a['SHOUT_CASE'];", diff --git a/tests/lib/rules/id-length.js b/tests/lib/rules/id-length.js index 5c2bd87334c..a4e36cd74d6 100644 --- a/tests/lib/rules/id-length.js +++ b/tests/lib/rules/id-length.js @@ -74,50 +74,106 @@ ruleTester.run("id-length", rule, { { code: "var handler = function (e) {};", errors: [{ message: "Identifier name 'e' is too short (< 2).", type: "Identifier" }] }, { code: "for (var i=0; i < 10; i++) { console.log(i); }", errors: [{ message: "Identifier name 'i' is too short (< 2).", type: "Identifier" }] }, { code: "var j=0; while (j > -10) { console.log(--j); }", errors: [{ message: "Identifier name 'j' is too short (< 2).", type: "Identifier" }] }, - { code: "var _$xt_$ = Foo(42)", options: [{ min: 2, max: 4 }], errors: [ - { message: "Identifier name '_$xt_$' is too long (> 4).", type: "Identifier" } - ] }, - { code: "var _$x$_t$ = Foo(42)", options: [{ min: 2, max: 4 }], errors: [ - { message: "Identifier name '_$x$_t$' is too long (> 4).", type: "Identifier" } - ] }, - { code: "(a) => { a * a };", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Identifier name 'a' is too short (< 2).", type: "Identifier" } - ] }, - { code: "function foo(x = 0) { }", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } - ] }, - { code: "class x { }", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } - ] }, - { code: "class Foo { x() {} }", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } - ] }, - { code: "function foo(...x) { }", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } - ] }, - { code: "var { x} = {};", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }, - { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } - ] }, - { code: "var { x: a} = {};", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } - ] }, - { code: "var { a: [x]} = {};", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Identifier name 'a' is too short (< 2).", type: "Identifier" } - ] }, - { code: "import x from 'y';", parserOptions: { sourceType: "module" }, errors: [ - { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } - ] }, - { code: "export var x = 0;", parserOptions: { sourceType: "module" }, errors: [ - { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } - ] }, - { code: "({ a: obj.x.y.z } = {});", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Identifier name 'a' is too short (< 2).", type: "Identifier" }, - { message: "Identifier name 'z' is too short (< 2).", type: "Identifier" } - ] }, - { code: "({ prop: obj.x } = {});", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } - ] }, + { + code: "var _$xt_$ = Foo(42)", + options: [{ min: 2, max: 4 }], + errors: [ + { message: "Identifier name '_$xt_$' is too long (> 4).", type: "Identifier" } + ] + }, + { + code: "var _$x$_t$ = Foo(42)", + options: [{ min: 2, max: 4 }], + errors: [ + { message: "Identifier name '_$x$_t$' is too long (> 4).", type: "Identifier" } + ] + }, + { + code: "(a) => { a * a };", + parserOptions: { ecmaVersion: 6 }, + errors: [ + { message: "Identifier name 'a' is too short (< 2).", type: "Identifier" } + ] + }, + { + code: "function foo(x = 0) { }", + parserOptions: { ecmaVersion: 6 }, + errors: [ + { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } + ] + }, + { + code: "class x { }", + parserOptions: { ecmaVersion: 6 }, + errors: [ + { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } + ] + }, + { + code: "class Foo { x() {} }", + parserOptions: { ecmaVersion: 6 }, + errors: [ + { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } + ] + }, + { + code: "function foo(...x) { }", + parserOptions: { ecmaVersion: 6 }, + errors: [ + { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } + ] + }, + { + code: "var { x} = {};", + parserOptions: { ecmaVersion: 6 }, + errors: [ + { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }, + { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } + ] + }, + { + code: "var { x: a} = {};", + parserOptions: { ecmaVersion: 6 }, + errors: [ + { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } + ] + }, + { + code: "var { a: [x]} = {};", + parserOptions: { ecmaVersion: 6 }, + errors: [ + { message: "Identifier name 'a' is too short (< 2).", type: "Identifier" } + ] + }, + { + code: "import x from 'y';", + parserOptions: { sourceType: "module" }, + errors: [ + { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } + ] + }, + { + code: "export var x = 0;", + parserOptions: { sourceType: "module" }, + errors: [ + { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } + ] + }, + { + code: "({ a: obj.x.y.z } = {});", + parserOptions: { ecmaVersion: 6 }, + errors: [ + { message: "Identifier name 'a' is too short (< 2).", type: "Identifier" }, + { message: "Identifier name 'z' is too short (< 2).", type: "Identifier" } + ] + }, + { + code: "({ prop: obj.x } = {});", + parserOptions: { ecmaVersion: 6 }, + errors: [ + { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" } + ] + }, { code: "var x = 1;", options: [{ properties: "never" }], errors: [{ message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }] } ] }); diff --git a/tests/lib/rules/new-parens.js b/tests/lib/rules/new-parens.js index 224ac834291..a93bcbd6f0d 100644 --- a/tests/lib/rules/new-parens.js +++ b/tests/lib/rules/new-parens.js @@ -54,8 +54,10 @@ ruleTester.run("new-parens", rule, { { code: "var a = (new Date)", output: "var a = (new Date())", - errors: [{ message: "Missing '()' invoking a constructor.", - type: "NewExpression" }] + errors: [{ + message: "Missing '()' invoking a constructor.", + type: "NewExpression" + }] }, { diff --git a/tests/lib/rules/no-catch-shadow.js b/tests/lib/rules/no-catch-shadow.js index 6bda019bca9..a302ae86b0c 100644 --- a/tests/lib/rules/no-catch-shadow.js +++ b/tests/lib/rules/no-catch-shadow.js @@ -34,7 +34,8 @@ ruleTester.run("no-catch-shadow", rule, { "}", "", "module.exports = broken;" - ].join("\n"), parserOptions: { ecmaVersion: 6 } + ].join("\n"), + parserOptions: { ecmaVersion: 6 } } ], invalid: [ diff --git a/tests/lib/rules/no-continue.js b/tests/lib/rules/no-continue.js index 561986c6456..16ed522829f 100644 --- a/tests/lib/rules/no-continue.js +++ b/tests/lib/rules/no-continue.js @@ -27,23 +27,31 @@ ruleTester.run("no-continue", rule, { invalid: [ { code: "var sum = 0, i; for(i = 0; i < 10; i++){ if(i <= 5) { continue; } sum += i; }", - errors: [{ message: "Unexpected use of continue statement.", - type: "ContinueStatement" }] + errors: [{ + message: "Unexpected use of continue statement.", + type: "ContinueStatement" + }] }, { code: "var sum = 0, i; myLabel: for(i = 0; i < 10; i++){ if(i <= 5) { continue myLabel; } sum += i; }", - errors: [{ message: "Unexpected use of continue statement.", - type: "ContinueStatement" }] + errors: [{ + message: "Unexpected use of continue statement.", + type: "ContinueStatement" + }] }, { code: "var sum = 0, i = 0; while(i < 10) { if(i <= 5) { i++; continue; } sum += i; i++; }", - errors: [{ message: "Unexpected use of continue statement.", - type: "ContinueStatement" }] + errors: [{ + message: "Unexpected use of continue statement.", + type: "ContinueStatement" + }] }, { code: "var sum = 0, i = 0; myLabel: while(i < 10) { if(i <= 5) { i++; continue myLabel; } sum += i; i++; }", - errors: [{ message: "Unexpected use of continue statement.", - type: "ContinueStatement" }] + errors: [{ + message: "Unexpected use of continue statement.", + type: "ContinueStatement" + }] } ] }); diff --git a/tests/lib/rules/no-else-return.js b/tests/lib/rules/no-else-return.js index eca303dbc1a..d081de88fbb 100644 --- a/tests/lib/rules/no-else-return.js +++ b/tests/lib/rules/no-else-return.js @@ -58,7 +58,8 @@ ruleTester.run("no-else-return", rule, { { code: "function foo3() { if (true) return x; else return y; }", output: "function foo3() { if (true) return x; return y; }", - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "ReturnStatement" }] }, + errors: [{ message: "Unnecessary 'else' after 'return'.", type: "ReturnStatement" }] + }, { code: "function foo4() { if (true) { if (false) return x; else return y; } else { return z; } }", output: "function foo4() { if (true) { if (false) return x; return y; } else { return z; } }", // Other case is fixed in the second pass. diff --git a/tests/lib/rules/no-extra-bind.js b/tests/lib/rules/no-extra-bind.js index 6912ab92d7d..1aced94560d 100644 --- a/tests/lib/rules/no-extra-bind.js +++ b/tests/lib/rules/no-extra-bind.js @@ -73,6 +73,7 @@ ruleTester.run("no-extra-bind", rule, { { code: "var a = function() { (function(){ (function(){ this.d }.bind(c)) }) }.bind(b)", output: "var a = function() { (function(){ (function(){ this.d }.bind(c)) }) }", - errors: [{ message: "The function binding is unnecessary.", type: "CallExpression", column: 71 }] } + errors: [{ message: "The function binding is unnecessary.", type: "CallExpression", column: 71 }] + } ] }); diff --git a/tests/lib/rules/no-extra-parens.js b/tests/lib/rules/no-extra-parens.js index 4823374a0b6..96690548a29 100644 --- a/tests/lib/rules/no-extra-parens.js +++ b/tests/lib/rules/no-extra-parens.js @@ -316,57 +316,84 @@ ruleTester.run("no-extra-parens", rule, { // ["all", { ignoreJSX: "all" }] { code: "const Component = (
)", options: ["all", { ignoreJSX: "all" }] }, - { code: [ - "const Component = (
", - "

", - "

);" - ].join("\n"), options: ["all", { ignoreJSX: "all" }] }, - { code: [ - "const Component = (", - "
", - ");" - ].join("\n"), options: ["all", { ignoreJSX: "all" }] }, - { code: [ - "const Component =", - " (
)" - ].join("\n"), options: ["all", { ignoreJSX: "all" }] }, + { + code: [ + "const Component = (
", + "

", + "

);" + ].join("\n"), + options: ["all", { ignoreJSX: "all" }] + }, + { + code: [ + "const Component = (", + "
", + ");" + ].join("\n"), + options: ["all", { ignoreJSX: "all" }] + }, + { + code: [ + "const Component =", + " (
)" + ].join("\n"), + options: ["all", { ignoreJSX: "all" }] + }, // ["all", { ignoreJSX: "single-line" }] { code: "const Component = (
);", options: ["all", { ignoreJSX: "single-line" }] }, - { code: [ - "const Component = (", - "
", - ");" - ].join("\n"), options: ["all", { ignoreJSX: "single-line" }] }, - { code: [ - "const Component =", - "(
)" - ].join("\n"), options: ["all", { ignoreJSX: "single-line" }] }, + { + code: [ + "const Component = (", + "
", + ");" + ].join("\n"), + options: ["all", { ignoreJSX: "single-line" }] + }, + { + code: [ + "const Component =", + "(
)" + ].join("\n"), + options: ["all", { ignoreJSX: "single-line" }] + }, // ["all", { ignoreJSX: "multi-line" }] - { code: [ - "const Component = (", - "
", - "

", - "

", - ");" - ].join("\n"), options: ["all", { ignoreJSX: "multi-line" }] }, - { code: [ - "const Component = (
", - "

", - "

);" - ].join("\n"), options: ["all", { ignoreJSX: "multi-line" }] }, - { code: [ - "const Component =", - "(
", - "

", - "

);" - ].join("\n"), options: ["all", { ignoreJSX: "multi-line" }] }, - { code: [ - "const Component = ()" - ].join("\n"), options: ["all", { ignoreJSX: "multi-line" }] }, + { + code: [ + "const Component = (", + "
", + "

", + "

", + ");" + ].join("\n"), + options: ["all", { ignoreJSX: "multi-line" }] + }, + { + code: [ + "const Component = (
", + "

", + "

);" + ].join("\n"), + options: ["all", { ignoreJSX: "multi-line" }] + }, + { + code: [ + "const Component =", + "(
", + "

", + "

);" + ].join("\n"), + options: ["all", { ignoreJSX: "multi-line" }] + }, + { + code: [ + "const Component = ()" + ].join("\n"), + options: ["all", { ignoreJSX: "multi-line" }] + }, // ["all", { enforceForArrowConditionals: false }] { code: "var a = b => 1 ? 2 : 3", options: ["all", { enforceForArrowConditionals: false }], parserOptions: { ecmaVersion: 6 } }, diff --git a/tests/lib/rules/no-implicit-coercion.js b/tests/lib/rules/no-implicit-coercion.js index 0e1541b5a94..cdc541b50f2 100644 --- a/tests/lib/rules/no-implicit-coercion.js +++ b/tests/lib/rules/no-implicit-coercion.js @@ -192,32 +192,38 @@ ruleTester.run("no-implicit-coercion", rule, { errors: [{ message: "use `foo = String(foo)` instead.", type: "AssignmentExpression" }] }, { - code: "var a = !!foo", output: "var a = Boolean(foo)", + code: "var a = !!foo", + output: "var a = Boolean(foo)", options: [{ boolean: true, allow: ["~"] }], errors: [{ message: "use `Boolean(foo)` instead.", type: "UnaryExpression" }] }, { - code: "var a = ~foo.indexOf(1)", output: null, + code: "var a = ~foo.indexOf(1)", + output: null, options: [{ boolean: true, allow: ["!!"] }], errors: [{ message: "use `foo.indexOf(1) !== -1` instead.", type: "UnaryExpression" }] }, { - code: "var a = 1 * foo", output: "var a = Number(foo)", + code: "var a = 1 * foo", + output: "var a = Number(foo)", options: [{ boolean: true, allow: ["+"] }], errors: [{ message: "use `Number(foo)` instead.", type: "BinaryExpression" }] }, { - code: "var a = +foo", output: "var a = Number(foo)", + code: "var a = +foo", + output: "var a = Number(foo)", options: [{ boolean: true, allow: ["*"] }], errors: [{ message: "use `Number(foo)` instead.", type: "UnaryExpression" }] }, { - code: "var a = \"\" + foo", output: "var a = String(foo)", + code: "var a = \"\" + foo", + output: "var a = String(foo)", options: [{ boolean: true, allow: ["*"] }], errors: [{ message: "use `String(foo)` instead.", type: "BinaryExpression" }] }, { - code: "var a = `` + foo", output: "var a = String(foo)", + code: "var a = `` + foo", + output: "var a = String(foo)", options: [{ boolean: true, allow: ["*"] }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "use `String(foo)` instead.", type: "BinaryExpression" }] diff --git a/tests/lib/rules/no-lone-blocks.js b/tests/lib/rules/no-lone-blocks.js index 82d8096dde5..9c4a0bb7531 100644 --- a/tests/lib/rules/no-lone-blocks.js +++ b/tests/lib/rules/no-lone-blocks.js @@ -63,9 +63,11 @@ ruleTester.run("no-lone-blocks", rule, { { code: "{var x = 1;}", errors: [{ message: "Block is redundant.", type: "BlockStatement" }] }, { code: "foo(); {} bar();", errors: [{ message: "Block is redundant.", type: "BlockStatement" }] }, { code: "if (foo) { bar(); {} baz(); }", errors: [{ message: "Nested block is redundant.", type: "BlockStatement" }] }, - { code: "{ \n{ } }", errors: [ - { message: "Block is redundant.", type: "BlockStatement", line: 1 }, - { message: "Nested block is redundant.", type: "BlockStatement", line: 2 }] + { + code: "{ \n{ } }", + errors: [ + { message: "Block is redundant.", type: "BlockStatement", line: 1 }, + { message: "Nested block is redundant.", type: "BlockStatement", line: 2 }] }, { code: "function foo() { bar(); {} baz(); }", errors: [{ message: "Nested block is redundant.", type: "BlockStatement" }] }, { code: "while (foo) { {} }", errors: [{ message: "Nested block is redundant.", type: "BlockStatement" }] }, diff --git a/tests/lib/rules/no-restricted-imports.js b/tests/lib/rules/no-restricted-imports.js index 7ee739eb262..444f3497921 100644 --- a/tests/lib/rules/no-restricted-imports.js +++ b/tests/lib/rules/no-restricted-imports.js @@ -38,7 +38,8 @@ ruleTester.run("no-restricted-imports", rule, { } ], invalid: [{ - code: "import \"fs\"", options: ["fs"], + code: "import \"fs\"", + options: ["fs"], errors: [{ message: "'fs' import is restricted from being used.", type: "ImportDeclaration" }] }, { code: "import os from \"os \";", diff --git a/tests/lib/rules/no-shadow-restricted-names.js b/tests/lib/rules/no-shadow-restricted-names.js index 41542e703f0..d3b84906e76 100644 --- a/tests/lib/rules/no-shadow-restricted-names.js +++ b/tests/lib/rules/no-shadow-restricted-names.js @@ -23,7 +23,8 @@ ruleTester.run("no-shadow-restricted-names", rule, { { code: "export default function() {}", parserOptions: { sourceType: "module" } } ], invalid: [ - { code: "function NaN(NaN) { var NaN; !function NaN(NaN) { try {} catch(NaN) {} }; }", + { + code: "function NaN(NaN) { var NaN; !function NaN(NaN) { try {} catch(NaN) {} }; }", errors: [ { message: "Shadowing of global property 'NaN'.", type: "Identifier" }, { message: "Shadowing of global property 'NaN'.", type: "Identifier" }, @@ -33,7 +34,8 @@ ruleTester.run("no-shadow-restricted-names", rule, { { message: "Shadowing of global property 'NaN'.", type: "Identifier" } ] }, - { code: "function undefined(undefined) { var undefined; !function undefined(undefined) { try {} catch(undefined) {} }; }", + { + code: "function undefined(undefined) { var undefined; !function undefined(undefined) { try {} catch(undefined) {} }; }", errors: [ { message: "Shadowing of global property 'undefined'.", type: "Identifier" }, { message: "Shadowing of global property 'undefined'.", type: "Identifier" }, @@ -43,7 +45,8 @@ ruleTester.run("no-shadow-restricted-names", rule, { { message: "Shadowing of global property 'undefined'.", type: "Identifier" } ] }, - { code: "function Infinity(Infinity) { var Infinity; !function Infinity(Infinity) { try {} catch(Infinity) {} }; }", + { + code: "function Infinity(Infinity) { var Infinity; !function Infinity(Infinity) { try {} catch(Infinity) {} }; }", errors: [ { message: "Shadowing of global property 'Infinity'.", type: "Identifier" }, { message: "Shadowing of global property 'Infinity'.", type: "Identifier" }, @@ -53,7 +56,8 @@ ruleTester.run("no-shadow-restricted-names", rule, { { message: "Shadowing of global property 'Infinity'.", type: "Identifier" } ] }, - { code: "function arguments(arguments) { var arguments; !function arguments(arguments) { try {} catch(arguments) {} }; }", + { + code: "function arguments(arguments) { var arguments; !function arguments(arguments) { try {} catch(arguments) {} }; }", errors: [ { message: "Shadowing of global property 'arguments'.", type: "Identifier" }, { message: "Shadowing of global property 'arguments'.", type: "Identifier" }, @@ -63,7 +67,8 @@ ruleTester.run("no-shadow-restricted-names", rule, { { message: "Shadowing of global property 'arguments'.", type: "Identifier" } ] }, - { code: "function eval(eval) { var eval; !function eval(eval) { try {} catch(eval) {} }; }", + { + code: "function eval(eval) { var eval; !function eval(eval) { try {} catch(eval) {} }; }", errors: [ { message: "Shadowing of global property 'eval'.", type: "Identifier" }, { message: "Shadowing of global property 'eval'.", type: "Identifier" }, @@ -73,7 +78,8 @@ ruleTester.run("no-shadow-restricted-names", rule, { { message: "Shadowing of global property 'eval'.", type: "Identifier" } ] }, - { code: "var eval = (eval) => { var eval; !function eval(eval) { try {} catch(eval) {} }; }", + { + code: "var eval = (eval) => { var eval; !function eval(eval) { try {} catch(eval) {} }; }", parserOptions: { ecmaVersion: 6 }, errors: [ { message: "Shadowing of global property 'eval'.", type: "Identifier" }, diff --git a/tests/lib/rules/sort-vars.js b/tests/lib/rules/sort-vars.js index c5cfb07293a..a911342f600 100644 --- a/tests/lib/rules/sort-vars.js +++ b/tests/lib/rules/sort-vars.js @@ -39,21 +39,41 @@ ruleTester.run("sort-vars", rule, { { code: "var {A, b, C} = x;", options: ignoreCaseArgs, parserOptions: { ecmaVersion: 6 } }, { code: "var test = [1,2,3];", parserOptions: { ecmaVersion: 6 } }, { code: "var {a,b} = [1,2];", parserOptions: { ecmaVersion: 6 } }, - { code: "var [a, B, c] = [1, 2, 3];", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } }, - { code: "var [A, B, c] = [1, 2, 3];", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } }, - { code: "var [A, b, C] = [1, 2, 3];", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } }, + { + code: "var [a, B, c] = [1, 2, 3];", + options: ignoreCaseArgs, + parserOptions: { ecmaVersion: 6 } + }, + { + code: "var [A, B, c] = [1, 2, 3];", + options: ignoreCaseArgs, + parserOptions: { ecmaVersion: 6 } + }, + { + code: "var [A, b, C] = [1, 2, 3];", + options: ignoreCaseArgs, + parserOptions: { ecmaVersion: 6 } + }, { code: "let {a, b, c} = x;", parserOptions: { ecmaVersion: 6 } }, - { code: "let [a, b, c] = [1, 2, 3];", - parserOptions: { ecmaVersion: 6 } }, - { code: "const {a, b, c} = {a: 1, b: true, c: \"Moo\"};", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } }, - { code: "const [a, b, c] = [1, true, \"Moo\"];", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } }, - { code: "const [c, a, b] = [1, true, \"Moo\"];", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } }, + { + code: "let [a, b, c] = [1, 2, 3];", + parserOptions: { ecmaVersion: 6 } + }, + { + code: "const {a, b, c} = {a: 1, b: true, c: \"Moo\"};", + options: ignoreCaseArgs, + parserOptions: { ecmaVersion: 6 } + }, + { + code: "const [a, b, c] = [1, true, \"Moo\"];", + options: ignoreCaseArgs, + parserOptions: { ecmaVersion: 6 } + }, + { + code: "const [c, a, b] = [1, true, \"Moo\"];", + options: ignoreCaseArgs, + parserOptions: { ecmaVersion: 6 } + }, { code: "var {a, x: {b, c}} = {};", parserOptions: { ecmaVersion: 6 } }, { code: "var {c, x: {a, c}} = {};", parserOptions: { ecmaVersion: 6 } }, { code: "var {a, x: [b, c]} = {};", parserOptions: { ecmaVersion: 6 } }, @@ -64,20 +84,27 @@ ruleTester.run("sort-vars", rule, { { code: "var [b, {x: {a, c}}] = {};", parserOptions: { ecmaVersion: 6 } }, { code: "var [b, d, a, c] = {};", parserOptions: { ecmaVersion: 6 } }, { code: "var e, [a, c, d] = {};", parserOptions: { ecmaVersion: 6 } }, - { code: "var a, [E, c, D] = [];", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 } }, + { + code: "var a, [E, c, D] = [];", + options: ignoreCaseArgs, + parserOptions: { ecmaVersion: 6 } + }, { code: "var a, f, [e, c, d] = [1,2,3];", parserOptions: { ecmaVersion: 6 } }, - { code: [ - "export default class {", - " render () {", - " let {", - " b", - " } = this,", - " a,", - " c;", - " }", - "}" - ].join("\n"), parserOptions: { sourceType: "module" }, env: { es6: true } }, + { + code: [ + "export default class {", + " render () {", + " let {", + " b", + " } = this,", + " a,", + " c;", + " }", + "}" + ].join("\n"), + parserOptions: { sourceType: "module" }, + env: { es6: true } + }, { code: "var {} = 1, a", @@ -96,10 +123,18 @@ ruleTester.run("sort-vars", rule, { { code: "var a, B, c;", errors: [expectedError] }, { code: "var B, a;", options: ignoreCaseArgs, errors: [expectedError] }, { code: "var B, A, c;", options: ignoreCaseArgs, errors: [expectedError] }, - { code: "var d, a, [b, c] = {};", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 }, errors: [expectedError] }, - { code: "var d, a, [b, {x: {c, e}}] = {};", options: ignoreCaseArgs, - parserOptions: { ecmaVersion: 6 }, errors: [expectedError] }, + { + code: "var d, a, [b, c] = {};", + options: ignoreCaseArgs, + parserOptions: { ecmaVersion: 6 }, + errors: [expectedError] + }, + { + code: "var d, a, [b, {x: {c, e}}] = {};", + options: ignoreCaseArgs, + parserOptions: { ecmaVersion: 6 }, + errors: [expectedError] + }, { code: "var {} = 1, b, a", diff --git a/tests/lib/rules/space-before-function-paren.js b/tests/lib/rules/space-before-function-paren.js index 5ea52209dff..c8c4ca4c329 100644 --- a/tests/lib/rules/space-before-function-paren.js +++ b/tests/lib/rules/space-before-function-paren.js @@ -84,16 +84,20 @@ ruleTester.run("space-before-function-paren", rule, { options: [{ named: "always", anonymous: "never" }], parserOptions: { ecmaVersion: 6 } }, - { code: "var foo = function() {}", + { + code: "var foo = function() {}", options: [{ named: "always", anonymous: "ignore" }] }, - { code: "var foo = function () {}", + { + code: "var foo = function () {}", options: [{ named: "always", anonymous: "ignore" }] }, - { code: "var bar = function foo() {}", + { + code: "var bar = function foo() {}", options: [{ named: "ignore", anonymous: "always" }] }, - { code: "var bar = function foo () {}", + { + code: "var bar = function foo () {}", options: [{ named: "ignore", anonymous: "always" }] }, { diff --git a/tests/lib/rules/use-isnan.js b/tests/lib/rules/use-isnan.js index 32087c68f69..9b42b61668a 100644 --- a/tests/lib/rules/use-isnan.js +++ b/tests/lib/rules/use-isnan.js @@ -37,37 +37,69 @@ ruleTester.run("use-isnan", rule, { "var x; if (x = NaN) { }" ], invalid: [ - { code: "123 == NaN;", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "123 === NaN;", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "NaN === \"abc\";", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "NaN == \"abc\";", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "123 != NaN;", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "123 !== NaN;", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "NaN !== \"abc\";", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "NaN != \"abc\";", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "NaN < \"abc\";", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "\"abc\" < NaN;", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "NaN > \"abc\";", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "\"abc\" > NaN;", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "NaN <= \"abc\";", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "\"abc\" <= NaN;", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "NaN >= \"abc\";", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] }, - { code: "\"abc\" >= NaN;", - errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] } + { + code: "123 == NaN;", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "123 === NaN;", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "NaN === \"abc\";", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "NaN == \"abc\";", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "123 != NaN;", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "123 !== NaN;", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "NaN !== \"abc\";", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "NaN != \"abc\";", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "NaN < \"abc\";", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "\"abc\" < NaN;", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "NaN > \"abc\";", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "\"abc\" > NaN;", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "NaN <= \"abc\";", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "\"abc\" <= NaN;", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "NaN >= \"abc\";", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + }, + { + code: "\"abc\" >= NaN;", + errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }] + } ] }); diff --git a/tests/lib/testers/rule-tester.js b/tests/lib/testers/rule-tester.js index 84e6febaecd..1c085ebde47 100644 --- a/tests/lib/testers/rule-tester.js +++ b/tests/lib/testers/rule-tester.js @@ -403,10 +403,13 @@ describe("RuleTester", () => { "Eval(foo)" ], invalid: [ - { code: "eval(foo)", errors: [ - { message: "eval sucks.", type: "CallExpression" }, - { message: "eval sucks.", type: "CallExpression" } - ] } + { + code: "eval(foo)", + errors: [ + { message: "eval sucks.", type: "CallExpression" }, + { message: "eval sucks.", type: "CallExpression" } + ] + } ] }); }, /Should have 2 errors but had 1/);