diff --git a/lib/rules/callback-return.js b/lib/rules/callback-return.js index 08600c01e58c..d11037177d72 100644 --- a/lib/rules/callback-return.js +++ b/lib/rules/callback-return.js @@ -19,7 +19,11 @@ module.exports = { schema: [{ type: "array", items: { type: "string" } - }] + }], + + messages: { + missingReturn: "Expected return with your callback function." + } }, create(context) { @@ -164,7 +168,7 @@ module.exports = { // as long as you're the child of a function at this point you should be asked to return if (findClosestParentOfType(node, ["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"])) { - context.report({ node, message: "Expected return with your callback function." }); + context.report({ node, messageId: "missingReturn" }); } } diff --git a/lib/rules/camelcase.js b/lib/rules/camelcase.js index 6fb1475b21db..6e8a34bdd8b5 100644 --- a/lib/rules/camelcase.js +++ b/lib/rules/camelcase.js @@ -27,7 +27,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + notCamelCase: "Identifier '{{name}}' is not in camel case." + } }, create(context) { @@ -61,7 +65,7 @@ module.exports = { function report(node) { if (reported.indexOf(node) < 0) { reported.push(node); - context.report({ node, message: "Identifier '{{name}}' is not in camel case.", data: { name: node.name } }); + context.report({ node, messageId: "notCamelCase", data: { name: node.name } }); } } diff --git a/lib/rules/capitalized-comments.js b/lib/rules/capitalized-comments.js index bb5e5825a36e..505a060bd50f 100644 --- a/lib/rules/capitalized-comments.js +++ b/lib/rules/capitalized-comments.js @@ -15,9 +15,7 @@ const astUtils = require("../ast-utils"); // Helpers //------------------------------------------------------------------------------ -const ALWAYS_MESSAGE = "Comments should not begin with a lowercase character", - NEVER_MESSAGE = "Comments should not begin with an uppercase character", - DEFAULT_IGNORE_PATTERN = astUtils.COMMENTS_IGNORE_PATTERN, +const DEFAULT_IGNORE_PATTERN = astUtils.COMMENTS_IGNORE_PATTERN, WHITESPACE = /\s/g, MAYBE_URL = /^\s*[^:/?#\s]+:\/\/[^?#]/, // TODO: Combine w/ max-len pattern? DEFAULTS = { @@ -131,7 +129,12 @@ module.exports = { } ] } - ] + ], + + messages: { + lowercase: "Comments should not begin with a lowercase character", + uppercase: "Comments should not begin with an uppercase character" + } }, create(context) { @@ -265,14 +268,14 @@ module.exports = { commentValid = isCommentValid(comment, options); if (!commentValid) { - const message = capitalize === "always" - ? ALWAYS_MESSAGE - : NEVER_MESSAGE; + const messageId = capitalize === "always" + ? "lowercase" + : "uppercase"; context.report({ node: null, // Intentionally using loc instead loc: comment.loc, - message, + messageId, fix(fixer) { const match = comment.value.match(LETTER_PATTERN); diff --git a/lib/rules/class-methods-use-this.js b/lib/rules/class-methods-use-this.js index d429c579b941..a0cde8c8ce72 100644 --- a/lib/rules/class-methods-use-this.js +++ b/lib/rules/class-methods-use-this.js @@ -27,7 +27,11 @@ module.exports = { } }, additionalProperties: false - }] + }], + + messages: { + missingThis: "Expected 'this' to be used by class method '{{name}}'." + } }, create(context) { const config = context.options[0] ? Object.assign({}, context.options[0]) : {}; @@ -79,9 +83,9 @@ module.exports = { if (isIncludedInstanceMethod(node.parent) && !methodUsesThis) { context.report({ node, - message: "Expected 'this' to be used by class method '{{classMethod}}'.", + messageId: "missingThis", data: { - classMethod: node.parent.key.name + name: node.parent.key.name } }); } diff --git a/lib/rules/comma-dangle.js b/lib/rules/comma-dangle.js index ddcc0cd229e9..5d450412c4ce 100644 --- a/lib/rules/comma-dangle.js +++ b/lib/rules/comma-dangle.js @@ -123,14 +123,17 @@ module.exports = { ] } ] + }, + + messages: { + unexpected: "Unexpected trailing comma.", + missing: "Missing trailing comma." } }, create(context) { const options = normalizeOptions(context.options[0]); const sourceCode = context.getSourceCode(); - const UNEXPECTED_MESSAGE = "Unexpected trailing comma."; - const MISSING_MESSAGE = "Missing trailing comma."; /** * Gets the last item of the given node. @@ -229,7 +232,7 @@ module.exports = { context.report({ node: lastItem, loc: trailingToken.loc.start, - message: UNEXPECTED_MESSAGE, + messageId: "unexpected", fix(fixer) { return fixer.remove(trailingToken); } @@ -266,7 +269,7 @@ module.exports = { context.report({ node: lastItem, loc: trailingToken.loc.end, - message: MISSING_MESSAGE, + messageId: "missing", fix(fixer) { return fixer.insertTextAfter(trailingToken, ","); } diff --git a/lib/rules/comma-spacing.js b/lib/rules/comma-spacing.js index 25a0e7d82c8a..b2f33fde5d77 100644 --- a/lib/rules/comma-spacing.js +++ b/lib/rules/comma-spacing.js @@ -33,7 +33,12 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + missing: "A space is required {{loc}} ','.", + unexpected: "There should be no space {{loc}} ','." + } }, create(context) { @@ -56,17 +61,17 @@ module.exports = { /** * Reports a spacing error with an appropriate message. * @param {ASTNode} node The binary expression node to report. - * @param {string} dir Is the error "before" or "after" the comma? + * @param {string} loc Is the error "before" or "after" the comma? * @param {ASTNode} otherNode The node at the left or right of `node` * @returns {void} * @private */ - function report(node, dir, otherNode) { + function report(node, loc, otherNode) { context.report({ node, fix(fixer) { - if (options[dir]) { - if (dir === "before") { + if (options[loc]) { + if (loc === "before") { return fixer.insertTextBefore(node, " "); } return fixer.insertTextAfter(node, " "); @@ -75,7 +80,7 @@ module.exports = { let start, end; const newText = ""; - if (dir === "before") { + if (loc === "before") { start = otherNode.range[1]; end = node.range[0]; } else { @@ -86,11 +91,9 @@ module.exports = { return fixer.replaceTextRange([start, end], newText); }, - message: options[dir] - ? "A space is required {{dir}} ','." - : "There should be no space {{dir}} ','.", + messageId: options[loc] ? "missing" : "unexpected", data: { - dir + loc } }); } diff --git a/lib/rules/comma-style.js b/lib/rules/comma-style.js index 1a9382bea35b..1a105b241156 100644 --- a/lib/rules/comma-style.js +++ b/lib/rules/comma-style.js @@ -35,7 +35,12 @@ module.exports = { }, additionalProperties: false } - ] + ], + messages: { + beforeAndAfter: "Bad line breaking before and after ','.", + after: "',' should be placed first.", + before: "',' should be placed last." + } }, create(context) { @@ -133,7 +138,7 @@ module.exports = { line: commaToken.loc.end.line, column: commaToken.loc.start.column }, - message: "Bad line breaking before and after ','.", + messageId: "beforeAndAfter", fix: getFixerFunction("between", previousItemToken, commaToken, currentItemToken) }); @@ -141,7 +146,7 @@ module.exports = { context.report({ node: reportItem, - message: "',' should be placed first.", + messageId: "after", fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken) }); @@ -153,7 +158,7 @@ module.exports = { line: commaToken.loc.end.line, column: commaToken.loc.end.column }, - message: "',' should be placed last.", + messageId: "before", fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken) }); } diff --git a/lib/rules/complexity.js b/lib/rules/complexity.js index e0313fa78f17..18d730fced43 100644 --- a/lib/rules/complexity.js +++ b/lib/rules/complexity.js @@ -49,7 +49,11 @@ module.exports = { } ] } - ] + ], + + messages: { + complex: "{{name}} has a complexity of {{complexity}}." + } }, create(context) { @@ -95,7 +99,7 @@ module.exports = { if (complexity > THRESHOLD) { context.report({ node, - message: "{{name}} has a complexity of {{complexity}}.", + messageId: "complex", data: { name, complexity } }); } diff --git a/lib/rules/computed-property-spacing.js b/lib/rules/computed-property-spacing.js index 0c05d9b4852d..89c8ff9e68d9 100644 --- a/lib/rules/computed-property-spacing.js +++ b/lib/rules/computed-property-spacing.js @@ -24,7 +24,15 @@ module.exports = { { enum: ["always", "never"] } - ] + ], + + messages: { + before: "There should be no space before '{{tokenValue}}'.", + after: "There should be no space after '{{tokenValue}}'.", + + missingBefore: "A space is required before '{{tokenValue}}'.", + missingAfter: "A space is required after '{{tokenValue}}'." + } }, create(context) { @@ -46,7 +54,7 @@ module.exports = { context.report({ node, loc: token.loc.start, - message: "There should be no space after '{{tokenValue}}'.", + messageId: "after", data: { tokenValue: token.value }, @@ -67,7 +75,7 @@ module.exports = { context.report({ node, loc: token.loc.start, - message: "There should be no space before '{{tokenValue}}'.", + messageId: "before", data: { tokenValue: token.value }, @@ -87,7 +95,7 @@ module.exports = { context.report({ node, loc: token.loc.start, - message: "A space is required after '{{tokenValue}}'.", + messageId: "missingAfter", data: { tokenValue: token.value }, @@ -107,7 +115,7 @@ module.exports = { context.report({ node, loc: token.loc.start, - message: "A space is required before '{{tokenValue}}'.", + messageId: "missingBefore", data: { tokenValue: token.value }, diff --git a/lib/rules/consistent-return.js b/lib/rules/consistent-return.js index 20469772a911..ea4ceb689d79 100644 --- a/lib/rules/consistent-return.js +++ b/lib/rules/consistent-return.js @@ -67,7 +67,13 @@ module.exports = { } }, additionalProperties: false - }] + }], + + messages: { + missingReturn: "Expected to return a value at the end of {{name}}.", + missingReturnValue: "{{name}} expected a return value.", + unexpectedReturnValue: "{{name}} expected no return value." + } }, create(context) { @@ -128,7 +134,7 @@ module.exports = { context.report({ node, loc, - message: "Expected to return a value at the end of {{name}}.", + messageId: "missingReturn", data: { name } }); } @@ -142,7 +148,7 @@ module.exports = { codePath, hasReturn: false, hasReturnValue: false, - message: "", + messageId: "", node }; }, @@ -162,17 +168,16 @@ module.exports = { if (!funcInfo.hasReturn) { funcInfo.hasReturn = true; funcInfo.hasReturnValue = hasReturnValue; - funcInfo.message = "{{name}} expected {{which}} return value."; + funcInfo.messageId = hasReturnValue ? "missingReturnValue" : "unexpectedReturnValue"; funcInfo.data = { name: funcInfo.node.type === "Program" ? "Program" - : lodash.upperFirst(astUtils.getFunctionNameWithKind(funcInfo.node)), - which: hasReturnValue ? "a" : "no" + : lodash.upperFirst(astUtils.getFunctionNameWithKind(funcInfo.node)) }; } else if (funcInfo.hasReturnValue !== hasReturnValue) { context.report({ node, - message: funcInfo.message, + messageId: funcInfo.messageId, data: funcInfo.data }); } diff --git a/lib/rules/consistent-this.js b/lib/rules/consistent-this.js index 35c2d56272a6..a73a4ada7203 100644 --- a/lib/rules/consistent-this.js +++ b/lib/rules/consistent-this.js @@ -23,6 +23,11 @@ module.exports = { minLength: 1 }, uniqueItems: true + }, + + messages: { + aliasIsNotThis: "Designated alias '{{name}}' is not assigned to 'this'.", + unexpectedAlias: "Unexpected alias '{{name}}' for 'this'." } }, @@ -39,11 +44,11 @@ module.exports = { * Reports that a variable declarator or assignment expression is assigning * a non-'this' value to the specified alias. * @param {ASTNode} node - The assigning node. - * @param {string} alias - the name of the alias that was incorrectly used. + * @param {string} name - the name of the alias that was incorrectly used. * @returns {void} */ - function reportBadAssignment(node, alias) { - context.report({ node, message: "Designated alias '{{alias}}' is not assigned to 'this'.", data: { alias } }); + function reportBadAssignment(node, name) { + context.report({ node, messageId: "aliasIsNotThis", data: { name } }); } /** @@ -62,7 +67,7 @@ module.exports = { reportBadAssignment(node, name); } } else if (isThis) { - context.report({ node, message: "Unexpected alias '{{name}}' for 'this'.", data: { name } }); + context.report({ node, messageId: "unexpectedAlias", data: { name } }); } } diff --git a/lib/rules/constructor-super.js b/lib/rules/constructor-super.js index d0a238df8edb..5b2c128709f9 100644 --- a/lib/rules/constructor-super.js +++ b/lib/rules/constructor-super.js @@ -98,7 +98,16 @@ module.exports = { recommended: true }, - schema: [] + schema: [], + + messages: { + missingSome: "Lacked a call of 'super()' in some code paths.", + missingAll: "Expected to call 'super()'.", + + duplicate: "Unexpected duplicate 'super()'.", + badSuper: "Unexpected 'super()' because 'super' is not a constructor.", + unexpected: "Unexpected 'super()'." + } }, create(context) { @@ -209,9 +218,9 @@ module.exports = { if (!calledInEveryPaths) { context.report({ - message: calledInSomePaths - ? "Lacked a call of 'super()' in some code paths." - : "Expected to call 'super()'.", + messageId: calledInSomePaths + ? "missingSome" + : "missingAll", node: node.parent }); } @@ -280,7 +289,7 @@ module.exports = { const node = nodes[i]; context.report({ - message: "Unexpected duplicate 'super()'.", + messageId: "duplicate", node }); } @@ -324,12 +333,12 @@ module.exports = { if (info) { if (duplicate) { context.report({ - message: "Unexpected duplicate 'super()'.", + messageId: "duplicate", node }); } else if (!funcInfo.superIsConstructor) { context.report({ - message: "Unexpected 'super()' because 'super' is not a constructor.", + messageId: "badSuper", node }); } else { @@ -338,7 +347,7 @@ module.exports = { } } else if (funcInfo.codePath.currentSegments.some(isReachable)) { context.report({ - message: "Unexpected 'super()'.", + messageId: "unexpected", node }); } diff --git a/lib/rules/curly.js b/lib/rules/curly.js index 2d867c72b58d..31338dc7b894 100644 --- a/lib/rules/curly.js +++ b/lib/rules/curly.js @@ -50,7 +50,12 @@ module.exports = { ] }, - fixable: "code" + fixable: "code", + + messages: { + missing: "Expected { after '{{name}}'{{suffix}}.", + unexpected: "Unnecessary { after '{{name}}'{{suffix}}." + } }, create(context) { @@ -154,7 +159,7 @@ module.exports = { context.report({ node, loc: (name !== "else" ? node : getElseKeyword(node)).loc.start, - message: "Expected { after '{{name}}'{{suffix}}.", + messageId: "missing", data: { name, suffix: (suffix ? ` ${suffix}` : "") @@ -228,7 +233,7 @@ module.exports = { context.report({ node, loc: (name !== "else" ? node : getElseKeyword(node)).loc.start, - message: "Unnecessary { after '{{name}}'{{suffix}}.", + messageId: "unexpected", data: { name, suffix: (suffix ? ` ${suffix}` : "") diff --git a/lib/rules/no-caller.js b/lib/rules/no-caller.js index 55a37b7d8640..24c0b910b508 100644 --- a/lib/rules/no-caller.js +++ b/lib/rules/no-caller.js @@ -17,7 +17,11 @@ module.exports = { recommended: false }, - schema: [] + schema: [], + + messages: { + unexpected: "Avoid arguments.{{prop}}." + } }, create(context) { @@ -29,7 +33,7 @@ module.exports = { propertyName = node.property.name; if (objectName === "arguments" && !node.computed && propertyName && propertyName.match(/^calle[er]$/)) { - context.report({ node, message: "Avoid arguments.{{property}}.", data: { property: propertyName } }); + context.report({ node, messageId: "unexpected", data: { prop: propertyName } }); } } diff --git a/lib/rules/no-case-declarations.js b/lib/rules/no-case-declarations.js index e801c6bb6e0d..a25ce7ccd8e0 100644 --- a/lib/rules/no-case-declarations.js +++ b/lib/rules/no-case-declarations.js @@ -16,7 +16,11 @@ module.exports = { recommended: true }, - schema: [] + schema: [], + + messages: { + unexpected: "Unexpected lexical declaration in case block." + } }, create(context) { @@ -46,7 +50,7 @@ module.exports = { if (isLexicalDeclaration(statement)) { context.report({ node, - message: "Unexpected lexical declaration in case block." + messageId: "unexpected" }); } } diff --git a/lib/rules/no-catch-shadow.js b/lib/rules/no-catch-shadow.js index 7cffae3b99d7..fcace3446200 100644 --- a/lib/rules/no-catch-shadow.js +++ b/lib/rules/no-catch-shadow.js @@ -23,7 +23,11 @@ module.exports = { recommended: false }, - schema: [] + schema: [], + + messages: { + mutable: "Value of '{{name}}' may be overwritten in IE 8 and earlier." + } }, create(context) { @@ -58,7 +62,7 @@ module.exports = { } if (paramIsShadowing(scope, node.param.name)) { - context.report({ node, message: "Value of '{{name}}' may be overwritten in IE 8 and earlier.", data: { name: node.param.name } }); + context.report({ node, messageId: "mutable", data: { name: node.param.name } }); } } }; diff --git a/lib/rules/no-class-assign.js b/lib/rules/no-class-assign.js index 4b0443abc728..f7d33f184151 100644 --- a/lib/rules/no-class-assign.js +++ b/lib/rules/no-class-assign.js @@ -19,7 +19,11 @@ module.exports = { recommended: true }, - schema: [] + schema: [], + + messages: { + class: "'{{name}}' is a class." + } }, create(context) { @@ -31,7 +35,7 @@ module.exports = { */ function checkVariable(variable) { astUtils.getModifyingReferences(variable.references).forEach(reference => { - context.report({ node: reference.identifier, message: "'{{name}}' is a class.", data: { name: reference.identifier.name } }); + context.report({ node: reference.identifier, messageId: "class", data: { name: reference.identifier.name } }); }); } diff --git a/lib/rules/no-compare-neg-zero.js b/lib/rules/no-compare-neg-zero.js index 604e22191992..33e1d169a22a 100644 --- a/lib/rules/no-compare-neg-zero.js +++ b/lib/rules/no-compare-neg-zero.js @@ -16,7 +16,10 @@ module.exports = { recommended: true }, fixable: null, - schema: [] + schema: [], + messages: { + unexpected: "Do not use the '{{operator}}' operator to compare against -0." + } }, create(context) { @@ -42,7 +45,7 @@ module.exports = { if (isNegZero(node.left) || isNegZero(node.right)) { context.report({ node, - message: "Do not use the '{{operator}}' operator to compare against -0.", + messageId: "unexpected", data: { operator: node.operator } }); } diff --git a/lib/rules/no-cond-assign.js b/lib/rules/no-cond-assign.js index 7c031c13f06d..d169ba29cd3c 100644 --- a/lib/rules/no-cond-assign.js +++ b/lib/rules/no-cond-assign.js @@ -29,7 +29,14 @@ module.exports = { { enum: ["except-parens", "always"] } - ] + ], + + messages: { + unexpected: "Unexpected assignment within {{type}}.", + + // must match JSHint's error message + missing: "Expected a conditional expression and instead saw an assignment." + } }, create(context) { @@ -94,11 +101,10 @@ module.exports = { ) ) { - // must match JSHint's error message context.report({ node, loc: node.test.loc.start, - message: "Expected a conditional expression and instead saw an assignment." + messageId: "missing" }); } } @@ -114,7 +120,7 @@ module.exports = { if (ancestor) { context.report({ node: ancestor, - message: "Unexpected assignment within {{type}}.", + messageId: "unexpected", data: { type: NODE_DESCRIPTIONS[ancestor.type] || ancestor.type } diff --git a/lib/rules/no-confusing-arrow.js b/lib/rules/no-confusing-arrow.js index fc69ca39a9ed..49a5b1df1bff 100644 --- a/lib/rules/no-confusing-arrow.js +++ b/lib/rules/no-confusing-arrow.js @@ -41,7 +41,11 @@ module.exports = { allowParens: { type: "boolean" } }, additionalProperties: false - }] + }], + + messages: { + confusing: "Arrow function used ambiguously with a conditional expression." + } }, create(context) { @@ -59,7 +63,7 @@ module.exports = { if (isConditional(body) && !(config.allowParens && astUtils.isParenthesised(sourceCode, body))) { context.report({ node, - message: "Arrow function used ambiguously with a conditional expression.", + messageId: "confusing", fix(fixer) { // if `allowParens` is not set to true dont bother wrapping in parens diff --git a/lib/rules/no-console.js b/lib/rules/no-console.js index 32bdf6d1f4d7..d2110938416c 100644 --- a/lib/rules/no-console.js +++ b/lib/rules/no-console.js @@ -38,7 +38,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unexpected: "Unexpected console statement." + } }, create(context) { @@ -101,7 +105,7 @@ module.exports = { context.report({ node, loc: node.loc, - message: "Unexpected console statement." + messageId: "unexpected" }); } diff --git a/lib/rules/no-const-assign.js b/lib/rules/no-const-assign.js index db1848a9819f..ec6d73051c99 100644 --- a/lib/rules/no-const-assign.js +++ b/lib/rules/no-const-assign.js @@ -19,7 +19,11 @@ module.exports = { recommended: true }, - schema: [] + schema: [], + + messages: { + const: "'{{name}}' is constant." + } }, create(context) { @@ -31,7 +35,7 @@ module.exports = { */ function checkVariable(variable) { astUtils.getModifyingReferences(variable.references).forEach(reference => { - context.report({ node: reference.identifier, message: "'{{name}}' is constant.", data: { name: reference.identifier.name } }); + context.report({ node: reference.identifier, messageId: "const", data: { name: reference.identifier.name } }); }); } diff --git a/lib/rules/no-constant-condition.js b/lib/rules/no-constant-condition.js index 31e5b372c434..2ea8582f4e04 100644 --- a/lib/rules/no-constant-condition.js +++ b/lib/rules/no-constant-condition.js @@ -27,8 +27,11 @@ module.exports = { }, additionalProperties: false } + ], - ] + messages: { + unexpected: "Unexpected constant condition." + } }, create(context) { @@ -138,7 +141,7 @@ module.exports = { function checkConstantConditionLoopInSet(node) { if (loopsInCurrentScope.has(node)) { loopsInCurrentScope.delete(node); - context.report({ node, message: "Unexpected constant condition." }); + context.report({ node, messageId: "unexpected" }); } } @@ -150,7 +153,7 @@ module.exports = { */ function reportIfConstant(node) { if (node.test && isConstant(node.test, true)) { - context.report({ node, message: "Unexpected constant condition." }); + context.report({ node, messageId: "unexpected" }); } } diff --git a/lib/rules/no-continue.js b/lib/rules/no-continue.js index 2615fba13e24..78ade8d3144b 100644 --- a/lib/rules/no-continue.js +++ b/lib/rules/no-continue.js @@ -17,14 +17,18 @@ module.exports = { recommended: false }, - schema: [] + schema: [], + + messages: { + unexpected: "Unexpected use of continue statement." + } }, create(context) { return { ContinueStatement(node) { - context.report({ node, message: "Unexpected use of continue statement." }); + context.report({ node, messageId: "unexpected" }); } }; diff --git a/lib/rules/no-control-regex.js b/lib/rules/no-control-regex.js index f5bba2755c4d..bfe6e2e65ad3 100644 --- a/lib/rules/no-control-regex.js +++ b/lib/rules/no-control-regex.js @@ -17,7 +17,11 @@ module.exports = { recommended: true }, - schema: [] + schema: [], + + messages: { + unexpected: "Unexpected control character(s) in regular expression: {{controlChars}}." + } }, create(context) { @@ -112,7 +116,7 @@ module.exports = { if (controlCharacters.length > 0) { context.report({ node, - message: "Unexpected control character(s) in regular expression: {{controlChars}}.", + messageId: "unexpected", data: { controlChars: controlCharacters.join(", ") } diff --git a/tests/lib/rules/callback-return.js b/tests/lib/rules/callback-return.js index 29f98136b41f..1e178915d0af 100644 --- a/tests/lib/rules/callback-return.js +++ b/tests/lib/rules/callback-return.js @@ -12,10 +12,9 @@ const rule = require("../../../lib/rules/callback-return"), RuleTester = require("../../../lib/testers/rule-tester"); //------------------------------------------------------------------------------ -// Helpers +// Tests //------------------------------------------------------------------------------ - const ruleTester = new RuleTester(); ruleTester.run("callback-return", rule, { @@ -157,7 +156,7 @@ ruleTester.run("callback-return", rule, { { code: "function a(err) { if (err) { callback (err); } }", errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 30, nodeType: "CallExpression" @@ -166,7 +165,7 @@ ruleTester.run("callback-return", rule, { { code: "function a(callback) { if (typeof callback !== 'undefined') { callback(); } }", errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 63, nodeType: "CallExpression" @@ -175,7 +174,7 @@ ruleTester.run("callback-return", rule, { { code: "function a(callback) { if (typeof callback !== 'undefined') callback(); }", errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 61, nodeType: "CallExpression" @@ -184,7 +183,7 @@ ruleTester.run("callback-return", rule, { { code: "function a(callback) { if (err) { callback(); horse && horse(); } }", errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 35, nodeType: "CallExpression" @@ -194,7 +193,7 @@ ruleTester.run("callback-return", rule, { code: "var x = (err) => { if (err) { callback (err); } }", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 31, nodeType: "CallExpression" @@ -204,7 +203,7 @@ ruleTester.run("callback-return", rule, { code: "var x = { x(err) { if (err) { callback (err); } } }", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 31, nodeType: "CallExpression" @@ -213,7 +212,7 @@ ruleTester.run("callback-return", rule, { { code: "function x(err) { if (err) {\n log();\n callback(err); } }", errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 3, column: 2, nodeType: "CallExpression" @@ -223,7 +222,7 @@ ruleTester.run("callback-return", rule, { code: "var x = { x(err) { if (err) { callback && callback (err); } } }", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 43, nodeType: "CallExpression" @@ -232,7 +231,7 @@ ruleTester.run("callback-return", rule, { { code: "function a(err) { callback (err); callback(); }", errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 19, nodeType: "CallExpression" @@ -241,7 +240,7 @@ ruleTester.run("callback-return", rule, { { code: "function a(err) { callback (err); horse(); }", errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 19, nodeType: "CallExpression" @@ -250,7 +249,7 @@ ruleTester.run("callback-return", rule, { { code: "function a(err) { if (err) { callback (err); horse(); return; } }", errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 30, nodeType: "CallExpression" @@ -260,7 +259,7 @@ ruleTester.run("callback-return", rule, { code: "var a = (err) => { callback (err); callback(); }", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 20, nodeType: "CallExpression" @@ -269,7 +268,7 @@ ruleTester.run("callback-return", rule, { { code: "function a(err) { if (err) { callback (err); } else if (x) { callback(err); return; } }", errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 30, nodeType: "CallExpression" @@ -278,7 +277,7 @@ ruleTester.run("callback-return", rule, { { code: "function x(err) { if (err) { return callback(); }\nelse if (abc) {\ncallback(); }\nelse {\nreturn callback(); } }", errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 3, column: 1, nodeType: "CallExpression" @@ -289,7 +288,7 @@ ruleTester.run("callback-return", rule, { code: "class x { horse() { if (err) { callback(); } callback(); } } ", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 32, nodeType: "CallExpression" @@ -301,12 +300,12 @@ ruleTester.run("callback-return", rule, { { code: "function x(err) { if (err) { callback() } else { callback() } }", errors: [{ - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 30, nodeType: "CallExpression" }, { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 50, nodeType: "CallExpression" @@ -316,7 +315,7 @@ ruleTester.run("callback-return", rule, { code: "function x(err) { if (err) return callback(); else callback(); }", errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 52, nodeType: "CallExpression" @@ -328,7 +327,7 @@ ruleTester.run("callback-return", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 18, nodeType: "CallExpression" @@ -339,7 +338,7 @@ ruleTester.run("callback-return", rule, { code: "function b() { switch(x) { case 'horse': callback(); } }", errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 42, nodeType: "CallExpression" @@ -351,7 +350,7 @@ ruleTester.run("callback-return", rule, { options: [["move"]], errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 42, nodeType: "CallExpression" @@ -365,7 +364,7 @@ ruleTester.run("callback-return", rule, { options: [["move"]], errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 33, nodeType: "CallExpression" @@ -377,7 +376,7 @@ ruleTester.run("callback-return", rule, { options: [["move"]], errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 47, nodeType: "CallExpression" @@ -389,7 +388,7 @@ ruleTester.run("callback-return", rule, { options: [["move"]], errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 51, nodeType: "CallExpression" @@ -401,7 +400,7 @@ ruleTester.run("callback-return", rule, { options: [["obj.method"]], errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 30, nodeType: "CallExpression" @@ -413,7 +412,7 @@ ruleTester.run("callback-return", rule, { options: [["obj.prop.method"]], errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 30, nodeType: "CallExpression" @@ -425,7 +424,7 @@ ruleTester.run("callback-return", rule, { options: [["obj.prop.method", "otherObj.prop.method"]], errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 30, nodeType: "CallExpression" @@ -437,7 +436,7 @@ ruleTester.run("callback-return", rule, { options: [["obj.method"]], errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 41, nodeType: "CallExpression" @@ -449,7 +448,7 @@ ruleTester.run("callback-return", rule, { options: [["obj.method"]], errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 2, column: 1, nodeType: "CallExpression" @@ -461,7 +460,7 @@ ruleTester.run("callback-return", rule, { options: [["obj.method"]], errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 30, nodeType: "CallExpression" @@ -473,7 +472,7 @@ ruleTester.run("callback-return", rule, { options: [["obj.method"]], errors: [ { - message: "Expected return with your callback function.", + messageId: "missingReturn", line: 1, column: 30, nodeType: "CallExpression" diff --git a/tests/lib/rules/camelcase.js b/tests/lib/rules/camelcase.js index 5983fb1c6e61..3dba1791e434 100644 --- a/tests/lib/rules/camelcase.js +++ b/tests/lib/rules/camelcase.js @@ -86,7 +86,8 @@ ruleTester.run("camelcase", rule, { code: "first_name = \"Nicholas\"", errors: [ { - message: "Identifier 'first_name' is not in camel case.", + messageId: "notCamelCase", + data: { name: "first_name" }, type: "Identifier" } ] @@ -95,7 +96,8 @@ ruleTester.run("camelcase", rule, { code: "__private_first_name = \"Patrick\"", errors: [ { - message: "Identifier '__private_first_name' is not in camel case.", + messageId: "notCamelCase", + data: { name: "__private_first_name" }, type: "Identifier" } ] @@ -104,7 +106,8 @@ ruleTester.run("camelcase", rule, { code: "function foo_bar(){}", errors: [ { - message: "Identifier 'foo_bar' is not in camel case.", + messageId: "notCamelCase", + data: { name: "foo_bar" }, type: "Identifier" } ] @@ -113,7 +116,8 @@ ruleTester.run("camelcase", rule, { code: "obj.foo_bar = function(){};", errors: [ { - message: "Identifier 'foo_bar' is not in camel case.", + messageId: "notCamelCase", + data: { name: "foo_bar" }, type: "Identifier" } ] @@ -122,7 +126,8 @@ ruleTester.run("camelcase", rule, { code: "bar_baz.foo = function(){};", errors: [ { - message: "Identifier 'bar_baz' is not in camel case.", + messageId: "notCamelCase", + data: { name: "bar_baz" }, type: "Identifier" } ] @@ -131,7 +136,8 @@ ruleTester.run("camelcase", rule, { code: "[foo_bar.baz]", errors: [ { - message: "Identifier 'foo_bar' is not in camel case.", + messageId: "notCamelCase", + data: { name: "foo_bar" }, type: "Identifier" } ] @@ -140,7 +146,8 @@ ruleTester.run("camelcase", rule, { code: "if (foo.bar_baz === boom.bam_pow) { [foo_bar.baz] }", errors: [ { - message: "Identifier 'foo_bar' is not in camel case.", + messageId: "notCamelCase", + data: { name: "foo_bar" }, type: "Identifier" } ] @@ -149,7 +156,8 @@ ruleTester.run("camelcase", rule, { code: "foo.bar_baz = boom.bam_pow", errors: [ { - message: "Identifier 'bar_baz' is not in camel case.", + messageId: "notCamelCase", + data: { name: "bar_baz" }, type: "Identifier" } ] @@ -158,7 +166,8 @@ ruleTester.run("camelcase", rule, { code: "var foo = { bar_baz: boom.bam_pow }", errors: [ { - message: "Identifier 'bar_baz' is not in camel case.", + messageId: "notCamelCase", + data: { name: "bar_baz" }, type: "Identifier" } ] @@ -167,7 +176,8 @@ ruleTester.run("camelcase", rule, { code: "foo.qux.boom_pow = { bar: boom.bam_pow }", errors: [ { - message: "Identifier 'boom_pow' is not in camel case.", + messageId: "notCamelCase", + data: { name: "boom_pow" }, type: "Identifier" } ] @@ -177,7 +187,8 @@ ruleTester.run("camelcase", rule, { options: [{ properties: "always" }], errors: [ { - message: "Identifier 'bar_baz' is not in camel case.", + messageId: "notCamelCase", + data: { name: "bar_baz" }, type: "Identifier" } ] @@ -187,7 +198,8 @@ ruleTester.run("camelcase", rule, { options: [{ properties: "always" }], errors: [ { - message: "Identifier 'a_b' is not in camel case.", + messageId: "notCamelCase", + data: { name: "a_b" }, type: "Identifier" } ] @@ -197,7 +209,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Identifier 'category_id' is not in camel case.", + messageId: "notCamelCase", + data: { name: "category_id" }, type: "Identifier" } ] @@ -207,7 +220,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Identifier 'category_id' is not in camel case.", + messageId: "notCamelCase", + data: { name: "category_id" }, type: "Identifier" } ] @@ -217,7 +231,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "Identifier 'no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camelcased" }, type: "Identifier" } ] @@ -227,7 +242,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "Identifier 'no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camelcased" }, type: "Identifier" } ] @@ -237,7 +253,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "Identifier 'no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camelcased" }, type: "Identifier" } ] @@ -247,7 +264,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "Identifier 'no_camel_cased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camel_cased" }, type: "Identifier" } ] @@ -257,7 +275,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "Identifier 'no_camel_cased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camel_cased" }, type: "Identifier" } ] @@ -267,7 +286,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "Identifier 'no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camelcased" }, type: "Identifier" } ] @@ -277,7 +297,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "Identifier 'another_no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "another_no_camelcased" }, type: "Identifier" } ] @@ -287,7 +308,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "Identifier 'no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camelcased" }, type: "Identifier" } ] @@ -297,7 +319,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "Identifier 'no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camelcased" }, type: "Identifier" } ] diff --git a/tests/lib/rules/capitalized-comments.js b/tests/lib/rules/capitalized-comments.js index ae798a8d5aa2..10abcede1fa2 100644 --- a/tests/lib/rules/capitalized-comments.js +++ b/tests/lib/rules/capitalized-comments.js @@ -11,14 +11,6 @@ const rule = require("../../../lib/rules/capitalized-comments"), RuleTester = require("../../../lib/testers/rule-tester"); - -//------------------------------------------------------------------------------ -// Helpers -//------------------------------------------------------------------------------ - -const ALWAYS_MESSAGE = "Comments should not begin with a lowercase character", - NEVER_MESSAGE = "Comments should not begin with an uppercase character"; - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ @@ -289,7 +281,7 @@ ruleTester.run("capitalized-comments", rule, { code: "//lowercase", output: "//Lowercase", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -298,7 +290,7 @@ ruleTester.run("capitalized-comments", rule, { code: "// lowercase", output: "// Lowercase", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -307,7 +299,7 @@ ruleTester.run("capitalized-comments", rule, { code: "/*lowercase */", output: "/*Lowercase */", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -316,7 +308,7 @@ ruleTester.run("capitalized-comments", rule, { code: "/* lowercase */", output: "/* Lowercase */", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -325,7 +317,7 @@ ruleTester.run("capitalized-comments", rule, { code: "/** lowercase */", output: "/** Lowercase */", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -334,7 +326,7 @@ ruleTester.run("capitalized-comments", rule, { code: "/*\nlowercase */", output: "/*\nLowercase */", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -343,7 +335,7 @@ ruleTester.run("capitalized-comments", rule, { code: "/**\nlowercase */", output: "/**\nLowercase */", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -352,7 +344,7 @@ ruleTester.run("capitalized-comments", rule, { code: "//über", output: "//Über", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -361,7 +353,7 @@ ruleTester.run("capitalized-comments", rule, { code: "//π", output: "//Π", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -370,7 +362,7 @@ ruleTester.run("capitalized-comments", rule, { code: "/* lowercase\nSecond line need not be lowercase */", output: "/* Lowercase\nSecond line need not be lowercase */", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -382,7 +374,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//Lowercase", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -392,7 +384,7 @@ ruleTester.run("capitalized-comments", rule, { output: "// Lowercase", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -402,7 +394,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*Lowercase */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -412,7 +404,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/* Lowercase */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -422,7 +414,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/** Lowercase */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -432,7 +424,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/**\nLowercase */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -442,7 +434,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//Über", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -452,7 +444,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//Π", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -462,7 +454,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/* Lowercase\nSecond line need not be lowercase */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -474,7 +466,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//uppercase", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 1, column: 1 }] @@ -484,7 +476,7 @@ ruleTester.run("capitalized-comments", rule, { output: "// uppercase", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 1, column: 1 }] @@ -494,7 +486,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*uppercase */", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 1, column: 1 }] @@ -504,7 +496,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/* uppercase */", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 1, column: 1 }] @@ -514,7 +506,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\nuppercase */", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 1, column: 1 }] @@ -524,7 +516,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//über", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 1, column: 1 }] @@ -534,7 +526,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//π", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 1, column: 1 }] @@ -544,7 +536,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/* uppercase\nsecond line need not be uppercase */", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 1, column: 1 }] @@ -556,7 +548,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//* Jscs: enable", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -566,7 +558,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//* Jscs:disable", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -576,7 +568,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//* Eslint-disable-line", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -586,7 +578,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//* Eslint-disable-next-line", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -596,7 +588,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\n * Eslint semi:off */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -606,7 +598,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\n * Eslint-env node */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -616,7 +608,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\n * Istanbul ignore next */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -626,7 +618,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\n * Jshint asi:true */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -636,7 +628,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\n * Jscs: enable */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -646,7 +638,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\n * Global var1, var2 */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -656,7 +648,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\n * Global var1:true, var2 */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -666,7 +658,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\n * Globals var1, var2 */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -676,7 +668,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\n * Globals var1:true, var2 */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -686,7 +678,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\n * Exported myVar */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -698,7 +690,7 @@ ruleTester.run("capitalized-comments", rule, { output: "foo(/* Invalid */a);", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 5 }] @@ -708,7 +700,7 @@ ruleTester.run("capitalized-comments", rule, { output: "foo(/* Invalid */a);", options: ["always", { ignoreInlineComments: false }], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 5 }] @@ -720,7 +712,7 @@ ruleTester.run("capitalized-comments", rule, { output: "foo(a, // Not an inline comment\nb);", options: ["always", { ignoreInlineComments: true }], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 8 }] @@ -730,7 +722,7 @@ ruleTester.run("capitalized-comments", rule, { output: "foo(a, /* Not an inline comment */\nb);", options: ["always", { ignoreInlineComments: true }], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 8 }] @@ -740,7 +732,7 @@ ruleTester.run("capitalized-comments", rule, { output: "foo(a,\n/* Not an inline comment */b);", options: ["always", { ignoreInlineComments: true }], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 2, column: 1 }] @@ -750,7 +742,7 @@ ruleTester.run("capitalized-comments", rule, { output: "foo(a,\n/* Not an inline comment */\nb);", options: ["always", { ignoreInlineComments: true }], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 2, column: 1 }] @@ -760,7 +752,7 @@ ruleTester.run("capitalized-comments", rule, { output: "foo(a, // not an inline comment\nb);", options: ["never", { ignoreInlineComments: true }], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 1, column: 8 }] @@ -770,7 +762,7 @@ ruleTester.run("capitalized-comments", rule, { output: "foo(a, /* not an inline comment */\nb);", options: ["never", { ignoreInlineComments: true }], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 1, column: 8 }] @@ -780,7 +772,7 @@ ruleTester.run("capitalized-comments", rule, { output: "foo(a,\n/* not an inline comment */b);", options: ["never", { ignoreInlineComments: true }], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 2, column: 1 }] @@ -790,7 +782,7 @@ ruleTester.run("capitalized-comments", rule, { output: "foo(a,\n/* not an inline comment */\nb);", options: ["never", { ignoreInlineComments: true }], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 2, column: 1 }] @@ -802,7 +794,7 @@ ruleTester.run("capitalized-comments", rule, { output: "// Not matching", options: ["always", { ignorePattern: "ignored?" }], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -812,7 +804,7 @@ ruleTester.run("capitalized-comments", rule, { output: "// not matching", options: ["never", { ignorePattern: "ignored?" }], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 1, column: 1 }] @@ -834,7 +826,7 @@ ruleTester.run("capitalized-comments", rule, { ].join("\n"), options: ["always", { ignoreConsecutiveComments: true }], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 4, column: 1 }] @@ -852,7 +844,7 @@ ruleTester.run("capitalized-comments", rule, { ].join("\n"), options: ["always", { ignoreConsecutiveComments: true }], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -868,7 +860,7 @@ ruleTester.run("capitalized-comments", rule, { ].join("\n"), options: ["never", { ignoreConsecutiveComments: true }], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 1, column: 1 }] @@ -886,7 +878,7 @@ ruleTester.run("capitalized-comments", rule, { ].join("\n"), options: ["always", { ignoreConsecutiveComments: false }], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 2, column: 1 }] @@ -898,7 +890,7 @@ ruleTester.run("capitalized-comments", rule, { output: "// Should fail. https://github.com", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "lowercase", line: 1, column: 1 }] @@ -908,7 +900,7 @@ ruleTester.run("capitalized-comments", rule, { output: "// should fail. https://github.com", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "uppercase", line: 1, column: 1 }] diff --git a/tests/lib/rules/class-methods-use-this.js b/tests/lib/rules/class-methods-use-this.js index fbddd027013c..369f04a64f98 100644 --- a/tests/lib/rules/class-methods-use-this.js +++ b/tests/lib/rules/class-methods-use-this.js @@ -37,49 +37,49 @@ ruleTester.run("class-methods-use-this", rule, { code: "class A { foo() {} }", parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "FunctionExpression", line: 1, column: 14, message: "Expected 'this' to be used by class method 'foo'." } + { type: "FunctionExpression", line: 1, column: 14, messageId: "missingThis", data: { name: "foo" } } ] }, { code: "class A { foo() {/**this**/} }", parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "FunctionExpression", line: 1, column: 14, message: "Expected 'this' to be used by class method 'foo'." } + { type: "FunctionExpression", line: 1, column: 14, messageId: "missingThis", data: { name: "foo" } } ] }, { code: "class A { foo() {var a = function () {this};} }", parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "FunctionExpression", line: 1, column: 14, message: "Expected 'this' to be used by class method 'foo'." } + { type: "FunctionExpression", line: 1, column: 14, messageId: "missingThis", data: { name: "foo" } } ] }, { code: "class A { foo() {var a = function () {var b = function(){this}};} }", parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "FunctionExpression", line: 1, column: 14, message: "Expected 'this' to be used by class method 'foo'." } + { type: "FunctionExpression", line: 1, column: 14, messageId: "missingThis", data: { name: "foo" } } ] }, { code: "class A { foo() {window.this} }", parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "FunctionExpression", line: 1, column: 14, message: "Expected 'this' to be used by class method 'foo'." } + { type: "FunctionExpression", line: 1, column: 14, messageId: "missingThis", data: { name: "foo" } } ] }, { code: "class A { foo() {that.this = 'this';} }", parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "FunctionExpression", line: 1, column: 14, message: "Expected 'this' to be used by class method 'foo'." } + { type: "FunctionExpression", line: 1, column: 14, messageId: "missingThis", data: { name: "foo" } } ] }, { code: "class A { foo() { () => undefined; } }", parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "FunctionExpression", line: 1, column: 14, message: "Expected 'this' to be used by class method 'foo'." } + { type: "FunctionExpression", line: 1, column: 14, messageId: "missingThis", data: { name: "foo" } } ] }, { @@ -87,7 +87,7 @@ ruleTester.run("class-methods-use-this", rule, { options: [{ exceptMethods: ["bar"] }], parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "FunctionExpression", line: 1, column: 14, message: "Expected 'this' to be used by class method 'foo'." } + { type: "FunctionExpression", line: 1, column: 14, messageId: "missingThis", data: { name: "foo" } } ] }, { @@ -95,7 +95,7 @@ ruleTester.run("class-methods-use-this", rule, { options: [{ exceptMethods: ["foo"] }], parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "FunctionExpression", line: 1, column: 34, message: "Expected 'this' to be used by class method 'hasOwnProperty'." } + { type: "FunctionExpression", line: 1, column: 34, messageId: "missingThis", data: { name: "hasOwnProperty" } } ] } ] diff --git a/tests/lib/rules/comma-dangle.js b/tests/lib/rules/comma-dangle.js index 1a4f80a77259..29027e9496aa 100644 --- a/tests/lib/rules/comma-dangle.js +++ b/tests/lib/rules/comma-dangle.js @@ -410,7 +410,7 @@ ruleTester.run("comma-dangle", rule, { output: "var foo = { bar: 'baz' }", errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 1, column: 23 @@ -422,7 +422,7 @@ ruleTester.run("comma-dangle", rule, { output: "var foo = {\nbar: 'baz'\n}", errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 2, column: 11 @@ -434,7 +434,7 @@ ruleTester.run("comma-dangle", rule, { output: "foo({ bar: 'baz', qux: 'quux' });", errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 1, column: 30 @@ -446,7 +446,7 @@ ruleTester.run("comma-dangle", rule, { output: "foo({\nbar: 'baz',\nqux: 'quux'\n});", errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 3, column: 12 @@ -458,7 +458,7 @@ ruleTester.run("comma-dangle", rule, { output: "var foo = [ 'baz' ]", errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Literal", line: 1, column: 18 @@ -470,7 +470,7 @@ ruleTester.run("comma-dangle", rule, { output: "var foo = [ 'baz'\n]", errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Literal", line: 1, column: 18 @@ -482,7 +482,7 @@ ruleTester.run("comma-dangle", rule, { output: "var foo = { bar: 'bar'\n\n }", errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 3, column: 1 @@ -497,7 +497,7 @@ ruleTester.run("comma-dangle", rule, { options: ["never"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 1, column: 23 @@ -510,7 +510,7 @@ ruleTester.run("comma-dangle", rule, { options: ["only-multiline"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 1, column: 23 @@ -523,7 +523,7 @@ ruleTester.run("comma-dangle", rule, { options: ["never"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 2, column: 11 @@ -536,7 +536,7 @@ ruleTester.run("comma-dangle", rule, { options: ["never"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 1, column: 30 @@ -549,7 +549,7 @@ ruleTester.run("comma-dangle", rule, { options: ["only-multiline"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 1, column: 30 @@ -563,7 +563,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always"], errors: [ { - message: "Missing trailing comma.", + messageId: "missing", type: "Property", line: 1, column: 23 @@ -576,7 +576,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always"], errors: [ { - message: "Missing trailing comma.", + messageId: "missing", type: "Property", line: 2, column: 11 @@ -589,7 +589,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always"], errors: [ { - message: "Missing trailing comma.", + messageId: "missing", type: "Property", line: 1, column: 30 @@ -602,7 +602,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always"], errors: [ { - message: "Missing trailing comma.", + messageId: "missing", type: "Property", line: 3, column: 12 @@ -615,7 +615,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always"], errors: [ { - message: "Missing trailing comma.", + messageId: "missing", type: "Literal", line: 1, column: 18 @@ -628,7 +628,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always"], errors: [ { - message: "Missing trailing comma.", + messageId: "missing", type: "Literal", line: 1, column: 18 @@ -641,7 +641,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always"], errors: [ { - message: "Missing trailing comma.", + messageId: "missing", type: "Property", line: 3, column: 6 @@ -655,7 +655,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always-multiline"], errors: [ { - message: "Missing trailing comma.", + messageId: "missing", type: "Property", line: 2, column: 11 @@ -680,7 +680,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always"], errors: [ { - message: "Missing trailing comma.", + messageId: "missing", type: "Identifier", line: 5, column: 4 @@ -705,7 +705,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always"], errors: [ { - message: "Missing trailing comma.", + messageId: "missing", type: "Property", line: 5, column: 4 @@ -732,7 +732,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always"], errors: [ { - message: "Missing trailing comma.", + messageId: "missing", type: "ConditionalExpression", line: 5, column: 4 @@ -745,7 +745,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always-multiline"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 1, column: 23 @@ -758,7 +758,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always-multiline"], errors: [ { - message: "Missing trailing comma.", + messageId: "missing", type: "Property", line: 3, column: 12 @@ -771,7 +771,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always-multiline"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 1, column: 30 @@ -784,7 +784,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always-multiline"], errors: [ { - message: "Missing trailing comma.", + messageId: "missing", type: "Literal", line: 2, column: 6 @@ -797,7 +797,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always-multiline"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Literal", line: 1, column: 17 @@ -810,7 +810,7 @@ ruleTester.run("comma-dangle", rule, { options: ["only-multiline"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Literal", line: 1, column: 17 @@ -823,7 +823,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always-multiline"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 3, column: 2 @@ -836,7 +836,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always-multiline"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 2, column: 11 @@ -849,7 +849,7 @@ ruleTester.run("comma-dangle", rule, { options: ["only-multiline"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 2, column: 11 @@ -862,7 +862,7 @@ ruleTester.run("comma-dangle", rule, { options: ["always-multiline"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "ObjectExpression", line: 6, column: 2 @@ -876,7 +876,7 @@ ruleTester.run("comma-dangle", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 1, column: 11 @@ -890,7 +890,7 @@ ruleTester.run("comma-dangle", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 1, column: 11 @@ -904,7 +904,7 @@ ruleTester.run("comma-dangle", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Identifier", line: 1, column: 11 @@ -918,7 +918,7 @@ ruleTester.run("comma-dangle", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Identifier", line: 1, column: 11 @@ -931,7 +931,7 @@ ruleTester.run("comma-dangle", rule, { options: ["never"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Literal", line: 1, column: 5 @@ -944,7 +944,7 @@ ruleTester.run("comma-dangle", rule, { options: ["only-multiline"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Literal", line: 1, column: 5 @@ -957,7 +957,7 @@ ruleTester.run("comma-dangle", rule, { options: ["never"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 1, column: 19 @@ -970,7 +970,7 @@ ruleTester.run("comma-dangle", rule, { options: ["only-multiline"], errors: [ { - message: "Unexpected trailing comma.", + messageId: "unexpected", type: "Property", line: 1, column: 19 @@ -984,91 +984,91 @@ ruleTester.run("comma-dangle", rule, { output: "import {foo,} from 'foo';", options: ["always"], parserOptions: { sourceType: "module" }, - errors: [{ message: "Missing trailing comma.", type: "ImportSpecifier" }] + errors: [{ messageId: "missing", type: "ImportSpecifier" }] }, { code: "import foo, {abc} from 'foo';", output: "import foo, {abc,} from 'foo';", options: ["always"], parserOptions: { sourceType: "module" }, - errors: [{ message: "Missing trailing comma.", type: "ImportSpecifier" }] + errors: [{ messageId: "missing", type: "ImportSpecifier" }] }, { code: "export {foo} from 'foo';", output: "export {foo,} from 'foo';", options: ["always"], parserOptions: { sourceType: "module" }, - errors: [{ message: "Missing trailing comma.", type: "ExportSpecifier" }] + errors: [{ messageId: "missing", type: "ExportSpecifier" }] }, { code: "import {foo,} from 'foo';", output: "import {foo} from 'foo';", options: ["never"], parserOptions: { sourceType: "module" }, - errors: [{ message: "Unexpected trailing comma.", type: "ImportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] }, { code: "import {foo,} from 'foo';", output: "import {foo} from 'foo';", options: ["only-multiline"], parserOptions: { sourceType: "module" }, - errors: [{ message: "Unexpected trailing comma.", type: "ImportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] }, { code: "import foo, {abc,} from 'foo';", output: "import foo, {abc} from 'foo';", options: ["never"], parserOptions: { sourceType: "module" }, - errors: [{ message: "Unexpected trailing comma.", type: "ImportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] }, { code: "import foo, {abc,} from 'foo';", output: "import foo, {abc} from 'foo';", options: ["only-multiline"], parserOptions: { sourceType: "module" }, - errors: [{ message: "Unexpected trailing comma.", type: "ImportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] }, { code: "export {foo,} from 'foo';", output: "export {foo} from 'foo';", options: ["never"], parserOptions: { sourceType: "module" }, - errors: [{ message: "Unexpected trailing comma.", type: "ExportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ExportSpecifier" }] }, { code: "export {foo,} from 'foo';", output: "export {foo} from 'foo';", options: ["only-multiline"], parserOptions: { sourceType: "module" }, - errors: [{ message: "Unexpected trailing comma.", type: "ExportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ExportSpecifier" }] }, { code: "import {foo,} from 'foo';", output: "import {foo} from 'foo';", options: ["always-multiline"], parserOptions: { sourceType: "module" }, - errors: [{ message: "Unexpected trailing comma.", type: "ImportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ImportSpecifier" }] }, { code: "export {foo,} from 'foo';", output: "export {foo} from 'foo';", options: ["always-multiline"], parserOptions: { sourceType: "module" }, - errors: [{ message: "Unexpected trailing comma.", type: "ExportSpecifier" }] + errors: [{ messageId: "unexpected", type: "ExportSpecifier" }] }, { code: "import {\n foo\n} from 'foo';", output: "import {\n foo,\n} from 'foo';", options: ["always-multiline"], parserOptions: { sourceType: "module" }, - errors: [{ message: "Missing trailing comma.", type: "ImportSpecifier" }] + errors: [{ messageId: "missing", type: "ImportSpecifier" }] }, { code: "export {\n foo\n} from 'foo';", output: "export {\n foo,\n} from 'foo';", options: ["always-multiline"], parserOptions: { sourceType: "module" }, - errors: [{ message: "Missing trailing comma.", type: "ExportSpecifier" }] + errors: [{ messageId: "missing", type: "ExportSpecifier" }] }, // https://github.com/eslint/eslint/issues/6233 @@ -1076,19 +1076,19 @@ ruleTester.run("comma-dangle", rule, { code: "var foo = {a: (1)}", output: "var foo = {a: (1),}", options: ["always"], - errors: [{ message: "Missing trailing comma.", type: "Property" }] + errors: [{ messageId: "missing", type: "Property" }] }, { code: "var foo = [(1)]", output: "var foo = [(1),]", options: ["always"], - errors: [{ message: "Missing trailing comma.", type: "Literal" }] + errors: [{ messageId: "missing", type: "Literal" }] }, { code: "var foo = [\n1,\n(2)\n]", output: "var foo = [\n1,\n(2),\n]", options: ["always-multiline"], - errors: [{ message: "Missing trailing comma.", type: "Literal" }] + errors: [{ messageId: "missing", type: "Literal" }] }, // trailing commas in functions @@ -1097,56 +1097,56 @@ ruleTester.run("comma-dangle", rule, { output: "function foo(a) {}", options: [{ functions: "never" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: [{ functions: "never" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(a,) => a", output: "(a) => a", options: [{ functions: "never" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(a,) => (a)", output: "(a) => (a)", options: [{ functions: "never" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "({foo(a,) {}})", output: "({foo(a) {}})", options: [{ functions: "never" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "class A {foo(a,) {}}", output: "class A {foo(a) {}}", options: [{ functions: "never" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: [{ functions: "never" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: [{ functions: "never" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "SpreadElement" }] + errors: [{ messageId: "unexpected", type: "SpreadElement" }] }, { @@ -1154,56 +1154,56 @@ ruleTester.run("comma-dangle", rule, { output: "function foo(a,) {}", options: [{ functions: "always" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Missing trailing comma.", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(function foo(a) {})", output: "(function foo(a,) {})", options: [{ functions: "always" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Missing trailing comma.", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(a) => a", output: "(a,) => a", options: [{ functions: "always" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Missing trailing comma.", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "(a) => (a)", output: "(a,) => (a)", options: [{ functions: "always" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Missing trailing comma.", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "({foo(a) {}})", output: "({foo(a,) {}})", options: [{ functions: "always" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Missing trailing comma.", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "class A {foo(a) {}}", output: "class A {foo(a,) {}}", options: [{ functions: "always" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Missing trailing comma.", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(a)", output: "foo(a,)", options: [{ functions: "always" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Missing trailing comma.", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(...a)", output: "foo(...a,)", options: [{ functions: "always" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Missing trailing comma.", type: "SpreadElement" }] + errors: [{ messageId: "missing", type: "SpreadElement" }] }, { @@ -1211,49 +1211,49 @@ ruleTester.run("comma-dangle", rule, { output: "function foo(a) {}", options: [{ functions: "always-multiline" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: [{ functions: "always-multiline" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: [{ functions: "always-multiline" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: [{ functions: "always-multiline" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "SpreadElement" }] + errors: [{ messageId: "unexpected", type: "SpreadElement" }] }, { code: "function foo(\na,\nb\n) {}", output: "function foo(\na,\nb,\n) {}", options: [{ functions: "always-multiline" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Missing trailing comma.", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(\na,\nb\n)", output: "foo(\na,\nb,\n)", options: [{ functions: "always-multiline" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Missing trailing comma.", type: "Identifier" }] + errors: [{ messageId: "missing", type: "Identifier" }] }, { code: "foo(\n...a,\n...b\n)", output: "foo(\n...a,\n...b,\n)", options: [{ functions: "always-multiline" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Missing trailing comma.", type: "SpreadElement" }] + errors: [{ messageId: "missing", type: "SpreadElement" }] }, { @@ -1261,28 +1261,28 @@ ruleTester.run("comma-dangle", rule, { output: "function foo(a) {}", options: [{ functions: "only-multiline" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "(function foo(a,) {})", output: "(function foo(a) {})", options: [{ functions: "only-multiline" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(a,)", output: "foo(a)", options: [{ functions: "only-multiline" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "Identifier" }] + errors: [{ messageId: "unexpected", type: "Identifier" }] }, { code: "foo(...a,)", output: "foo(...a)", options: [{ functions: "only-multiline" }], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected trailing comma.", type: "SpreadElement" }] + errors: [{ messageId: "unexpected", type: "SpreadElement" }] }, // separated options @@ -1306,8 +1306,8 @@ export {d,}; }], parserOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ - { message: "Unexpected trailing comma.", line: 1 }, - { message: "Unexpected trailing comma.", line: 1 } + { messageId: "unexpected", line: 1 }, + { messageId: "unexpected", line: 1 } ] }, { @@ -1330,8 +1330,8 @@ export {d,}; }], parserOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ - { message: "Unexpected trailing comma.", line: 2 }, - { message: "Unexpected trailing comma.", line: 2 } + { messageId: "unexpected", line: 2 }, + { messageId: "unexpected", line: 2 } ] }, { @@ -1354,7 +1354,7 @@ export {d,}; }], parserOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ - { message: "Unexpected trailing comma.", line: 3 } + { messageId: "unexpected", line: 3 } ] }, { @@ -1377,7 +1377,7 @@ export {d}; }], parserOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ - { message: "Unexpected trailing comma.", line: 4 } + { messageId: "unexpected", line: 4 } ] }, { @@ -1400,8 +1400,8 @@ export {d,}; }], parserOptions: { ecmaVersion: 8, sourceType: "module" }, errors: [ - { message: "Unexpected trailing comma.", line: 5 }, - { message: "Unexpected trailing comma.", line: 5 } + { messageId: "unexpected", line: 5 }, + { messageId: "unexpected", line: 5 } ] }, @@ -1410,28 +1410,28 @@ export {d,}; code: "function foo({a}: {a: string,}) {}", output: "function foo({a,}: {a: string,}) {}", options: ["always"], - errors: [{ message: "Missing trailing comma." }], + errors: [{ messageId: "missing" }], parser: parser("object-pattern-1") }, { code: "function foo({a,}: {a: string}) {}", output: "function foo({a}: {a: string}) {}", options: ["never"], - errors: [{ message: "Unexpected trailing comma." }], + errors: [{ messageId: "unexpected" }], parser: parser("object-pattern-2") }, { code: "function foo(a): {b: boolean,} {}", output: "function foo(a,): {b: boolean,} {}", options: [{ functions: "always" }], - errors: [{ message: "Missing trailing comma." }], + errors: [{ messageId: "missing" }], parser: parser("return-type-1") }, { code: "function foo(a,): {b: boolean} {}", output: "function foo(a): {b: boolean} {}", options: [{ functions: "never" }], - errors: [{ message: "Unexpected trailing comma." }], + errors: [{ messageId: "unexpected" }], parser: parser("return-type-2") } ] diff --git a/tests/lib/rules/comma-spacing.js b/tests/lib/rules/comma-spacing.js index f166360d6363..d5c8ff0ec847 100644 --- a/tests/lib/rules/comma-spacing.js +++ b/tests/lib/rules/comma-spacing.js @@ -131,11 +131,13 @@ ruleTester.run("comma-spacing", rule, { options: [{ before: true, after: true }], errors: [ { - message: "A space is required before ','.", + messageId: "missing", + data: { loc: "before" }, type: "Punctuator" }, { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -146,11 +148,13 @@ ruleTester.run("comma-spacing", rule, { options: [{ before: true, after: true }], errors: [ { - message: "A space is required before ','.", + messageId: "missing", + data: { loc: "before" }, type: "Punctuator" }, { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -164,7 +168,8 @@ ruleTester.run("comma-spacing", rule, { type: "Punctuator" }, { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -209,7 +214,8 @@ ruleTester.run("comma-spacing", rule, { type: "Punctuator" }, { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -230,7 +236,8 @@ ruleTester.run("comma-spacing", rule, { options: [{ before: true, after: false }], errors: [ { - message: "A space is required before ','.", + messageId: "missing", + data: { loc: "before" }, type: "Punctuator" }, { @@ -256,7 +263,8 @@ ruleTester.run("comma-spacing", rule, { options: [{ before: true, after: false }], errors: [ { - message: "A space is required before ','.", + messageId: "missing", + data: { loc: "before" }, type: "Punctuator" } ] @@ -267,7 +275,8 @@ ruleTester.run("comma-spacing", rule, { options: [{ before: true, after: false }], errors: [ { - message: "A space is required before ','.", + messageId: "missing", + data: { loc: "before" }, type: "Punctuator" }, { @@ -282,7 +291,8 @@ ruleTester.run("comma-spacing", rule, { options: [{ before: false, after: true }], errors: [ { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -304,7 +314,8 @@ ruleTester.run("comma-spacing", rule, { options: [{ before: true, after: true }], errors: [ { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -315,11 +326,13 @@ ruleTester.run("comma-spacing", rule, { options: [{ before: true, after: true }], errors: [ { - message: "A space is required before ','.", + messageId: "missing", + data: { loc: "before" }, type: "Punctuator" }, { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -330,11 +343,13 @@ ruleTester.run("comma-spacing", rule, { options: [{ before: true, after: true }], errors: [ { - message: "A space is required before ','.", + messageId: "missing", + data: { loc: "before" }, type: "Punctuator" }, { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -364,7 +379,8 @@ ruleTester.run("comma-spacing", rule, { type: "Punctuator" }, { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -375,11 +391,13 @@ ruleTester.run("comma-spacing", rule, { options: [{ before: true, after: true }], errors: [ { - message: "A space is required before ','.", + messageId: "missing", + data: { loc: "before" }, type: "Punctuator" }, { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -391,11 +409,13 @@ ruleTester.run("comma-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "A space is required before ','.", + messageId: "missing", + data: { loc: "before" }, type: "Punctuator" }, { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -407,11 +427,13 @@ ruleTester.run("comma-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "A space is required before ','.", + messageId: "missing", + data: { loc: "before" }, type: "Punctuator" }, { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -427,7 +449,8 @@ ruleTester.run("comma-spacing", rule, { type: "Punctuator" }, { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -442,7 +465,8 @@ ruleTester.run("comma-spacing", rule, { type: "Punctuator" }, { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -462,7 +486,8 @@ ruleTester.run("comma-spacing", rule, { output: "myfunc(404, true, /* bla bla bla */ 'hello');", errors: [ { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] @@ -472,7 +497,8 @@ ruleTester.run("comma-spacing", rule, { output: "myfunc(404, // comment\n true, 'hello');", errors: [ { - message: "A space is required after ','.", + messageId: "missing", + data: { loc: "after" }, type: "Punctuator" } ] diff --git a/tests/lib/rules/comma-style.js b/tests/lib/rules/comma-style.js index 6ccb11fd0cba..79d6f914a990 100644 --- a/tests/lib/rules/comma-style.js +++ b/tests/lib/rules/comma-style.js @@ -11,10 +11,6 @@ const rule = require("../../../lib/rules/comma-style"), RuleTester = require("../../../lib/testers/rule-tester"); -const BAD_LN_BRK_MSG = "Bad line breaking before and after ','.", - FIRST_MSG = "',' should be placed first.", - LAST_MSG = "',' should be placed last."; - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ @@ -219,7 +215,7 @@ ruleTester.run("comma-style", rule, { code: "var foo = { a: 1. //comment \n, b: 2\n}", output: "var foo = { a: 1., //comment \n b: 2\n}", errors: [{ - message: LAST_MSG, + messageId: "before", type: "Property" }] }, @@ -227,7 +223,7 @@ ruleTester.run("comma-style", rule, { code: "var foo = { a: 1. //comment \n //comment1 \n //comment2 \n, b: 2\n}", output: "var foo = { a: 1., //comment \n //comment1 \n //comment2 \n b: 2\n}", errors: [{ - message: LAST_MSG, + messageId: "before", type: "Property" }] }, @@ -235,7 +231,7 @@ ruleTester.run("comma-style", rule, { code: "var foo = 1\n,\nbar = 2;", output: "var foo = 1,\nbar = 2;", errors: [{ - message: BAD_LN_BRK_MSG, + messageId: "beforeAndAfter", type: "VariableDeclarator" }] }, @@ -243,7 +239,7 @@ ruleTester.run("comma-style", rule, { code: "var foo = 1 //comment\n,\nbar = 2;", output: "var foo = 1, //comment\nbar = 2;", errors: [{ - message: BAD_LN_BRK_MSG, + messageId: "beforeAndAfter", type: "VariableDeclarator" }] }, @@ -251,7 +247,7 @@ ruleTester.run("comma-style", rule, { code: "var foo = 1 //comment\n, // comment 2\nbar = 2;", output: "var foo = 1, //comment // comment 2\nbar = 2;", errors: [{ - message: BAD_LN_BRK_MSG, + messageId: "beforeAndAfter", type: "VariableDeclarator" }] }, @@ -259,7 +255,7 @@ ruleTester.run("comma-style", rule, { code: "var foo = 1\n,bar = 2;", output: "var foo = 1,\nbar = 2;", errors: [{ - message: LAST_MSG, + messageId: "before", type: "VariableDeclarator" }] }, @@ -267,7 +263,7 @@ ruleTester.run("comma-style", rule, { code: "f([1,2\n,3]);", output: "f([1,2,\n3]);", errors: [{ - message: LAST_MSG, + messageId: "before", type: "Literal" }] }, @@ -275,7 +271,7 @@ ruleTester.run("comma-style", rule, { code: "f([1,2\n,]);", output: "f([1,2,\n]);", errors: [{ - message: LAST_MSG, + messageId: "before", type: "Punctuator" }] }, @@ -283,7 +279,7 @@ ruleTester.run("comma-style", rule, { code: "f([,2\n,3]);", output: "f([,2,\n3]);", errors: [{ - message: LAST_MSG, + messageId: "before", type: "Literal" }] }, @@ -291,7 +287,7 @@ ruleTester.run("comma-style", rule, { code: "var foo = ['apples'\n, 'oranges'];", output: "var foo = ['apples',\n 'oranges'];", errors: [{ - message: LAST_MSG, + messageId: "before", type: "Literal" }] }, @@ -307,7 +303,7 @@ ruleTester.run("comma-style", rule, { ecmaVersion: 6 }, errors: [{ - message: LAST_MSG, + messageId: "before", type: "Identifier" }] }, @@ -320,7 +316,7 @@ ruleTester.run("comma-style", rule, { } }], errors: [{ - message: LAST_MSG, + messageId: "before", type: "Literal" }] }, @@ -333,7 +329,7 @@ ruleTester.run("comma-style", rule, { } }], errors: [{ - message: LAST_MSG, + messageId: "before", type: "Identifier" }] }, @@ -350,7 +346,7 @@ ruleTester.run("comma-style", rule, { sourceType: "module" }, errors: [{ - message: LAST_MSG, + messageId: "before", type: "Identifier" }] }, @@ -366,7 +362,7 @@ ruleTester.run("comma-style", rule, { ecmaVersion: 6 }, errors: [{ - message: LAST_MSG, + messageId: "before", type: "Identifier" }] }, @@ -382,7 +378,7 @@ ruleTester.run("comma-style", rule, { ecmaVersion: 6 }, errors: [{ - message: LAST_MSG, + messageId: "before", type: "Identifier" }] }, @@ -398,7 +394,7 @@ ruleTester.run("comma-style", rule, { ecmaVersion: 6 }, errors: [{ - message: LAST_MSG, + messageId: "before", type: "Identifier" }] }, @@ -415,7 +411,7 @@ ruleTester.run("comma-style", rule, { sourceType: "module" }, errors: [{ - message: LAST_MSG, + messageId: "before", type: "ImportSpecifier" }] }, @@ -431,7 +427,7 @@ ruleTester.run("comma-style", rule, { ecmaVersion: 6 }, errors: [{ - message: LAST_MSG, + messageId: "before", type: "Property" }] }, @@ -440,7 +436,7 @@ ruleTester.run("comma-style", rule, { output: "var foo = 1\n,bar = 2;", options: ["first"], errors: [{ - message: FIRST_MSG, + messageId: "after", type: "VariableDeclarator" }] }, @@ -449,7 +445,7 @@ ruleTester.run("comma-style", rule, { output: "f([1\n,2,3]);", options: ["first"], errors: [{ - message: FIRST_MSG, + messageId: "after", type: "Literal" }] }, @@ -458,7 +454,7 @@ ruleTester.run("comma-style", rule, { output: "var foo = ['apples' \n ,'oranges'];", options: ["first"], errors: [{ - message: FIRST_MSG, + messageId: "after", type: "Literal" }] }, @@ -467,7 +463,7 @@ ruleTester.run("comma-style", rule, { output: "var foo = {'a': 1 \n ,'b': 2\n ,'c': 3};", options: ["first"], errors: [{ - message: FIRST_MSG, + messageId: "after", type: "Property" }] }, @@ -476,7 +472,7 @@ ruleTester.run("comma-style", rule, { output: "var a = 'a',\no = 'o',\narr = [1\n,2];", options: ["first", { exceptions: { VariableDeclaration: true } }], errors: [{ - message: FIRST_MSG, + messageId: "after", type: "Literal" }] }, @@ -485,7 +481,7 @@ ruleTester.run("comma-style", rule, { output: "var a = 'a',\nobj = {a: 'a'\n,b: 'b'};", options: ["first", { exceptions: { VariableDeclaration: true } }], errors: [{ - message: FIRST_MSG, + messageId: "after", type: "Property" }] }, @@ -494,7 +490,7 @@ ruleTester.run("comma-style", rule, { output: "var a = 'a'\n,obj = {a: 'a',\nb: 'b'};", options: ["first", { exceptions: { ObjectExpression: true } }], errors: [{ - message: FIRST_MSG, + messageId: "after", type: "VariableDeclarator" }] }, @@ -503,7 +499,7 @@ ruleTester.run("comma-style", rule, { output: "var a = 'a'\n,arr = [1,\n2];", options: ["first", { exceptions: { ArrayExpression: true } }], errors: [{ - message: FIRST_MSG, + messageId: "after", type: "VariableDeclarator" }] }, @@ -512,7 +508,7 @@ ruleTester.run("comma-style", rule, { output: "var ar =[1,\n{a: 'a'\n,b: 'b'}];", options: ["first", { exceptions: { ArrayExpression: true } }], errors: [{ - message: FIRST_MSG, + messageId: "after", type: "Property" }] }, @@ -521,7 +517,7 @@ ruleTester.run("comma-style", rule, { output: "var ar =[1\n,{a: 'a',\nb: 'b'}];", options: ["first", { exceptions: { ObjectExpression: true } }], errors: [{ - message: FIRST_MSG, + messageId: "after", type: "ObjectExpression" }] }, @@ -530,7 +526,7 @@ ruleTester.run("comma-style", rule, { output: "var ar ={fst:1,\nsnd: [1\n,2]};", options: ["first", { exceptions: { ObjectExpression: true } }], errors: [{ - message: FIRST_MSG, + messageId: "after", type: "Literal" }] }, @@ -539,7 +535,7 @@ ruleTester.run("comma-style", rule, { output: "var ar ={fst:1\n,snd: [1,\n2]};", options: ["first", { exceptions: { ArrayExpression: true } }], errors: [{ - message: FIRST_MSG, + messageId: "after", type: "Property" }] }, @@ -547,14 +543,14 @@ ruleTester.run("comma-style", rule, { code: "var foo = [\n(bar\n)\n,\nbaz\n];", output: "var foo = [\n(bar\n),\nbaz\n];", errors: [{ - message: BAD_LN_BRK_MSG, + messageId: "beforeAndAfter", type: "Identifier" }] }, { code: "[(foo),\n,\nbar]", output: "[(foo),,\nbar]", - errors: [{ message: BAD_LN_BRK_MSG }] + errors: [{ messageId: "beforeAndAfter" }] } ] }); diff --git a/tests/lib/rules/complexity.js b/tests/lib/rules/complexity.js index b1b031173ddf..9e675f37fd9d 100644 --- a/tests/lib/rules/complexity.js +++ b/tests/lib/rules/complexity.js @@ -34,6 +34,19 @@ function createComplexity(complexity) { return funcString; } +/** + * Create an expected error object + * @param {string} name The name of the symbol being tested + * @param {number} complexity The cyclomatic complexity value of the symbol + * @returns {Object} The error object + */ +function makeError(name, complexity) { + return { + messageId: "complex", + data: { name, complexity } + }; +} + const ruleTester = new RuleTester(); ruleTester.run("complexity", rule, { @@ -63,10 +76,10 @@ ruleTester.run("complexity", rule, { { code: "function b(x) {}", options: [{ max: 1 }] } ], invalid: [ - { code: "function a(x) {}", options: [0], errors: [{ message: "Function 'a' has a complexity of 1." }] }, - { code: "var func = function () {}", options: [0], errors: [{ message: "Function has a complexity of 1." }] }, - { code: "var obj = { a(x) {} }", options: [0], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Method 'a' has a complexity of 1." }] }, - { code: "class Test { a(x) {} }", options: [0], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Method 'a' has a complexity of 1." }] }, + { code: "function a(x) {}", options: [0], errors: [makeError("Function 'a'", 1)] }, + { code: "var func = function () {}", options: [0], errors: [makeError("Function", 1)] }, + { code: "var obj = { a(x) {} }", options: [0], parserOptions: { ecmaVersion: 6 }, errors: [makeError("Method 'a'", 1)] }, + { code: "class Test { a(x) {} }", options: [0], parserOptions: { ecmaVersion: 6 }, errors: [makeError("Method 'a'", 1)] }, { code: "var a = (x) => {if (true) {return x;}}", options: [1], errors: 1, settings: { ecmascript: 6 } }, { code: "function a(x) {if (true) {return x;}}", options: [1], errors: 1 }, { code: "function a(x) {if (true) {return x;} else {return x+1;}}", options: [1], errors: 1 }, @@ -87,14 +100,14 @@ ruleTester.run("complexity", rule, { { code: "function a(x) {do {'foo';} while (true)}", options: [1], errors: 1 }, { code: "function a(x) {(function() {while(true){'foo';}})(); (function() {while(true){'bar';}})();}", options: [1], errors: 2 }, { code: "function a(x) {(function() {while(true){'foo';}})(); (function() {'bar';})();}", options: [1], errors: 1 }, - { code: "var obj = { a(x) { return x ? 0 : 1; } };", options: [1], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Method 'a' has a complexity of 2." }] }, - { code: "var obj = { a: function b(x) { return x ? 0 : 1; } };", options: [1], errors: [{ message: "Method 'b' has a complexity of 2." }] }, + { code: "var obj = { a(x) { return x ? 0 : 1; } };", options: [1], parserOptions: { ecmaVersion: 6 }, errors: [makeError("Method 'a'", 2)] }, + { code: "var obj = { a: function b(x) { return x ? 0 : 1; } };", options: [1], errors: [makeError("Method 'b'", 2)] }, { code: createComplexity(21), - errors: [{ message: "Function 'test' has a complexity of 21." }] + errors: [makeError("Function 'test'", 21)] }, // object property options - { code: "function a(x) {}", options: [{ max: 0 }], errors: [{ message: "Function 'a' has a complexity of 1." }] } + { code: "function a(x) {}", options: [{ max: 0 }], errors: [makeError("Function 'a'", 1)] } ] }); diff --git a/tests/lib/rules/computed-property-spacing.js b/tests/lib/rules/computed-property-spacing.js index eadc7eabed43..4562aed157b5 100644 --- a/tests/lib/rules/computed-property-spacing.js +++ b/tests/lib/rules/computed-property-spacing.js @@ -82,7 +82,8 @@ ruleTester.run("computed-property-spacing", rule, { options: ["always"], errors: [ { - message: "A space is required before ']'.", + messageId: "missingBefore", + data: { tokenValue: "]" }, type: "MemberExpression", column: 17, line: 1 @@ -95,7 +96,8 @@ ruleTester.run("computed-property-spacing", rule, { options: ["always"], errors: [ { - message: "A space is required after '['.", + messageId: "missingAfter", + data: { tokenValue: "[" }, type: "MemberExpression", column: 14, line: 1 @@ -108,7 +110,8 @@ ruleTester.run("computed-property-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space after '['.", + messageId: "after", + data: { tokenValue: "[" }, type: "MemberExpression", column: 14, line: 1 @@ -121,7 +124,8 @@ ruleTester.run("computed-property-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space before ']'.", + messageId: "before", + data: { tokenValue: "]" }, type: "MemberExpression" } ] @@ -132,13 +136,15 @@ ruleTester.run("computed-property-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space after '['.", + messageId: "after", + data: { tokenValue: "[" }, type: "MemberExpression", column: 4, line: 1 }, { - message: "There should be no space before ']'.", + messageId: "before", + data: { tokenValue: "]" }, type: "MemberExpression", column: 10, line: 1 @@ -151,7 +157,8 @@ ruleTester.run("computed-property-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space before ']'.", + messageId: "before", + data: { tokenValue: "]" }, type: "MemberExpression", column: 9, line: 1 @@ -164,7 +171,8 @@ ruleTester.run("computed-property-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space after '['.", + messageId: "after", + data: { tokenValue: "[" }, type: "MemberExpression", column: 4, line: 1 @@ -177,13 +185,15 @@ ruleTester.run("computed-property-spacing", rule, { options: ["always"], errors: [ { - message: "A space is required after '['.", + messageId: "missingAfter", + data: { tokenValue: "[" }, type: "MemberExpression", column: 14, line: 1 }, { - message: "A space is required before ']'.", + messageId: "missingBefore", + data: { tokenValue: "]" }, type: "MemberExpression", column: 16, line: 1 @@ -199,13 +209,15 @@ ruleTester.run("computed-property-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "A space is required after '['.", + messageId: "missingAfter", + data: { tokenValue: "[" }, type: "Property", column: 10, line: 1 }, { - message: "A space is required before ']'.", + messageId: "missingBefore", + data: { tokenValue: "]" }, type: "Property", column: 12, line: 1 @@ -219,7 +231,8 @@ ruleTester.run("computed-property-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "A space is required after '['.", + messageId: "missingAfter", + data: { tokenValue: "[" }, type: "Property", column: 10, line: 1 @@ -233,7 +246,8 @@ ruleTester.run("computed-property-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "A space is required before ']'.", + messageId: "missingBefore", + data: { tokenValue: "]" }, type: "Property", column: 13, line: 1 @@ -249,13 +263,15 @@ ruleTester.run("computed-property-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "There should be no space after '['.", + messageId: "after", + data: { tokenValue: "[" }, type: "Property", column: 10, line: 1 }, { - message: "There should be no space before ']'.", + messageId: "before", + data: { tokenValue: "]" }, type: "Property", column: 14, line: 1 @@ -269,7 +285,8 @@ ruleTester.run("computed-property-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "There should be no space before ']'.", + messageId: "before", + data: { tokenValue: "]" }, type: "Property", column: 13, line: 1 @@ -283,7 +300,8 @@ ruleTester.run("computed-property-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "There should be no space after '['.", + messageId: "after", + data: { tokenValue: "[" }, type: "Property", column: 10, line: 1 @@ -297,7 +315,8 @@ ruleTester.run("computed-property-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "There should be no space after '['.", + messageId: "after", + data: { tokenValue: "[" }, type: "Property", column: 10, line: 1 diff --git a/tests/lib/rules/consistent-return.js b/tests/lib/rules/consistent-return.js index 2bf4a0d0a1c4..15c205500b3f 100644 --- a/tests/lib/rules/consistent-return.js +++ b/tests/lib/rules/consistent-return.js @@ -50,7 +50,8 @@ ruleTester.run("consistent-return", rule, { code: "function foo() { if (true) return true; else return; }", errors: [ { - message: "Function 'foo' expected a return value.", + messageId: "missingReturnValue", + data: { name: "Function 'foo'" }, type: "ReturnStatement" } ] @@ -60,7 +61,8 @@ ruleTester.run("consistent-return", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Arrow function expected a return value.", + messageId: "missingReturnValue", + data: { name: "Arrow function" }, type: "ReturnStatement" } ] @@ -69,7 +71,8 @@ ruleTester.run("consistent-return", rule, { code: "function foo() { if (true) return; else return false; }", errors: [ { - message: "Function 'foo' expected no return value.", + messageId: "unexpectedReturnValue", + data: { name: "Function 'foo'" }, type: "ReturnStatement" } ] @@ -78,7 +81,8 @@ ruleTester.run("consistent-return", rule, { code: "f(function() { if (true) return true; else return; })", errors: [ { - message: "Function expected a return value.", + messageId: "missingReturnValue", + data: { name: "Function" }, type: "ReturnStatement" } ] @@ -87,7 +91,8 @@ ruleTester.run("consistent-return", rule, { code: "f(function() { if (true) return; else return false; })", errors: [ { - message: "Function expected no return value.", + messageId: "unexpectedReturnValue", + data: { name: "Function" }, type: "ReturnStatement" } ] @@ -97,7 +102,8 @@ ruleTester.run("consistent-return", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Arrow function expected no return value.", + messageId: "unexpectedReturnValue", + data: { name: "Arrow function" }, type: "ReturnStatement" } ] @@ -107,7 +113,8 @@ ruleTester.run("consistent-return", rule, { options: [{ treatUndefinedAsUnspecified: true }], errors: [ { - message: "Function 'foo' expected a return value.", + messageId: "missingReturnValue", + data: { name: "Function 'foo'" }, type: "ReturnStatement", column: 41 } @@ -118,7 +125,8 @@ ruleTester.run("consistent-return", rule, { options: [{ treatUndefinedAsUnspecified: true }], errors: [ { - message: "Function 'foo' expected a return value.", + messageId: "missingReturnValue", + data: { name: "Function 'foo'" }, type: "ReturnStatement", column: 41 } @@ -129,7 +137,8 @@ ruleTester.run("consistent-return", rule, { options: [{ treatUndefinedAsUnspecified: true }], errors: [ { - message: "Function 'foo' expected no return value.", + messageId: "unexpectedReturnValue", + data: { name: "Function 'foo'" }, type: "ReturnStatement", column: 46 } @@ -140,7 +149,8 @@ ruleTester.run("consistent-return", rule, { options: [{ treatUndefinedAsUnspecified: true }], errors: [ { - message: "Function 'foo' expected no return value.", + messageId: "unexpectedReturnValue", + data: { name: "Function 'foo'" }, type: "ReturnStatement", column: 43 } @@ -151,7 +161,8 @@ ruleTester.run("consistent-return", rule, { parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { - message: "Program expected a return value.", + messageId: "missingReturnValue", + data: { name: "Program" }, type: "ReturnStatement" } ] @@ -160,7 +171,8 @@ ruleTester.run("consistent-return", rule, { code: "function foo() { if (a) return true; }", errors: [ { - message: "Expected to return a value at the end of function 'foo'.", + messageId: "missingReturn", + data: { name: "function 'foo'" }, type: "FunctionDeclaration", column: 10 } @@ -170,7 +182,8 @@ ruleTester.run("consistent-return", rule, { code: "function _foo() { if (a) return true; }", errors: [ { - message: "Expected to return a value at the end of function '_foo'.", + messageId: "missingReturn", + data: { name: "function '_foo'" }, type: "FunctionDeclaration", column: 10 } @@ -180,7 +193,8 @@ ruleTester.run("consistent-return", rule, { code: "f(function foo() { if (a) return true; });", errors: [ { - message: "Expected to return a value at the end of function 'foo'.", + messageId: "missingReturn", + data: { name: "function 'foo'" }, type: "FunctionExpression", column: 12 } @@ -190,7 +204,8 @@ ruleTester.run("consistent-return", rule, { code: "f(function() { if (a) return true; });", errors: [ { - message: "Expected to return a value at the end of function.", + messageId: "missingReturn", + data: { name: "function" }, type: "FunctionExpression", column: 3 } @@ -201,7 +216,8 @@ ruleTester.run("consistent-return", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Expected to return a value at the end of arrow function.", + messageId: "missingReturn", + data: { name: "arrow function" }, type: "ArrowFunctionExpression", column: 6 } @@ -212,7 +228,8 @@ ruleTester.run("consistent-return", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Expected to return a value at the end of method 'foo'.", + messageId: "missingReturn", + data: { name: "method 'foo'" }, type: "FunctionExpression", column: 12 } @@ -223,7 +240,8 @@ ruleTester.run("consistent-return", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Expected to return a value at the end of method 'foo'.", + messageId: "missingReturn", + data: { name: "method 'foo'" }, type: "FunctionExpression", column: 10 } @@ -234,7 +252,8 @@ ruleTester.run("consistent-return", rule, { parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { - message: "Expected to return a value at the end of program.", + messageId: "missingReturn", + data: { name: "program" }, type: "Program", column: 1 } @@ -245,7 +264,8 @@ ruleTester.run("consistent-return", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Expected to return a value at the end of method 'CapitalizedFunction'.", + messageId: "missingReturn", + data: { name: "method 'CapitalizedFunction'" }, type: "FunctionExpression", column: 11 } @@ -256,7 +276,8 @@ ruleTester.run("consistent-return", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Expected to return a value at the end of method 'constructor'.", + messageId: "missingReturn", + data: { name: "method 'constructor'" }, type: "FunctionExpression", column: 4 } diff --git a/tests/lib/rules/consistent-this.js b/tests/lib/rules/consistent-this.js index 782e302d214a..c533debdd575 100644 --- a/tests/lib/rules/consistent-this.js +++ b/tests/lib/rules/consistent-this.js @@ -54,16 +54,16 @@ ruleTester.run("consistent-this", rule, { destructuringTest("[foo, bar] = this") ], invalid: [ - { code: "var context = this", errors: [{ message: "Unexpected alias 'context' for 'this'.", type: "VariableDeclarator" }] }, - { code: "var that = this", options: ["self"], errors: [{ message: "Unexpected alias 'that' for 'this'.", type: "VariableDeclarator" }] }, - { code: "var foo = 42, self = this", options: ["that"], errors: [{ message: "Unexpected alias 'self' for 'this'.", type: "VariableDeclarator" }] }, - { code: "var self = 42", options: ["self"], errors: [{ message: "Designated alias 'self' is not assigned to 'this'.", type: "VariableDeclarator" }] }, - { code: "var self", options: ["self"], errors: [{ message: "Designated alias 'self' is not assigned to 'this'.", type: "VariableDeclarator" }] }, - { code: "var self; self = 42", options: ["self"], errors: [{ message: "Designated alias 'self' is not assigned to 'this'.", type: "VariableDeclarator" }, { message: "Designated alias 'self' is not assigned to 'this'.", type: "AssignmentExpression" }] }, - { code: "context = this", options: ["that"], errors: [{ message: "Unexpected alias 'context' for 'this'.", type: "AssignmentExpression" }] }, - { code: "that = this", options: ["self"], errors: [{ message: "Unexpected alias 'that' for 'this'.", type: "AssignmentExpression" }] }, - { code: "self = this", options: ["that"], errors: [{ message: "Unexpected alias 'self' for 'this'.", type: "AssignmentExpression" }] }, - { code: "self += this", options: ["self"], errors: [{ message: "Designated alias 'self' is not assigned to 'this'.", type: "AssignmentExpression" }] }, - { code: "var self; (function() { self = this; }())", options: ["self"], errors: [{ message: "Designated alias 'self' is not assigned to 'this'.", type: "VariableDeclarator" }] } + { code: "var context = this", errors: [{ messageId: "unexpectedAlias", data: { name: "context" }, type: "VariableDeclarator" }] }, + { code: "var that = this", options: ["self"], errors: [{ messageId: "unexpectedAlias", data: { name: "that" }, type: "VariableDeclarator" }] }, + { code: "var foo = 42, self = this", options: ["that"], errors: [{ messageId: "unexpectedAlias", data: { name: "self" }, type: "VariableDeclarator" }] }, + { code: "var self = 42", options: ["self"], errors: [{ messageId: "aliasIsNotThis", data: { name: "self" }, type: "VariableDeclarator" }] }, + { code: "var self", options: ["self"], errors: [{ messageId: "aliasIsNotThis", data: { name: "self" }, type: "VariableDeclarator" }] }, + { code: "var self; self = 42", options: ["self"], errors: [{ messageId: "aliasIsNotThis", data: { name: "self" }, type: "VariableDeclarator" }, { messageId: "aliasIsNotThis", data: { name: "self" }, type: "AssignmentExpression" }] }, + { code: "context = this", options: ["that"], errors: [{ messageId: "unexpectedAlias", data: { name: "context" }, type: "AssignmentExpression" }] }, + { code: "that = this", options: ["self"], errors: [{ messageId: "unexpectedAlias", data: { name: "that" }, type: "AssignmentExpression" }] }, + { code: "self = this", options: ["that"], errors: [{ messageId: "unexpectedAlias", data: { name: "self" }, type: "AssignmentExpression" }] }, + { code: "self += this", options: ["self"], errors: [{ messageId: "aliasIsNotThis", data: { name: "self" }, type: "AssignmentExpression" }] }, + { code: "var self; (function() { self = this; }())", options: ["self"], errors: [{ messageId: "aliasIsNotThis", data: { name: "self" }, type: "VariableDeclarator" }] } ] }); diff --git a/tests/lib/rules/constructor-super.js b/tests/lib/rules/constructor-super.js index 98fca60dbea2..fef067a90a19 100644 --- a/tests/lib/rules/constructor-super.js +++ b/tests/lib/rules/constructor-super.js @@ -84,130 +84,130 @@ ruleTester.run("constructor-super", rule, { // non derived classes. { code: "class A { constructor() { super(); } }", - errors: [{ message: "Unexpected 'super()'.", type: "CallExpression" }] + errors: [{ messageId: "unexpected", type: "CallExpression" }] }, // inherit from non constructors. { code: "class A extends null { constructor() { super(); } }", - errors: [{ message: "Unexpected 'super()' because 'super' is not a constructor.", type: "CallExpression" }] + errors: [{ messageId: "badSuper", type: "CallExpression" }] }, { code: "class A extends null { constructor() { } }", - errors: [{ message: "Expected to call 'super()'.", type: "MethodDefinition" }] + errors: [{ messageId: "missingAll", type: "MethodDefinition" }] }, { code: "class A extends 100 { constructor() { super(); } }", - errors: [{ message: "Unexpected 'super()' because 'super' is not a constructor.", type: "CallExpression" }] + errors: [{ messageId: "badSuper", type: "CallExpression" }] }, { code: "class A extends 'test' { constructor() { super(); } }", - errors: [{ message: "Unexpected 'super()' because 'super' is not a constructor.", type: "CallExpression" }] + errors: [{ messageId: "badSuper", type: "CallExpression" }] }, // derived classes. { code: "class A extends B { constructor() { } }", - errors: [{ message: "Expected to call 'super()'.", type: "MethodDefinition" }] + errors: [{ messageId: "missingAll", type: "MethodDefinition" }] }, { code: "class A extends B { constructor() { for (var a of b) super.foo(); } }", - errors: [{ message: "Expected to call 'super()'.", type: "MethodDefinition" }] + errors: [{ messageId: "missingAll", type: "MethodDefinition" }] }, // nested execution scope. { code: "class A extends B { constructor() { function c() { super(); } } }", - errors: [{ message: "Expected to call 'super()'.", type: "MethodDefinition" }] + errors: [{ messageId: "missingAll", type: "MethodDefinition" }] }, { code: "class A extends B { constructor() { var c = function() { super(); } } }", - errors: [{ message: "Expected to call 'super()'.", type: "MethodDefinition" }] + errors: [{ messageId: "missingAll", type: "MethodDefinition" }] }, { code: "class A extends B { constructor() { var c = () => super(); } }", - errors: [{ message: "Expected to call 'super()'.", type: "MethodDefinition" }] + errors: [{ messageId: "missingAll", type: "MethodDefinition" }] }, { code: "class A extends B { constructor() { class C extends D { constructor() { super(); } } } }", - errors: [{ message: "Expected to call 'super()'.", type: "MethodDefinition", column: 21 }] + errors: [{ messageId: "missingAll", type: "MethodDefinition", column: 21 }] }, { code: "class A extends B { constructor() { var C = class extends D { constructor() { super(); } } } }", - errors: [{ message: "Expected to call 'super()'.", type: "MethodDefinition", column: 21 }] + errors: [{ messageId: "missingAll", type: "MethodDefinition", column: 21 }] }, { code: "class A extends B { constructor() { super(); class C extends D { constructor() { } } } }", - errors: [{ message: "Expected to call 'super()'.", type: "MethodDefinition", column: 66 }] + errors: [{ messageId: "missingAll", type: "MethodDefinition", column: 66 }] }, { code: "class A extends B { constructor() { super(); var C = class extends D { constructor() { } } } }", - errors: [{ message: "Expected to call 'super()'.", type: "MethodDefinition", column: 72 }] + errors: [{ messageId: "missingAll", type: "MethodDefinition", column: 72 }] }, // lacked in some code path. { code: "class A extends B { constructor() { if (a) super(); } }", - errors: [{ message: "Lacked a call of 'super()' in some code paths.", type: "MethodDefinition" }] + errors: [{ messageId: "missingSome", type: "MethodDefinition" }] }, { code: "class A extends B { constructor() { if (a); else super(); } }", - errors: [{ message: "Lacked a call of 'super()' in some code paths.", type: "MethodDefinition" }] + errors: [{ messageId: "missingSome", type: "MethodDefinition" }] }, { code: "class A extends B { constructor() { a && super(); } }", - errors: [{ message: "Lacked a call of 'super()' in some code paths.", type: "MethodDefinition" }] + errors: [{ messageId: "missingSome", type: "MethodDefinition" }] }, { code: "class A extends B { constructor() { switch (a) { case 0: super(); } } }", - errors: [{ message: "Lacked a call of 'super()' in some code paths.", type: "MethodDefinition" }] + errors: [{ messageId: "missingSome", type: "MethodDefinition" }] }, { code: "class A extends B { constructor() { switch (a) { case 0: break; default: super(); } } }", - errors: [{ message: "Lacked a call of 'super()' in some code paths.", type: "MethodDefinition" }] + errors: [{ messageId: "missingSome", type: "MethodDefinition" }] }, { code: "class A extends B { constructor() { try { super(); } catch (err) {} } }", - errors: [{ message: "Lacked a call of 'super()' in some code paths.", type: "MethodDefinition" }] + errors: [{ messageId: "missingSome", type: "MethodDefinition" }] }, { code: "class A extends B { constructor() { try { a; } catch (err) { super(); } } }", - errors: [{ message: "Lacked a call of 'super()' in some code paths.", type: "MethodDefinition" }] + errors: [{ messageId: "missingSome", type: "MethodDefinition" }] }, { code: "class A extends B { constructor() { if (a) return; super(); } }", - errors: [{ message: "Lacked a call of 'super()' in some code paths.", type: "MethodDefinition" }] + errors: [{ messageId: "missingSome", type: "MethodDefinition" }] }, // duplicate. { code: "class A extends B { constructor() { super(); super(); } }", - errors: [{ message: "Unexpected duplicate 'super()'.", type: "CallExpression", column: 46 }] + errors: [{ messageId: "duplicate", type: "CallExpression", column: 46 }] }, { code: "class A extends B { constructor() { super() || super(); } }", - errors: [{ message: "Unexpected duplicate 'super()'.", type: "CallExpression", column: 48 }] + errors: [{ messageId: "duplicate", type: "CallExpression", column: 48 }] }, { code: "class A extends B { constructor() { if (a) super(); super(); } }", - errors: [{ message: "Unexpected duplicate 'super()'.", type: "CallExpression", column: 53 }] + errors: [{ messageId: "duplicate", type: "CallExpression", column: 53 }] }, { code: "class A extends B { constructor() { switch (a) { case 0: super(); default: super(); } } }", - errors: [{ message: "Unexpected duplicate 'super()'.", type: "CallExpression", column: 76 }] + errors: [{ messageId: "duplicate", type: "CallExpression", column: 76 }] }, { code: "class A extends B { constructor(a) { while (a) super(); } }", errors: [ - { message: "Lacked a call of 'super()' in some code paths.", type: "MethodDefinition" }, - { message: "Unexpected duplicate 'super()'.", type: "CallExpression", column: 48 } + { messageId: "missingSome", type: "MethodDefinition" }, + { messageId: "duplicate", type: "CallExpression", column: 48 } ] }, // ignores `super()` on unreachable paths. { code: "class A extends B { constructor() { return; super(); } }", - errors: [{ message: "Expected to call 'super()'.", type: "MethodDefinition" }] + errors: [{ messageId: "missingAll", type: "MethodDefinition" }] }, // https://github.com/eslint/eslint/issues/8248 @@ -217,7 +217,7 @@ ruleTester.run("constructor-super", rule, { for (a in b) for (c in d); } }`, - errors: [{ message: "Expected to call 'super()'.", type: "MethodDefinition" }] + errors: [{ messageId: "missingAll", type: "MethodDefinition" }] } ] }); diff --git a/tests/lib/rules/curly.js b/tests/lib/rules/curly.js index f9a04790d3bd..eebb20e54f1f 100644 --- a/tests/lib/rules/curly.js +++ b/tests/lib/rules/curly.js @@ -219,7 +219,8 @@ ruleTester.run("curly", rule, { output: "if (foo) {bar()}", errors: [ { - message: "Expected { after 'if' condition.", + messageId: "missing", + data: { name: "if", suffix: " condition" }, type: "IfStatement" } ] @@ -229,7 +230,8 @@ ruleTester.run("curly", rule, { output: "if (foo) { bar() } else {baz()}", errors: [ { - message: "Expected { after 'else'.", + messageId: "missing", + data: { name: "else", suffix: "" }, type: "IfStatement" } ] @@ -239,7 +241,8 @@ ruleTester.run("curly", rule, { output: "if (foo) { bar() } else if (faa) {baz()}", errors: [ { - message: "Expected { after 'if' condition.", + messageId: "missing", + data: { name: "if", suffix: " condition" }, type: "IfStatement" } ] @@ -249,7 +252,8 @@ ruleTester.run("curly", rule, { output: "while (foo) {bar()}", errors: [ { - message: "Expected { after 'while' condition.", + messageId: "missing", + data: { name: "while", suffix: " condition" }, type: "WhileStatement" } ] @@ -259,7 +263,8 @@ ruleTester.run("curly", rule, { output: "do {bar();} while (foo)", errors: [ { - message: "Expected { after 'do'.", + messageId: "missing", + data: { name: "do", suffix: "" }, type: "DoWhileStatement" } ] @@ -269,7 +274,8 @@ ruleTester.run("curly", rule, { output: "for (;foo;) {bar()}", errors: [ { - message: "Expected { after 'for' condition.", + messageId: "missing", + data: { name: "for", suffix: " condition" }, type: "ForStatement" } ] @@ -301,7 +307,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'for' condition.", + messageId: "unexpected", + data: { name: "for", suffix: " condition" }, type: "ForStatement" } ] @@ -312,7 +319,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'if' condition.", + messageId: "unexpected", + data: { name: "if", suffix: " condition" }, type: "IfStatement" } ] @@ -323,7 +331,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'while' condition.", + messageId: "unexpected", + data: { name: "while", suffix: " condition" }, type: "WhileStatement" } ] @@ -334,7 +343,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'else'.", + messageId: "unexpected", + data: { name: "else", suffix: "" }, type: "IfStatement" } ] @@ -345,7 +355,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'if' condition.", + messageId: "unexpected", + data: { name: "if", suffix: " condition" }, type: "IfStatement" } ] @@ -356,7 +367,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'if' condition.", + messageId: "unexpected", + data: { name: "if", suffix: " condition" }, type: "IfStatement" } ] @@ -391,7 +403,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'else'.", + messageId: "unexpected", + data: { name: "else", suffix: "" }, type: "IfStatement", line: 6, column: 3 @@ -427,7 +440,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'if' condition.", + messageId: "missing", + data: { name: "if", suffix: " condition" }, type: "IfStatement" } ] @@ -438,7 +452,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'while' condition.", + messageId: "missing", + data: { name: "while", suffix: " condition" }, type: "WhileStatement" } ] @@ -449,7 +464,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'for' condition.", + messageId: "missing", + data: { name: "for", suffix: " condition" }, type: "ForStatement" } ] @@ -460,7 +476,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'while' condition.", + messageId: "missing", + data: { name: "while", suffix: " condition" }, type: "WhileStatement" } ] @@ -471,7 +488,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'if' condition.", + messageId: "missing", + data: { name: "if", suffix: " condition" }, type: "IfStatement" } ] @@ -482,7 +500,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'do'.", + messageId: "missing", + data: { name: "do", suffix: "" }, type: "DoWhileStatement" } ] @@ -539,7 +558,8 @@ ruleTester.run("curly", rule, { options: ["multi-or-nest"], errors: [ { - message: "Expected { after 'if' condition.", + messageId: "missing", + data: { name: "if", suffix: " condition" }, type: "IfStatement" } ] @@ -550,7 +570,8 @@ ruleTester.run("curly", rule, { options: ["multi-or-nest"], errors: [ { - message: "Expected { after 'while' condition.", + messageId: "missing", + data: { name: "while", suffix: " condition" }, type: "WhileStatement" } ] @@ -561,7 +582,8 @@ ruleTester.run("curly", rule, { options: ["multi-or-nest"], errors: [ { - message: "Unnecessary { after 'if' condition.", + messageId: "unexpected", + data: { name: "if", suffix: " condition" }, type: "IfStatement" } ] @@ -572,7 +594,8 @@ ruleTester.run("curly", rule, { options: ["multi-or-nest"], errors: [ { - message: "Unnecessary { after 'while' condition.", + messageId: "unexpected", + data: { name: "while", suffix: " condition" }, type: "WhileStatement" } ] @@ -583,7 +606,8 @@ ruleTester.run("curly", rule, { options: ["multi-or-nest"], errors: [ { - message: "Unnecessary { after 'for' condition.", + messageId: "unexpected", + data: { name: "for", suffix: " condition" }, type: "ForStatement" } ] @@ -640,7 +664,8 @@ ruleTester.run("curly", rule, { options: ["multi", "consistent"], errors: [ { - message: "Expected { after 'if' condition.", + messageId: "missing", + data: { name: "if", suffix: " condition" }, type: "IfStatement" } ] @@ -651,7 +676,8 @@ ruleTester.run("curly", rule, { options: ["multi", "consistent"], errors: [ { - message: "Expected { after 'else'.", + messageId: "missing", + data: { name: "else", suffix: "" }, type: "IfStatement" } ] @@ -662,7 +688,8 @@ ruleTester.run("curly", rule, { options: ["multi", "consistent"], errors: [ { - message: "Unnecessary { after 'else'.", + messageId: "unexpected", + data: { name: "else", suffix: "" }, type: "IfStatement" } ] @@ -673,11 +700,13 @@ ruleTester.run("curly", rule, { options: ["multi", "consistent"], errors: [ { - message: "Expected { after 'if' condition.", + messageId: "missing", + data: { name: "if", suffix: " condition" }, type: "IfStatement" }, { - message: "Expected { after 'if' condition.", + messageId: "missing", + data: { name: "if", suffix: " condition" }, type: "IfStatement" } ] @@ -688,7 +717,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'do'.", + messageId: "unexpected", + data: { name: "do", suffix: "" }, type: "DoWhileStatement" } ] @@ -699,7 +729,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'do'.", + messageId: "unexpected", + data: { name: "do", suffix: "" }, type: "DoWhileStatement" } ] @@ -710,7 +741,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'if' condition.", + messageId: "unexpected", + data: { name: "if", suffix: " condition" }, type: "IfStatement" } ] @@ -721,7 +753,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'do'.", + messageId: "unexpected", + data: { name: "do", suffix: "" }, type: "DoWhileStatement" } ] diff --git a/tests/lib/rules/no-caller.js b/tests/lib/rules/no-caller.js index da56c5180e11..a55a823e01de 100644 --- a/tests/lib/rules/no-caller.js +++ b/tests/lib/rules/no-caller.js @@ -26,7 +26,7 @@ ruleTester.run("no-caller", rule, { "var x = arguments[caller]" ], invalid: [ - { code: "var x = arguments.callee", errors: [{ message: "Avoid arguments.callee.", type: "MemberExpression" }] }, - { code: "var x = arguments.caller", errors: [{ message: "Avoid arguments.caller.", type: "MemberExpression" }] } + { code: "var x = arguments.callee", errors: [{ messageId: "unexpected", data: { prop: "callee" }, type: "MemberExpression" }] }, + { code: "var x = arguments.caller", errors: [{ messageId: "unexpected", data: { prop: "caller" }, type: "MemberExpression" }] } ] }); diff --git a/tests/lib/rules/no-case-declarations.js b/tests/lib/rules/no-case-declarations.js index 8d86f311a759..d72ad515d7e0 100644 --- a/tests/lib/rules/no-case-declarations.js +++ b/tests/lib/rules/no-case-declarations.js @@ -41,42 +41,42 @@ ruleTester.run("no-case-declarations", rule, { { code: "switch (a) { case 1: let x = 1; break; }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unexpected lexical declaration in case block." }] + errors: [{ messageId: "unexpected" }] }, { code: "switch (a) { default: let x = 2; break; }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unexpected lexical declaration in case block." }] + errors: [{ messageId: "unexpected" }] }, { code: "switch (a) { case 1: const x = 1; break; }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unexpected lexical declaration in case block." }] + errors: [{ messageId: "unexpected" }] }, { code: "switch (a) { default: const x = 2; break; }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unexpected lexical declaration in case block." }] + errors: [{ messageId: "unexpected" }] }, { code: "switch (a) { case 1: function f() {} break; }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unexpected lexical declaration in case block." }] + errors: [{ messageId: "unexpected" }] }, { code: "switch (a) { default: function f() {} break; }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unexpected lexical declaration in case block." }] + errors: [{ messageId: "unexpected" }] }, { code: "switch (a) { case 1: class C {} break; }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unexpected lexical declaration in case block." }] + errors: [{ messageId: "unexpected" }] }, { code: "switch (a) { default: class C {} break; }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unexpected lexical declaration in case block." }] + errors: [{ messageId: "unexpected" }] } ] }); diff --git a/tests/lib/rules/no-catch-shadow.js b/tests/lib/rules/no-catch-shadow.js index a302ae86b0c8..35b54ca86c31 100644 --- a/tests/lib/rules/no-catch-shadow.js +++ b/tests/lib/rules/no-catch-shadow.js @@ -39,9 +39,9 @@ ruleTester.run("no-catch-shadow", rule, { } ], invalid: [ - { code: "var foo = 1; try { bar(); } catch(foo) { }", errors: [{ message: "Value of 'foo' may be overwritten in IE 8 and earlier.", type: "CatchClause" }] }, - { code: "function foo(){} try { bar(); } catch(foo) { }", errors: [{ message: "Value of 'foo' may be overwritten in IE 8 and earlier.", type: "CatchClause" }] }, - { code: "function foo(){ try { bar(); } catch(foo) { } }", errors: [{ message: "Value of 'foo' may be overwritten in IE 8 and earlier.", type: "CatchClause" }] }, - { code: "var foo = function(){ try { bar(); } catch(foo) { } };", errors: [{ message: "Value of 'foo' may be overwritten in IE 8 and earlier.", type: "CatchClause" }] } + { code: "var foo = 1; try { bar(); } catch(foo) { }", errors: [{ messageId: "mutable", data: { name: "foo" }, type: "CatchClause" }] }, + { code: "function foo(){} try { bar(); } catch(foo) { }", errors: [{ messageId: "mutable", data: { name: "foo" }, type: "CatchClause" }] }, + { code: "function foo(){ try { bar(); } catch(foo) { } }", errors: [{ messageId: "mutable", data: { name: "foo" }, type: "CatchClause" }] }, + { code: "var foo = function(){ try { bar(); } catch(foo) { } };", errors: [{ messageId: "mutable", data: { name: "foo" }, type: "CatchClause" }] } ] }); diff --git a/tests/lib/rules/no-class-assign.js b/tests/lib/rules/no-class-assign.js index 119fd9812efa..3781b1f20d60 100644 --- a/tests/lib/rules/no-class-assign.js +++ b/tests/lib/rules/no-class-assign.js @@ -37,33 +37,33 @@ ruleTester.run("no-class-assign", rule, { invalid: [ { code: "class A { } A = 0;", - errors: [{ message: "'A' is a class.", type: "Identifier" }] + errors: [{ messageId: "class", data: { name: "A" }, type: "Identifier" }] }, { code: "class A { } ({A} = 0);", - errors: [{ message: "'A' is a class.", type: "Identifier" }] + errors: [{ messageId: "class", data: { name: "A" }, type: "Identifier" }] }, { code: "class A { } ({b: A = 0} = {});", - errors: [{ message: "'A' is a class.", type: "Identifier" }] + errors: [{ messageId: "class", data: { name: "A" }, type: "Identifier" }] }, { code: "A = 0; class A { }", - errors: [{ message: "'A' is a class.", type: "Identifier" }] + errors: [{ messageId: "class", data: { name: "A" }, type: "Identifier" }] }, { code: "class A { b() { A = 0; } }", - errors: [{ message: "'A' is a class.", type: "Identifier" }] + errors: [{ messageId: "class", data: { name: "A" }, type: "Identifier" }] }, { code: "let A = class A { b() { A = 0; } }", - errors: [{ message: "'A' is a class.", type: "Identifier" }] + errors: [{ messageId: "class", data: { name: "A" }, type: "Identifier" }] }, { code: "class A { } A = 0; A = 1;", errors: [ - { message: "'A' is a class.", type: "Identifier", line: 1, column: 13 }, - { message: "'A' is a class.", type: "Identifier", line: 1, column: 20 } + { messageId: "class", data: { name: "A" }, type: "Identifier", line: 1, column: 13 }, + { messageId: "class", data: { name: "A" }, type: "Identifier", line: 1, column: 20 } ] } ] diff --git a/tests/lib/rules/no-compare-neg-zero.js b/tests/lib/rules/no-compare-neg-zero.js index d8f4812f35a1..19429026080a 100644 --- a/tests/lib/rules/no-compare-neg-zero.js +++ b/tests/lib/rules/no-compare-neg-zero.js @@ -55,84 +55,96 @@ ruleTester.run("no-compare-neg-zero", rule, { { code: "x === -0", errors: [{ - message: "Do not use the '===' operator to compare against -0.", + messageId: "unexpected", + data: { operator: "===" }, type: "BinaryExpression" }] }, { code: "-0 === x", errors: [{ - message: "Do not use the '===' operator to compare against -0.", + messageId: "unexpected", + data: { operator: "===" }, type: "BinaryExpression" }] }, { code: "x == -0", errors: [{ - message: "Do not use the '==' operator to compare against -0.", + messageId: "unexpected", + data: { operator: "==" }, type: "BinaryExpression" }] }, { code: "-0 == x", errors: [{ - message: "Do not use the '==' operator to compare against -0.", + messageId: "unexpected", + data: { operator: "==" }, type: "BinaryExpression" }] }, { code: "x > -0", errors: [{ - message: "Do not use the '>' operator to compare against -0.", + messageId: "unexpected", + data: { operator: ">" }, type: "BinaryExpression" }] }, { code: "-0 > x", errors: [{ - message: "Do not use the '>' operator to compare against -0.", + messageId: "unexpected", + data: { operator: ">" }, type: "BinaryExpression" }] }, { code: "x >= -0", errors: [{ - message: "Do not use the '>=' operator to compare against -0.", + messageId: "unexpected", + data: { operator: ">=" }, type: "BinaryExpression" }] }, { code: "-0 >= x", errors: [{ - message: "Do not use the '>=' operator to compare against -0.", + messageId: "unexpected", + data: { operator: ">=" }, type: "BinaryExpression" }] }, { code: "x < -0", errors: [{ - message: "Do not use the '<' operator to compare against -0.", + messageId: "unexpected", + data: { operator: "<" }, type: "BinaryExpression" }] }, { code: "-0 < x", errors: [{ - message: "Do not use the '<' operator to compare against -0.", + messageId: "unexpected", + data: { operator: "<" }, type: "BinaryExpression" }] }, { code: "x <= -0", errors: [{ - message: "Do not use the '<=' operator to compare against -0.", + messageId: "unexpected", + data: { operator: "<=" }, type: "BinaryExpression" }] }, { code: "-0 <= x", errors: [{ - message: "Do not use the '<=' operator to compare against -0.", + messageId: "unexpected", + data: { operator: "<=" }, type: "BinaryExpression" }] } diff --git a/tests/lib/rules/no-cond-assign.js b/tests/lib/rules/no-cond-assign.js index 36cd15a1e101..b192635c8872 100644 --- a/tests/lib/rules/no-cond-assign.js +++ b/tests/lib/rules/no-cond-assign.js @@ -11,7 +11,6 @@ const rule = require("../../../lib/rules/no-cond-assign"), RuleTester = require("../../../lib/testers/rule-tester"); -const ERROR_MESSAGE = "Expected a conditional expression and instead saw an assignment."; //------------------------------------------------------------------------------ // Tests @@ -44,22 +43,22 @@ ruleTester.run("no-cond-assign", rule, { { code: "x = 0;", options: ["always"] } ], invalid: [ - { code: "var x; if (x = 0) { var b = 1; }", errors: [{ message: ERROR_MESSAGE, type: "IfStatement", line: 1, column: 12 }] }, - { code: "var x; while (x = 0) { var b = 1; }", errors: [{ message: ERROR_MESSAGE, type: "WhileStatement" }] }, - { code: "var x = 0, y; do { y = x; } while (x = x + 1);", errors: [{ message: ERROR_MESSAGE, type: "DoWhileStatement" }] }, - { code: "var x; for(; x+=1 ;){};", errors: [{ message: ERROR_MESSAGE, type: "ForStatement" }] }, - { code: "var x; if ((x) = (0));", errors: [{ message: ERROR_MESSAGE, type: "IfStatement" }] }, - { code: "if (someNode || (someNode = parentNode)) { }", options: ["always"], errors: [{ message: "Unexpected assignment within an 'if' statement.", type: "IfStatement" }] }, - { code: "while (someNode || (someNode = parentNode)) { }", options: ["always"], errors: [{ message: "Unexpected assignment within a 'while' statement.", type: "WhileStatement" }] }, - { code: "do { } while (someNode || (someNode = parentNode));", options: ["always"], errors: [{ message: "Unexpected assignment within a 'do...while' statement.", type: "DoWhileStatement" }] }, - { code: "for (; (typeof l === 'undefined' ? (l = 0) : l); i++) { }", options: ["always"], errors: [{ message: "Unexpected assignment within a 'for' statement.", type: "ForStatement" }] }, - { code: "if (x = 0) { }", options: ["always"], errors: [{ message: "Unexpected assignment within an 'if' statement.", type: "IfStatement" }] }, - { code: "while (x = 0) { }", options: ["always"], errors: [{ message: "Unexpected assignment within a 'while' statement.", type: "WhileStatement" }] }, - { code: "do { } while (x = x + 1);", options: ["always"], errors: [{ message: "Unexpected assignment within a 'do...while' statement.", type: "DoWhileStatement" }] }, - { code: "for(; x = y; ) { }", options: ["always"], errors: [{ message: "Unexpected assignment within a 'for' statement.", type: "ForStatement" }] }, - { code: "if ((x = 0)) { }", options: ["always"], errors: [{ message: "Unexpected assignment within an 'if' statement.", type: "IfStatement" }] }, - { code: "while ((x = 0)) { }", options: ["always"], errors: [{ message: "Unexpected assignment within a 'while' statement.", type: "WhileStatement" }] }, - { code: "do { } while ((x = x + 1));", options: ["always"], errors: [{ message: "Unexpected assignment within a 'do...while' statement.", type: "DoWhileStatement" }] }, - { code: "for(; (x = y); ) { }", options: ["always"], errors: [{ message: "Unexpected assignment within a 'for' statement.", type: "ForStatement" }] } + { code: "var x; if (x = 0) { var b = 1; }", errors: [{ messageId: "missing", type: "IfStatement", line: 1, column: 12 }] }, + { code: "var x; while (x = 0) { var b = 1; }", errors: [{ messageId: "missing", type: "WhileStatement" }] }, + { code: "var x = 0, y; do { y = x; } while (x = x + 1);", errors: [{ messageId: "missing", type: "DoWhileStatement" }] }, + { code: "var x; for(; x+=1 ;){};", errors: [{ messageId: "missing", type: "ForStatement" }] }, + { code: "var x; if ((x) = (0));", errors: [{ messageId: "missing", type: "IfStatement" }] }, + { code: "if (someNode || (someNode = parentNode)) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "an 'if' statement" }, type: "IfStatement" }] }, + { code: "while (someNode || (someNode = parentNode)) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'while' statement" }, type: "WhileStatement" }] }, + { code: "do { } while (someNode || (someNode = parentNode));", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'do...while' statement" }, type: "DoWhileStatement" }] }, + { code: "for (; (typeof l === 'undefined' ? (l = 0) : l); i++) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'for' statement" }, type: "ForStatement" }] }, + { code: "if (x = 0) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "an 'if' statement" }, type: "IfStatement" }] }, + { code: "while (x = 0) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'while' statement" }, type: "WhileStatement" }] }, + { code: "do { } while (x = x + 1);", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'do...while' statement" }, type: "DoWhileStatement" }] }, + { code: "for(; x = y; ) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'for' statement" }, type: "ForStatement" }] }, + { code: "if ((x = 0)) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "an 'if' statement" }, type: "IfStatement" }] }, + { code: "while ((x = 0)) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'while' statement" }, type: "WhileStatement" }] }, + { code: "do { } while ((x = x + 1));", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'do...while' statement" }, type: "DoWhileStatement" }] }, + { code: "for(; (x = y); ) { }", options: ["always"], errors: [{ messageId: "unexpected", data: { type: "a 'for' statement" }, type: "ForStatement" }] } ] }); diff --git a/tests/lib/rules/no-confusing-arrow.js b/tests/lib/rules/no-confusing-arrow.js index e79461beee06..7df2538a2d08 100644 --- a/tests/lib/rules/no-confusing-arrow.js +++ b/tests/lib/rules/no-confusing-arrow.js @@ -29,40 +29,40 @@ ruleTester.run("no-confusing-arrow", rule, { { code: "a => 1 ? 2 : 3", output: null, - errors: [{ message: "Arrow function used ambiguously with a conditional expression." }] + errors: [{ messageId: "confusing" }] }, { code: "var x = a => 1 ? 2 : 3", output: null, - errors: [{ message: "Arrow function used ambiguously with a conditional expression." }] + errors: [{ messageId: "confusing" }] }, { code: "var x = (a) => 1 ? 2 : 3", output: null, - errors: [{ message: "Arrow function used ambiguously with a conditional expression." }] + errors: [{ messageId: "confusing" }] }, { code: "var x = a => (1 ? 2 : 3)", output: null, - errors: [{ message: "Arrow function used ambiguously with a conditional expression." }] + errors: [{ messageId: "confusing" }] }, { code: "a => 1 ? 2 : 3", output: "a => (1 ? 2 : 3)", options: [{ allowParens: true }], - errors: [{ message: "Arrow function used ambiguously with a conditional expression." }] + errors: [{ messageId: "confusing" }] }, { code: "var x = a => 1 ? 2 : 3", output: "var x = a => (1 ? 2 : 3)", options: [{ allowParens: true }], - errors: [{ message: "Arrow function used ambiguously with a conditional expression." }] + errors: [{ messageId: "confusing" }] }, { code: "var x = (a) => 1 ? 2 : 3", output: "var x = (a) => (1 ? 2 : 3)", options: [{ allowParens: true }], - errors: [{ message: "Arrow function used ambiguously with a conditional expression." }] + errors: [{ messageId: "confusing" }] } ] }); diff --git a/tests/lib/rules/no-console.js b/tests/lib/rules/no-console.js index ceb04ac2d9a8..76a39227e5cd 100644 --- a/tests/lib/rules/no-console.js +++ b/tests/lib/rules/no-console.js @@ -40,24 +40,24 @@ ruleTester.run("no-console", rule, { invalid: [ // no options - { code: "console.log(foo)", errors: [{ message: "Unexpected console statement.", type: "MemberExpression" }] }, - { code: "console.error(foo)", errors: [{ message: "Unexpected console statement.", type: "MemberExpression" }] }, - { code: "console.info(foo)", errors: [{ message: "Unexpected console statement.", type: "MemberExpression" }] }, - { code: "console.warn(foo)", errors: [{ message: "Unexpected console statement.", type: "MemberExpression" }] }, + { code: "console.log(foo)", errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, + { code: "console.error(foo)", errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, + { code: "console.info(foo)", errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, + { code: "console.warn(foo)", errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, // one option - { code: "console.log(foo)", options: [{ allow: ["error"] }], errors: [{ message: "Unexpected console statement.", type: "MemberExpression" }] }, - { code: "console.error(foo)", options: [{ allow: ["warn"] }], errors: [{ message: "Unexpected console statement.", type: "MemberExpression" }] }, - { code: "console.info(foo)", options: [{ allow: ["log"] }], errors: [{ message: "Unexpected console statement.", type: "MemberExpression" }] }, - { code: "console.warn(foo)", options: [{ allow: ["error"] }], errors: [{ message: "Unexpected console statement.", type: "MemberExpression" }] }, + { code: "console.log(foo)", options: [{ allow: ["error"] }], errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, + { code: "console.error(foo)", options: [{ allow: ["warn"] }], errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, + { code: "console.info(foo)", options: [{ allow: ["log"] }], errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, + { code: "console.warn(foo)", options: [{ allow: ["error"] }], errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, // multiple options - { code: "console.log(foo)", options: [{ allow: ["warn", "info"] }], errors: [{ message: "Unexpected console statement.", type: "MemberExpression" }] }, - { code: "console.error(foo)", options: [{ allow: ["warn", "info", "log"] }], errors: [{ message: "Unexpected console statement.", type: "MemberExpression" }] }, - { code: "console.info(foo)", options: [{ allow: ["warn", "error", "log"] }], errors: [{ message: "Unexpected console statement.", type: "MemberExpression" }] }, - { code: "console.warn(foo)", options: [{ allow: ["info", "log"] }], errors: [{ message: "Unexpected console statement.", type: "MemberExpression" }] }, + { code: "console.log(foo)", options: [{ allow: ["warn", "info"] }], errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, + { code: "console.error(foo)", options: [{ allow: ["warn", "info", "log"] }], errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, + { code: "console.info(foo)", options: [{ allow: ["warn", "error", "log"] }], errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, + { code: "console.warn(foo)", options: [{ allow: ["info", "log"] }], errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, // In case that implicit global variable of 'console' exists - { code: "console.log(foo)", errors: [{ message: "Unexpected console statement.", type: "MemberExpression" }], env: { node: true } } + { code: "console.log(foo)", errors: [{ messageId: "unexpected", type: "MemberExpression" }], env: { node: true } } ] }); diff --git a/tests/lib/rules/no-const-assign.js b/tests/lib/rules/no-const-assign.js index 761ea73cc783..c6b03da9e1c4 100644 --- a/tests/lib/rules/no-const-assign.js +++ b/tests/lib/rules/no-const-assign.js @@ -38,50 +38,50 @@ ruleTester.run("no-const-assign", rule, { invalid: [ { code: "const x = 0; x = 1;", - errors: [{ message: "'x' is constant.", type: "Identifier" }] + errors: [{ messageId: "const", data: { name: "x" }, type: "Identifier" }] }, { code: "const {a: x} = {a: 0}; x = 1;", - errors: [{ message: "'x' is constant.", type: "Identifier" }] + errors: [{ messageId: "const", data: { name: "x" }, type: "Identifier" }] }, { code: "const x = 0; ({x} = {x: 1});", - errors: [{ message: "'x' is constant.", type: "Identifier" }] + errors: [{ messageId: "const", data: { name: "x" }, type: "Identifier" }] }, { code: "const x = 0; ({a: x = 1} = {});", - errors: [{ message: "'x' is constant.", type: "Identifier" }] + errors: [{ messageId: "const", data: { name: "x" }, type: "Identifier" }] }, { code: "const x = 0; x += 1;", - errors: [{ message: "'x' is constant.", type: "Identifier" }] + errors: [{ messageId: "const", data: { name: "x" }, type: "Identifier" }] }, { code: "const x = 0; ++x;", - errors: [{ message: "'x' is constant.", type: "Identifier" }] + errors: [{ messageId: "const", data: { name: "x" }, type: "Identifier" }] }, { code: "for (const i = 0; i < 10; ++i) { foo(i); }", - errors: [{ message: "'i' is constant.", type: "Identifier" }] + errors: [{ messageId: "const", data: { name: "i" }, type: "Identifier" }] }, { code: "const x = 0; x = 1; x = 2;", errors: [ - { message: "'x' is constant.", type: "Identifier", line: 1, column: 14 }, - { message: "'x' is constant.", type: "Identifier", line: 1, column: 21 } + { messageId: "const", data: { name: "x" }, type: "Identifier", line: 1, column: 14 }, + { messageId: "const", data: { name: "x" }, type: "Identifier", line: 1, column: 21 } ] }, { code: "const x = 0; function foo() { x = x + 1; }", - errors: [{ message: "'x' is constant.", type: "Identifier" }] + errors: [{ messageId: "const", data: { name: "x" }, type: "Identifier" }] }, { code: "const x = 0; function foo(a) { x = a; }", - errors: [{ message: "'x' is constant.", type: "Identifier" }] + errors: [{ messageId: "const", data: { name: "x" }, type: "Identifier" }] }, { code: "const x = 0; while (true) { x = x + 1; }", - errors: [{ message: "'x' is constant.", type: "Identifier" }] + errors: [{ messageId: "const", data: { name: "x" }, type: "Identifier" }] } ] }); diff --git a/tests/lib/rules/no-constant-condition.js b/tests/lib/rules/no-constant-condition.js index b113ebb09de5..d8b5a35084a6 100644 --- a/tests/lib/rules/no-constant-condition.js +++ b/tests/lib/rules/no-constant-condition.js @@ -71,90 +71,90 @@ ruleTester.run("no-constant-condition", rule, { "function* foo() { for (let x = yield; ; x++) { yield; }}" ], invalid: [ - { code: "for(;true;);", errors: [{ message: "Unexpected constant condition.", type: "ForStatement" }] }, - { code: "do{}while(true)", errors: [{ message: "Unexpected constant condition.", type: "DoWhileStatement" }] }, - { code: "do{}while(t = -2)", errors: [{ message: "Unexpected constant condition.", type: "DoWhileStatement" }] }, - { code: "true ? 1 : 2;", errors: [{ message: "Unexpected constant condition.", type: "ConditionalExpression" }] }, - { code: "q = 0 ? 1 : 2;", errors: [{ message: "Unexpected constant condition.", type: "ConditionalExpression" }] }, - { code: "(q = 0) ? 1 : 2;", errors: [{ message: "Unexpected constant condition.", type: "ConditionalExpression" }] }, - { code: "if(-2);", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(true);", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if({});", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(0 < 1);", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(0 || 1);", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(a, 1);", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - - { code: "while([]);", errors: [{ message: "Unexpected constant condition.", type: "WhileStatement" }] }, - { code: "while(~!0);", errors: [{ message: "Unexpected constant condition.", type: "WhileStatement" }] }, - { code: "while(x = 1);", errors: [{ message: "Unexpected constant condition.", type: "WhileStatement" }] }, - { code: "while(function(){});", errors: [{ message: "Unexpected constant condition.", type: "WhileStatement" }] }, - { code: "while(true);", errors: [{ message: "Unexpected constant condition.", type: "WhileStatement" }] }, - { code: "while(() => {});", errors: [{ message: "Unexpected constant condition.", type: "WhileStatement" }] }, + { code: "for(;true;);", errors: [{ messageId: "unexpected", type: "ForStatement" }] }, + { code: "do{}while(true)", errors: [{ messageId: "unexpected", type: "DoWhileStatement" }] }, + { code: "do{}while(t = -2)", errors: [{ messageId: "unexpected", type: "DoWhileStatement" }] }, + { code: "true ? 1 : 2;", errors: [{ messageId: "unexpected", type: "ConditionalExpression" }] }, + { code: "q = 0 ? 1 : 2;", errors: [{ messageId: "unexpected", type: "ConditionalExpression" }] }, + { code: "(q = 0) ? 1 : 2;", errors: [{ messageId: "unexpected", type: "ConditionalExpression" }] }, + { code: "if(-2);", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(true);", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if({});", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(0 < 1);", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(0 || 1);", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(a, 1);", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + + { code: "while([]);", errors: [{ messageId: "unexpected", type: "WhileStatement" }] }, + { code: "while(~!0);", errors: [{ messageId: "unexpected", type: "WhileStatement" }] }, + { code: "while(x = 1);", errors: [{ messageId: "unexpected", type: "WhileStatement" }] }, + { code: "while(function(){});", errors: [{ messageId: "unexpected", type: "WhileStatement" }] }, + { code: "while(true);", errors: [{ messageId: "unexpected", type: "WhileStatement" }] }, + { code: "while(() => {});", errors: [{ messageId: "unexpected", type: "WhileStatement" }] }, // #5228 , typeof conditions - { code: "if(typeof x){}", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(typeof 'abc' === 'string'){}", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(a = typeof b){}", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(a, typeof b){}", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(typeof 'a' == 'string' || typeof 'b' == 'string'){}", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "while(typeof x){}", errors: [{ message: "Unexpected constant condition.", type: "WhileStatement" }] }, + { code: "if(typeof x){}", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(typeof 'abc' === 'string'){}", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(a = typeof b){}", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(a, typeof b){}", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(typeof 'a' == 'string' || typeof 'b' == 'string'){}", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "while(typeof x){}", errors: [{ messageId: "unexpected", type: "WhileStatement" }] }, // #5726, void conditions - { code: "if(1 || void x);", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(void x);", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(y = void x);", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(x, void x);", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(void x === void y);", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(void x && a);", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(a && void x);", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, + { code: "if(1 || void x);", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(void x);", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(y = void x);", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(x, void x);", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(void x === void y);", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(void x && a);", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(a && void x);", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, // #5693 - { code: "if(false && abc==='str'){}", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(true || abc==='str'){}", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(abc==='str' || true){}", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(abc==='str' || true || def ==='str'){}", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(false || true){}", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, - { code: "if(typeof abc==='str' || true){}", errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] }, + { code: "if(false && abc==='str'){}", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(true || abc==='str'){}", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(abc==='str' || true){}", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(abc==='str' || true || def ==='str'){}", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(false || true){}", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, + { code: "if(typeof abc==='str' || true){}", errors: [{ messageId: "unexpected", type: "IfStatement" }] }, { code: "function* foo(){while(true){} yield 'foo';}", - errors: [{ message: "Unexpected constant condition.", type: "WhileStatement" }] + errors: [{ messageId: "unexpected", type: "WhileStatement" }] }, { code: "function* foo(){while(true){if (true) {yield 'foo';}}}", - errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpected", type: "IfStatement" }] }, { code: "function* foo(){while(true){yield 'foo';} while(true) {}}", - errors: [{ message: "Unexpected constant condition.", type: "WhileStatement" }] + errors: [{ messageId: "unexpected", type: "WhileStatement" }] }, { code: "var a = function* foo(){while(true){} yield 'foo';}", - errors: [{ message: "Unexpected constant condition.", type: "WhileStatement" }] + errors: [{ messageId: "unexpected", type: "WhileStatement" }] }, { code: "while (true) { function* foo() {yield;}}", - errors: [{ message: "Unexpected constant condition.", type: "WhileStatement" }] + errors: [{ messageId: "unexpected", type: "WhileStatement" }] }, { code: "function* foo(){if (true) {yield 'foo';}}", - errors: [{ message: "Unexpected constant condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpected", type: "IfStatement" }] }, { code: "function* foo() {for (let foo = yield; true;) {}}", - errors: [{ message: "Unexpected constant condition.", type: "ForStatement" }] + errors: [{ messageId: "unexpected", type: "ForStatement" }] }, { code: "function* foo() {for (foo = yield; true;) {}}", - errors: [{ message: "Unexpected constant condition.", type: "ForStatement" }] + errors: [{ messageId: "unexpected", type: "ForStatement" }] }, { code: "function foo() {while (true) {function* bar() {while (true) {yield;}}}}", - errors: [{ message: "Unexpected constant condition.", type: "WhileStatement" }] + errors: [{ messageId: "unexpected", type: "WhileStatement" }] }, { code: "function* foo() { for (let foo = 1 + 2 + 3 + (yield); true; baz) {}}", - errors: [{ message: "Unexpected constant condition.", type: "ForStatement" }] + errors: [{ messageId: "unexpected", type: "ForStatement" }] } ] }); diff --git a/tests/lib/rules/no-continue.js b/tests/lib/rules/no-continue.js index 16ed522829f9..12e5baf69d39 100644 --- a/tests/lib/rules/no-continue.js +++ b/tests/lib/rules/no-continue.js @@ -28,28 +28,28 @@ ruleTester.run("no-continue", rule, { { code: "var sum = 0, i; for(i = 0; i < 10; i++){ if(i <= 5) { continue; } sum += i; }", errors: [{ - message: "Unexpected use of continue statement.", + messageId: "unexpected", 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.", + messageId: "unexpected", 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.", + messageId: "unexpected", 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.", + messageId: "unexpected", type: "ContinueStatement" }] } diff --git a/tests/lib/rules/no-control-regex.js b/tests/lib/rules/no-control-regex.js index caa052335db7..ebadafc30016 100644 --- a/tests/lib/rules/no-control-regex.js +++ b/tests/lib/rules/no-control-regex.js @@ -29,13 +29,13 @@ ruleTester.run("no-control-regex", rule, { "new (function foo(){})('\\x1f')" ], invalid: [ - { code: `var regex = ${/\x1f/}`, errors: [{ message: "Unexpected control character(s) in regular expression: \\x1f.", type: "Literal" }] }, // eslint-disable-line no-control-regex - { code: `var regex = ${/\\\x1f\\x1e/}`, errors: [{ message: "Unexpected control character(s) in regular expression: \\x1f, \\x1e.", type: "Literal" }] }, // eslint-disable-line no-control-regex - { code: `var regex = ${/\\\x1fFOO\\x00/}`, errors: [{ message: "Unexpected control character(s) in regular expression: \\x1f, \\x00.", type: "Literal" }] }, // eslint-disable-line no-control-regex - { code: `var regex = ${/FOO\\\x1fFOO\\x1f/}`, errors: [{ message: "Unexpected control character(s) in regular expression: \\x1f, \\x1f.", type: "Literal" }] }, // eslint-disable-line no-control-regex - { code: "var regex = new RegExp('\\x1f\\x1e')", errors: [{ message: "Unexpected control character(s) in regular expression: \\x1f, \\x1e.", type: "Literal" }] }, - { code: "var regex = new RegExp('\\x1fFOO\\x00')", errors: [{ message: "Unexpected control character(s) in regular expression: \\x1f, \\x00.", type: "Literal" }] }, - { code: "var regex = new RegExp('FOO\\x1fFOO\\x1f')", errors: [{ message: "Unexpected control character(s) in regular expression: \\x1f, \\x1f.", type: "Literal" }] }, - { code: "var regex = RegExp('\\x1f')", errors: [{ message: "Unexpected control character(s) in regular expression: \\x1f.", type: "Literal" }] } + { code: `var regex = ${/\x1f/}`, errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] }, // eslint-disable-line no-control-regex + { code: `var regex = ${/\\\x1f\\x1e/}`, errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f, \\x1e" }, type: "Literal" }] }, // eslint-disable-line no-control-regex + { code: `var regex = ${/\\\x1fFOO\\x00/}`, errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f, \\x00" }, type: "Literal" }] }, // eslint-disable-line no-control-regex + { code: `var regex = ${/FOO\\\x1fFOO\\x1f/}`, errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f, \\x1f" }, type: "Literal" }] }, // eslint-disable-line no-control-regex + { code: "var regex = new RegExp('\\x1f\\x1e')", errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f, \\x1e" }, type: "Literal" }] }, + { code: "var regex = new RegExp('\\x1fFOO\\x00')", errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f, \\x00" }, type: "Literal" }] }, + { code: "var regex = new RegExp('FOO\\x1fFOO\\x1f')", errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f, \\x1f" }, type: "Literal" }] }, + { code: "var regex = RegExp('\\x1f')", errors: [{ messageId: "unexpected", data: { controlChars: "\\x1f" }, type: "Literal" }] } ] });