diff --git a/lib/rules/accessor-pairs.js b/lib/rules/accessor-pairs.js index b01b29b1763..51ac2c2183a 100644 --- a/lib/rules/accessor-pairs.js +++ b/lib/rules/accessor-pairs.js @@ -89,7 +89,11 @@ module.exports = { } }, additionalProperties: false - }] + }], + messages: { + getter: "Getter is not present.", + setter: "Setter is not present." + } }, create(context) { const config = context.options[0] || {}; @@ -140,9 +144,9 @@ module.exports = { } if (checkSetWithoutGet && isSetPresent && !isGetPresent) { - context.report({ node, message: "Getter is not present." }); + context.report({ node, messageId: "getter" }); } else if (checkGetWithoutSet && isGetPresent && !isSetPresent) { - context.report({ node, message: "Setter is not present." }); + context.report({ node, messageId: "setter" }); } } diff --git a/lib/rules/array-bracket-newline.js b/lib/rules/array-bracket-newline.js index b939d65b3f1..e1904057265 100644 --- a/lib/rules/array-bracket-newline.js +++ b/lib/rules/array-bracket-newline.js @@ -41,7 +41,13 @@ module.exports = { } ] } - ] + ], + messages: { + unexpectedOpeningLinebreak: "There should be no linebreak after '['.", + unexpectedClosingLinebreak: "There should be no linebreak before ']'.", + missingOpeningLinebreak: "A linebreak is required after '['.", + missingClosingLinebreak: "A linebreak is required before ']'." + } }, create(context) { @@ -106,7 +112,7 @@ module.exports = { context.report({ node, loc: token.loc, - message: "There should be no linebreak after '['.", + messageId: "unexpectedOpeningLinebreak", fix(fixer) { const nextToken = sourceCode.getTokenAfter(token, { includeComments: true }); @@ -129,7 +135,7 @@ module.exports = { context.report({ node, loc: token.loc, - message: "There should be no linebreak before ']'.", + messageId: "unexpectedClosingLinebreak", fix(fixer) { const previousToken = sourceCode.getTokenBefore(token, { includeComments: true }); @@ -152,7 +158,7 @@ module.exports = { context.report({ node, loc: token.loc, - message: "A linebreak is required after '['.", + messageId: "missingOpeningLinebreak", fix(fixer) { return fixer.insertTextAfter(token, "\n"); } @@ -169,7 +175,7 @@ module.exports = { context.report({ node, loc: token.loc, - message: "A linebreak is required before ']'.", + messageId: "missingClosingLinebreak", fix(fixer) { return fixer.insertTextBefore(token, "\n"); } diff --git a/lib/rules/array-bracket-spacing.js b/lib/rules/array-bracket-spacing.js index 933458a42a1..c64ff3dc27e 100644 --- a/lib/rules/array-bracket-spacing.js +++ b/lib/rules/array-bracket-spacing.js @@ -38,7 +38,13 @@ module.exports = { }, additionalProperties: false } - ] + ], + messages: { + unexpectedSpaceAfter: "There should be no space after '{{tokenValue}}'.", + unexpectedSpaceBefore: "There should be no space before '{{tokenValue}}'.", + missingSpaceAfter: "A space is required after '{{tokenValue}}'.", + missingSpaceBefore: "A space is required before '{{tokenValue}}'." + } }, create(context) { const spaced = context.options[0] === "always", @@ -76,7 +82,7 @@ module.exports = { context.report({ node, loc: token.loc.start, - message: "There should be no space after '{{tokenValue}}'.", + messageId: "unexpectedSpaceAfter", data: { tokenValue: token.value }, @@ -98,7 +104,7 @@ module.exports = { context.report({ node, loc: token.loc.start, - message: "There should be no space before '{{tokenValue}}'.", + messageId: "unexpectedSpaceBefore", data: { tokenValue: token.value }, @@ -120,7 +126,7 @@ module.exports = { context.report({ node, loc: token.loc.start, - message: "A space is required after '{{tokenValue}}'.", + messageId: "missingSpaceAfter", data: { tokenValue: token.value }, @@ -140,7 +146,7 @@ module.exports = { context.report({ node, loc: token.loc.start, - message: "A space is required before '{{tokenValue}}'.", + messageId: "missingSpaceBefore", data: { tokenValue: token.value }, diff --git a/lib/rules/array-callback-return.js b/lib/rules/array-callback-return.js index 69655481d80..ad0d02697f1 100644 --- a/lib/rules/array-callback-return.js +++ b/lib/rules/array-callback-return.js @@ -156,7 +156,13 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + expectedAtEnd: "Expected to return a value at the end of {{name}}.", + expectedInside: "Expected to return a value in {{name}}.", + expectedReturnValue: "{{name}} expected a return value." + } }, create(context) { @@ -188,9 +194,9 @@ module.exports = { context.report({ node, loc: getLocation(node, context.getSourceCode()).loc.start, - message: funcInfo.hasReturn - ? "Expected to return a value at the end of {{name}}." - : "Expected to return a value in {{name}}.", + messageId: funcInfo.hasReturn + ? "expectedAtEnd" + : "expectedInside", data: { name: astUtils.getFunctionNameWithKind(funcInfo.node) } @@ -230,7 +236,7 @@ module.exports = { if (!options.allowImplicit && !node.argument) { context.report({ node, - message: "{{name}} expected a return value.", + messageId: "expectedReturnValue", data: { name: lodash.upperFirst(astUtils.getFunctionNameWithKind(funcInfo.node)) } diff --git a/lib/rules/array-element-newline.js b/lib/rules/array-element-newline.js index 22352c7e33d..d8a8652dbe0 100644 --- a/lib/rules/array-element-newline.js +++ b/lib/rules/array-element-newline.js @@ -41,7 +41,12 @@ module.exports = { } ] } - ] + ], + + messages: { + unexpectedLineBreak: "There should be no linebreak here.", + missingLineBreak: "There should be a linebreak after this element." + } }, create(context) { @@ -100,7 +105,7 @@ module.exports = { start: tokenBefore.loc.end, end: token.loc.start }, - message: "There should be no linebreak here.", + messageId: "unexpectedLineBreak", fix(fixer) { if (astUtils.isCommentToken(tokenBefore)) { return null; @@ -149,7 +154,7 @@ module.exports = { start: tokenBefore.loc.end, end: token.loc.start }, - message: "There should be a linebreak after this element.", + messageId: "missingLineBreak", fix(fixer) { return fixer.replaceTextRange([tokenBefore.range[1], token.range[0]], "\n"); } diff --git a/lib/rules/arrow-body-style.js b/lib/rules/arrow-body-style.js index afbf46fd545..1f0d1377b5e 100644 --- a/lib/rules/arrow-body-style.js +++ b/lib/rules/arrow-body-style.js @@ -55,7 +55,15 @@ module.exports = { ] }, - fixable: "code" + fixable: "code", + + messages: { + unexpectedOtherBlock: "Unexpected block statement surrounding arrow body.", + unexpectedEmptyBlock: "Unexpected block statement surrounding arrow body; put a value of `undefined` immediately after the `=>`.", + unexpectedObjectBlock: "Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`.", + unexpectedSingleBlock: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`.", + expectedBlock: "Expected block statement surrounding arrow body." + } }, create(context) { @@ -110,22 +118,22 @@ module.exports = { } if (never || asNeeded && blockBody[0].type === "ReturnStatement") { - let message; + let messageId; if (blockBody.length === 0) { - message = "Unexpected block statement surrounding arrow body; put a value of `undefined` immediately after the `=>`."; + messageId = "unexpectedEmptyBlock"; } else if (blockBody.length > 1) { - message = "Unexpected block statement surrounding arrow body."; + messageId = "unexpectedOtherBlock"; } else if (astUtils.isOpeningBraceToken(sourceCode.getFirstToken(blockBody[0], { skip: 1 }))) { - message = "Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`."; + messageId = "unexpectedObjectBlock"; } else { - message = "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`."; + messageId = "unexpectedSingleBlock"; } context.report({ node, loc: arrowBody.loc.start, - message, + messageId, fix(fixer) { const fixes = []; @@ -190,7 +198,7 @@ module.exports = { context.report({ node, loc: arrowBody.loc.start, - message: "Expected block statement surrounding arrow body.", + messageId: "expectedBlock", fix(fixer) { const fixes = []; const arrowToken = sourceCode.getTokenBefore(arrowBody, astUtils.isArrowToken); diff --git a/lib/rules/arrow-parens.js b/lib/rules/arrow-parens.js index 5a0fd61b348..8cabb7f90f2 100644 --- a/lib/rules/arrow-parens.js +++ b/lib/rules/arrow-parens.js @@ -38,15 +38,19 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unexpectedParens: "Unexpected parentheses around single function argument.", + expectedParens: "Expected parentheses around arrow function argument.", + + unexpectedParensInline: "Unexpected parentheses around single function argument having a body with no curly braces.", + expectedParensBlock: "Expected parentheses around arrow function argument having a body with curly braces." + } }, create(context) { - const message = "Expected parentheses around arrow function argument."; - const asNeededMessage = "Unexpected parentheses around single function argument."; const asNeeded = context.options[0] === "as-needed"; - const requireForBlockBodyMessage = "Unexpected parentheses around single function argument having a body with no curly braces"; - const requireForBlockBodyNoParensMessage = "Expected parentheses around arrow function argument having a body with curly braces."; const requireForBlockBody = asNeeded && context.options[1] && context.options[1].requireForBlockBody === true; const sourceCode = context.getSourceCode(); @@ -94,7 +98,7 @@ module.exports = { if (astUtils.isOpeningParenToken(firstTokenOfParam)) { context.report({ node, - message: requireForBlockBodyMessage, + messageId: "unexpectedParensInline", fix: fixParamsWithParenthesis }); } @@ -108,7 +112,7 @@ module.exports = { if (!astUtils.isOpeningParenToken(firstTokenOfParam)) { context.report({ node, - message: requireForBlockBodyNoParensMessage, + messageId: "expectedParensBlock", fix(fixer) { return fixer.replaceText(firstTokenOfParam, `(${firstTokenOfParam.value})`); } @@ -127,7 +131,7 @@ module.exports = { if (astUtils.isOpeningParenToken(firstTokenOfParam)) { context.report({ node, - message: asNeededMessage, + messageId: "unexpectedParens", fix: fixParamsWithParenthesis }); } @@ -141,7 +145,7 @@ module.exports = { if (after.value !== ")") { context.report({ node, - message, + messageId: "expectedParens", fix(fixer) { return fixer.replaceText(firstTokenOfParam, `(${firstTokenOfParam.value})`); } diff --git a/lib/rules/arrow-spacing.js b/lib/rules/arrow-spacing.js index d2c5b9b77bf..52f8fcab97a 100644 --- a/lib/rules/arrow-spacing.js +++ b/lib/rules/arrow-spacing.js @@ -38,7 +38,15 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + expectedBefore: "Missing space before =>.", + unexpectedBefore: "Unexpected space before =>.", + + expectedAfter: "Missing space after =>.", + unexpectedAfter: "Unexpected space after =>." + } }, create(context) { @@ -96,7 +104,7 @@ module.exports = { if (countSpace.before === 0) { context.report({ node: tokens.before, - message: "Missing space before =>.", + messageId: "expectedBefore", fix(fixer) { return fixer.insertTextBefore(tokens.arrow, " "); } @@ -108,7 +116,7 @@ module.exports = { if (countSpace.before > 0) { context.report({ node: tokens.before, - message: "Unexpected space before =>.", + messageId: "unexpectedBefore", fix(fixer) { return fixer.removeRange([tokens.before.range[1], tokens.arrow.range[0]]); } @@ -122,7 +130,7 @@ module.exports = { if (countSpace.after === 0) { context.report({ node: tokens.after, - message: "Missing space after =>.", + messageId: "expectedAfter", fix(fixer) { return fixer.insertTextAfter(tokens.arrow, " "); } @@ -134,7 +142,7 @@ module.exports = { if (countSpace.after > 0) { context.report({ node: tokens.after, - message: "Unexpected space after =>.", + messageId: "unexpectedAfter", fix(fixer) { return fixer.removeRange([tokens.arrow.range[1], tokens.after.range[0]]); } diff --git a/lib/rules/block-scoped-var.js b/lib/rules/block-scoped-var.js index 58cef1741a8..1000fbc83c6 100644 --- a/lib/rules/block-scoped-var.js +++ b/lib/rules/block-scoped-var.js @@ -17,7 +17,11 @@ module.exports = { url: "https://eslint.org/docs/rules/block-scoped-var" }, - schema: [] + schema: [], + + messages: { + outOfScope: "'{{name}}' used outside of binding context." + } }, create(context) { @@ -48,7 +52,7 @@ module.exports = { function report(reference) { const identifier = reference.identifier; - context.report({ node: identifier, message: "'{{name}}' used outside of binding context.", data: { name: identifier.name } }); + context.report({ node: identifier, messageId: "outOfScope", data: { name: identifier.name } }); } /** diff --git a/lib/rules/block-spacing.js b/lib/rules/block-spacing.js index 4fbf6d4c0bf..536381362a0 100644 --- a/lib/rules/block-spacing.js +++ b/lib/rules/block-spacing.js @@ -24,12 +24,17 @@ module.exports = { schema: [ { enum: ["always", "never"] } - ] + ], + + messages: { + missing: "Requires a space {{location}} '{{token}}'", + extra: "Unexpected space(s) {{location}} '{{token}}'" + } }, create(context) { const always = (context.options[0] !== "never"), - message = always ? "Requires a space" : "Unexpected space(s)", + messageId = always ? "missing" : "extra", sourceCode = context.getSourceCode(); /** @@ -98,9 +103,10 @@ module.exports = { context.report({ node, loc: openBrace.loc.start, - message: "{{message}} after '{'.", + messageId, data: { - message + location: "after", + token: openBrace.value }, fix(fixer) { if (always) { @@ -115,9 +121,10 @@ module.exports = { context.report({ node, loc: closeBrace.loc.start, - message: "{{message}} before '}'.", + messageId, data: { - message + location: "before", + token: closeBrace.value }, fix(fixer) { if (always) { diff --git a/lib/rules/brace-style.js b/lib/rules/brace-style.js index bc0ddbd78f2..e2cbafe2192 100644 --- a/lib/rules/brace-style.js +++ b/lib/rules/brace-style.js @@ -35,7 +35,16 @@ module.exports = { } ], - fixable: "whitespace" + fixable: "whitespace", + + messages: { + nextLineOpen: "Opening curly brace does not appear on the same line as controlling statement.", + sameLineOpen: "Opening curly brace appears on the same line as controlling statement.", + blockSameLine: "Statement inside of curly braces should be on next line.", + nextLineClose: "Closing curly brace does not appear on the same line as the subsequent block.", + singleLineClose: "Closing curly brace should be on the same line as opening curly brace or on the line after the previous block.", + sameLineClose: "Closing curly brace appears on the same line as the subsequent block." + } }, create(context) { @@ -43,13 +52,6 @@ module.exports = { params = context.options[1] || {}, sourceCode = context.getSourceCode(); - const OPEN_MESSAGE = "Opening curly brace does not appear on the same line as controlling statement.", - OPEN_MESSAGE_ALLMAN = "Opening curly brace appears on the same line as controlling statement.", - BODY_MESSAGE = "Statement inside of curly braces should be on next line.", - CLOSE_MESSAGE = "Closing curly brace does not appear on the same line as the subsequent block.", - CLOSE_MESSAGE_SINGLE = "Closing curly brace should be on the same line as opening curly brace or on the line after the previous block.", - CLOSE_MESSAGE_STROUSTRUP_ALLMAN = "Closing curly brace appears on the same line as the subsequent block."; - //-------------------------------------------------------------------------- // Helpers //-------------------------------------------------------------------------- @@ -86,7 +88,7 @@ module.exports = { if (style !== "allman" && !astUtils.isTokenOnSameLine(tokenBeforeOpeningCurly, openingCurly)) { context.report({ node: openingCurly, - message: OPEN_MESSAGE, + messageId: "nextLineOpen", fix: removeNewlineBetween(tokenBeforeOpeningCurly, openingCurly) }); } @@ -94,7 +96,7 @@ module.exports = { if (style === "allman" && astUtils.isTokenOnSameLine(tokenBeforeOpeningCurly, openingCurly) && !singleLineException) { context.report({ node: openingCurly, - message: OPEN_MESSAGE_ALLMAN, + messageId: "sameLineOpen", fix: fixer => fixer.insertTextBefore(openingCurly, "\n") }); } @@ -102,7 +104,7 @@ module.exports = { if (astUtils.isTokenOnSameLine(openingCurly, tokenAfterOpeningCurly) && tokenAfterOpeningCurly !== closingCurly && !singleLineException) { context.report({ node: openingCurly, - message: BODY_MESSAGE, + messageId: "blockSameLine", fix: fixer => fixer.insertTextAfter(openingCurly, "\n") }); } @@ -110,7 +112,7 @@ module.exports = { if (tokenBeforeClosingCurly !== openingCurly && !singleLineException && astUtils.isTokenOnSameLine(tokenBeforeClosingCurly, closingCurly)) { context.report({ node: closingCurly, - message: CLOSE_MESSAGE_SINGLE, + messageId: "singleLineClose", fix: fixer => fixer.insertTextBefore(closingCurly, "\n") }); } @@ -127,7 +129,7 @@ module.exports = { if (style === "1tbs" && !astUtils.isTokenOnSameLine(curlyToken, keywordToken)) { context.report({ node: curlyToken, - message: CLOSE_MESSAGE, + messageId: "nextLineClose", fix: removeNewlineBetween(curlyToken, keywordToken) }); } @@ -135,7 +137,7 @@ module.exports = { if (style !== "1tbs" && astUtils.isTokenOnSameLine(curlyToken, keywordToken)) { context.report({ node: curlyToken, - message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, + messageId: "sameLineClose", fix: fixer => fixer.insertTextAfter(curlyToken, "\n") }); } diff --git a/lib/rules/callback-return.js b/lib/rules/callback-return.js index ed85c7181a9..f55fed87db0 100644 --- a/lib/rules/callback-return.js +++ b/lib/rules/callback-return.js @@ -20,7 +20,11 @@ module.exports = { schema: [{ type: "array", items: { type: "string" } - }] + }], + + messages: { + missingReturn: "Expected return with your callback function." + } }, create(context) { @@ -166,7 +170,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 86822f97529..84db54ff289 100644 --- a/lib/rules/camelcase.js +++ b/lib/rules/camelcase.js @@ -28,7 +28,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + notCamelCase: "Identifier '{{name}}' is not in camel case." + } }, create(context) { @@ -62,7 +66,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 19b5f6a7175..c98a4464acb 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 = { @@ -132,7 +130,12 @@ module.exports = { } ] } - ] + ], + + messages: { + unexpectedLowercaseComment: "Comments should not begin with a lowercase character", + unexpectedUppercaseComment: "Comments should not begin with an uppercase character" + } }, create(context) { @@ -267,14 +270,14 @@ module.exports = { commentValid = isCommentValid(comment, options); if (!commentValid) { - const message = capitalize === "always" - ? ALWAYS_MESSAGE - : NEVER_MESSAGE; + const messageId = capitalize === "always" + ? "unexpectedLowercaseComment" + : "unexpectedUppercaseComment"; 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 774086780ae..b7d94135bb7 100644 --- a/lib/rules/class-methods-use-this.js +++ b/lib/rules/class-methods-use-this.js @@ -28,7 +28,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]) : {}; @@ -80,9 +84,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 180979d4032..50de7b59b22 100644 --- a/lib/rules/comma-dangle.js +++ b/lib/rules/comma-dangle.js @@ -124,14 +124,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. @@ -230,7 +233,7 @@ module.exports = { context.report({ node: lastItem, loc: trailingToken.loc.start, - message: UNEXPECTED_MESSAGE, + messageId: "unexpected", fix(fixer) { return fixer.remove(trailingToken); } @@ -267,7 +270,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 dd3de7f3543..2a48e54d51c 100644 --- a/lib/rules/comma-spacing.js +++ b/lib/rules/comma-spacing.js @@ -34,7 +34,12 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + missing: "A space is required {{loc}} ','.", + unexpected: "There should be no space {{loc}} ','." + } }, create(context) { @@ -57,17 +62,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, " "); @@ -76,7 +81,7 @@ module.exports = { let start, end; const newText = ""; - if (dir === "before") { + if (loc === "before") { start = otherNode.range[1]; end = node.range[0]; } else { @@ -87,11 +92,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 1d7eef231b5..5ba2dbb28b2 100644 --- a/lib/rules/comma-style.js +++ b/lib/rules/comma-style.js @@ -36,7 +36,12 @@ module.exports = { }, additionalProperties: false } - ] + ], + messages: { + unexpectedLineBeforeAndAfterComma: "Bad line breaking before and after ','.", + expectedCommaFirst: "',' should be placed first.", + expectedCommaLast: "',' should be placed last." + } }, create(context) { @@ -135,7 +140,7 @@ module.exports = { line: commaToken.loc.end.line, column: commaToken.loc.start.column }, - message: "Bad line breaking before and after ','.", + messageId: "unexpectedLineBeforeAndAfterComma", fix: getFixerFunction("between", previousItemToken, commaToken, currentItemToken) }); @@ -143,7 +148,7 @@ module.exports = { context.report({ node: reportItem, - message: "',' should be placed first.", + messageId: "expectedCommaFirst", fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken) }); @@ -155,7 +160,7 @@ module.exports = { line: commaToken.loc.end.line, column: commaToken.loc.end.column }, - message: "',' should be placed last.", + messageId: "expectedCommaLast", fix: getFixerFunction(style, previousItemToken, commaToken, currentItemToken) }); } diff --git a/lib/rules/complexity.js b/lib/rules/complexity.js index 1838d4bf8ed..0b864413659 100644 --- a/lib/rules/complexity.js +++ b/lib/rules/complexity.js @@ -50,7 +50,11 @@ module.exports = { } ] } - ] + ], + + messages: { + complex: "{{name}} has a complexity of {{complexity}}." + } }, create(context) { @@ -96,7 +100,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 57408afb453..51334a2ab4d 100644 --- a/lib/rules/computed-property-spacing.js +++ b/lib/rules/computed-property-spacing.js @@ -25,7 +25,15 @@ module.exports = { { enum: ["always", "never"] } - ] + ], + + messages: { + unexpectedSpaceBefore: "There should be no space before '{{tokenValue}}'.", + unexpectedSpaceAfter: "There should be no space after '{{tokenValue}}'.", + + missingSpaceBefore: "A space is required before '{{tokenValue}}'.", + missingSpaceAfter: "A space is required after '{{tokenValue}}'." + } }, create(context) { @@ -47,7 +55,7 @@ module.exports = { context.report({ node, loc: token.loc.start, - message: "There should be no space after '{{tokenValue}}'.", + messageId: "unexpectedSpaceAfter", data: { tokenValue: token.value }, @@ -68,7 +76,7 @@ module.exports = { context.report({ node, loc: token.loc.start, - message: "There should be no space before '{{tokenValue}}'.", + messageId: "unexpectedSpaceBefore", data: { tokenValue: token.value }, @@ -88,7 +96,7 @@ module.exports = { context.report({ node, loc: token.loc.start, - message: "A space is required after '{{tokenValue}}'.", + messageId: "missingSpaceAfter", data: { tokenValue: token.value }, @@ -108,7 +116,7 @@ module.exports = { context.report({ node, loc: token.loc.start, - message: "A space is required before '{{tokenValue}}'.", + messageId: "missingSpaceBefore", data: { tokenValue: token.value }, diff --git a/lib/rules/consistent-return.js b/lib/rules/consistent-return.js index a436dd1fc0c..c86b1717ef0 100644 --- a/lib/rules/consistent-return.js +++ b/lib/rules/consistent-return.js @@ -68,7 +68,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) { @@ -129,7 +135,7 @@ module.exports = { context.report({ node, loc, - message: "Expected to return a value at the end of {{name}}.", + messageId: "missingReturn", data: { name } }); } @@ -143,7 +149,7 @@ module.exports = { codePath, hasReturn: false, hasReturnValue: false, - message: "", + messageId: "", node }; }, @@ -163,17 +169,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 60690007f2d..5cc3a647dab 100644 --- a/lib/rules/consistent-this.js +++ b/lib/rules/consistent-this.js @@ -24,6 +24,11 @@ module.exports = { minLength: 1 }, uniqueItems: true + }, + + messages: { + aliasNotAssignedToThis: "Designated alias '{{name}}' is not assigned to 'this'.", + unexpectedAlias: "Unexpected alias '{{name}}' for 'this'." } }, @@ -40,11 +45,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: "aliasNotAssignedToThis", data: { name } }); } /** @@ -63,7 +68,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 30637472f19..3cbc2f59f89 100644 --- a/lib/rules/constructor-super.js +++ b/lib/rules/constructor-super.js @@ -99,7 +99,16 @@ module.exports = { url: "https://eslint.org/docs/rules/constructor-super" }, - 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) { @@ -210,9 +219,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 }); } @@ -281,7 +290,7 @@ module.exports = { const node = nodes[i]; context.report({ - message: "Unexpected duplicate 'super()'.", + messageId: "duplicate", node }); } @@ -325,12 +334,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 { @@ -339,7 +348,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 7fdf57eda17..f1e4f49c63a 100644 --- a/lib/rules/curly.js +++ b/lib/rules/curly.js @@ -51,7 +51,14 @@ module.exports = { ] }, - fixable: "code" + fixable: "code", + + messages: { + missingCurlyAfter: "Expected { after '{{name}}'.", + missingCurlyAfterCondition: "Expected { after '{{name}}' condition.", + unexpectedCurlyAfter: "Unnecessary { after '{{name}}'.", + unexpectedCurlyAfterCondition: "Unnecessary { after '{{name}}' condition." + } }, create(context) { @@ -142,28 +149,6 @@ module.exports = { return false; } - /** - * Reports "Expected { after ..." error - * @param {ASTNode} node The node to report. - * @param {ASTNode} bodyNode The body node that is incorrectly missing curly brackets - * @param {string} name The name to report. - * @param {string} suffix Additional string to add to the end of a report. - * @returns {void} - * @private - */ - function reportExpectedBraceError(node, bodyNode, name, suffix) { - context.report({ - node, - loc: (name !== "else" ? node : getElseKeyword(node)).loc.start, - message: "Expected { after '{{name}}'{{suffix}}.", - data: { - name, - suffix: (suffix ? ` ${suffix}` : "") - }, - fix: fixer => fixer.replaceText(bodyNode, `{${sourceCode.getText(bodyNode)}}`) - }); - } - /** * Determines if a semicolon needs to be inserted after removing a set of curly brackets, in order to avoid a SyntaxError. * @param {Token} closingBracket The } token @@ -218,62 +203,12 @@ module.exports = { return false; } - /** - * Reports "Unnecessary { after ..." error - * @param {ASTNode} node The node to report. - * @param {ASTNode} bodyNode The block statement that is incorrectly surrounded by parens - * @param {string} name The name to report. - * @param {string} suffix Additional string to add to the end of a report. - * @returns {void} - * @private - */ - function reportUnnecessaryBraceError(node, bodyNode, name, suffix) { - context.report({ - node, - loc: (name !== "else" ? node : getElseKeyword(node)).loc.start, - message: "Unnecessary { after '{{name}}'{{suffix}}.", - data: { - name, - suffix: (suffix ? ` ${suffix}` : "") - }, - fix(fixer) { - - /* - * `do while` expressions sometimes need a space to be inserted after `do`. - * e.g. `do{foo()} while (bar)` should be corrected to `do foo() while (bar)` - */ - const needsPrecedingSpace = node.type === "DoWhileStatement" && - sourceCode.getTokenBefore(bodyNode).range[1] === bodyNode.range[0] && - !astUtils.canTokensBeAdjacent("do", sourceCode.getFirstToken(bodyNode, { skip: 1 })); - - const openingBracket = sourceCode.getFirstToken(bodyNode); - const closingBracket = sourceCode.getLastToken(bodyNode); - const lastTokenInBlock = sourceCode.getTokenBefore(closingBracket); - - if (needsSemicolon(closingBracket)) { - - /* - * If removing braces would cause a SyntaxError due to multiple statements on the same line (or - * change the semantics of the code due to ASI), don't perform a fix. - */ - return null; - } - - const resultingBodyText = sourceCode.getText().slice(openingBracket.range[1], lastTokenInBlock.range[0]) + - sourceCode.getText(lastTokenInBlock) + - sourceCode.getText().slice(lastTokenInBlock.range[1], closingBracket.range[0]); - - return fixer.replaceText(bodyNode, (needsPrecedingSpace ? " " : "") + resultingBodyText); - } - }); - } - /** * Prepares to check the body of a node to see if it's a block statement. * @param {ASTNode} node The node to report if there's a problem. * @param {ASTNode} body The body node to check for blocks. * @param {string} name The name to report if there's a problem. - * @param {string} suffix Additional string to add to the end of a report. + * @param {{ condition: boolean }} opts Options to pass to the report functions * @returns {Object} a prepared check object, with "actual", "expected", "check" properties. * "actual" will be `true` or `false` whether the body is already a block statement. * "expected" will be `true` or `false` if the body should be a block statement or not, or @@ -282,7 +217,7 @@ module.exports = { * "check" will be a function reporting appropriate problems depending on the other * properties. */ - function prepareCheck(node, body, name, suffix) { + function prepareCheck(node, body, name, opts) { const hasBlock = (body.type === "BlockStatement"); let expected = null; @@ -314,9 +249,53 @@ module.exports = { check() { if (this.expected !== null && this.expected !== this.actual) { if (this.expected) { - reportExpectedBraceError(node, body, name, suffix); + context.report({ + node, + loc: (name !== "else" ? node : getElseKeyword(node)).loc.start, + messageId: opts && opts.condition ? "missingCurlyAfterCondition" : "missingCurlyAfter", + data: { + name + }, + fix: fixer => fixer.replaceText(body, `{${sourceCode.getText(body)}}`) + }); } else { - reportUnnecessaryBraceError(node, body, name, suffix); + context.report({ + node, + loc: (name !== "else" ? node : getElseKeyword(node)).loc.start, + messageId: opts && opts.condition ? "unexpectedCurlyAfterCondition" : "unexpectedCurlyAfter", + data: { + name + }, + fix(fixer) { + + /* + * `do while` expressions sometimes need a space to be inserted after `do`. + * e.g. `do{foo()} while (bar)` should be corrected to `do foo() while (bar)` + */ + const needsPrecedingSpace = node.type === "DoWhileStatement" && + sourceCode.getTokenBefore(body).range[1] === body.range[0] && + !astUtils.canTokensBeAdjacent("do", sourceCode.getFirstToken(body, { skip: 1 })); + + const openingBracket = sourceCode.getFirstToken(body); + const closingBracket = sourceCode.getLastToken(body); + const lastTokenInBlock = sourceCode.getTokenBefore(closingBracket); + + if (needsSemicolon(closingBracket)) { + + /* + * If removing braces would cause a SyntaxError due to multiple statements on the same line (or + * change the semantics of the code due to ASI), don't perform a fix. + */ + return null; + } + + const resultingBodyText = sourceCode.getText().slice(openingBracket.range[1], lastTokenInBlock.range[0]) + + sourceCode.getText(lastTokenInBlock) + + sourceCode.getText().slice(lastTokenInBlock.range[1], closingBracket.range[0]); + + return fixer.replaceText(body, (needsPrecedingSpace ? " " : "") + resultingBodyText); + } + }); } } } @@ -333,7 +312,7 @@ module.exports = { const preparedChecks = []; do { - preparedChecks.push(prepareCheck(node, node.consequent, "if", "condition")); + preparedChecks.push(prepareCheck(node, node.consequent, "if", { condition: true })); if (node.alternate && node.alternate.type !== "IfStatement") { preparedChecks.push(prepareCheck(node, node.alternate, "else")); break; @@ -377,7 +356,7 @@ module.exports = { }, WhileStatement(node) { - prepareCheck(node, node.body, "while", "condition").check(); + prepareCheck(node, node.body, "while", { condition: true }).check(); }, DoWhileStatement(node) { @@ -385,7 +364,7 @@ module.exports = { }, ForStatement(node) { - prepareCheck(node, node.body, "for", "condition").check(); + prepareCheck(node, node.body, "for", { condition: true }).check(); }, ForInStatement(node) { diff --git a/lib/rules/default-case.js b/lib/rules/default-case.js index a66300a99b5..cf123198f4a 100644 --- a/lib/rules/default-case.js +++ b/lib/rules/default-case.js @@ -27,7 +27,11 @@ module.exports = { } }, additionalProperties: false - }] + }], + + messages: { + missingDefaultCase: "Expected a default case." + } }, create(context) { @@ -82,7 +86,7 @@ module.exports = { } if (!comment || !commentPattern.test(comment.value.trim())) { - context.report({ node, message: "Expected a default case." }); + context.report({ node, messageId: "missingDefaultCase" }); } } } diff --git a/lib/rules/dot-location.js b/lib/rules/dot-location.js index c02476e0354..7ff8ca65ae4 100644 --- a/lib/rules/dot-location.js +++ b/lib/rules/dot-location.js @@ -26,7 +26,12 @@ module.exports = { } ], - fixable: "code" + fixable: "code", + + messages: { + expectedDotAfterObject: "Expected dot to be on same line as object.", + expectedDotBeforeProperty: "Expected dot to be on same line as property." + } }, create(context) { @@ -58,7 +63,7 @@ module.exports = { context.report({ node, loc: dot.loc.start, - message: "Expected dot to be on same line as object.", + messageId: "expectedDotAfterObject", fix: fixer => fixer.replaceTextRange([obj.range[1], prop.range[0]], `${neededTextAfterObj}.${textBeforeDot}${textAfterDot}`) }); } @@ -66,7 +71,7 @@ module.exports = { context.report({ node, loc: dot.loc.start, - message: "Expected dot to be on same line as property.", + messageId: "expectedDotBeforeProperty", fix: fixer => fixer.replaceTextRange([obj.range[1], prop.range[0]], `${textBeforeDot}${textAfterDot}.`) }); } diff --git a/lib/rules/dot-notation.js b/lib/rules/dot-notation.js index 10c73b41f04..c381661d41f 100644 --- a/lib/rules/dot-notation.js +++ b/lib/rules/dot-notation.js @@ -41,7 +41,12 @@ module.exports = { } ], - fixable: "code" + fixable: "code", + + messages: { + useDot: "[{{key}}] is better written in dot notation.", + useBrackets: ".{{key}} is a syntax error." + } }, create(context) { @@ -71,9 +76,9 @@ module.exports = { context.report({ node: node.property, - message: "[{{propertyValue}}] is better written in dot notation.", + messageId: "useDot", data: { - propertyValue: formattedValue + key: formattedValue }, fix(fixer) { const leftBracket = sourceCode.getTokenAfter(node.object, astUtils.isOpeningBracketToken); @@ -124,9 +129,9 @@ module.exports = { ) { context.report({ node: node.property, - message: ".{{propertyName}} is a syntax error.", + messageId: "useBrackets", data: { - propertyName: node.property.name + key: node.property.name }, fix(fixer) { const dot = sourceCode.getTokenBefore(node.property); diff --git a/lib/rules/eol-last.js b/lib/rules/eol-last.js index f96352676c7..3ecf4227399 100644 --- a/lib/rules/eol-last.js +++ b/lib/rules/eol-last.js @@ -27,7 +27,11 @@ module.exports = { { enum: ["always", "never", "unix", "windows"] } - ] + ], + messages: { + missing: "Newline required at end of file but not found.", + unexpected: "Newline not allowed at end of file." + } }, create(context) { @@ -75,7 +79,7 @@ module.exports = { context.report({ node, loc: location, - message: "Newline required at end of file but not found.", + messageId: "missing", fix(fixer) { return fixer.insertTextAfterRange([0, src.length], appendCRLF ? CRLF : LF); } @@ -86,7 +90,7 @@ module.exports = { context.report({ node, loc: location, - message: "Newline not allowed at end of file.", + messageId: "unexpected", fix(fixer) { const finalEOLs = /(?:\r?\n)+$/, match = finalEOLs.exec(sourceCode.text), diff --git a/lib/rules/eqeqeq.js b/lib/rules/eqeqeq.js index fc65450af4b..ec9d0a78218 100644 --- a/lib/rules/eqeqeq.js +++ b/lib/rules/eqeqeq.js @@ -56,7 +56,11 @@ module.exports = { ] }, - fixable: "code" + fixable: "code", + + messages: { + unexpected: "Expected '{{expectedOperator}}' and instead saw '{{actualOperator}}'." + } }, create(context) { @@ -134,7 +138,7 @@ module.exports = { context.report({ node, loc: getOperatorLocation(node), - message: "Expected '{{expectedOperator}}' and instead saw '{{actualOperator}}'.", + messageId: "unexpected", data: { expectedOperator, actualOperator: node.operator }, fix(fixer) { diff --git a/lib/rules/no-alert.js b/lib/rules/no-alert.js index b4fd2312150..69d419da1c5 100644 --- a/lib/rules/no-alert.js +++ b/lib/rules/no-alert.js @@ -23,17 +23,6 @@ function isProhibitedIdentifier(name) { return /^(alert|confirm|prompt)$/.test(name); } -/** - * Reports the given node and identifier name. - * @param {RuleContext} context The ESLint rule context. - * @param {ASTNode} node The node to report on. - * @param {string} identifierName The name of the identifier. - * @returns {void} - */ -function report(context, node, identifierName) { - context.report(node, "Unexpected {{name}}.", { name: identifierName }); -} - /** * Finds the eslint-scope reference in the given scope. * @param {Object} scope The scope to search. @@ -92,7 +81,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-alert" }, - schema: [] + schema: [], + + messages: { + unexpected: "Unexpected {{name}}." + } }, create(context) { @@ -103,17 +96,25 @@ module.exports = { // without window. if (callee.type === "Identifier") { - const identifierName = callee.name; + const name = callee.name; if (!isShadowed(currentScope, callee) && isProhibitedIdentifier(callee.name)) { - report(context, node, identifierName); + context.report({ + node, + messageId: "unexpected", + data: { name } + }); } } else if (callee.type === "MemberExpression" && isGlobalThisReferenceOrGlobalWindow(currentScope, callee.object)) { - const identifierName = getPropertyName(callee); - - if (isProhibitedIdentifier(identifierName)) { - report(context, node, identifierName); + const name = getPropertyName(callee); + + if (isProhibitedIdentifier(name)) { + context.report({ + node, + messageId: "unexpected", + data: { name } + }); } } diff --git a/lib/rules/no-array-constructor.js b/lib/rules/no-array-constructor.js index 187389fdff3..51676f78211 100644 --- a/lib/rules/no-array-constructor.js +++ b/lib/rules/no-array-constructor.js @@ -18,7 +18,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-array-constructor" }, - schema: [] + schema: [], + + messages: { + preferLiteral: "The array literal notation [] is preferable." + } }, create(context) { @@ -35,7 +39,7 @@ module.exports = { node.callee.type === "Identifier" && node.callee.name === "Array" ) { - context.report({ node, message: "The array literal notation [] is preferrable." }); + context.report({ node, messageId: "preferLiteral" }); } } diff --git a/lib/rules/no-await-in-loop.js b/lib/rules/no-await-in-loop.js index 7d4f8a0a6ba..7a9427e6abf 100644 --- a/lib/rules/no-await-in-loop.js +++ b/lib/rules/no-await-in-loop.js @@ -31,7 +31,10 @@ module.exports = { recommended: false, url: "https://eslint.org/docs/rules/no-await-in-loop" }, - schema: [] + schema: [], + messages: { + unexpectedAwait: "Unexpected `await` inside a loop." + } }, create(context) { return { @@ -72,7 +75,7 @@ module.exports = { ) { context.report({ node, - message: "Unexpected `await` inside a loop." + messageId: "unexpectedAwait" }); return; } diff --git a/lib/rules/no-bitwise.js b/lib/rules/no-bitwise.js index 8376674f65f..36bbdaf349c 100644 --- a/lib/rules/no-bitwise.js +++ b/lib/rules/no-bitwise.js @@ -46,7 +46,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unexpected: "Unexpected use of '{{operator}}'." + } }, create(context) { @@ -60,7 +64,7 @@ module.exports = { * @returns {void} */ function report(node) { - context.report({ node, message: "Unexpected use of '{{operator}}'.", data: { operator: node.operator } }); + context.report({ node, messageId: "unexpected", data: { operator: node.operator } }); } /** diff --git a/lib/rules/no-buffer-constructor.js b/lib/rules/no-buffer-constructor.js index 55f181ee697..2cf2ee47c86 100644 --- a/lib/rules/no-buffer-constructor.js +++ b/lib/rules/no-buffer-constructor.js @@ -16,7 +16,10 @@ module.exports = { recommended: false, url: "https://eslint.org/docs/rules/no-buffer-constructor" }, - schema: [] + schema: [], + messages: { + deprecated: "{{expr}} is deprecated. Use Buffer.from(), Buffer.alloc(), or Buffer.allocUnsafe() instead." + } }, create(context) { @@ -29,8 +32,8 @@ module.exports = { "CallExpression[callee.name='Buffer'], NewExpression[callee.name='Buffer']"(node) { context.report({ node, - message: "{{example}} is deprecated. Use Buffer.from(), Buffer.alloc(), or Buffer.allocUnsafe() instead.", - data: { example: node.type === "CallExpression" ? "Buffer()" : "new Buffer()" } + messageId: "deprecated", + data: { expr: node.type === "CallExpression" ? "Buffer()" : "new Buffer()" } }); } }; diff --git a/lib/rules/no-caller.js b/lib/rules/no-caller.js index df10bf3736b..9756b212ffe 100644 --- a/lib/rules/no-caller.js +++ b/lib/rules/no-caller.js @@ -18,7 +18,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-caller" }, - schema: [] + schema: [], + + messages: { + unexpected: "Avoid arguments.{{prop}}." + } }, create(context) { @@ -30,7 +34,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 03c730ddbdb..862be4c57d9 100644 --- a/lib/rules/no-case-declarations.js +++ b/lib/rules/no-case-declarations.js @@ -17,7 +17,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-case-declarations" }, - schema: [] + schema: [], + + messages: { + unexpected: "Unexpected lexical declaration in case block." + } }, create(context) { @@ -47,7 +51,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 69a4e6aff85..907792278fc 100644 --- a/lib/rules/no-catch-shadow.js +++ b/lib/rules/no-catch-shadow.js @@ -24,7 +24,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-catch-shadow" }, - schema: [] + schema: [], + + messages: { + mutable: "Value of '{{name}}' may be overwritten in IE 8 and earlier." + } }, create(context) { @@ -61,7 +65,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 56e75122a25..58dddd6a684 100644 --- a/lib/rules/no-class-assign.js +++ b/lib/rules/no-class-assign.js @@ -20,7 +20,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-class-assign" }, - schema: [] + schema: [], + + messages: { + class: "'{{name}}' is a class." + } }, create(context) { @@ -32,7 +36,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 09cf2950630..6903bd06544 100644 --- a/lib/rules/no-compare-neg-zero.js +++ b/lib/rules/no-compare-neg-zero.js @@ -17,7 +17,10 @@ module.exports = { url: "https://eslint.org/docs/rules/no-compare-neg-zero" }, fixable: null, - schema: [] + schema: [], + messages: { + unexpected: "Do not use the '{{operator}}' operator to compare against -0." + } }, create(context) { @@ -43,7 +46,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 e761be14ecd..f949bcc884b 100644 --- a/lib/rules/no-cond-assign.js +++ b/lib/rules/no-cond-assign.js @@ -30,7 +30,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) { @@ -95,11 +102,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" }); } } @@ -115,7 +121,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 542a4060e27..297e3b14808 100644 --- a/lib/rules/no-confusing-arrow.js +++ b/lib/rules/no-confusing-arrow.js @@ -42,7 +42,11 @@ module.exports = { allowParens: { type: "boolean" } }, additionalProperties: false - }] + }], + + messages: { + confusing: "Arrow function used ambiguously with a conditional expression." + } }, create(context) { @@ -60,7 +64,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 b00582ebada..fd5c33a8e79 100644 --- a/lib/rules/no-console.js +++ b/lib/rules/no-console.js @@ -39,7 +39,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unexpected: "Unexpected console statement." + } }, create(context) { @@ -102,7 +106,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 8a08a52df4e..043fe05df72 100644 --- a/lib/rules/no-const-assign.js +++ b/lib/rules/no-const-assign.js @@ -20,7 +20,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-const-assign" }, - schema: [] + schema: [], + + messages: { + const: "'{{name}}' is constant." + } }, create(context) { @@ -32,7 +36,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 5611d617ec8..724da974127 100644 --- a/lib/rules/no-constant-condition.js +++ b/lib/rules/no-constant-condition.js @@ -28,8 +28,11 @@ module.exports = { }, additionalProperties: false } + ], - ] + messages: { + unexpected: "Unexpected constant condition." + } }, create(context) { @@ -139,7 +142,7 @@ module.exports = { function checkConstantConditionLoopInSet(node) { if (loopsInCurrentScope.has(node)) { loopsInCurrentScope.delete(node); - context.report({ node: node.test, message: "Unexpected constant condition." }); + context.report({ node: node.test, messageId: "unexpected" }); } } @@ -151,7 +154,7 @@ module.exports = { */ function reportIfConstant(node) { if (node.test && isConstant(node.test, true)) { - context.report({ node: node.test, message: "Unexpected constant condition." }); + context.report({ node: node.test, messageId: "unexpected" }); } } diff --git a/lib/rules/no-continue.js b/lib/rules/no-continue.js index 52061ef5328..3075b77f9fd 100644 --- a/lib/rules/no-continue.js +++ b/lib/rules/no-continue.js @@ -18,14 +18,18 @@ module.exports = { url: "https://eslint.org/docs/rules/no-continue" }, - 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 676c666128e..e3afce787bd 100644 --- a/lib/rules/no-control-regex.js +++ b/lib/rules/no-control-regex.js @@ -18,7 +18,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-control-regex" }, - schema: [] + schema: [], + + messages: { + unexpected: "Unexpected control character(s) in regular expression: {{controlChars}}." + } }, create(context) { @@ -26,7 +30,7 @@ module.exports = { /** * Get the regex expression * @param {ASTNode} node node to evaluate - * @returns {*} Regex if found else null + * @returns {RegExp|null} Regex if found else null * @private */ function getRegExp(node) { @@ -114,7 +118,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/lib/rules/no-debugger.js b/lib/rules/no-debugger.js index 7d816e3a000..f00e819df09 100644 --- a/lib/rules/no-debugger.js +++ b/lib/rules/no-debugger.js @@ -20,7 +20,10 @@ module.exports = { url: "https://eslint.org/docs/rules/no-debugger" }, fixable: "code", - schema: [] + schema: [], + messages: { + unexpected: "Unexpected 'debugger' statement." + } }, create(context) { @@ -29,7 +32,7 @@ module.exports = { DebuggerStatement(node) { context.report({ node, - message: "Unexpected 'debugger' statement.", + messageId: "unexpected", fix(fixer) { if (astUtils.STATEMENT_LIST_PARENTS.has(node.parent.type)) { return fixer.remove(node); diff --git a/lib/rules/no-delete-var.js b/lib/rules/no-delete-var.js index 9ca09f1deae..f54a396ec2d 100644 --- a/lib/rules/no-delete-var.js +++ b/lib/rules/no-delete-var.js @@ -18,7 +18,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-delete-var" }, - schema: [] + schema: [], + + messages: { + unexpected: "Variables should not be deleted." + } }, create(context) { @@ -27,7 +31,7 @@ module.exports = { UnaryExpression(node) { if (node.operator === "delete" && node.argument.type === "Identifier") { - context.report({ node, message: "Variables should not be deleted." }); + context.report({ node, messageId: "unexpected" }); } } }; diff --git a/lib/rules/no-div-regex.js b/lib/rules/no-div-regex.js index 87423f8861a..c050249fd6e 100644 --- a/lib/rules/no-div-regex.js +++ b/lib/rules/no-div-regex.js @@ -18,7 +18,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-div-regex" }, - schema: [] + schema: [], + + messages: { + unexpected: "A regular expression literal can be confused with '/='." + } }, create(context) { @@ -30,7 +34,7 @@ module.exports = { const token = sourceCode.getFirstToken(node); if (token.type === "RegularExpression" && token.value[1] === "=") { - context.report({ node, message: "A regular expression literal can be confused with '/='." }); + context.report({ node, messageId: "unexpected" }); } } }; diff --git a/lib/rules/no-dupe-args.js b/lib/rules/no-dupe-args.js index a71d01f9bd2..e5a7f4154e7 100644 --- a/lib/rules/no-dupe-args.js +++ b/lib/rules/no-dupe-args.js @@ -18,7 +18,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-dupe-args" }, - schema: [] + schema: [], + + messages: { + unexpected: "Duplicate param '{{name}}'." + } }, create(context) { @@ -54,7 +58,7 @@ module.exports = { if (defs.length >= 2) { context.report({ node, - message: "Duplicate param '{{name}}'.", + messageId: "unexpected", data: { name: variable.name } }); } diff --git a/lib/rules/no-dupe-class-members.js b/lib/rules/no-dupe-class-members.js index cc7f8da284a..d0fc3597360 100644 --- a/lib/rules/no-dupe-class-members.js +++ b/lib/rules/no-dupe-class-members.js @@ -18,7 +18,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-dupe-class-members" }, - schema: [] + schema: [], + + messages: { + unexpected: "Duplicate name '{{name}}'." + } }, create(context) { @@ -102,7 +106,7 @@ module.exports = { } if (isDuplicate) { - context.report({ node, message: "Duplicate name '{{name}}'.", data: { name } }); + context.report({ node, messageId: "unexpected", data: { name } }); } } }; diff --git a/lib/rules/no-dupe-keys.js b/lib/rules/no-dupe-keys.js index 10955e45037..577710c65d5 100644 --- a/lib/rules/no-dupe-keys.js +++ b/lib/rules/no-dupe-keys.js @@ -91,7 +91,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-dupe-keys" }, - schema: [] + schema: [], + + messages: { + unexpected: "Duplicate key '{{name}}'." + } }, create(context) { @@ -123,7 +127,7 @@ module.exports = { context.report({ node: info.node, loc: node.key.loc, - message: "Duplicate key '{{name}}'.", + messageId: "unexpected", data: { name } }); } diff --git a/lib/rules/no-duplicate-case.js b/lib/rules/no-duplicate-case.js index 2a9d9551114..128b1fc1b1c 100644 --- a/lib/rules/no-duplicate-case.js +++ b/lib/rules/no-duplicate-case.js @@ -19,7 +19,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-duplicate-case" }, - schema: [] + schema: [], + + messages: { + unexpected: "Duplicate case label." + } }, create(context) { @@ -33,7 +37,7 @@ module.exports = { const key = sourceCode.getText(switchCase.test); if (mapping[key]) { - context.report({ node: switchCase, message: "Duplicate case label." }); + context.report({ node: switchCase, messageId: "unexpected" }); } else { mapping[key] = switchCase; } diff --git a/lib/rules/no-else-return.js b/lib/rules/no-else-return.js index 91cb5b97963..015ceddc4fc 100644 --- a/lib/rules/no-else-return.js +++ b/lib/rules/no-else-return.js @@ -34,7 +34,12 @@ module.exports = { }, additionalProperties: false }], - fixable: "code" + + fixable: "code", + + messages: { + unexpected: "Unnecessary 'else' after 'return'." + } }, create(context) { @@ -52,7 +57,7 @@ module.exports = { function displayReport(node) { context.report({ node, - message: "Unnecessary 'else' after 'return'.", + messageId: "unexpected", fix: fixer => { const sourceCode = context.getSourceCode(); const startToken = sourceCode.getFirstToken(node); diff --git a/lib/rules/no-empty-character-class.js b/lib/rules/no-empty-character-class.js index 3c4806632e5..1f5c7333aa0 100644 --- a/lib/rules/no-empty-character-class.js +++ b/lib/rules/no-empty-character-class.js @@ -36,7 +36,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-empty-character-class" }, - schema: [] + schema: [], + + messages: { + unexpected: "Empty class." + } }, create(context) { @@ -48,7 +52,7 @@ module.exports = { const token = sourceCode.getFirstToken(node); if (token.type === "RegularExpression" && !regex.test(token.value)) { - context.report({ node, message: "Empty class." }); + context.report({ node, messageId: "unexpected" }); } } diff --git a/lib/rules/no-empty-function.js b/lib/rules/no-empty-function.js index 3852774e6b2..d9948cd4a33 100644 --- a/lib/rules/no-empty-function.js +++ b/lib/rules/no-empty-function.js @@ -109,7 +109,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unexpected: "Unexpected empty {{name}}." + } }, create(context) { @@ -146,7 +150,7 @@ module.exports = { context.report({ node, loc: node.body.loc.start, - message: "Unexpected empty {{name}}.", + messageId: "unexpected", data: { name } }); } diff --git a/lib/rules/no-empty-pattern.js b/lib/rules/no-empty-pattern.js index 1d0c3ab4b1d..939710560fa 100644 --- a/lib/rules/no-empty-pattern.js +++ b/lib/rules/no-empty-pattern.js @@ -17,19 +17,23 @@ module.exports = { url: "https://eslint.org/docs/rules/no-empty-pattern" }, - schema: [] + schema: [], + + messages: { + unexpected: "Unexpected empty {{type}} pattern." + } }, create(context) { return { ObjectPattern(node) { if (node.properties.length === 0) { - context.report({ node, message: "Unexpected empty object pattern." }); + context.report({ node, messageId: "unexpected", data: { type: "object" } }); } }, ArrayPattern(node) { if (node.elements.length === 0) { - context.report({ node, message: "Unexpected empty array pattern." }); + context.report({ node, messageId: "unexpected", data: { type: "array" } }); } } }; diff --git a/lib/rules/no-empty.js b/lib/rules/no-empty.js index 15f1df67908..a598d40f8ca 100644 --- a/lib/rules/no-empty.js +++ b/lib/rules/no-empty.js @@ -33,7 +33,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unexpected: "Empty {{type}} statement." + } }, create(context) { @@ -64,13 +68,13 @@ module.exports = { return; } - context.report({ node, message: "Empty block statement." }); + context.report({ node, messageId: "unexpected", data: { type: "block" } }); }, SwitchStatement(node) { if (typeof node.cases === "undefined" || node.cases.length === 0) { - context.report({ node, message: "Empty switch statement." }); + context.report({ node, messageId: "unexpected", data: { type: "switch" } }); } } }; diff --git a/lib/rules/no-eq-null.js b/lib/rules/no-eq-null.js index 22dbd49d421..eadd16de37f 100644 --- a/lib/rules/no-eq-null.js +++ b/lib/rules/no-eq-null.js @@ -19,7 +19,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-eq-null" }, - schema: [] + schema: [], + + messages: { + unexpected: "Use '===' to compare with null." + } }, create(context) { @@ -31,7 +35,7 @@ module.exports = { if (node.right.type === "Literal" && node.right.raw === "null" && badOperator || node.left.type === "Literal" && node.left.raw === "null" && badOperator) { - context.report({ node, message: "Use '===' to compare with null." }); + context.report({ node, messageId: "unexpected" }); } } }; diff --git a/lib/rules/no-eval.js b/lib/rules/no-eval.js index 8cf4aa307b0..f77451ec381 100644 --- a/lib/rules/no-eval.js +++ b/lib/rules/no-eval.js @@ -91,7 +91,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unexpected: "eval can be harmful." + } }, create(context) { @@ -160,7 +164,7 @@ module.exports = { context.report({ node, loc: locationNode.loc.start, - message: "eval can be harmful." + messageId: "unexpected" }); } diff --git a/lib/rules/no-ex-assign.js b/lib/rules/no-ex-assign.js index 6ede2fc210b..feace415e50 100644 --- a/lib/rules/no-ex-assign.js +++ b/lib/rules/no-ex-assign.js @@ -20,7 +20,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-ex-assign" }, - schema: [] + schema: [], + + messages: { + unexpected: "Do not assign to the exception parameter." + } }, create(context) { @@ -32,7 +36,7 @@ module.exports = { */ function checkVariable(variable) { astUtils.getModifyingReferences(variable.references).forEach(reference => { - context.report({ node: reference.identifier, message: "Do not assign to the exception parameter." }); + context.report({ node: reference.identifier, messageId: "unexpected" }); }); } diff --git a/lib/rules/no-extend-native.js b/lib/rules/no-extend-native.js index 2e170017a87..3ba13090a67 100644 --- a/lib/rules/no-extend-native.js +++ b/lib/rules/no-extend-native.js @@ -45,7 +45,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unexpected: "{{builtin}} prototype is read only, properties should not be added." + } }, create(context) { @@ -67,7 +71,7 @@ module.exports = { function reportNode(node, builtin) { context.report({ node, - message: "{{builtin}} prototype is read only, properties should not be added.", + messageId: "unexpected", data: { builtin } diff --git a/lib/rules/no-extra-bind.js b/lib/rules/no-extra-bind.js index 21b96c3c261..8d901808fd6 100644 --- a/lib/rules/no-extra-bind.js +++ b/lib/rules/no-extra-bind.js @@ -25,7 +25,11 @@ module.exports = { schema: [], - fixable: "code" + fixable: "code", + + messages: { + unexpected: "The function binding is unnecessary." + } }, create(context) { @@ -41,7 +45,7 @@ module.exports = { function report(node) { context.report({ node: node.parent.parent, - message: "The function binding is unnecessary.", + messageId: "unexpected", loc: node.parent.property.loc.start, fix(fixer) { const firstTokenToRemove = context.getSourceCode() diff --git a/lib/rules/no-extra-boolean-cast.js b/lib/rules/no-extra-boolean-cast.js index 471e8b5b82c..38191361715 100644 --- a/lib/rules/no-extra-boolean-cast.js +++ b/lib/rules/no-extra-boolean-cast.js @@ -26,7 +26,12 @@ module.exports = { schema: [], - fixable: "code" + fixable: "code", + + messages: { + unexpectedCall: "Redundant Boolean call.", + unexpectedNegation: "Redundant double negation." + } }, create(context) { @@ -82,7 +87,7 @@ module.exports = { ) { context.report({ node, - message: "Redundant double negation.", + messageId: "unexpectedNegation", fix: fixer => fixer.replaceText(parent, sourceCode.getText(node.argument)) }); } @@ -97,7 +102,7 @@ module.exports = { if (isInBooleanContext(node, parent)) { context.report({ node, - message: "Redundant Boolean call.", + messageId: "unexpectedCall", fix: fixer => { if (!node.arguments.length) { return fixer.replaceText(parent, "true"); diff --git a/lib/rules/no-extra-label.js b/lib/rules/no-extra-label.js index f90a403cbfd..73a3fea9c96 100644 --- a/lib/rules/no-extra-label.js +++ b/lib/rules/no-extra-label.js @@ -26,7 +26,11 @@ module.exports = { schema: [], - fixable: "code" + fixable: "code", + + messages: { + unexpected: "This label '{{name}}' is unnecessary." + } }, create(context) { @@ -109,7 +113,7 @@ module.exports = { if (info.breakable && info.label && info.label.name === labelNode.name) { context.report({ node: labelNode, - message: "This label '{{name}}' is unnecessary.", + messageId: "unexpected", data: labelNode, fix: fixer => fixer.removeRange([sourceCode.getFirstToken(node).range[1], labelNode.range[1]]) }); diff --git a/lib/rules/no-extra-parens.js b/lib/rules/no-extra-parens.js index 4bf8f995009..daf069e9b9f 100644 --- a/lib/rules/no-extra-parens.js +++ b/lib/rules/no-extra-parens.js @@ -55,6 +55,10 @@ module.exports = { maxItems: 2 } ] + }, + + messages: { + unexpected: "Gratuitous parentheses around expression." } }, @@ -312,7 +316,7 @@ module.exports = { context.report({ node, loc: leftParenToken.loc.start, - message: "Gratuitous parentheses around expression.", + messageId: "unexpected", fix(fixer) { const parenthesizedSource = sourceCode.text.slice(leftParenToken.range[1], rightParenToken.range[0]); diff --git a/lib/rules/no-extra-semi.js b/lib/rules/no-extra-semi.js index 5668c7e095e..a0741088589 100644 --- a/lib/rules/no-extra-semi.js +++ b/lib/rules/no-extra-semi.js @@ -26,7 +26,11 @@ module.exports = { }, fixable: "code", - schema: [] + schema: [], + + messages: { + unexpected: "Unnecessary semicolon." + } }, create(context) { @@ -40,7 +44,7 @@ module.exports = { function report(nodeOrToken) { context.report({ node: nodeOrToken, - message: "Unnecessary semicolon.", + messageId: "unexpected", fix(fixer) { /* diff --git a/tests/lib/cli-engine.js b/tests/lib/cli-engine.js index 48bc82f10b8..e267ed3b2af 100644 --- a/tests/lib/cli-engine.js +++ b/tests/lib/cli-engine.js @@ -1395,6 +1395,7 @@ describe("CLIEngine", () => { column: 9, line: 2, message: "Expected '===' and instead saw '=='.", + messageId: "unexpected", nodeType: "BinaryExpression", ruleId: "eqeqeq", severity: 2, diff --git a/tests/lib/rules/accessor-pairs.js b/tests/lib/rules/accessor-pairs.js index f694707fd18..6470324f998 100644 --- a/tests/lib/rules/accessor-pairs.js +++ b/tests/lib/rules/accessor-pairs.js @@ -18,6 +18,9 @@ const rule = require("../../../lib/rules/accessor-pairs"), const ruleTester = new RuleTester(); +const getterError = { messageId: "getter" }; +const setterError = { messageId: "setter" }; + ruleTester.run("accessor-pairs", rule, { valid: [ "var o = { a: 1 };", @@ -46,49 +49,35 @@ ruleTester.run("accessor-pairs", rule, { invalid: [ { code: "var o = {\n set a(value) {\n val = value; \n} \n};", - errors: [{ - message: "Getter is not present." - }] + errors: [getterError] }, { code: "var o = {\n get a() {\n return val; \n} \n};", options: [{ getWithoutSet: true }], - errors: [{ - message: "Setter is not present." - }] + errors: [setterError] }, { code: "var o = {d: 1};\n Object.defineProperty(o, 'c', \n{set: function(value) {\n val = value; \n} \n});", - errors: [{ - message: "Getter is not present." - }] + errors: [getterError] }, { code: "Reflect.defineProperty(obj, 'foo', {set: function(value) {}});", - errors: [{ - message: "Getter is not present." - }] + errors: [getterError] }, { code: "Object.defineProperties(obj, {foo: {set: function(value) {}}});", - errors: [{ - message: "Getter is not present." - }] + errors: [getterError] }, { code: "Object.create(null, {foo: {set: function(value) {}}});", - errors: [{ - message: "Getter is not present." - }] + errors: [getterError] }, { code: "var expr = 'foo'; var o = { set [expr](value) { val = value; } };", parserOptions: { ecmaVersion: 6 }, - errors: [{ - message: "Getter is not present." - }] + errors: [getterError] } ] }); diff --git a/tests/lib/rules/array-bracket-newline.js b/tests/lib/rules/array-bracket-newline.js index 86eee8fba3b..bde0f56a227 100644 --- a/tests/lib/rules/array-bracket-newline.js +++ b/tests/lib/rules/array-bracket-newline.js @@ -19,11 +19,6 @@ const RuleTester = require("../../../lib/testers/rule-tester"); const ruleTester = new RuleTester(); -const ERR_NO_BREAK_AFTER = "There should be no linebreak after '['."; -const ERR_BREAK_AFTER = "A linebreak is required after '['."; -const ERR_NO_BREAK_BEFORE = "There should be no linebreak before ']'."; -const ERR_BREAK_BEFORE = "A linebreak is required before ']'."; - ruleTester.run("array-bracket-newline", rule, { valid: [ @@ -187,7 +182,7 @@ ruleTester.run("array-bracket-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11, @@ -195,7 +190,7 @@ ruleTester.run("array-bracket-newline", rule, { endColumn: 12 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 1, column: 12, @@ -210,13 +205,13 @@ ruleTester.run("array-bracket-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 1, column: 13 @@ -229,7 +224,7 @@ ruleTester.run("array-bracket-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 2, column: 2, @@ -244,7 +239,7 @@ ruleTester.run("array-bracket-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 2, column: 2 @@ -257,7 +252,7 @@ ruleTester.run("array-bracket-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11, @@ -265,7 +260,7 @@ ruleTester.run("array-bracket-newline", rule, { endColumn: 12 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 1, column: 16, @@ -280,7 +275,7 @@ ruleTester.run("array-bracket-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 @@ -293,13 +288,13 @@ ruleTester.run("array-bracket-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 1, column: 34 @@ -312,13 +307,13 @@ ruleTester.run("array-bracket-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 2, column: 2 @@ -331,13 +326,13 @@ ruleTester.run("array-bracket-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 3, column: 2 @@ -352,13 +347,13 @@ ruleTester.run("array-bracket-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 2, column: 1 @@ -371,7 +366,7 @@ ruleTester.run("array-bracket-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11, @@ -379,7 +374,7 @@ ruleTester.run("array-bracket-newline", rule, { endColumn: 12 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1, @@ -394,13 +389,13 @@ ruleTester.run("array-bracket-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -413,13 +408,13 @@ ruleTester.run("array-bracket-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -432,13 +427,13 @@ ruleTester.run("array-bracket-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 18 @@ -451,13 +446,13 @@ ruleTester.run("array-bracket-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -470,13 +465,13 @@ ruleTester.run("array-bracket-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 4, column: 1 @@ -489,13 +484,13 @@ ruleTester.run("array-bracket-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 5, column: 1 @@ -510,7 +505,7 @@ ruleTester.run("array-bracket-newline", rule, { options: ["consistent"], errors: [ { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 2, column: 2, @@ -525,7 +520,7 @@ ruleTester.run("array-bracket-newline", rule, { options: ["consistent"], errors: [ { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 2, column: 1, @@ -542,13 +537,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 2, column: 1 @@ -561,13 +556,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -580,13 +575,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -599,13 +594,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -618,13 +613,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 2, column: 2 @@ -637,13 +632,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 3, column: 2 @@ -658,13 +653,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: 2 }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 2, column: 1 @@ -677,13 +672,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: 2 }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -696,13 +691,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: 2 }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 1, column: 16 @@ -715,13 +710,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: 2 }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 2, column: 2 @@ -734,13 +729,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: 2 }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 5, column: 1 @@ -755,13 +750,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: 0 }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 1, column: 12 @@ -774,13 +769,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: 0 }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 1, column: 13 @@ -793,13 +788,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: 0 }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 1, column: 16 @@ -812,13 +807,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: 0 }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 2, column: 2 @@ -832,13 +827,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: 0 }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 3, column: 2 @@ -853,13 +848,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: null }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 2, column: 1 @@ -872,13 +867,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: null }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -891,13 +886,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: null }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -910,13 +905,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: null }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 4, column: 1 @@ -929,13 +924,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ minItems: null }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 5, column: 1 @@ -950,13 +945,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true, minItems: null }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 2, column: 1 @@ -969,13 +964,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true, minItems: null }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -988,13 +983,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true, minItems: null }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -1007,13 +1002,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true, minItems: null }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 2, column: 2 @@ -1026,13 +1021,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true, minItems: null }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 3, column: 2 @@ -1047,13 +1042,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true, minItems: 2 }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 2, column: 1 @@ -1066,13 +1061,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true, minItems: 2 }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -1085,13 +1080,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true, minItems: 2 }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 1, column: 16 @@ -1104,13 +1099,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true, minItems: 2 }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 2, column: 2 @@ -1123,13 +1118,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: true, minItems: 2 }], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 3, column: 2 @@ -1147,7 +1142,7 @@ ruleTester.run("array-bracket-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 2, column: 5 @@ -1160,13 +1155,13 @@ ruleTester.run("array-bracket-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayExpression", line: 1, column: 17 @@ -1179,7 +1174,7 @@ ruleTester.run("array-bracket-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 @@ -1194,13 +1189,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: false }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 2, column: 1 @@ -1213,13 +1208,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: false }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -1232,13 +1227,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: false }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 3, column: 1 @@ -1251,13 +1246,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: false }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 4, column: 1 @@ -1270,13 +1265,13 @@ ruleTester.run("array-bracket-newline", rule, { options: [{ multiline: false }], errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayExpression", line: 1, column: 11 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayExpression", line: 5, column: 1 @@ -1295,13 +1290,13 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayPattern", line: 1, column: 5 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayPattern", line: 1, column: 6 @@ -1315,13 +1310,13 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayPattern", line: 1, column: 5 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayPattern", line: 1, column: 7 @@ -1335,7 +1330,7 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayPattern", line: 2, column: 2 @@ -1349,7 +1344,7 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayPattern", line: 2, column: 2 @@ -1363,13 +1358,13 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayPattern", line: 1, column: 5 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayPattern", line: 1, column: 10 @@ -1383,7 +1378,7 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayPattern", line: 1, column: 5 @@ -1397,13 +1392,13 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayPattern", line: 1, column: 5 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayPattern", line: 1, column: 28 @@ -1417,13 +1412,13 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayPattern", line: 1, column: 5 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayPattern", line: 2, column: 2 @@ -1439,7 +1434,7 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayPattern", line: 2, column: 2, @@ -1455,7 +1450,7 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayPattern", line: 2, column: 1, @@ -1473,13 +1468,13 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayPattern", line: 1, column: 5 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayPattern", line: 2, column: 1 @@ -1493,13 +1488,13 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_NO_BREAK_AFTER, + messageId: "unexpectedOpeningLinebreak", type: "ArrayPattern", line: 1, column: 5 }, { - message: ERR_NO_BREAK_BEFORE, + messageId: "unexpectedClosingLinebreak", type: "ArrayPattern", line: 3, column: 1 @@ -1513,13 +1508,13 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayPattern", line: 1, column: 5 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayPattern", line: 1, column: 10 @@ -1533,13 +1528,13 @@ ruleTester.run("array-bracket-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_AFTER, + messageId: "missingOpeningLinebreak", type: "ArrayPattern", line: 1, column: 5 }, { - message: ERR_BREAK_BEFORE, + messageId: "missingClosingLinebreak", type: "ArrayPattern", line: 2, column: 2 diff --git a/tests/lib/rules/array-bracket-spacing.js b/tests/lib/rules/array-bracket-spacing.js index d8406faf38b..da3dadd6ec5 100644 --- a/tests/lib/rules/array-bracket-spacing.js +++ b/tests/lib/rules/array-bracket-spacing.js @@ -185,7 +185,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 @@ -200,13 +203,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always", { objectsInArrays: false }], errors: [ { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 }, { - message: "A space is required before ']'.", + messageId: "missingSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 36 @@ -219,13 +228,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always", { objectsInArrays: false }], errors: [ { - message: "A space is required after '['.", + messageId: "missingSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 }, { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 35 @@ -238,13 +253,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always", { objectsInArrays: false }], errors: [ { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 }, { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 50 @@ -259,13 +280,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always", { singleValue: false }], errors: [ { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 }, { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 19 @@ -278,7 +305,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always", { singleValue: false }], errors: [ { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 18 @@ -291,13 +321,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["never", { singleValue: true }], errors: [ { - message: "A space is required after '['.", + messageId: "missingSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 }, { - message: "A space is required before ']'.", + messageId: "missingSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 17 @@ -312,7 +348,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always", { arraysInArrays: false }], errors: [ { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 @@ -325,7 +364,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always", { arraysInArrays: false }], errors: [ { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 31 @@ -338,7 +380,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always", { arraysInArrays: false }], errors: [ { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 34 @@ -351,7 +396,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always", { arraysInArrays: false }], errors: [ { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 @@ -364,13 +412,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always", { arraysInArrays: false }], errors: [ { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 }, { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 35 @@ -385,13 +439,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "A space is required after '['.", + messageId: "missingSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayPattern", line: 1, column: 5 }, { - message: "A space is required before ']'.", + messageId: "missingSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayPattern", line: 1, column: 9 @@ -403,7 +463,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "A space is required after '['.", + messageId: "missingSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayPattern", line: 1, column: 5 @@ -415,13 +478,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "A space is required after '['.", + messageId: "missingSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayPattern", line: 1, column: 5 }, { - message: "A space is required before ']'.", + messageId: "missingSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayPattern", line: 1, column: 12 @@ -433,7 +502,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "A space is required before ']'.", + messageId: "missingSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayPattern", line: 1, column: 13 @@ -445,13 +517,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "A space is required after '['.", + messageId: "missingSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayPattern", line: 1, column: 5 }, { - message: "A space is required before ']'.", + messageId: "missingSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayPattern", line: 1, column: 14 @@ -463,7 +541,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "A space is required after '['.", + messageId: "missingSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayPattern", line: 1, column: 5 @@ -475,7 +556,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always", { arraysInArrays: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayPattern", line: 1, column: 5 @@ -487,7 +571,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always", { objectsInArrays: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayPattern", line: 1, column: 1 @@ -499,7 +586,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always", { objectsInArrays: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayPattern", line: 1, column: 15 @@ -513,13 +603,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["never", { arraysInArrays: true }], errors: [ { - message: "A space is required after '['.", + messageId: "missingSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 }, { - message: "A space is required before ']'.", + messageId: "missingSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 29 @@ -532,7 +628,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["never", { arraysInArrays: true }], errors: [ { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 @@ -547,7 +646,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["never", { objectsInArrays: true }], errors: [ { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 @@ -562,13 +664,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always"], errors: [ { - message: "A space is required after '['.", + messageId: "missingSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 }, { - message: "A space is required before ']'.", + messageId: "missingSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 22 @@ -581,7 +689,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always"], errors: [ { - message: "A space is required after '['.", + messageId: "missingSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 @@ -594,7 +705,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["always"], errors: [ { - message: "A space is required before ']'.", + messageId: "missingSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 23 @@ -609,13 +723,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 }, { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 24 @@ -628,7 +748,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 23 @@ -641,7 +764,10 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 @@ -654,13 +780,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 11 }, { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayExpression", line: 1, column: 13 @@ -673,13 +805,19 @@ ruleTester.run("array-bracket-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 15 }, { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayExpression", line: 1, column: 26 @@ -697,13 +835,19 @@ ruleTester.run("array-bracket-spacing", rule, { }, errors: [ { - message: "There should be no space after '['.", + messageId: "unexpectedSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayPattern", line: 1, column: 2 }, { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayPattern", line: 1, column: 9 @@ -720,13 +864,19 @@ ruleTester.run("array-bracket-spacing", rule, { }, errors: [ { - message: "A space is required after '['.", + messageId: "missingSpaceAfter", + data: { + tokenValue: "[" + }, type: "ArrayPattern", line: 1, column: 2 }, { - message: "A space is required before ']'.", + messageId: "missingSpaceBefore", + data: { + tokenValue: "]" + }, type: "ArrayPattern", line: 1, column: 7 diff --git a/tests/lib/rules/array-callback-return.js b/tests/lib/rules/array-callback-return.js index 0600bf7830e..47d74fe3994 100644 --- a/tests/lib/rules/array-callback-return.js +++ b/tests/lib/rules/array-callback-return.js @@ -82,47 +82,47 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.map(function* () {})", parserOptions: { ecmaVersion: 6 } } ], invalid: [ - { code: "Array.from(x, function() {})", errors: ["Expected to return a value in function."] }, - { code: "Array.from(x, function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, - { code: "Int32Array.from(x, function() {})", errors: ["Expected to return a value in function."] }, - { code: "Int32Array.from(x, function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, - { code: "foo.every(function() {})", errors: ["Expected to return a value in function."] }, - { code: "foo.every(function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, - { code: "foo.filter(function() {})", errors: ["Expected to return a value in function."] }, - { code: "foo.filter(function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, - { code: "foo.find(function() {})", errors: ["Expected to return a value in function."] }, - { code: "foo.find(function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, - { code: "foo.findIndex(function() {})", errors: ["Expected to return a value in function."] }, - { code: "foo.findIndex(function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, - { code: "foo.map(function() {})", errors: ["Expected to return a value in function."] }, - { code: "foo.map(function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, - { code: "foo.reduce(function() {})", errors: ["Expected to return a value in function."] }, - { code: "foo.reduce(function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, - { code: "foo.reduceRight(function() {})", errors: ["Expected to return a value in function."] }, - { code: "foo.reduceRight(function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, - { code: "foo.some(function() {})", errors: ["Expected to return a value in function."] }, - { code: "foo.some(function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, - { code: "foo.sort(function() {})", errors: ["Expected to return a value in function."] }, - { code: "foo.sort(function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, - { code: "foo.bar.baz.every(function() {})", errors: ["Expected to return a value in function."] }, - { code: "foo.bar.baz.every(function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, - { code: "foo[\"every\"](function() {})", errors: ["Expected to return a value in function."] }, - { code: "foo[\"every\"](function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, - { code: "foo[`every`](function() {})", parserOptions: { ecmaVersion: 6 }, errors: ["Expected to return a value in function."] }, - { code: "foo[`every`](function foo() {})", parserOptions: { ecmaVersion: 6 }, errors: ["Expected to return a value in function 'foo'."] }, + { code: "Array.from(x, function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "Array.from(x, function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "Int32Array.from(x, function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "Int32Array.from(x, function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "foo.every(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "foo.every(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "foo.filter(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "foo.filter(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "foo.find(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "foo.find(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "foo.findIndex(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "foo.findIndex(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "foo.map(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "foo.map(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "foo.reduce(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "foo.reduce(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "foo.reduceRight(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "foo.reduceRight(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "foo.some(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "foo.some(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "foo.sort(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "foo.sort(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "foo.bar.baz.every(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "foo.bar.baz.every(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "foo[\"every\"](function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "foo[\"every\"](function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "foo[`every`](function() {})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "foo[`every`](function foo() {})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, { code: "foo.every(() => {})", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Expected to return a value in arrow function.", column: 14 }] }, { code: "foo.every(function() { if (a) return true; })", errors: [{ message: "Expected to return a value at the end of function.", column: 11 }] }, { code: "foo.every(function cb() { if (a) return true; })", errors: [{ message: "Expected to return a value at the end of function 'cb'.", column: 20 }] }, - { code: "foo.every(function() { switch (a) { case 0: break; default: return true; } })", errors: ["Expected to return a value at the end of function."] }, - { code: "foo.every(function foo() { switch (a) { case 0: break; default: return true; } })", errors: ["Expected to return a value at the end of function 'foo'."] }, - { code: "foo.every(function() { try { bar(); } catch (err) { return true; } })", errors: ["Expected to return a value at the end of function."] }, - { code: "foo.every(function foo() { try { bar(); } catch (err) { return true; } })", errors: ["Expected to return a value at the end of function 'foo'."] }, - { code: "foo.every(function() { return; })", errors: ["Function expected a return value."] }, - { code: "foo.every(function foo() { return; })", errors: ["Function 'foo' expected a return value."] }, - { code: "foo.every(function() { if (a) return; })", errors: ["Expected to return a value at the end of function.", "Function expected a return value."] }, - { code: "foo.every(function foo() { if (a) return; })", errors: ["Expected to return a value at the end of function 'foo'.", "Function 'foo' expected a return value."] }, - { code: "foo.every(function() { if (a) return; else return; })", errors: ["Function expected a return value.", "Function expected a return value."] }, - { code: "foo.every(function foo() { if (a) return; else return; })", errors: ["Function 'foo' expected a return value.", "Function 'foo' expected a return value."] }, + { code: "foo.every(function() { switch (a) { case 0: break; default: return true; } })", errors: [{ messageId: "expectedAtEnd", data: { name: "function" } }] }, + { code: "foo.every(function foo() { switch (a) { case 0: break; default: return true; } })", errors: [{ messageId: "expectedAtEnd", data: { name: "function 'foo'" } }] }, + { code: "foo.every(function() { try { bar(); } catch (err) { return true; } })", errors: [{ messageId: "expectedAtEnd", data: { name: "function" } }] }, + { code: "foo.every(function foo() { try { bar(); } catch (err) { return true; } })", errors: [{ messageId: "expectedAtEnd", data: { name: "function 'foo'" } }] }, + { code: "foo.every(function() { return; })", errors: [{ messageId: "expectedReturnValue", data: { name: "Function" } }] }, + { code: "foo.every(function foo() { return; })", errors: [{ messageId: "expectedReturnValue", data: { name: "Function 'foo'" } }] }, + { code: "foo.every(function() { if (a) return; })", errors: ["Expected to return a value at the end of function.", { messageId: "expectedReturnValue", data: { name: "Function" } }] }, + { code: "foo.every(function foo() { if (a) return; })", errors: ["Expected to return a value at the end of function 'foo'.", { messageId: "expectedReturnValue", data: { name: "Function 'foo'" } }] }, + { code: "foo.every(function() { if (a) return; else return; })", errors: [{ messageId: "expectedReturnValue", data: { name: "Function" } }, { messageId: "expectedReturnValue", data: { name: "Function" } }] }, + { code: "foo.every(function foo() { if (a) return; else return; })", errors: [{ messageId: "expectedReturnValue", data: { name: "Function 'foo'" } }, { messageId: "expectedReturnValue", data: { name: "Function 'foo'" } }] }, { code: "foo.every(cb || function() {})", errors: ["Expected to return a value in function."] }, { code: "foo.every(cb || function foo() {})", errors: ["Expected to return a value in function 'foo'."] }, { code: "foo.every(a ? function() {} : function() {})", errors: ["Expected to return a value in function.", "Expected to return a value in function."] }, diff --git a/tests/lib/rules/array-element-newline.js b/tests/lib/rules/array-element-newline.js index c918c0ce053..f652105fc24 100644 --- a/tests/lib/rules/array-element-newline.js +++ b/tests/lib/rules/array-element-newline.js @@ -19,9 +19,6 @@ const RuleTester = require("../../../lib/testers/rule-tester"); const ruleTester = new RuleTester(); -const ERR_NO_BREAK_HERE = "There should be no linebreak here."; -const ERR_BREAK_HERE = "There should be a linebreak after this element."; - ruleTester.run("array-element-newline", rule, { valid: [ @@ -137,7 +134,7 @@ ruleTester.run("array-element-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 14, endLine: 1, @@ -151,14 +148,14 @@ ruleTester.run("array-element-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 14, endLine: 1, endColumn: 15 }, { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 17, endLine: 1, @@ -172,14 +169,14 @@ ruleTester.run("array-element-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 14, endLine: 1, endColumn: 14 }, { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 16, endLine: 1, @@ -193,14 +190,14 @@ ruleTester.run("array-element-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 14, endLine: 1, endColumn: 15 }, { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 19, endLine: 1, @@ -214,12 +211,12 @@ ruleTester.run("array-element-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 14 }, { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 3, column: 3 } @@ -231,7 +228,7 @@ ruleTester.run("array-element-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 14 } @@ -243,14 +240,14 @@ ruleTester.run("array-element-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 14, endLine: 1, endColumn: 15 }, { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 25, endLine: 1, @@ -264,14 +261,14 @@ ruleTester.run("array-element-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 31, endLine: 1, endColumn: 31 }, { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 35, endLine: 1, @@ -285,14 +282,14 @@ ruleTester.run("array-element-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 14, endLine: 1, endColumn: 14 }, { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 20, endLine: 1, @@ -306,14 +303,14 @@ ruleTester.run("array-element-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 14, endLine: 1, endColumn: 15 }, { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 19, endLine: 1, @@ -327,7 +324,7 @@ ruleTester.run("array-element-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 4, column: 3 } @@ -339,7 +336,7 @@ ruleTester.run("array-element-newline", rule, { options: ["always"], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 4, column: 4 } @@ -353,7 +350,7 @@ ruleTester.run("array-element-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 2, column: 3 } @@ -365,7 +362,7 @@ ruleTester.run("array-element-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 3, column: 2 } @@ -377,7 +374,7 @@ ruleTester.run("array-element-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 3, column: 2 } @@ -389,7 +386,7 @@ ruleTester.run("array-element-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 2, column: 18 } @@ -401,7 +398,7 @@ ruleTester.run("array-element-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 2, column: 3 } @@ -413,14 +410,14 @@ ruleTester.run("array-element-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 2, column: 3, endLine: 3, endColumn: 1 }, { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 3, column: 3, endLine: 4, @@ -434,7 +431,7 @@ ruleTester.run("array-element-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 4, column: 3 } @@ -446,7 +443,7 @@ ruleTester.run("array-element-newline", rule, { options: ["never"], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 4, column: 21 } @@ -460,7 +457,7 @@ ruleTester.run("array-element-newline", rule, { options: [{ multiline: true }], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 1, column: 14 } @@ -472,7 +469,7 @@ ruleTester.run("array-element-newline", rule, { options: [{ multiline: true }], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 4, column: 3 } @@ -484,7 +481,7 @@ ruleTester.run("array-element-newline", rule, { options: [{ multiline: true }], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 4, column: 21 } @@ -498,7 +495,7 @@ ruleTester.run("array-element-newline", rule, { options: [{ minItems: null }], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 1, column: 14 } @@ -510,12 +507,12 @@ ruleTester.run("array-element-newline", rule, { options: [{ minItems: null }], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 1, column: 14 }, { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 2, column: 3 } @@ -527,7 +524,7 @@ ruleTester.run("array-element-newline", rule, { options: [{ minItems: null }], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 4, column: 3 } @@ -541,7 +538,7 @@ ruleTester.run("array-element-newline", rule, { options: [{ minItems: 0 }], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 14 } @@ -553,12 +550,12 @@ ruleTester.run("array-element-newline", rule, { options: [{ minItems: 0 }], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 14 }, { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 17 } @@ -570,7 +567,7 @@ ruleTester.run("array-element-newline", rule, { options: [{ minItems: 0 }], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 4, column: 3 } @@ -584,7 +581,7 @@ ruleTester.run("array-element-newline", rule, { options: [{ minItems: 3 }], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 1, column: 14 } @@ -596,12 +593,12 @@ ruleTester.run("array-element-newline", rule, { options: [{ minItems: 3 }], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 14 }, { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 17 } @@ -613,7 +610,7 @@ ruleTester.run("array-element-newline", rule, { options: [{ minItems: 3 }], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 4, column: 3 } @@ -627,12 +624,12 @@ ruleTester.run("array-element-newline", rule, { options: [{ multiline: true, minItems: 3 }], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 14 }, { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 17 } @@ -644,7 +641,7 @@ ruleTester.run("array-element-newline", rule, { options: [{ multiline: true, minItems: 3 }], errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 1, column: 14 } @@ -656,7 +653,7 @@ ruleTester.run("array-element-newline", rule, { options: [{ multiline: true, minItems: 3 }], errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 4, column: 3 } @@ -674,7 +671,7 @@ ruleTester.run("array-element-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 8 } @@ -687,12 +684,12 @@ ruleTester.run("array-element-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 8 }, { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 11 } @@ -707,7 +704,7 @@ ruleTester.run("array-element-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_NO_BREAK_HERE, + messageId: "unexpectedLineBreak", line: 1, column: 8 } @@ -720,12 +717,12 @@ ruleTester.run("array-element-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 8 }, { - message: ERR_BREAK_HERE, + messageId: "missingLineBreak", line: 1, column: 11 } diff --git a/tests/lib/rules/arrow-body-style.js b/tests/lib/rules/arrow-body-style.js index b1b341093f3..14572e98a9c 100644 --- a/tests/lib/rules/arrow-body-style.js +++ b/tests/lib/rules/arrow-body-style.js @@ -54,7 +54,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Expected block statement surrounding arrow body." + messageId: "expectedBlock" } ] }, @@ -67,7 +67,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 18, type: "ArrowFunctionExpression", - message: "Expected block statement surrounding arrow body." + messageId: "expectedBlock" } ] }, @@ -80,7 +80,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -93,7 +93,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -106,7 +106,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -119,7 +119,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; put a value of `undefined` immediately after the `=>`." + messageId: "unexpectedEmptyBlock" } ] }, @@ -132,7 +132,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -145,7 +145,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`." + messageId: "unexpectedObjectBlock" } ] }, @@ -158,7 +158,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -171,7 +171,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -184,7 +184,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -197,7 +197,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -210,7 +210,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`." + messageId: "unexpectedObjectBlock" } ] }, @@ -219,7 +219,7 @@ ruleTester.run("arrow-body-style", rule, { output: null, // not fixed options: ["never"], errors: [ - { line: 1, column: 27, type: "ArrowFunctionExpression", message: "Unexpected block statement surrounding arrow body." } + { line: 1, column: 27, type: "ArrowFunctionExpression", messageId: "unexpectedOtherBlock" } ] }, { @@ -231,7 +231,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -244,7 +244,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -257,7 +257,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 18, type: "ArrowFunctionExpression", - message: "Expected block statement surrounding arrow body." + messageId: "expectedBlock" } ] }, @@ -270,7 +270,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 18, type: "ArrowFunctionExpression", - message: "Expected block statement surrounding arrow body." + messageId: "expectedBlock" } ] }, @@ -283,7 +283,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 24, type: "ArrowFunctionExpression", - message: "Expected block statement surrounding arrow body." + messageId: "expectedBlock" } ] }, @@ -296,7 +296,7 @@ ruleTester.run("arrow-body-style", rule, { output: null, options: ["never"], errors: [ - { line: 1, column: 17, type: "ArrowFunctionExpression", message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." } + { line: 1, column: 17, type: "ArrowFunctionExpression", messageId: "unexpectedSingleBlock" } ] }, { @@ -308,7 +308,7 @@ ruleTester.run("arrow-body-style", rule, { output: null, options: ["never"], errors: [ - { line: 1, column: 17, type: "ArrowFunctionExpression", message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." } + { line: 1, column: 17, type: "ArrowFunctionExpression", messageId: "unexpectedSingleBlock" } ] }, { @@ -326,7 +326,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -339,7 +339,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 50, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -352,7 +352,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 60, type: "ArrowFunctionExpression", - message: "Expected block statement surrounding arrow body." + messageId: "expectedBlock" } ] }, @@ -364,7 +364,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -376,7 +376,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -388,7 +388,7 @@ ruleTester.run("arrow-body-style", rule, { line: 1, column: 17, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -408,7 +408,7 @@ ruleTester.run("arrow-body-style", rule, { line: 2, column: 31, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`." + messageId: "unexpectedSingleBlock" } ] }, @@ -432,7 +432,7 @@ ruleTester.run("arrow-body-style", rule, { line: 2, column: 31, type: "ArrowFunctionExpression", - message: "Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`." + messageId: "unexpectedObjectBlock" } ] }, @@ -440,13 +440,13 @@ ruleTester.run("arrow-body-style", rule, { code: "var foo = () => ({foo: 1}).foo();", output: "var foo = () => {return {foo: 1}.foo()};", options: ["always"], - errors: ["Expected block statement surrounding arrow body."] + errors: [{ messageId: "expectedBlock" }] }, { code: "var foo = () => ({foo: 1}.foo());", output: "var foo = () => {return {foo: 1}.foo()};", options: ["always"], - errors: ["Expected block statement surrounding arrow body."] + errors: [{ messageId: "expectedBlock" }] } ] }); diff --git a/tests/lib/rules/arrow-parens.js b/tests/lib/rules/arrow-parens.js index 3fcd6fda606..8062d7313c1 100644 --- a/tests/lib/rules/arrow-parens.js +++ b/tests/lib/rules/arrow-parens.js @@ -71,10 +71,6 @@ const valid = [ { code: "(a): T => a", options: ["as-needed", { requireForBlockBody: true }], parser: parser("return-type") } ]; -const message = "Expected parentheses around arrow function argument."; -const asNeededMessage = "Unexpected parentheses around single function argument."; -const requireForBlockBodyMessage = "Unexpected parentheses around single function argument having a body with no curly braces"; -const requireForBlockBodyNoParensMessage = "Expected parentheses around arrow function argument having a body with curly braces."; const type = "ArrowFunctionExpression"; const invalid = [ @@ -86,7 +82,7 @@ const invalid = [ errors: [{ line: 1, column: 1, - message, + messageId: "expectedParens", type }] }, @@ -96,7 +92,7 @@ const invalid = [ errors: [{ line: 1, column: 1, - message, + messageId: "expectedParens", type }] }, @@ -106,7 +102,7 @@ const invalid = [ errors: [{ line: 1, column: 1, - message, + messageId: "expectedParens", type }] }, @@ -116,7 +112,7 @@ const invalid = [ errors: [{ line: 1, column: 8, - message, + messageId: "expectedParens", type }] }, @@ -126,7 +122,7 @@ const invalid = [ errors: [{ line: 1, column: 8, - message, + messageId: "expectedParens", type }] }, @@ -136,7 +132,7 @@ const invalid = [ errors: [{ line: 1, column: 3, - message, + messageId: "expectedParens", type }] }, @@ -147,7 +143,7 @@ const invalid = [ errors: [{ line: 1, column: 3, - message, + messageId: "expectedParens", type }] }, @@ -160,7 +156,7 @@ const invalid = [ errors: [{ line: 1, column: 1, - message: asNeededMessage, + messageId: "unexpectedParens", type }] }, @@ -172,7 +168,7 @@ const invalid = [ errors: [{ line: 1, column: 1, - message: asNeededMessage, + messageId: "unexpectedParens", type }] }, @@ -184,7 +180,7 @@ const invalid = [ errors: [{ line: 1, column: 1, - message: asNeededMessage, + messageId: "unexpectedParens", type }] }, @@ -196,7 +192,7 @@ const invalid = [ errors: [{ line: 1, column: 1, - message: asNeededMessage, + messageId: "unexpectedParens", type }] }, @@ -209,7 +205,7 @@ const invalid = [ errors: [{ line: 1, column: 1, - message: requireForBlockBodyNoParensMessage, + messageId: "expectedParensBlock", type }] }, @@ -220,7 +216,7 @@ const invalid = [ errors: [{ line: 1, column: 1, - message: requireForBlockBodyMessage, + messageId: "unexpectedParensInline", type }] }, @@ -232,7 +228,7 @@ const invalid = [ errors: [{ line: 1, column: 1, - message: requireForBlockBodyNoParensMessage, + messageId: "expectedParensBlock", type }] }, @@ -244,7 +240,7 @@ const invalid = [ errors: [{ line: 1, column: 1, - message: requireForBlockBodyMessage, + messageId: "unexpectedParensInline", type }] }, @@ -256,7 +252,7 @@ const invalid = [ errors: [{ line: 1, column: 1, - message: requireForBlockBodyMessage, + messageId: "unexpectedParensInline", type }] } diff --git a/tests/lib/rules/arrow-spacing.js b/tests/lib/rules/arrow-spacing.js index 53c6dcd5ea9..643fc70495a 100644 --- a/tests/lib/rules/arrow-spacing.js +++ b/tests/lib/rules/arrow-spacing.js @@ -91,8 +91,8 @@ const invalid = [ output: "a => a", options: [{ after: true, before: true }], errors: [ - { column: 1, line: 1, type: "Identifier" }, - { column: 4, line: 1, type: "Identifier" } + { column: 1, line: 1, type: "Identifier", messageId: "expectedBefore" }, + { column: 4, line: 1, type: "Identifier", messageId: "expectedAfter" } ] }, { @@ -100,8 +100,8 @@ const invalid = [ output: "() => {}", options: [{ after: true, before: true }], errors: [ - { column: 2, line: 1, type: "Punctuator" }, - { column: 5, line: 1, type: "Punctuator" } + { column: 2, line: 1, type: "Punctuator", messageId: "expectedBefore" }, + { column: 5, line: 1, type: "Punctuator", messageId: "expectedAfter" } ] }, { @@ -109,8 +109,8 @@ const invalid = [ output: "(a) => {}", options: [{ after: true, before: true }], errors: [ - { column: 3, line: 1, type: "Punctuator" }, - { column: 6, line: 1, type: "Punctuator" } + { column: 3, line: 1, type: "Punctuator", messageId: "expectedBefore" }, + { column: 6, line: 1, type: "Punctuator", messageId: "expectedAfter" } ] }, { @@ -118,8 +118,8 @@ const invalid = [ output: "a =>a", options: [{ after: false, before: true }], errors: [ - { column: 1, line: 1, type: "Identifier" }, - { column: 5, line: 1, type: "Identifier" } + { column: 1, line: 1, type: "Identifier", messageId: "expectedBefore" }, + { column: 5, line: 1, type: "Identifier", messageId: "unexpectedAfter" } ] }, { @@ -127,8 +127,8 @@ const invalid = [ output: "() =>{}", options: [{ after: false, before: true }], errors: [ - { column: 2, line: 1, type: "Punctuator" }, - { column: 6, line: 1, type: "Punctuator" } + { column: 2, line: 1, type: "Punctuator", messageId: "expectedBefore" }, + { column: 6, line: 1, type: "Punctuator", messageId: "unexpectedAfter" } ] }, { @@ -136,8 +136,8 @@ const invalid = [ output: "(a) =>{}", options: [{ after: false, before: true }], errors: [ - { column: 3, line: 1, type: "Punctuator" }, - { column: 7, line: 1, type: "Punctuator" } + { column: 3, line: 1, type: "Punctuator", messageId: "expectedBefore" }, + { column: 7, line: 1, type: "Punctuator", messageId: "unexpectedAfter" } ] }, { @@ -145,8 +145,8 @@ const invalid = [ output: "a =>a", options: [{ after: false, before: true }], errors: [ - { column: 1, line: 1, type: "Identifier" }, - { column: 6, line: 1, type: "Identifier" } + { column: 1, line: 1, type: "Identifier", messageId: "expectedBefore" }, + { column: 6, line: 1, type: "Identifier", messageId: "unexpectedAfter" } ] }, { @@ -154,8 +154,8 @@ const invalid = [ output: "() =>{}", options: [{ after: false, before: true }], errors: [ - { column: 2, line: 1, type: "Punctuator" }, - { column: 7, line: 1, type: "Punctuator" } + { column: 2, line: 1, type: "Punctuator", messageId: "expectedBefore" }, + { column: 7, line: 1, type: "Punctuator", messageId: "unexpectedAfter" } ] }, { @@ -163,8 +163,8 @@ const invalid = [ output: "(a) =>{}", options: [{ after: false, before: true }], errors: [ - { column: 3, line: 1, type: "Punctuator" }, - { column: 8, line: 1, type: "Punctuator" } + { column: 3, line: 1, type: "Punctuator", messageId: "expectedBefore" }, + { column: 8, line: 1, type: "Punctuator", messageId: "unexpectedAfter" } ] }, { @@ -172,8 +172,8 @@ const invalid = [ output: "a=> a", options: [{ after: true, before: false }], errors: [ - { column: 1, line: 1, type: "Identifier" }, - { column: 5, line: 1, type: "Identifier" } + { column: 1, line: 1, type: "Identifier", messageId: "unexpectedBefore" }, + { column: 5, line: 1, type: "Identifier", messageId: "expectedAfter" } ] }, { @@ -181,8 +181,8 @@ const invalid = [ output: "()=> {}", options: [{ after: true, before: false }], errors: [ - { column: 2, line: 1, type: "Punctuator" }, - { column: 6, line: 1, type: "Punctuator" } + { column: 2, line: 1, type: "Punctuator", messageId: "unexpectedBefore" }, + { column: 6, line: 1, type: "Punctuator", messageId: "expectedAfter" } ] }, { @@ -190,8 +190,8 @@ const invalid = [ output: "(a)=> {}", options: [{ after: true, before: false }], errors: [ - { column: 3, line: 1, type: "Punctuator" }, - { column: 7, line: 1, type: "Punctuator" } + { column: 3, line: 1, type: "Punctuator", messageId: "unexpectedBefore" }, + { column: 7, line: 1, type: "Punctuator", messageId: "expectedAfter" } ] }, { @@ -199,8 +199,8 @@ const invalid = [ output: "a=> a", options: [{ after: true, before: false }], errors: [ - { column: 1, line: 1, type: "Identifier" }, - { column: 6, line: 1, type: "Identifier" } + { column: 1, line: 1, type: "Identifier", messageId: "unexpectedBefore" }, + { column: 6, line: 1, type: "Identifier", messageId: "expectedAfter" } ] }, { @@ -208,8 +208,8 @@ const invalid = [ output: "()=> {}", options: [{ after: true, before: false }], errors: [ - { column: 2, line: 1, type: "Punctuator" }, - { column: 7, line: 1, type: "Punctuator" } + { column: 2, line: 1, type: "Punctuator", messageId: "unexpectedBefore" }, + { column: 7, line: 1, type: "Punctuator", messageId: "expectedAfter" } ] }, { @@ -217,8 +217,8 @@ const invalid = [ output: "(a)=> {}", options: [{ after: true, before: false }], errors: [ - { column: 3, line: 1, type: "Punctuator" }, - { column: 8, line: 1, type: "Punctuator" } + { column: 3, line: 1, type: "Punctuator", messageId: "unexpectedBefore" }, + { column: 8, line: 1, type: "Punctuator", messageId: "expectedAfter" } ] }, { @@ -226,8 +226,8 @@ const invalid = [ output: "a=>a", options: [{ after: false, before: false }], errors: [ - { column: 1, line: 1, type: "Identifier" }, - { column: 6, line: 1, type: "Identifier" } + { column: 1, line: 1, type: "Identifier", messageId: "unexpectedBefore" }, + { column: 6, line: 1, type: "Identifier", messageId: "unexpectedAfter" } ] }, { @@ -235,8 +235,8 @@ const invalid = [ output: "()=>{}", options: [{ after: false, before: false }], errors: [ - { column: 2, line: 1, type: "Punctuator" }, - { column: 7, line: 1, type: "Punctuator" } + { column: 2, line: 1, type: "Punctuator", messageId: "unexpectedBefore" }, + { column: 7, line: 1, type: "Punctuator", messageId: "unexpectedAfter" } ] }, { @@ -244,8 +244,8 @@ const invalid = [ output: "(a)=>{}", options: [{ after: false, before: false }], errors: [ - { column: 3, line: 1, type: "Punctuator" }, - { column: 8, line: 1, type: "Punctuator" } + { column: 3, line: 1, type: "Punctuator", messageId: "unexpectedBefore" }, + { column: 8, line: 1, type: "Punctuator", messageId: "unexpectedAfter" } ] }, { @@ -253,8 +253,8 @@ const invalid = [ output: "a=>a", options: [{ after: false, before: false }], errors: [ - { column: 1, line: 1, type: "Identifier" }, - { column: 8, line: 1, type: "Identifier" } + { column: 1, line: 1, type: "Identifier", messageId: "unexpectedBefore" }, + { column: 8, line: 1, type: "Identifier", messageId: "unexpectedAfter" } ] }, { @@ -262,8 +262,8 @@ const invalid = [ output: "()=>{}", options: [{ after: false, before: false }], errors: [ - { column: 2, line: 1, type: "Punctuator" }, - { column: 9, line: 1, type: "Punctuator" } + { column: 2, line: 1, type: "Punctuator", messageId: "unexpectedBefore" }, + { column: 9, line: 1, type: "Punctuator", messageId: "unexpectedAfter" } ] }, { @@ -271,8 +271,8 @@ const invalid = [ output: "(a)=>{}", options: [{ after: false, before: false }], errors: [ - { column: 3, line: 1, type: "Punctuator" }, - { column: 10, line: 1, type: "Punctuator" } + { column: 3, line: 1, type: "Punctuator", messageId: "unexpectedBefore" }, + { column: 10, line: 1, type: "Punctuator", messageId: "unexpectedAfter" } ] }, { @@ -280,7 +280,7 @@ const invalid = [ output: "(a) =>{}", options: [{ after: false }], errors: [ - { column: 1, line: 2, type: "Punctuator" } + { column: 1, line: 2, type: "Punctuator", messageId: "unexpectedAfter" } ] }, @@ -289,20 +289,20 @@ const invalid = [ code: "(a = ()=>0)=>1", output: "(a = () => 0) => 1", errors: [ - { column: 7, line: 1, message: "Missing space before =>." }, - { column: 10, line: 1, message: "Missing space after =>." }, - { column: 11, line: 1, message: "Missing space before =>." }, - { column: 14, line: 1, message: "Missing space after =>." } + { column: 7, line: 1, messageId: "expectedBefore" }, + { column: 10, line: 1, messageId: "expectedAfter" }, + { column: 11, line: 1, messageId: "expectedBefore" }, + { column: 14, line: 1, messageId: "expectedAfter" } ] }, { code: "(a = ()=>0)=>(1)", output: "(a = () => 0) => (1)", errors: [ - { column: 7, line: 1, message: "Missing space before =>." }, - { column: 10, line: 1, message: "Missing space after =>." }, - { column: 11, line: 1, message: "Missing space before =>." }, - { column: 14, line: 1, message: "Missing space after =>." } + { column: 7, line: 1, messageId: "expectedBefore" }, + { column: 10, line: 1, messageId: "expectedAfter" }, + { column: 11, line: 1, messageId: "expectedBefore" }, + { column: 14, line: 1, messageId: "expectedAfter" } ] } ]; diff --git a/tests/lib/rules/block-scoped-var.js b/tests/lib/rules/block-scoped-var.js index 75f02f0a455..14803a92255 100644 --- a/tests/lib/rules/block-scoped-var.js +++ b/tests/lib/rules/block-scoped-var.js @@ -113,57 +113,57 @@ ruleTester.run("block-scoped-var", rule, { { code: "(function () { foo(); })(); function foo() {}", parserOptions: { sourceType: "module" } } ], invalid: [ - { code: "function f(){ x; { var x; } }", errors: [{ message: "'x' used outside of binding context.", type: "Identifier" }] }, - { code: "function f(){ { var x; } x; }", errors: [{ message: "'x' used outside of binding context.", type: "Identifier" }] }, - { code: "function f() { var a; { var b = 0; } a = b; }", errors: [{ message: "'b' used outside of binding context.", type: "Identifier" }] }, - { code: "function f() { try { var a = 0; } catch (e) { var b = a; } }", errors: [{ message: "'a' used outside of binding context.", type: "Identifier" }] }, + { code: "function f(){ x; { var x; } }", errors: [{ messageId: "outOfScope", data: { name: "x" }, type: "Identifier" }] }, + { code: "function f(){ { var x; } x; }", errors: [{ messageId: "outOfScope", data: { name: "x" }, type: "Identifier" }] }, + { code: "function f() { var a; { var b = 0; } a = b; }", errors: [{ messageId: "outOfScope", data: { name: "b" }, type: "Identifier" }] }, + { code: "function f() { try { var a = 0; } catch (e) { var b = a; } }", errors: [{ messageId: "outOfScope", data: { name: "a" }, type: "Identifier" }] }, { code: "function a() { for(var b in {}) { var c = b; } c; }", - errors: [{ message: "'c' used outside of binding context.", type: "Identifier" }] + errors: [{ messageId: "outOfScope", data: { name: "c" }, type: "Identifier" }] }, { code: "function a() { for(var b of {}) { var c = b; } c; }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'c' used outside of binding context.", type: "Identifier" }] + errors: [{ messageId: "outOfScope", data: { name: "c" }, type: "Identifier" }] }, { code: "function f(){ switch(2) { case 1: var b = 2; b; break; default: b; break;} b; }", - errors: [{ message: "'b' used outside of binding context.", type: "Identifier" }] + errors: [{ messageId: "outOfScope", data: { name: "b" }, type: "Identifier" }] }, { code: "for (var a = 0;;) {} a;", - errors: [{ message: "'a' used outside of binding context.", type: "Identifier" }] + errors: [{ messageId: "outOfScope", data: { name: "a" }, type: "Identifier" }] }, { code: "for (var a in []) {} a;", - errors: [{ message: "'a' used outside of binding context.", type: "Identifier" }] + errors: [{ messageId: "outOfScope", data: { name: "a" }, type: "Identifier" }] }, { code: "for (var a of []) {} a;", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'a' used outside of binding context.", type: "Identifier" }] + errors: [{ messageId: "outOfScope", data: { name: "a" }, type: "Identifier" }] }, { code: "{ var a = 0; } a;", parserOptions: { sourceType: "module" }, - errors: [{ message: "'a' used outside of binding context.", type: "Identifier" }] + errors: [{ messageId: "outOfScope", data: { name: "a" }, type: "Identifier" }] }, { code: "if (true) { var a; } a;", - errors: [{ message: "'a' used outside of binding context.", type: "Identifier" }] + errors: [{ messageId: "outOfScope", data: { name: "a" }, type: "Identifier" }] }, { code: "if (true) { var a = 1; } else { var a = 2; }", errors: [ - { message: "'a' used outside of binding context.", type: "Identifier" }, - { message: "'a' used outside of binding context.", type: "Identifier" } + { messageId: "outOfScope", data: { name: "a" }, type: "Identifier" }, + { messageId: "outOfScope", data: { name: "a" }, type: "Identifier" } ] }, { code: "for (var i = 0;;) {} for(var i = 0;;) {}", errors: [ - { message: "'i' used outside of binding context.", type: "Identifier" }, - { message: "'i' used outside of binding context.", type: "Identifier" } + { messageId: "outOfScope", data: { name: "i" }, type: "Identifier" }, + { messageId: "outOfScope", data: { name: "i" }, type: "Identifier" } ] } ] diff --git a/tests/lib/rules/block-spacing.js b/tests/lib/rules/block-spacing.js index 4b09af6b933..2c1a4a6f932 100644 --- a/tests/lib/rules/block-spacing.js +++ b/tests/lib/rules/block-spacing.js @@ -73,100 +73,100 @@ ruleTester.run("block-spacing", rule, { output: "{ foo(); }", options: ["always"], errors: [ - { type: "BlockStatement", line: 1, column: 1, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 8, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 1, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 8, messageId: "missing", data: { location: "before", token: "}" } } ] }, { code: "{foo();}", output: "{ foo(); }", errors: [ - { type: "BlockStatement", line: 1, column: 1, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 8, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 1, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 8, messageId: "missing", data: { location: "before", token: "}" } } ] }, { code: "{ foo();}", output: "{ foo(); }", errors: [ - { type: "BlockStatement", line: 1, column: 9, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 9, messageId: "missing", data: { location: "before", token: "}" } } ] }, { code: "{foo(); }", output: "{ foo(); }", errors: [ - { type: "BlockStatement", line: 1, column: 1, message: "Requires a space after '{'." } + { type: "BlockStatement", line: 1, column: 1, messageId: "missing", data: { location: "after", token: "{" } } ] }, { code: "{\nfoo();}", output: "{\nfoo(); }", errors: [ - { type: "BlockStatement", line: 2, column: 7, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 2, column: 7, messageId: "missing", data: { location: "before", token: "}" } } ] }, { code: "{foo();\n}", output: "{ foo();\n}", errors: [ - { type: "BlockStatement", line: 1, column: 1, message: "Requires a space after '{'." } + { type: "BlockStatement", line: 1, column: 1, messageId: "missing", data: { location: "after", token: "{" } } ] }, { code: "if (a) {foo();}", output: "if (a) { foo(); }", errors: [ - { type: "BlockStatement", line: 1, column: 8, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 15, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 8, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 15, messageId: "missing", data: { location: "before", token: "}" } } ] }, { code: "if (a) {} else {foo();}", output: "if (a) {} else { foo(); }", errors: [ - { type: "BlockStatement", line: 1, column: 16, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 23, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 16, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 23, messageId: "missing", data: { location: "before", token: "}" } } ] }, { code: "switch (a) {case 0: foo();}", output: "switch (a) { case 0: foo(); }", errors: [ - { type: "SwitchStatement", line: 1, column: 12, message: "Requires a space after '{'." }, - { type: "SwitchStatement", line: 1, column: 27, message: "Requires a space before '}'." } + { type: "SwitchStatement", line: 1, column: 12, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "SwitchStatement", line: 1, column: 27, messageId: "missing", data: { location: "before", token: "}" } } ] }, { code: "while (a) {foo();}", output: "while (a) { foo(); }", errors: [ - { type: "BlockStatement", line: 1, column: 11, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 18, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 11, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 18, messageId: "missing", data: { location: "before", token: "}" } } ] }, { code: "do {foo();} while (a);", output: "do { foo(); } while (a);", errors: [ - { type: "BlockStatement", line: 1, column: 4, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 11, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 4, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 11, messageId: "missing", data: { location: "before", token: "}" } } ] }, { code: "for (;;) {foo();}", output: "for (;;) { foo(); }", errors: [ - { type: "BlockStatement", line: 1, column: 10, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 17, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 10, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 17, messageId: "missing", data: { location: "before", token: "}" } } ] }, { code: "for (var a in b) {foo();}", output: "for (var a in b) { foo(); }", errors: [ - { type: "BlockStatement", line: 1, column: 18, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 25, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 18, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 25, messageId: "missing", data: { location: "before", token: "}" } } ] }, { @@ -174,36 +174,36 @@ ruleTester.run("block-spacing", rule, { output: "for (var a of b) { foo(); }", parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "BlockStatement", line: 1, column: 18, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 25, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 18, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 25, messageId: "missing", data: { location: "before", token: "}" } } ] }, { code: "try {foo();} catch (e) {foo();} finally {foo();}", output: "try { foo(); } catch (e) { foo(); } finally { foo(); }", errors: [ - { type: "BlockStatement", line: 1, column: 5, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 12, message: "Requires a space before '}'." }, - { type: "BlockStatement", line: 1, column: 24, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 31, message: "Requires a space before '}'." }, - { type: "BlockStatement", line: 1, column: 41, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 48, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 5, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 12, messageId: "missing", data: { location: "before", token: "}" } }, + { type: "BlockStatement", line: 1, column: 24, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 31, messageId: "missing", data: { location: "before", token: "}" } }, + { type: "BlockStatement", line: 1, column: 41, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 48, messageId: "missing", data: { location: "before", token: "}" } } ] }, { code: "function foo() {bar();}", output: "function foo() { bar(); }", errors: [ - { type: "BlockStatement", line: 1, column: 16, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 23, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 16, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 23, messageId: "missing", data: { location: "before", token: "}" } } ] }, { code: "(function() {bar();});", output: "(function() { bar(); });", errors: [ - { type: "BlockStatement", line: 1, column: 13, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 20, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 13, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 20, messageId: "missing", data: { location: "before", token: "}" } } ] }, { @@ -211,8 +211,8 @@ ruleTester.run("block-spacing", rule, { output: "(() => { bar(); });", parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "BlockStatement", line: 1, column: 8, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 15, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 8, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 15, messageId: "missing", data: { location: "before", token: "}" } } ] }, { @@ -220,8 +220,8 @@ ruleTester.run("block-spacing", rule, { output: "if (a) { /* comment */ foo(); /* comment */ }", parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "BlockStatement", line: 1, column: 8, message: "Requires a space after '{'." }, - { type: "BlockStatement", line: 1, column: 43, message: "Requires a space before '}'." } + { type: "BlockStatement", line: 1, column: 8, messageId: "missing", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 43, messageId: "missing", data: { location: "before", token: "}" } } ] }, { @@ -229,7 +229,7 @@ ruleTester.run("block-spacing", rule, { output: "if (a) { //comment\n foo(); }", parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "BlockStatement", line: 1, column: 8, message: "Requires a space after '{'." } + { type: "BlockStatement", line: 1, column: 8, messageId: "missing", data: { location: "after", token: "{" } } ] }, @@ -240,8 +240,8 @@ ruleTester.run("block-spacing", rule, { output: "{foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 1, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 10, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 1, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 10, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -249,7 +249,7 @@ ruleTester.run("block-spacing", rule, { output: "{foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 1, message: "Unexpected space(s) after '{'." } + { type: "BlockStatement", line: 1, column: 1, messageId: "extra", data: { location: "after", token: "{" } } ] }, { @@ -257,7 +257,7 @@ ruleTester.run("block-spacing", rule, { output: "{foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 9, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 9, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -265,7 +265,7 @@ ruleTester.run("block-spacing", rule, { output: "{\nfoo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 2, column: 8, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 2, column: 8, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -273,7 +273,7 @@ ruleTester.run("block-spacing", rule, { output: "{foo();\n}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 1, message: "Unexpected space(s) after '{'." } + { type: "BlockStatement", line: 1, column: 1, messageId: "extra", data: { location: "after", token: "{" } } ] }, { @@ -281,8 +281,8 @@ ruleTester.run("block-spacing", rule, { output: "if (a) {foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 8, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 17, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 8, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 17, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -290,8 +290,8 @@ ruleTester.run("block-spacing", rule, { output: "if (a) {} else {foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 16, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 25, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 16, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 25, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -299,8 +299,8 @@ ruleTester.run("block-spacing", rule, { output: "switch (a) {case 0: foo();}", options: ["never"], errors: [ - { type: "SwitchStatement", line: 1, column: 12, message: "Unexpected space(s) after '{'." }, - { type: "SwitchStatement", line: 1, column: 29, message: "Unexpected space(s) before '}'." } + { type: "SwitchStatement", line: 1, column: 12, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "SwitchStatement", line: 1, column: 29, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -308,8 +308,8 @@ ruleTester.run("block-spacing", rule, { output: "while (a) {foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 11, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 20, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 11, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 20, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -317,8 +317,8 @@ ruleTester.run("block-spacing", rule, { output: "do {foo();} while (a);", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 4, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 13, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 4, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 13, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -326,8 +326,8 @@ ruleTester.run("block-spacing", rule, { output: "for (;;) {foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 10, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 19, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 10, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 19, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -335,8 +335,8 @@ ruleTester.run("block-spacing", rule, { output: "for (var a in b) {foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 18, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 27, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 18, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 27, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -345,8 +345,8 @@ ruleTester.run("block-spacing", rule, { options: ["never"], parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "BlockStatement", line: 1, column: 18, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 27, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 18, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 27, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -354,12 +354,12 @@ ruleTester.run("block-spacing", rule, { output: "try {foo();} catch (e) {foo();} finally {foo();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 5, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 14, message: "Unexpected space(s) before '}'." }, - { type: "BlockStatement", line: 1, column: 26, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 35, message: "Unexpected space(s) before '}'." }, - { type: "BlockStatement", line: 1, column: 45, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 54, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 5, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 14, messageId: "extra", data: { location: "before", token: "}" } }, + { type: "BlockStatement", line: 1, column: 26, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 35, messageId: "extra", data: { location: "before", token: "}" } }, + { type: "BlockStatement", line: 1, column: 45, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 54, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -367,8 +367,8 @@ ruleTester.run("block-spacing", rule, { output: "function foo() {bar();}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 16, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 25, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 16, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 25, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -376,8 +376,8 @@ ruleTester.run("block-spacing", rule, { output: "(function() {bar();});", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 13, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 22, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 13, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 22, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -386,8 +386,8 @@ ruleTester.run("block-spacing", rule, { options: ["never"], parserOptions: { ecmaVersion: 6 }, errors: [ - { type: "BlockStatement", line: 1, column: 8, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 17, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 8, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 17, messageId: "extra", data: { location: "before", token: "}" } } ] }, { @@ -395,8 +395,8 @@ ruleTester.run("block-spacing", rule, { output: "if (a) {/* comment */ foo(); /* comment */}", options: ["never"], errors: [ - { type: "BlockStatement", line: 1, column: 8, message: "Unexpected space(s) after '{'." }, - { type: "BlockStatement", line: 1, column: 45, message: "Unexpected space(s) before '}'." } + { type: "BlockStatement", line: 1, column: 8, messageId: "extra", data: { location: "after", token: "{" } }, + { type: "BlockStatement", line: 1, column: 45, messageId: "extra", data: { location: "before", token: "}" } } ] } ] diff --git a/tests/lib/rules/brace-style.js b/tests/lib/rules/brace-style.js index 0b93f9c48b2..33b186731ae 100644 --- a/tests/lib/rules/brace-style.js +++ b/tests/lib/rules/brace-style.js @@ -11,12 +11,6 @@ const rule = require("../../../lib/rules/brace-style"), RuleTester = require("../../../lib/testers/rule-tester"); -const OPEN_MESSAGE = "Opening curly brace does not appear on the same line as controlling statement.", - OPEN_MESSAGE_ALLMAN = "Opening curly brace appears on the same line as controlling statement.", - BODY_MESSAGE = "Statement inside of curly braces should be on next line.", - CLOSE_MESSAGE = "Closing curly brace does not appear on the same line as the subsequent block.", - CLOSE_MESSAGE_SINGLE = "Closing curly brace should be on the same line as opening curly brace or on the line after the previous block.", - CLOSE_MESSAGE_STROUSTRUP_ALLMAN = "Closing curly brace appears on the same line as the subsequent block."; //------------------------------------------------------------------------------ // Tests @@ -201,143 +195,143 @@ ruleTester.run("brace-style", rule, { { code: "if (f) {\nbar;\n}\nelse\nbaz;", output: "if (f) {\nbar;\n} else\nbaz;", - errors: [{ message: CLOSE_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineClose", type: "Punctuator" }] }, { code: "var foo = () => { return; }", output: "var foo = () => {\n return; \n}", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: BODY_MESSAGE, type: "Punctuator" }, { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { code: "function foo() { return; }", output: "function foo() {\n return; \n}", - errors: [{ message: BODY_MESSAGE, type: "Punctuator" }, { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { code: "function foo() \n { \n return; }", output: "function foo() { \n return; \n}", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }, { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { code: "!function foo() \n { \n return; }", output: "!function foo() { \n return; \n}", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }, { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { code: "if (foo) \n { \n bar(); }", output: "if (foo) { \n bar(); \n}", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }, { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { code: "if (a) { \nb();\n } else \n { c(); }", output: "if (a) { \nb();\n } else {\n c(); \n}", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }, { message: BODY_MESSAGE, type: "Punctuator" }, { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { code: "while (foo) \n { \n bar(); }", output: "while (foo) { \n bar(); \n}", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }, { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { code: "for (;;) \n { \n bar(); }", output: "for (;;) { \n bar(); \n}", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }, { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { code: "with (foo) \n { \n bar(); }", output: "with (foo) { \n bar(); \n}", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }, { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { code: "switch (foo) \n { \n case \"bar\": break; }", output: "switch (foo) { \n case \"bar\": break; \n}", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }, { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { code: "switch (foo) \n { }", output: "switch (foo) { }", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "try \n { \n bar(); \n } catch (e) {}", output: "try { \n bar(); \n } catch (e) {}", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "try { \n bar(); \n } catch (e) \n {}", output: "try { \n bar(); \n } catch (e) {}", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "do \n { \n bar(); \n} while (true)", output: "do { \n bar(); \n} while (true)", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "for (foo in bar) \n { \n baz(); \n }", output: "for (foo in bar) { \n baz(); \n }", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "for (foo of bar) \n { \n baz(); \n }", output: "for (foo of bar) { \n baz(); \n }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "try { \n bar(); \n }\ncatch (e) {\n}", output: "try { \n bar(); \n } catch (e) {\n}", - errors: [{ message: CLOSE_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineClose", type: "Punctuator" }] }, { code: "try { \n bar(); \n } catch (e) {\n}\n finally {\n}", output: "try { \n bar(); \n } catch (e) {\n} finally {\n}", - errors: [{ message: CLOSE_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineClose", type: "Punctuator" }] }, { code: "if (a) { \nb();\n } \n else { \nc();\n }", output: "if (a) { \nb();\n } else { \nc();\n }", - errors: [{ message: CLOSE_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineClose", type: "Punctuator" }] }, { code: "try { \n bar(); \n }\ncatch (e) {\n} finally {\n}", output: "try { \n bar(); \n }\ncatch (e) {\n}\n finally {\n}", options: ["stroustrup"], - errors: [{ message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }] + errors: [{ messageId: "sameLineClose", type: "Punctuator" }] }, { code: "try { \n bar(); \n } catch (e) {\n}\n finally {\n}", output: "try { \n bar(); \n }\n catch (e) {\n}\n finally {\n}", options: ["stroustrup"], - errors: [{ message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }] + errors: [{ messageId: "sameLineClose", type: "Punctuator" }] }, { code: "if (a) { \nb();\n } else { \nc();\n }", output: "if (a) { \nb();\n }\n else { \nc();\n }", options: ["stroustrup"], - errors: [{ message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }] + errors: [{ messageId: "sameLineClose", type: "Punctuator" }] }, { code: "if (foo) {\nbaz();\n} else if (bar) {\nbaz();\n}\nelse {\nqux();\n}", output: "if (foo) {\nbaz();\n}\n else if (bar) {\nbaz();\n}\nelse {\nqux();\n}", options: ["stroustrup"], - errors: [{ message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }] + errors: [{ messageId: "sameLineClose", type: "Punctuator" }] }, { code: "if (foo) {\npoop();\n} \nelse if (bar) {\nbaz();\n} else if (thing) {\nboom();\n}\nelse {\nqux();\n}", output: "if (foo) {\npoop();\n} \nelse if (bar) {\nbaz();\n}\n else if (thing) {\nboom();\n}\nelse {\nqux();\n}", options: ["stroustrup"], - errors: [{ message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }] + errors: [{ messageId: "sameLineClose", type: "Punctuator" }] }, { code: "try { \n bar(); \n }\n catch (e) {\n}\n finally {\n}", output: "try \n{ \n bar(); \n }\n catch (e) \n{\n}\n finally \n{\n}", options: ["allman"], errors: [ - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator", line: 1 }, - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator", line: 4 }, - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator", line: 6 } + { messageId: "sameLineOpen", type: "Punctuator", line: 1 }, + { messageId: "sameLineOpen", type: "Punctuator", line: 4 }, + { messageId: "sameLineOpen", type: "Punctuator", line: 6 } ] }, { @@ -345,9 +339,9 @@ ruleTester.run("brace-style", rule, { output: "switch(x) \n{\n case 1: \nbar(); \n}\n ", options: ["allman"], errors: [ - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator", line: 1 }, - { message: BODY_MESSAGE, type: "Punctuator", line: 1 }, - { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator", line: 2 } + { messageId: "sameLineOpen", type: "Punctuator", line: 1 }, + { messageId: "blockSameLine", type: "Punctuator", line: 1 }, + { messageId: "singleLineClose", type: "Punctuator", line: 2 } ] }, { @@ -355,9 +349,9 @@ ruleTester.run("brace-style", rule, { output: "if (a) \n{ \nb();\n }\n else \n{ \nc();\n }", options: ["allman"], errors: [ - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" }, - { message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }, - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" } + { messageId: "sameLineOpen", type: "Punctuator" }, + { messageId: "sameLineClose", type: "Punctuator" }, + { messageId: "sameLineOpen", type: "Punctuator" } ] }, { @@ -365,10 +359,10 @@ ruleTester.run("brace-style", rule, { output: "if (foo) \n{\nbaz();\n}\n else if (bar) \n{\nbaz();\n}\nelse \n{\nqux();\n}", options: ["allman"], errors: [ - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" }, - { message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }, - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" }, - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" } + { messageId: "sameLineOpen", type: "Punctuator" }, + { messageId: "sameLineClose", type: "Punctuator" }, + { messageId: "sameLineOpen", type: "Punctuator" }, + { messageId: "sameLineOpen", type: "Punctuator" } ] }, { @@ -376,11 +370,11 @@ ruleTester.run("brace-style", rule, { output: "if (foo)\n{\n poop();\n} \nelse if (bar) \n{\nbaz();\n}\n else if (thing) \n{\nboom();\n}\nelse \n{\nqux();\n}", options: ["allman"], errors: [ - { message: BODY_MESSAGE, type: "Punctuator" }, - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" }, - { message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }, - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" }, - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" } + { messageId: "blockSameLine", type: "Punctuator" }, + { messageId: "sameLineOpen", type: "Punctuator" }, + { messageId: "sameLineClose", type: "Punctuator" }, + { messageId: "sameLineOpen", type: "Punctuator" }, + { messageId: "sameLineOpen", type: "Punctuator" } ] }, { @@ -388,7 +382,7 @@ ruleTester.run("brace-style", rule, { output: "if (foo)\n{\n bar(); \n}", options: ["allman"], errors: [ - { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" } + { messageId: "singleLineClose", type: "Punctuator" } ] }, { @@ -396,7 +390,7 @@ ruleTester.run("brace-style", rule, { output: "try\n{\n somethingRisky();\n}\n catch (e)\n{\n handleError()\n}", options: ["allman"], errors: [ - { message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" } + { messageId: "sameLineClose", type: "Punctuator" } ] }, @@ -405,150 +399,150 @@ ruleTester.run("brace-style", rule, { code: "function foo() { return; \n}", output: "function foo() {\n return; \n}", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: BODY_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "blockSameLine", type: "Punctuator" }] }, { code: "function foo() { a(); b(); return; \n}", output: "function foo() {\n a(); b(); return; \n}", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: BODY_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "blockSameLine", type: "Punctuator" }] }, { code: "function foo() { \n return; }", output: "function foo() { \n return; \n}", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "singleLineClose", type: "Punctuator" }] }, { code: "function foo() {\na();\nb();\nreturn; }", output: "function foo() {\na();\nb();\nreturn; \n}", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "singleLineClose", type: "Punctuator" }] }, { code: "!function foo() { \n return; }", output: "!function foo() { \n return; \n}", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "singleLineClose", type: "Punctuator" }] }, { code: "if (a) { b();\n } else { c(); }", output: "if (a) {\n b();\n } else { c(); }", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: BODY_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "blockSameLine", type: "Punctuator" }] }, { code: "if (a) { b(); }\nelse { c(); }", output: "if (a) { b(); } else { c(); }", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: CLOSE_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineClose", type: "Punctuator" }] }, { code: "while (foo) { \n bar(); }", output: "while (foo) { \n bar(); \n}", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "singleLineClose", type: "Punctuator" }] }, { code: "for (;;) { bar(); \n }", output: "for (;;) {\n bar(); \n }", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: BODY_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "blockSameLine", type: "Punctuator" }] }, { code: "with (foo) { bar(); \n }", output: "with (foo) {\n bar(); \n }", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: BODY_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "blockSameLine", type: "Punctuator" }] }, { code: "switch (foo) \n { \n case \"bar\": break; }", output: "switch (foo) { \n case \"bar\": break; \n}", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }, { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { code: "switch (foo) \n { }", output: "switch (foo) { }", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "try { bar(); }\ncatch (e) { baz(); }", output: "try { bar(); } catch (e) { baz(); }", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: CLOSE_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineClose", type: "Punctuator" }] }, { code: "try \n { \n bar(); \n } catch (e) {}", output: "try { \n bar(); \n } catch (e) {}", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "try { \n bar(); \n } catch (e) \n {}", output: "try { \n bar(); \n } catch (e) {}", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "do \n { \n bar(); \n} while (true)", output: "do { \n bar(); \n} while (true)", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "for (foo in bar) \n { \n baz(); \n }", output: "for (foo in bar) { \n baz(); \n }", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "try { \n bar(); \n }\ncatch (e) {\n}", output: "try { \n bar(); \n } catch (e) {\n}", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: CLOSE_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineClose", type: "Punctuator" }] }, { code: "try { \n bar(); \n } catch (e) {\n}\n finally {\n}", output: "try { \n bar(); \n } catch (e) {\n} finally {\n}", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: CLOSE_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineClose", type: "Punctuator" }] }, { code: "if (a) { \nb();\n } \n else { \nc();\n }", output: "if (a) { \nb();\n } else { \nc();\n }", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: CLOSE_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineClose", type: "Punctuator" }] }, { code: "try { \n bar(); \n }\ncatch (e) {\n} finally {\n}", output: "try { \n bar(); \n }\ncatch (e) {\n}\n finally {\n}", options: ["stroustrup", { allowSingleLine: true }], - errors: [{ message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }] + errors: [{ messageId: "sameLineClose", type: "Punctuator" }] }, { code: "try { \n bar(); \n } catch (e) {\n}\n finally {\n}", output: "try { \n bar(); \n }\n catch (e) {\n}\n finally {\n}", options: ["stroustrup", { allowSingleLine: true }], - errors: [{ message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }] + errors: [{ messageId: "sameLineClose", type: "Punctuator" }] }, { code: "if (a) { \nb();\n } else { \nc();\n }", output: "if (a) { \nb();\n }\n else { \nc();\n }", options: ["stroustrup", { allowSingleLine: true }], - errors: [{ message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }] + errors: [{ messageId: "sameLineClose", type: "Punctuator" }] }, { code: "if (foo)\n{ poop();\n} \nelse if (bar) {\nbaz();\n} else if (thing) {\nboom();\n}\nelse {\nqux();\n}", output: "if (foo)\n{\n poop();\n} \nelse if (bar) \n{\nbaz();\n}\n else if (thing) \n{\nboom();\n}\nelse \n{\nqux();\n}", options: ["allman", { allowSingleLine: true }], errors: [ - { message: BODY_MESSAGE, type: "Punctuator" }, - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" }, - { message: CLOSE_MESSAGE_STROUSTRUP_ALLMAN, type: "Punctuator" }, - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" }, - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" } + { messageId: "blockSameLine", type: "Punctuator" }, + { messageId: "sameLineOpen", type: "Punctuator" }, + { messageId: "sameLineClose", type: "Punctuator" }, + { messageId: "sameLineOpen", type: "Punctuator" }, + { messageId: "sameLineOpen", type: "Punctuator" } ] }, @@ -556,80 +550,80 @@ ruleTester.run("brace-style", rule, { { code: "if (foo) // comment \n{\nbar();\n}", output: null, - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, // https://github.com/eslint/eslint/issues/7493 { code: "if (foo) {\n bar\n.baz }", output: "if (foo) {\n bar\n.baz \n}", - errors: [{ message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "singleLineClose", type: "Punctuator" }] }, { code: "if (foo)\n{\n bar\n.baz }", output: "if (foo)\n{\n bar\n.baz \n}", options: ["allman"], - errors: [{ message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "singleLineClose", type: "Punctuator" }] }, { code: "if (foo) { bar\n.baz }", output: "if (foo) {\n bar\n.baz \n}", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: BODY_MESSAGE, type: "Punctuator" }, { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "blockSameLine", type: "Punctuator" }, { messageId: "singleLineClose", type: "Punctuator" }] }, { code: "if (foo) { bar\n.baz }", output: "if (foo) \n{\n bar\n.baz \n}", options: ["allman", { allowSingleLine: true }], errors: [ - { message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" }, - { message: BODY_MESSAGE, type: "Punctuator" }, - { message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" } + { messageId: "sameLineOpen", type: "Punctuator" }, + { messageId: "blockSameLine", type: "Punctuator" }, + { messageId: "singleLineClose", type: "Punctuator" } ] }, { code: "switch (x) {\n case 1: foo() }", output: "switch (x) {\n case 1: foo() \n}", options: ["1tbs", { allowSingleLine: true }], - errors: [{ message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "singleLineClose", type: "Punctuator" }] }, { code: "class Foo\n{\n}", output: "class Foo {\n}", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "(class\n{\n})", output: "(class {\n})", - errors: [{ message: OPEN_MESSAGE, type: "Punctuator" }] + errors: [{ messageId: "nextLineOpen", type: "Punctuator" }] }, { code: "class Foo{\n}", output: "class Foo\n{\n}", options: ["allman"], - errors: [{ message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" }] + errors: [{ messageId: "sameLineOpen", type: "Punctuator" }] }, { code: "(class {\n})", output: "(class \n{\n})", options: ["allman"], - errors: [{ message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" }] + errors: [{ messageId: "sameLineOpen", type: "Punctuator" }] }, { code: "class Foo {\nbar() {\n}}", output: "class Foo {\nbar() {\n}\n}", - errors: [{ message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "singleLineClose", type: "Punctuator" }] }, { code: "(class Foo {\nbar() {\n}})", output: "(class Foo {\nbar() {\n}\n})", - errors: [{ message: CLOSE_MESSAGE_SINGLE, type: "Punctuator" }] + errors: [{ messageId: "singleLineClose", type: "Punctuator" }] }, { code: "class\nFoo{}", output: "class\nFoo\n{}", options: ["allman"], - errors: [{ message: OPEN_MESSAGE_ALLMAN, type: "Punctuator" }] + errors: [{ messageId: "sameLineOpen", type: "Punctuator" }] }, // https://github.com/eslint/eslint/issues/7621 @@ -651,8 +645,8 @@ ruleTester.run("brace-style", rule, { } `, errors: [ - { message: OPEN_MESSAGE, type: "Punctuator" }, - { message: CLOSE_MESSAGE, type: "Punctuator" } + { messageId: "nextLineOpen", type: "Punctuator" }, + { messageId: "nextLineClose", type: "Punctuator" } ] } ] diff --git a/tests/lib/rules/callback-return.js b/tests/lib/rules/callback-return.js index 29f98136b41..1e178915d0a 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 81251ff2c5b..78921bc508b 100644 --- a/tests/lib/rules/camelcase.js +++ b/tests/lib/rules/camelcase.js @@ -173,7 +173,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" } ] @@ -182,7 +183,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" } ] @@ -191,7 +193,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" } ] @@ -200,7 +203,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" } ] @@ -209,7 +213,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" } ] @@ -218,7 +223,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" } ] @@ -227,7 +233,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" } ] @@ -236,7 +243,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" } ] @@ -245,7 +253,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" } ] @@ -254,7 +263,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" } ] @@ -264,7 +274,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" } ] @@ -274,7 +285,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" } ] @@ -284,7 +296,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" } ] @@ -294,7 +307,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" } ] @@ -314,7 +328,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" } ] @@ -324,7 +339,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" } ] @@ -334,7 +350,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" } ] @@ -344,7 +361,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" } ] @@ -354,7 +372,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" } ] @@ -364,7 +383,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" } ] @@ -374,7 +394,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" } ] @@ -384,7 +405,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" } ] @@ -394,7 +416,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 ae798a8d5aa..eda2f5234ec 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: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -298,7 +290,7 @@ ruleTester.run("capitalized-comments", rule, { code: "// lowercase", output: "// Lowercase", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -307,7 +299,7 @@ ruleTester.run("capitalized-comments", rule, { code: "/*lowercase */", output: "/*Lowercase */", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -316,7 +308,7 @@ ruleTester.run("capitalized-comments", rule, { code: "/* lowercase */", output: "/* Lowercase */", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -325,7 +317,7 @@ ruleTester.run("capitalized-comments", rule, { code: "/** lowercase */", output: "/** Lowercase */", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -334,7 +326,7 @@ ruleTester.run("capitalized-comments", rule, { code: "/*\nlowercase */", output: "/*\nLowercase */", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -343,7 +335,7 @@ ruleTester.run("capitalized-comments", rule, { code: "/**\nlowercase */", output: "/**\nLowercase */", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -352,7 +344,7 @@ ruleTester.run("capitalized-comments", rule, { code: "//über", output: "//Über", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -361,7 +353,7 @@ ruleTester.run("capitalized-comments", rule, { code: "//π", output: "//Π", errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -382,7 +374,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//Lowercase", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -392,7 +384,7 @@ ruleTester.run("capitalized-comments", rule, { output: "// Lowercase", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -402,7 +394,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*Lowercase */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -412,7 +404,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/* Lowercase */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -422,7 +414,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/** Lowercase */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -432,7 +424,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/**\nLowercase */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -442,7 +434,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//Über", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -452,7 +444,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//Π", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -474,7 +466,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//uppercase", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "unexpectedUppercaseComment", line: 1, column: 1 }] @@ -484,7 +476,7 @@ ruleTester.run("capitalized-comments", rule, { output: "// uppercase", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "unexpectedUppercaseComment", line: 1, column: 1 }] @@ -494,7 +486,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*uppercase */", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "unexpectedUppercaseComment", line: 1, column: 1 }] @@ -504,7 +496,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/* uppercase */", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "unexpectedUppercaseComment", line: 1, column: 1 }] @@ -514,7 +506,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\nuppercase */", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "unexpectedUppercaseComment", line: 1, column: 1 }] @@ -524,7 +516,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//über", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "unexpectedUppercaseComment", line: 1, column: 1 }] @@ -534,7 +526,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//π", options: ["never"], errors: [{ - message: NEVER_MESSAGE, + messageId: "unexpectedUppercaseComment", 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: "unexpectedUppercaseComment", line: 1, column: 1 }] @@ -556,7 +548,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//* Jscs: enable", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -566,7 +558,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//* Jscs:disable", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -576,7 +568,7 @@ ruleTester.run("capitalized-comments", rule, { output: "//* Eslint-disable-line", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -636,7 +628,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\n * Jscs: enable */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -686,7 +678,7 @@ ruleTester.run("capitalized-comments", rule, { output: "/*\n * Exported myVar */", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -698,7 +690,7 @@ ruleTester.run("capitalized-comments", rule, { output: "foo(/* Invalid */a);", options: ["always"], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedUppercaseComment", 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: "unexpectedUppercaseComment", 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: "unexpectedUppercaseComment", 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: "unexpectedUppercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedUppercaseComment", line: 1, column: 1 }] @@ -834,7 +826,7 @@ ruleTester.run("capitalized-comments", rule, { ].join("\n"), options: ["always", { ignoreConsecutiveComments: true }], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 4, column: 1 }] @@ -852,7 +844,7 @@ ruleTester.run("capitalized-comments", rule, { ].join("\n"), options: ["always", { ignoreConsecutiveComments: true }], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", line: 1, column: 1 }] @@ -868,7 +860,7 @@ ruleTester.run("capitalized-comments", rule, { ].join("\n"), options: ["never", { ignoreConsecutiveComments: true }], errors: [{ - message: NEVER_MESSAGE, + messageId: "unexpectedUppercaseComment", line: 1, column: 1 }] @@ -886,7 +878,7 @@ ruleTester.run("capitalized-comments", rule, { ].join("\n"), options: ["always", { ignoreConsecutiveComments: false }], errors: [{ - message: ALWAYS_MESSAGE, + messageId: "unexpectedLowercaseComment", 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: "unexpectedLowercaseComment", 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: "unexpectedUppercaseComment", 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 fbddd027013..369f04a64f9 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 1a4f80a7725..29027e9496a 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 f166360d636..d5c8ff0ec84 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 d8bf438c7a4..2bed575bf86 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 //------------------------------------------------------------------------------ @@ -245,7 +241,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: "expectedCommaLast", type: "Property" }] }, @@ -253,7 +249,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: "expectedCommaLast", type: "Property" }] }, @@ -261,7 +257,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: "unexpectedLineBeforeAndAfterComma", type: "VariableDeclarator" }] }, @@ -269,7 +265,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: "unexpectedLineBeforeAndAfterComma", type: "VariableDeclarator" }] }, @@ -277,7 +273,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: "unexpectedLineBeforeAndAfterComma", type: "VariableDeclarator" }] }, @@ -289,13 +285,13 @@ ruleTester.run("comma-style", rule, { NewExpression: false } }], - errors: [{ message: BAD_LN_BRK_MSG }] + errors: [{ messageId: "unexpectedLineBeforeAndAfterComma" }] }, { code: "var foo = 1\n,bar = 2;", output: "var foo = 1,\nbar = 2;", errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "VariableDeclarator" }] }, @@ -303,7 +299,7 @@ ruleTester.run("comma-style", rule, { code: "f([1,2\n,3]);", output: "f([1,2,\n3]);", errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "Literal" }] }, @@ -311,7 +307,7 @@ ruleTester.run("comma-style", rule, { code: "f([1,2\n,]);", output: "f([1,2,\n]);", errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "Punctuator" }] }, @@ -319,7 +315,7 @@ ruleTester.run("comma-style", rule, { code: "f([,2\n,3]);", output: "f([,2,\n3]);", errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "Literal" }] }, @@ -327,7 +323,7 @@ ruleTester.run("comma-style", rule, { code: "var foo = ['apples'\n, 'oranges'];", output: "var foo = ['apples',\n 'oranges'];", errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "Literal" }] }, @@ -343,7 +339,7 @@ ruleTester.run("comma-style", rule, { ecmaVersion: 6 }, errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "Identifier" }] }, @@ -356,7 +352,7 @@ ruleTester.run("comma-style", rule, { } }], errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "Literal" }] }, @@ -369,7 +365,7 @@ ruleTester.run("comma-style", rule, { } }], errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "Identifier" }] }, @@ -386,7 +382,7 @@ ruleTester.run("comma-style", rule, { sourceType: "module" }, errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "Identifier" }] }, @@ -402,7 +398,7 @@ ruleTester.run("comma-style", rule, { ecmaVersion: 6 }, errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "Identifier" }] }, @@ -418,7 +414,7 @@ ruleTester.run("comma-style", rule, { ecmaVersion: 6 }, errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "Identifier" }] }, @@ -434,7 +430,7 @@ ruleTester.run("comma-style", rule, { ecmaVersion: 6 }, errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "Identifier" }] }, @@ -451,7 +447,7 @@ ruleTester.run("comma-style", rule, { sourceType: "module" }, errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "ImportSpecifier" }] }, @@ -467,7 +463,7 @@ ruleTester.run("comma-style", rule, { ecmaVersion: 6 }, errors: [{ - message: LAST_MSG, + messageId: "expectedCommaLast", type: "Property" }] }, @@ -476,7 +472,7 @@ ruleTester.run("comma-style", rule, { output: "var foo = 1\n,bar = 2;", options: ["first"], errors: [{ - message: FIRST_MSG, + messageId: "expectedCommaFirst", type: "VariableDeclarator" }] }, @@ -485,7 +481,7 @@ ruleTester.run("comma-style", rule, { output: "f([1\n,2,3]);", options: ["first"], errors: [{ - message: FIRST_MSG, + messageId: "expectedCommaFirst", type: "Literal" }] }, @@ -494,7 +490,7 @@ ruleTester.run("comma-style", rule, { output: "var foo = ['apples' \n ,'oranges'];", options: ["first"], errors: [{ - message: FIRST_MSG, + messageId: "expectedCommaFirst", type: "Literal" }] }, @@ -503,7 +499,7 @@ ruleTester.run("comma-style", rule, { output: "var foo = {'a': 1 \n ,'b': 2\n ,'c': 3};", options: ["first"], errors: [{ - message: FIRST_MSG, + messageId: "expectedCommaFirst", type: "Property" }] }, @@ -512,7 +508,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: "expectedCommaFirst", type: "Literal" }] }, @@ -521,7 +517,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: "expectedCommaFirst", type: "Property" }] }, @@ -530,7 +526,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: "expectedCommaFirst", type: "VariableDeclarator" }] }, @@ -539,7 +535,7 @@ ruleTester.run("comma-style", rule, { output: "var a = 'a'\n,arr = [1,\n2];", options: ["first", { exceptions: { ArrayExpression: true } }], errors: [{ - message: FIRST_MSG, + messageId: "expectedCommaFirst", type: "VariableDeclarator" }] }, @@ -548,7 +544,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: "expectedCommaFirst", type: "Property" }] }, @@ -557,7 +553,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: "expectedCommaFirst", type: "ObjectExpression" }] }, @@ -566,7 +562,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: "expectedCommaFirst", type: "Literal" }] }, @@ -575,7 +571,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: "expectedCommaFirst", type: "Property" }] }, @@ -587,20 +583,20 @@ ruleTester.run("comma-style", rule, { NewExpression: false } }], - errors: [{ message: FIRST_MSG }] + errors: [{ messageId: "expectedCommaFirst" }] }, { code: "var foo = [\n(bar\n)\n,\nbaz\n];", output: "var foo = [\n(bar\n),\nbaz\n];", errors: [{ - message: BAD_LN_BRK_MSG, + messageId: "unexpectedLineBeforeAndAfterComma", type: "Identifier" }] }, { code: "[(foo),\n,\nbar]", output: "[(foo),,\nbar]", - errors: [{ message: BAD_LN_BRK_MSG }] + errors: [{ messageId: "unexpectedLineBeforeAndAfterComma" }] }, { code: "new Foo(a\n,b);", @@ -610,7 +606,7 @@ ruleTester.run("comma-style", rule, { NewExpression: false } }], - errors: [{ message: LAST_MSG }] + errors: [{ messageId: "expectedCommaLast" }] } ] }); diff --git a/tests/lib/rules/complexity.js b/tests/lib/rules/complexity.js index 9e2b5d92b5d..159d27c8c26 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 eadc7eabed4..b5a4825286e 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: "missingSpaceBefore", + 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: "missingSpaceAfter", + 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: "unexpectedSpaceAfter", + 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: "unexpectedSpaceBefore", + 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: "unexpectedSpaceAfter", + data: { tokenValue: "[" }, type: "MemberExpression", column: 4, line: 1 }, { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + 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: "unexpectedSpaceBefore", + 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: "unexpectedSpaceAfter", + 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: "missingSpaceAfter", + data: { tokenValue: "[" }, type: "MemberExpression", column: 14, line: 1 }, { - message: "A space is required before ']'.", + messageId: "missingSpaceBefore", + 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: "missingSpaceAfter", + data: { tokenValue: "[" }, type: "Property", column: 10, line: 1 }, { - message: "A space is required before ']'.", + messageId: "missingSpaceBefore", + 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: "missingSpaceAfter", + 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: "missingSpaceBefore", + 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: "unexpectedSpaceAfter", + data: { tokenValue: "[" }, type: "Property", column: 10, line: 1 }, { - message: "There should be no space before ']'.", + messageId: "unexpectedSpaceBefore", + 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: "unexpectedSpaceBefore", + 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: "unexpectedSpaceAfter", + 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: "unexpectedSpaceAfter", + 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 2bf4a0d0a1c..15c205500b3 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 782e302d214..7a37dd999e7 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: "aliasNotAssignedToThis", data: { name: "self" }, type: "VariableDeclarator" }] }, + { code: "var self", options: ["self"], errors: [{ messageId: "aliasNotAssignedToThis", data: { name: "self" }, type: "VariableDeclarator" }] }, + { code: "var self; self = 42", options: ["self"], errors: [{ messageId: "aliasNotAssignedToThis", data: { name: "self" }, type: "VariableDeclarator" }, { messageId: "aliasNotAssignedToThis", 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: "aliasNotAssignedToThis", data: { name: "self" }, type: "AssignmentExpression" }] }, + { code: "var self; (function() { self = this; }())", options: ["self"], errors: [{ messageId: "aliasNotAssignedToThis", data: { name: "self" }, type: "VariableDeclarator" }] } ] }); diff --git a/tests/lib/rules/constructor-super.js b/tests/lib/rules/constructor-super.js index d4da041f6db..89d5b6193d2 100644 --- a/tests/lib/rules/constructor-super.js +++ b/tests/lib/rules/constructor-super.js @@ -102,130 +102,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 @@ -235,7 +235,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 f9a04790d3b..028465fde99 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: "missingCurlyAfterCondition", + data: { name: "if" }, type: "IfStatement" } ] @@ -229,7 +230,8 @@ ruleTester.run("curly", rule, { output: "if (foo) { bar() } else {baz()}", errors: [ { - message: "Expected { after 'else'.", + messageId: "missingCurlyAfter", + data: { name: "else" }, 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: "missingCurlyAfterCondition", + data: { name: "if" }, type: "IfStatement" } ] @@ -249,7 +252,8 @@ ruleTester.run("curly", rule, { output: "while (foo) {bar()}", errors: [ { - message: "Expected { after 'while' condition.", + messageId: "missingCurlyAfterCondition", + data: { name: "while" }, type: "WhileStatement" } ] @@ -259,7 +263,8 @@ ruleTester.run("curly", rule, { output: "do {bar();} while (foo)", errors: [ { - message: "Expected { after 'do'.", + messageId: "missingCurlyAfter", + data: { name: "do" }, type: "DoWhileStatement" } ] @@ -269,7 +274,8 @@ ruleTester.run("curly", rule, { output: "for (;foo;) {bar()}", errors: [ { - message: "Expected { after 'for' condition.", + messageId: "missingCurlyAfterCondition", + data: { name: "for" }, type: "ForStatement" } ] @@ -279,7 +285,8 @@ ruleTester.run("curly", rule, { output: "for (var foo in bar) {console.log(foo)}", errors: [ { - message: "Expected { after 'for-in'.", + messageId: "missingCurlyAfter", + data: { name: "for-in" }, type: "ForInStatement" } ] @@ -290,7 +297,8 @@ ruleTester.run("curly", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Expected { after 'for-of'.", + messageId: "missingCurlyAfter", + data: { name: "for-of" }, type: "ForOfStatement" } ] @@ -301,7 +309,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'for' condition.", + messageId: "unexpectedCurlyAfterCondition", + data: { name: "for" }, type: "ForStatement" } ] @@ -312,7 +321,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'if' condition.", + messageId: "unexpectedCurlyAfterCondition", + data: { name: "if" }, type: "IfStatement" } ] @@ -323,7 +333,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'while' condition.", + messageId: "unexpectedCurlyAfterCondition", + data: { name: "while" }, type: "WhileStatement" } ] @@ -334,7 +345,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'else'.", + messageId: "unexpectedCurlyAfter", + data: { name: "else" }, type: "IfStatement" } ] @@ -345,7 +357,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'if' condition.", + messageId: "unexpectedCurlyAfterCondition", + data: { name: "if" }, type: "IfStatement" } ] @@ -356,7 +369,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'if' condition.", + messageId: "unexpectedCurlyAfterCondition", + data: { name: "if" }, type: "IfStatement" } ] @@ -391,7 +405,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'else'.", + messageId: "unexpectedCurlyAfter", + data: { name: "else" }, type: "IfStatement", line: 6, column: 3 @@ -404,7 +419,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'for-in'.", + messageId: "unexpectedCurlyAfter", + data: { name: "for-in" }, type: "ForInStatement" } ] @@ -416,7 +432,8 @@ ruleTester.run("curly", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Unnecessary { after 'for-of'.", + messageId: "unexpectedCurlyAfter", + data: { name: "for-of" }, type: "ForOfStatement" } ] @@ -427,7 +444,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'if' condition.", + messageId: "missingCurlyAfterCondition", + data: { name: "if" }, type: "IfStatement" } ] @@ -438,7 +456,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'while' condition.", + messageId: "missingCurlyAfterCondition", + data: { name: "while" }, type: "WhileStatement" } ] @@ -449,7 +468,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'for' condition.", + messageId: "missingCurlyAfterCondition", + data: { name: "for" }, type: "ForStatement" } ] @@ -460,7 +480,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'while' condition.", + messageId: "missingCurlyAfterCondition", + data: { name: "while" }, type: "WhileStatement" } ] @@ -471,7 +492,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'if' condition.", + messageId: "missingCurlyAfterCondition", + data: { name: "if" }, type: "IfStatement" } ] @@ -482,7 +504,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'do'.", + messageId: "missingCurlyAfter", + data: { name: "do" }, type: "DoWhileStatement" } ] @@ -493,7 +516,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'for-in'.", + messageId: "missingCurlyAfter", + data: { name: "for-in" }, type: "ForInStatement" } ] @@ -504,7 +528,8 @@ ruleTester.run("curly", rule, { options: ["multi-line"], errors: [ { - message: "Expected { after 'for-in'.", + messageId: "missingCurlyAfter", + data: { name: "for-in" }, type: "ForInStatement" } ] @@ -516,7 +541,8 @@ ruleTester.run("curly", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Expected { after 'for-of'.", + messageId: "missingCurlyAfter", + data: { name: "for-of" }, type: "ForOfStatement" } ] @@ -528,7 +554,8 @@ ruleTester.run("curly", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Expected { after 'for-of'.", + messageId: "missingCurlyAfter", + data: { name: "for-of" }, type: "ForOfStatement" } ] @@ -539,7 +566,8 @@ ruleTester.run("curly", rule, { options: ["multi-or-nest"], errors: [ { - message: "Expected { after 'if' condition.", + messageId: "missingCurlyAfterCondition", + data: { name: "if" }, type: "IfStatement" } ] @@ -550,7 +578,8 @@ ruleTester.run("curly", rule, { options: ["multi-or-nest"], errors: [ { - message: "Expected { after 'while' condition.", + messageId: "missingCurlyAfterCondition", + data: { name: "while" }, type: "WhileStatement" } ] @@ -561,7 +590,8 @@ ruleTester.run("curly", rule, { options: ["multi-or-nest"], errors: [ { - message: "Unnecessary { after 'if' condition.", + messageId: "unexpectedCurlyAfterCondition", + data: { name: "if" }, type: "IfStatement" } ] @@ -572,7 +602,8 @@ ruleTester.run("curly", rule, { options: ["multi-or-nest"], errors: [ { - message: "Unnecessary { after 'while' condition.", + messageId: "unexpectedCurlyAfterCondition", + data: { name: "while" }, type: "WhileStatement" } ] @@ -583,7 +614,8 @@ ruleTester.run("curly", rule, { options: ["multi-or-nest"], errors: [ { - message: "Unnecessary { after 'for' condition.", + messageId: "unexpectedCurlyAfterCondition", + data: { name: "for" }, type: "ForStatement" } ] @@ -594,7 +626,8 @@ ruleTester.run("curly", rule, { options: ["multi-or-nest"], errors: [ { - message: "Expected { after 'for-in'.", + messageId: "missingCurlyAfter", + data: { name: "for-in" }, type: "ForInStatement" } ] @@ -605,7 +638,8 @@ ruleTester.run("curly", rule, { options: ["multi-or-nest"], errors: [ { - message: "Unnecessary { after 'for-in'.", + messageId: "unexpectedCurlyAfter", + data: { name: "for-in" }, type: "ForInStatement" } ] @@ -617,7 +651,8 @@ ruleTester.run("curly", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Expected { after 'for-of'.", + messageId: "missingCurlyAfter", + data: { name: "for-of" }, type: "ForOfStatement" } ] @@ -629,7 +664,8 @@ ruleTester.run("curly", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Unnecessary { after 'for-of'.", + messageId: "unexpectedCurlyAfter", + data: { name: "for-of" }, type: "ForOfStatement" } ] @@ -640,7 +676,8 @@ ruleTester.run("curly", rule, { options: ["multi", "consistent"], errors: [ { - message: "Expected { after 'if' condition.", + messageId: "missingCurlyAfterCondition", + data: { name: "if" }, type: "IfStatement" } ] @@ -651,7 +688,8 @@ ruleTester.run("curly", rule, { options: ["multi", "consistent"], errors: [ { - message: "Expected { after 'else'.", + messageId: "missingCurlyAfter", + data: { name: "else" }, type: "IfStatement" } ] @@ -662,7 +700,8 @@ ruleTester.run("curly", rule, { options: ["multi", "consistent"], errors: [ { - message: "Unnecessary { after 'else'.", + messageId: "unexpectedCurlyAfter", + data: { name: "else" }, type: "IfStatement" } ] @@ -673,11 +712,13 @@ ruleTester.run("curly", rule, { options: ["multi", "consistent"], errors: [ { - message: "Expected { after 'if' condition.", + messageId: "missingCurlyAfterCondition", + data: { name: "if" }, type: "IfStatement" }, { - message: "Expected { after 'if' condition.", + messageId: "missingCurlyAfterCondition", + data: { name: "if" }, type: "IfStatement" } ] @@ -688,7 +729,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'do'.", + messageId: "unexpectedCurlyAfter", + data: { name: "do" }, type: "DoWhileStatement" } ] @@ -699,7 +741,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'do'.", + messageId: "unexpectedCurlyAfter", + data: { name: "do" }, type: "DoWhileStatement" } ] @@ -710,7 +753,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'if' condition.", + messageId: "unexpectedCurlyAfterCondition", + data: { name: "if" }, type: "IfStatement" } ] @@ -721,7 +765,8 @@ ruleTester.run("curly", rule, { options: ["multi"], errors: [ { - message: "Unnecessary { after 'do'.", + messageId: "unexpectedCurlyAfter", + data: { name: "do" }, type: "DoWhileStatement" } ] @@ -732,44 +777,44 @@ ruleTester.run("curly", rule, { code: "if (foo) { bar }\n++baz;", output: null, options: ["multi"], - errors: [{ message: "Unnecessary { after 'if' condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (foo) { bar; }\n++baz;", output: "if (foo) bar; \n++baz;", options: ["multi"], - errors: [{ message: "Unnecessary { after 'if' condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (foo) { bar++ }\nbaz;", output: null, options: ["multi"], - errors: [{ message: "Unnecessary { after 'if' condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (foo) { bar }\n[1, 2, 3].map(foo);", output: null, options: ["multi"], - errors: [{ message: "Unnecessary { after 'if' condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (foo) { bar }\n(1).toString();", output: null, options: ["multi"], - errors: [{ message: "Unnecessary { after 'if' condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (foo) { bar }\n/regex/.test('foo');", output: null, options: ["multi"], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unnecessary { after 'if' condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (foo) { bar }\nBaz();", output: "if (foo) bar \nBaz();", options: ["multi"], - errors: [{ message: "Unnecessary { after 'if' condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: @@ -787,39 +832,39 @@ ruleTester.run("curly", rule, { " }\n" + " else e();", options: ["multi"], - errors: [{ message: "Unnecessary { after 'if' condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (foo) { while (bar) {} } else {}", output: "if (foo) while (bar) {} else {}", options: ["multi"], - errors: [{ message: "Unnecessary { after 'if' condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (foo) { var foo = () => {} } else {}", output: null, options: ["multi"], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unnecessary { after 'if' condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (foo) { var foo = function() {} } else {}", output: null, options: ["multi"], - errors: [{ message: "Unnecessary { after 'if' condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (foo) { var foo = function*() {} } else {}", output: null, options: ["multi"], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unnecessary { after 'if' condition.", type: "IfStatement" }] + errors: [{ messageId: "unexpectedCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] }, { code: "if (true)\nfoo()\n;[1, 2, 3].bar()", output: "if (true)\n{foo()\n;}[1, 2, 3].bar()", options: ["multi-line"], - errors: [{ message: "Expected { after 'if' condition.", type: "IfStatement" }] + errors: [{ messageId: "missingCurlyAfterCondition", data: { name: "if" }, type: "IfStatement" }] } ] }); diff --git a/tests/lib/rules/default-case.js b/tests/lib/rules/default-case.js index 1ade2e63da5..a0e21aeca23 100644 --- a/tests/lib/rules/default-case.js +++ b/tests/lib/rules/default-case.js @@ -63,21 +63,21 @@ ruleTester.run("default-case", rule, { { code: "switch (a) { case 1: break; }", errors: [{ - message: "Expected a default case.", + messageId: "missingDefaultCase", type: "SwitchStatement" }] }, { code: "switch (a) { \n // no default \n case 1: break; }", errors: [{ - message: "Expected a default case.", + messageId: "missingDefaultCase", type: "SwitchStatement" }] }, { code: "switch (a) { case 1: break; \n // no default \n // nope \n }", errors: [{ - message: "Expected a default case.", + messageId: "missingDefaultCase", type: "SwitchStatement" }] }, @@ -87,7 +87,7 @@ ruleTester.run("default-case", rule, { commentPattern: "skipped default case" }], errors: [{ - message: "Expected a default case.", + messageId: "missingDefaultCase", type: "SwitchStatement" }] }, @@ -97,7 +97,7 @@ ruleTester.run("default-case", rule, { commentPattern: "default omitted" }], errors: [{ - message: "Expected a default case.", + messageId: "missingDefaultCase", type: "SwitchStatement" }] }, @@ -107,7 +107,7 @@ ruleTester.run("default-case", rule, { commentPattern: ".?" }], errors: [{ - message: "Expected a default case.", + messageId: "missingDefaultCase", type: "SwitchStatement" }] } diff --git a/tests/lib/rules/dot-location.js b/tests/lib/rules/dot-location.js index 64e798bc8ee..381afc55966 100644 --- a/tests/lib/rules/dot-location.js +++ b/tests/lib/rules/dot-location.js @@ -44,43 +44,43 @@ ruleTester.run("dot-location", rule, { code: "obj\n.property", output: "obj.\nproperty", options: ["object"], - errors: [{ message: "Expected dot to be on same line as object.", type: "MemberExpression", line: 2, column: 1 }] + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] }, { code: "obj.\nproperty", output: "obj\n.property", options: ["property"], - errors: [{ message: "Expected dot to be on same line as property.", type: "MemberExpression", line: 1, column: 4 }] + errors: [{ messageId: "expectedDotBeforeProperty", type: "MemberExpression", line: 1, column: 4 }] }, { code: "(obj).\nproperty", output: "(obj)\n.property", options: ["property"], - errors: [{ message: "Expected dot to be on same line as property.", type: "MemberExpression", line: 1, column: 6 }] + errors: [{ messageId: "expectedDotBeforeProperty", type: "MemberExpression", line: 1, column: 6 }] }, { code: "5\n.toExponential()", output: "5 .\ntoExponential()", options: ["object"], - errors: [{ message: "Expected dot to be on same line as object.", type: "MemberExpression", line: 2, column: 1 }] + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] }, { code: "-5\n.toExponential()", output: "-5 .\ntoExponential()", options: ["object"], - errors: [{ message: "Expected dot to be on same line as object.", type: "MemberExpression", line: 2, column: 1 }] + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 1 }] }, { code: "foo /* a */ . /* b */ \n /* c */ bar", output: "foo /* a */ /* b */ \n /* c */ .bar", options: ["property"], - errors: [{ message: "Expected dot to be on same line as property.", type: "MemberExpression", line: 1, column: 13 }] + errors: [{ messageId: "expectedDotBeforeProperty", type: "MemberExpression", line: 1, column: 13 }] }, { code: "foo /* a */ \n /* b */ . /* c */ bar", output: "foo. /* a */ \n /* b */ /* c */ bar", options: ["object"], - errors: [{ message: "Expected dot to be on same line as object.", type: "MemberExpression", line: 2, column: 10 }] + errors: [{ messageId: "expectedDotAfterObject", type: "MemberExpression", line: 2, column: 10 }] } ] }); diff --git a/tests/lib/rules/dot-notation.js b/tests/lib/rules/dot-notation.js index 9d1be6a8a37..1261fb8853e 100644 --- a/tests/lib/rules/dot-notation.js +++ b/tests/lib/rules/dot-notation.js @@ -18,6 +18,16 @@ const rule = require("../../../lib/rules/dot-notation"), const ruleTester = new RuleTester(); +/** + * Quote a string in "double quotes" because it’s painful + * with a double-quoted string literal + * @param {string} str The string to quote + * @returns {string} `"${str}"` + */ +function q(str) { + return `"${str}"`; +} + ruleTester.run("dot-notation", rule, { valid: [ "a.b;", @@ -54,45 +64,45 @@ ruleTester.run("dot-notation", rule, { code: "a.true;", output: "a[\"true\"];", options: [{ allowKeywords: false }], - errors: [{ message: ".true is a syntax error." }] + errors: [{ messageId: "useBrackets", data: { key: "true" } }] }, { code: "a['true'];", output: "a.true;", - errors: [{ message: "[\"true\"] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: q("true") } }] }, { code: "a[`time`];", output: "a.time;", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "[`time`] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: "`time`" } }] }, { code: "a[null];", output: "a.null;", - errors: [{ message: "[null] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: "null" } }] }, { code: "a['b'];", output: "a.b;", - errors: [{ message: "[\"b\"] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: q("b") } }] }, { code: "a.b['c'];", output: "a.b.c;", - errors: [{ message: "[\"c\"] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: q("c") } }] }, { code: "a['_dangle'];", output: "a._dangle;", options: [{ allowPattern: "^[a-z]+(_[a-z]+)+$" }], - errors: [{ message: "[\"_dangle\"] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: q("_dangle") } }] }, { code: "a['SHOUT_CASE'];", output: "a.SHOUT_CASE;", options: [{ allowPattern: "^[a-z]+(_[a-z]+)+$" }], - errors: [{ message: "[\"SHOUT_CASE\"] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: q("SHOUT_CASE") } }] }, { code: @@ -102,7 +112,8 @@ ruleTester.run("dot-notation", rule, { "a\n" + " .SHOUT_CASE;", errors: [{ - message: "[\"SHOUT_CASE\"] is better written in dot notation.", + messageId: "useDot", + data: { key: q("SHOUT_CASE") }, line: 2, column: 4 }] @@ -122,12 +133,14 @@ ruleTester.run("dot-notation", rule, { " .catch(function(){});", errors: [ { - message: "[\"catch\"] is better written in dot notation.", + messageId: "useDot", + data: { key: q("catch") }, line: 3, column: 6 }, { - message: "[\"catch\"] is better written in dot notation.", + messageId: "useDot", + data: { key: q("catch") }, line: 5, column: 6 } @@ -141,59 +154,59 @@ ruleTester.run("dot-notation", rule, { "foo\n" + " [\"while\"];", options: [{ allowKeywords: false }], - errors: [{ message: ".while is a syntax error." }] + errors: [{ messageId: "useBrackets", data: { key: "while" } }] }, { code: "foo[ /* comment */ 'bar' ]", output: null, // Not fixed due to comment - errors: [{ message: "[\"bar\"] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: q("bar") } }] }, { code: "foo[ 'bar' /* comment */ ]", output: null, // Not fixed due to comment - errors: [{ message: "[\"bar\"] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: q("bar") } }] }, { code: "foo[ 'bar' ];", output: "foo.bar;", - errors: [{ message: "[\"bar\"] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: q("bar") } }] }, { code: "foo. /* comment */ while", output: null, // Not fixed due to comment options: [{ allowKeywords: false }], - errors: [{ message: ".while is a syntax error." }] + errors: [{ messageId: "useBrackets", data: { key: "while" } }] }, { code: "foo[('bar')]", output: "foo.bar", - errors: [{ message: "[\"bar\"] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: q("bar") } }] }, { code: "foo[(null)]", output: "foo.null", - errors: [{ message: "[null] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: "null" } }] }, { code: "(foo)['bar']", output: "(foo).bar", - errors: [{ message: "[\"bar\"] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: q("bar") } }] }, { code: "1['toString']", output: "1 .toString", - errors: [{ message: "[\"toString\"] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: q("toString") } }] }, { code: "foo['bar']instanceof baz", output: "foo.bar instanceof baz", - errors: [{ message: "[\"bar\"] is better written in dot notation." }] + errors: [{ messageId: "useDot", data: { key: q("bar") } }] }, { code: "let.if()", output: null, // `let["if"]()` is a syntax error because `let[` indicates a destructuring variable declaration options: [{ allowKeywords: false }], - errors: [{ message: ".if is a syntax error." }] + errors: [{ messageId: "useBrackets", data: { key: "if" } }] } ] }); diff --git a/tests/lib/rules/eol-last.js b/tests/lib/rules/eol-last.js index fdc9e5d99c8..b5e1e54685b 100644 --- a/tests/lib/rules/eol-last.js +++ b/tests/lib/rules/eol-last.js @@ -55,48 +55,48 @@ ruleTester.run("eol-last", rule, { { code: "var a = 123;", output: "var a = 123;\n", - errors: [{ message: "Newline required at end of file but not found.", type: "Program" }] + errors: [{ messageId: "missing", type: "Program" }] }, { code: "var a = 123;\n ", output: "var a = 123;\n \n", - errors: [{ message: "Newline required at end of file but not found.", type: "Program" }] + errors: [{ messageId: "missing", type: "Program" }] }, { code: "var a = 123;\n", output: "var a = 123;", options: ["never"], - errors: [{ message: "Newline not allowed at end of file.", type: "Program" }] + errors: [{ messageId: "unexpected", type: "Program" }] }, { code: "var a = 123;\r\n", output: "var a = 123;", options: ["never"], - errors: [{ message: "Newline not allowed at end of file.", type: "Program" }] + errors: [{ messageId: "unexpected", type: "Program" }] }, { code: "var a = 123;\r\n\r\n", output: "var a = 123;", options: ["never"], - errors: [{ message: "Newline not allowed at end of file.", type: "Program" }] + errors: [{ messageId: "unexpected", type: "Program" }] }, { code: "var a = 123;\nvar b = 456;\n", output: "var a = 123;\nvar b = 456;", options: ["never"], - errors: [{ message: "Newline not allowed at end of file.", type: "Program" }] + errors: [{ messageId: "unexpected", type: "Program" }] }, { code: "var a = 123;\r\nvar b = 456;\r\n", output: "var a = 123;\r\nvar b = 456;", options: ["never"], - errors: [{ message: "Newline not allowed at end of file.", type: "Program" }] + errors: [{ messageId: "unexpected", type: "Program" }] }, { code: "var a = 123;\n\n", output: "var a = 123;", options: ["never"], - errors: [{ message: "Newline not allowed at end of file.", type: "Program" }] + errors: [{ messageId: "unexpected", type: "Program" }] }, // Deprecated: `"unix"` parameter @@ -104,13 +104,13 @@ ruleTester.run("eol-last", rule, { code: "var a = 123;", output: "var a = 123;\n", options: ["unix"], - errors: [{ message: "Newline required at end of file but not found.", type: "Program" }] + errors: [{ messageId: "missing", type: "Program" }] }, { code: "var a = 123;\n ", output: "var a = 123;\n \n", options: ["unix"], - errors: [{ message: "Newline required at end of file but not found.", type: "Program" }] + errors: [{ messageId: "missing", type: "Program" }] }, // Deprecated: `"windows"` parameter @@ -118,13 +118,13 @@ ruleTester.run("eol-last", rule, { code: "var a = 123;", output: "var a = 123;\r\n", options: ["windows"], - errors: [{ message: "Newline required at end of file but not found.", type: "Program" }] + errors: [{ messageId: "missing", type: "Program" }] }, { code: "var a = 123;\r\n ", output: "var a = 123;\r\n \r\n", options: ["windows"], - errors: [{ message: "Newline required at end of file but not found.", type: "Program" }] + errors: [{ messageId: "missing", type: "Program" }] } ] }); diff --git a/tests/lib/rules/eqeqeq.js b/tests/lib/rules/eqeqeq.js index da504839508..cf565363f45 100644 --- a/tests/lib/rules/eqeqeq.js +++ b/tests/lib/rules/eqeqeq.js @@ -18,6 +18,11 @@ const rule = require("../../../lib/rules/eqeqeq"), const ruleTester = new RuleTester(); +const wantedEqEqEq = { expectedOperator: "===", actualOperator: "==" }; +const wantedNotEqEq = { expectedOperator: "!==", actualOperator: "!=" }; +const wantedEqEq = { expectedOperator: "==", actualOperator: "===" }; +const wantedNotEq = { expectedOperator: "!=", actualOperator: "!==" }; + ruleTester.run("eqeqeq", rule, { valid: [ "a === b", @@ -48,44 +53,56 @@ ruleTester.run("eqeqeq", rule, { { code: "foo === /abc/u", options: ["always", { null: "never" }], parserOptions: { ecmaVersion: 6 } } ], invalid: [ - { code: "a == b", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "a != b", errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression" }] }, - { code: "typeof a == 'number'", output: "typeof a === 'number'", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "typeof a == 'number'", output: "typeof a === 'number'", options: ["always"], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "'string' != typeof a", output: "'string' !== typeof a", errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression" }] }, - { code: "true == true", output: "true === true", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "2 == 3", output: "2 === 3", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "2 == 3", output: "2 === 3", options: ["always"], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "'hello' != 'world'", output: "'hello' !== 'world'", errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression" }] }, - { code: "'hello' != 'world'", output: "'hello' !== 'world'", options: ["always"], errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression" }] }, - { code: "a == null", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "a == null", options: ["always"], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "null != a", errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression" }] }, - { code: "true == 1", options: ["smart"], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "0 != '1'", options: ["smart"], errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression" }] }, - { code: "'wee' == /wee/", options: ["smart"], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "typeof a == 'number'", output: "typeof a === 'number'", options: ["allow-null"], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "'string' != typeof a", output: "'string' !== typeof a", options: ["allow-null"], errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression" }] }, - { code: "'hello' != 'world'", output: "'hello' !== 'world'", options: ["allow-null"], errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression" }] }, - { code: "2 == 3", output: "2 === 3", options: ["allow-null"], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "true == true", output: "true === true", options: ["allow-null"], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "true == null", options: ["always", { null: "always" }], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "true != null", options: ["always", { null: "always" }], errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression" }] }, - { code: "null == null", output: "null === null", options: ["always", { null: "always" }], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression" }] }, - { code: "null != null", output: "null !== null", options: ["always", { null: "always" }], errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression" }] }, - { code: "true === null", options: ["always", { null: "never" }], errors: [{ message: "Expected '==' and instead saw '==='.", type: "BinaryExpression" }] }, - { code: "true !== null", options: ["always", { null: "never" }], errors: [{ message: "Expected '!=' and instead saw '!=='.", type: "BinaryExpression" }] }, - { code: "null === null", output: "null == null", options: ["always", { null: "never" }], errors: [{ message: "Expected '==' and instead saw '==='.", type: "BinaryExpression" }] }, - { code: "null !== null", output: "null != null", options: ["always", { null: "never" }], errors: [{ message: "Expected '!=' and instead saw '!=='.", type: "BinaryExpression" }] }, - { code: "a\n==\nb", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression", line: 2 }] }, - { code: "(a) == b", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression", line: 1 }] }, - { code: "(a) != b", errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression", line: 1 }] }, - { code: "a == (b)", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression", line: 1 }] }, - { code: "a != (b)", errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression", line: 1 }] }, - { code: "(a) == (b)", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression", line: 1 }] }, - { code: "(a) != (b)", errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression", line: 1 }] }, - { code: "(a == b) == (c)", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression", line: 1 }, { message: "Expected '===' and instead saw '=='.", type: "BinaryExpression", line: 1 }] }, - { code: "(a != b) != (c)", errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression", line: 1 }, { message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression", line: 1 }] } + { code: "a == b", errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "a != b", errors: [{ messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression" }] }, + { code: "typeof a == 'number'", output: "typeof a === 'number'", errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "typeof a == 'number'", output: "typeof a === 'number'", options: ["always"], errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "'string' != typeof a", output: "'string' !== typeof a", errors: [{ messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression" }] }, + { code: "true == true", output: "true === true", errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "2 == 3", output: "2 === 3", errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "2 == 3", output: "2 === 3", options: ["always"], errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "'hello' != 'world'", output: "'hello' !== 'world'", errors: [{ messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression" }] }, + { code: "'hello' != 'world'", output: "'hello' !== 'world'", options: ["always"], errors: [{ messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression" }] }, + { code: "a == null", errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "a == null", options: ["always"], errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "null != a", errors: [{ messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression" }] }, + { code: "true == 1", options: ["smart"], errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "0 != '1'", options: ["smart"], errors: [{ messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression" }] }, + { code: "'wee' == /wee/", options: ["smart"], errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "typeof a == 'number'", output: "typeof a === 'number'", options: ["allow-null"], errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "'string' != typeof a", output: "'string' !== typeof a", options: ["allow-null"], errors: [{ messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression" }] }, + { code: "'hello' != 'world'", output: "'hello' !== 'world'", options: ["allow-null"], errors: [{ messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression" }] }, + { code: "2 == 3", output: "2 === 3", options: ["allow-null"], errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "true == true", output: "true === true", options: ["allow-null"], errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "true == null", options: ["always", { null: "always" }], errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "true != null", options: ["always", { null: "always" }], errors: [{ messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression" }] }, + { code: "null == null", output: "null === null", options: ["always", { null: "always" }], errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression" }] }, + { code: "null != null", output: "null !== null", options: ["always", { null: "always" }], errors: [{ messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression" }] }, + { code: "true === null", options: ["always", { null: "never" }], errors: [{ messageId: "unexpected", data: wantedEqEq, type: "BinaryExpression" }] }, + { code: "true !== null", options: ["always", { null: "never" }], errors: [{ messageId: "unexpected", data: wantedNotEq, type: "BinaryExpression" }] }, + { code: "null === null", output: "null == null", options: ["always", { null: "never" }], errors: [{ messageId: "unexpected", data: wantedEqEq, type: "BinaryExpression" }] }, + { code: "null !== null", output: "null != null", options: ["always", { null: "never" }], errors: [{ messageId: "unexpected", data: wantedNotEq, type: "BinaryExpression" }] }, + { code: "a\n==\nb", errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression", line: 2 }] }, + { code: "(a) == b", errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression", line: 1 }] }, + { code: "(a) != b", errors: [{ messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression", line: 1 }] }, + { code: "a == (b)", errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression", line: 1 }] }, + { code: "a != (b)", errors: [{ messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression", line: 1 }] }, + { code: "(a) == (b)", errors: [{ messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression", line: 1 }] }, + { code: "(a) != (b)", errors: [{ messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression", line: 1 }] }, + { + code: "(a == b) == (c)", + errors: [ + { messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression", line: 1 }, + { messageId: "unexpected", data: wantedEqEqEq, type: "BinaryExpression", line: 1 } + ] + }, + { + code: "(a != b) != (c)", + errors: [ + { messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression", line: 1 }, + { messageId: "unexpected", data: wantedNotEqEq, type: "BinaryExpression", line: 1 } + ] + } // If no output is provided, assert that no output is produced. ].map(invalidCase => Object.assign({ output: null }, invalidCase)) diff --git a/tests/lib/rules/no-alert.js b/tests/lib/rules/no-alert.js index 03f4a2d07c5..0f8de5a4cac 100644 --- a/tests/lib/rules/no-alert.js +++ b/tests/lib/rules/no-alert.js @@ -39,71 +39,71 @@ ruleTester.run("no-alert", rule, { invalid: [ { code: "alert(foo)", - errors: [{ message: "Unexpected alert.", type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "window.alert(foo)", - errors: [{ message: "Unexpected alert.", type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "window['alert'](foo)", - errors: [{ message: "Unexpected alert.", type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "confirm(foo)", - errors: [{ message: "Unexpected confirm.", type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "confirm" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "window.confirm(foo)", - errors: [{ message: "Unexpected confirm.", type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "confirm" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "window['confirm'](foo)", - errors: [{ message: "Unexpected confirm.", type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "confirm" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "prompt(foo)", - errors: [{ message: "Unexpected prompt.", type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "prompt" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "window.prompt(foo)", - errors: [{ message: "Unexpected prompt.", type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "prompt" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "window['prompt'](foo)", - errors: [{ message: "Unexpected prompt.", type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "prompt" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "function alert() {} window.alert(foo)", - errors: [{ message: "Unexpected alert.", type: "CallExpression", line: 1, column: 21 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 21 }] }, { code: "var alert = function() {};\nwindow.alert(foo)", - errors: [{ message: "Unexpected alert.", type: "CallExpression", line: 2, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 2, column: 1 }] }, { code: "function foo(alert) { window.alert(); }", - errors: [{ message: "Unexpected alert.", type: "CallExpression", line: 1, column: 23 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 23 }] }, { code: "function foo() { alert(); }", - errors: [{ message: "Unexpected alert.", type: "CallExpression", line: 1, column: 18 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 18 }] }, { code: "function foo() { var alert = function() {}; }\nalert();", - errors: [{ message: "Unexpected alert.", type: "CallExpression", line: 2, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 2, column: 1 }] }, { code: "this.alert(foo)", - errors: [{ message: "Unexpected alert.", type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "this['alert'](foo)", - errors: [{ message: "Unexpected alert.", type: "CallExpression", line: 1, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 1, column: 1 }] }, { code: "function foo() { var window = bar; window.alert(); }\nwindow.alert();", - errors: [{ message: "Unexpected alert.", type: "CallExpression", line: 2, column: 1 }] + errors: [{ messageId: "unexpected", data: { name: "alert" }, type: "CallExpression", line: 2, column: 1 }] } ] }); diff --git a/tests/lib/rules/no-array-constructor.js b/tests/lib/rules/no-array-constructor.js index 9dddedfa22c..b42c4a7fd39 100644 --- a/tests/lib/rules/no-array-constructor.js +++ b/tests/lib/rules/no-array-constructor.js @@ -30,9 +30,9 @@ ruleTester.run("no-array-constructor", rule, { "Array.foo()" ], invalid: [ - { code: "new Array()", errors: [{ message: "The array literal notation [] is preferrable.", type: "NewExpression" }] }, - { code: "new Array", errors: [{ message: "The array literal notation [] is preferrable.", type: "NewExpression" }] }, - { code: "new Array(x, y)", errors: [{ message: "The array literal notation [] is preferrable.", type: "NewExpression" }] }, - { code: "new Array(0, 1, 2)", errors: [{ message: "The array literal notation [] is preferrable.", type: "NewExpression" }] } + { code: "new Array()", errors: [{ messageId: "preferLiteral", type: "NewExpression" }] }, + { code: "new Array", errors: [{ messageId: "preferLiteral", type: "NewExpression" }] }, + { code: "new Array(x, y)", errors: [{ messageId: "preferLiteral", type: "NewExpression" }] }, + { code: "new Array(0, 1, 2)", errors: [{ messageId: "preferLiteral", type: "NewExpression" }] } ] }); diff --git a/tests/lib/rules/no-await-in-loop.js b/tests/lib/rules/no-await-in-loop.js index 15673ded2c8..bb74db1c039 100644 --- a/tests/lib/rules/no-await-in-loop.js +++ b/tests/lib/rules/no-await-in-loop.js @@ -8,7 +8,7 @@ const rule = require("../../../lib/rules/no-await-in-loop"), RuleTester = require("../../../lib/testers/rule-tester"); -const message = "Unexpected `await` inside a loop."; +const error = { messageId: "unexpectedAwait" }; const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: "2017" } }); @@ -41,29 +41,29 @@ ruleTester.run("no-await-in-loop", rule, { invalid: [ // While loops - { code: "async function foo() { while (baz) { await bar; } }", errors: [message] }, - { code: "async function foo() { while (await foo()) { } }", errors: [message] }, + { code: "async function foo() { while (baz) { await bar; } }", errors: [error] }, + { code: "async function foo() { while (await foo()) { } }", errors: [error] }, // For of loops - { code: "async function foo() { for (var bar of baz) { await bar; } }", errors: [message] }, - { code: "async function foo() { for (var bar of baz) await bar; }", errors: [message] }, + { code: "async function foo() { for (var bar of baz) { await bar; } }", errors: [error] }, + { code: "async function foo() { for (var bar of baz) await bar; }", errors: [error] }, // For in loops - { code: "async function foo() { for (var bar in baz) { await bar; } }", errors: [message] }, + { code: "async function foo() { for (var bar in baz) { await bar; } }", errors: [error] }, // For loops - { code: "async function foo() { for (var i; i < n; i++) { await bar; } }", errors: [message] }, - { code: "async function foo() { for (var i; await foo(i); i++) { } }", errors: [message] }, - { code: "async function foo() { for (var i; i < n; i = await bar) { } }", errors: [message] }, + { code: "async function foo() { for (var i; i < n; i++) { await bar; } }", errors: [error] }, + { code: "async function foo() { for (var i; await foo(i); i++) { } }", errors: [error] }, + { code: "async function foo() { for (var i; i < n; i = await bar) { } }", errors: [error] }, // Do while loops - { code: "async function foo() { do { await bar; } while (baz); }", errors: [message] }, - { code: "async function foo() { do { } while (await bar); }", errors: [message] }, + { code: "async function foo() { do { await bar; } while (baz); }", errors: [error] }, + { code: "async function foo() { do { } while (await bar); }", errors: [error] }, // Deep in a loop body - { code: "async function foo() { while (true) { if (bar) { foo(await bar); } } }", errors: [message] }, + { code: "async function foo() { while (true) { if (bar) { foo(await bar); } } }", errors: [error] }, // Deep in a loop condition - { code: "async function foo() { while (xyz || 5 > await x) { } }", errors: [message] } + { code: "async function foo() { while (xyz || 5 > await x) { } }", errors: [error] } ] }); diff --git a/tests/lib/rules/no-bitwise.js b/tests/lib/rules/no-bitwise.js index f5edfc6c527..f1ab5ba2373 100644 --- a/tests/lib/rules/no-bitwise.js +++ b/tests/lib/rules/no-bitwise.js @@ -29,18 +29,18 @@ ruleTester.run("no-bitwise", rule, { { code: "a|0", options: [{ allow: ["|"], int32Hint: false }] } ], invalid: [ - { code: "a ^ b", errors: [{ message: "Unexpected use of '^'.", type: "BinaryExpression" }] }, - { code: "a | b", errors: [{ message: "Unexpected use of '|'.", type: "BinaryExpression" }] }, - { code: "a & b", errors: [{ message: "Unexpected use of '&'.", type: "BinaryExpression" }] }, - { code: "a << b", errors: [{ message: "Unexpected use of '<<'.", type: "BinaryExpression" }] }, - { code: "a >> b", errors: [{ message: "Unexpected use of '>>'.", type: "BinaryExpression" }] }, - { code: "a >>> b", errors: [{ message: "Unexpected use of '>>>'.", type: "BinaryExpression" }] }, - { code: "~a", errors: [{ message: "Unexpected use of '~'.", type: "UnaryExpression" }] }, - { code: "a ^= b", errors: [{ message: "Unexpected use of '^='.", type: "AssignmentExpression" }] }, - { code: "a |= b", errors: [{ message: "Unexpected use of '|='.", type: "AssignmentExpression" }] }, - { code: "a &= b", errors: [{ message: "Unexpected use of '&='.", type: "AssignmentExpression" }] }, - { code: "a <<= b", errors: [{ message: "Unexpected use of '<<='.", type: "AssignmentExpression" }] }, - { code: "a >>= b", errors: [{ message: "Unexpected use of '>>='.", type: "AssignmentExpression" }] }, - { code: "a >>>= b", errors: [{ message: "Unexpected use of '>>>='.", type: "AssignmentExpression" }] } + { code: "a ^ b", errors: [{ messageId: "unexpected", data: { operator: "^" }, type: "BinaryExpression" }] }, + { code: "a | b", errors: [{ messageId: "unexpected", data: { operator: "|" }, type: "BinaryExpression" }] }, + { code: "a & b", errors: [{ messageId: "unexpected", data: { operator: "&" }, type: "BinaryExpression" }] }, + { code: "a << b", errors: [{ messageId: "unexpected", data: { operator: "<<" }, type: "BinaryExpression" }] }, + { code: "a >> b", errors: [{ messageId: "unexpected", data: { operator: ">>" }, type: "BinaryExpression" }] }, + { code: "a >>> b", errors: [{ messageId: "unexpected", data: { operator: ">>>" }, type: "BinaryExpression" }] }, + { code: "~a", errors: [{ messageId: "unexpected", data: { operator: "~" }, type: "UnaryExpression" }] }, + { code: "a ^= b", errors: [{ messageId: "unexpected", data: { operator: "^=" }, type: "AssignmentExpression" }] }, + { code: "a |= b", errors: [{ messageId: "unexpected", data: { operator: "|=" }, type: "AssignmentExpression" }] }, + { code: "a &= b", errors: [{ messageId: "unexpected", data: { operator: "&=" }, type: "AssignmentExpression" }] }, + { code: "a <<= b", errors: [{ messageId: "unexpected", data: { operator: "<<=" }, type: "AssignmentExpression" }] }, + { code: "a >>= b", errors: [{ messageId: "unexpected", data: { operator: ">>=" }, type: "AssignmentExpression" }] }, + { code: "a >>>= b", errors: [{ messageId: "unexpected", data: { operator: ">>>=" }, type: "AssignmentExpression" }] } ] }); diff --git a/tests/lib/rules/no-buffer-constructor.js b/tests/lib/rules/no-buffer-constructor.js index c3540e5e4ef..9bdaccb17d1 100644 --- a/tests/lib/rules/no-buffer-constructor.js +++ b/tests/lib/rules/no-buffer-constructor.js @@ -17,11 +17,17 @@ const RuleTester = require("../../../lib/testers/rule-tester"); //------------------------------------------------------------------------------ const CALL_ERROR = { - message: "Buffer() is deprecated. Use Buffer.from(), Buffer.alloc(), or Buffer.allocUnsafe() instead.", + messageId: "deprecated", + data: { + expr: "Buffer()" + }, type: "CallExpression" }; const CONSTRUCT_ERROR = { - message: "new Buffer() is deprecated. Use Buffer.from(), Buffer.alloc(), or Buffer.allocUnsafe() instead.", + messageId: "deprecated", + data: { + expr: "new Buffer()" + }, type: "NewExpression" }; diff --git a/tests/lib/rules/no-caller.js b/tests/lib/rules/no-caller.js index da56c5180e1..a55a823e01d 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 8d86f311a75..d72ad515d7e 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 3d1024f9ea8..cd6c3f32b63 100644 --- a/tests/lib/rules/no-catch-shadow.js +++ b/tests/lib/rules/no-catch-shadow.js @@ -43,9 +43,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 119fd9812ef..3781b1f20d6 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 d8f4812f35a..19429026080 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 36cd15a1e10..b192635c887 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 e79461beee0..7df2538a2d0 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 ceb04ac2d9a..76a39227e5c 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 761ea73cc78..c6b03da9e1c 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 9f7bc4c0d24..1ec03f0e7ab 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: "Literal" }] }, - { code: "do{}while(true)", errors: [{ message: "Unexpected constant condition.", type: "Literal" }] }, - { code: "do{}while(t = -2)", errors: [{ message: "Unexpected constant condition.", type: "AssignmentExpression" }] }, - { code: "true ? 1 : 2;", errors: [{ message: "Unexpected constant condition.", type: "Literal" }] }, - { code: "q = 0 ? 1 : 2;", errors: [{ message: "Unexpected constant condition.", type: "Literal" }] }, - { code: "(q = 0) ? 1 : 2;", errors: [{ message: "Unexpected constant condition.", type: "AssignmentExpression" }] }, - { code: "if(-2);", errors: [{ message: "Unexpected constant condition.", type: "UnaryExpression" }] }, - { code: "if(true);", errors: [{ message: "Unexpected constant condition.", type: "Literal" }] }, - { code: "if({});", errors: [{ message: "Unexpected constant condition.", type: "ObjectExpression" }] }, - { code: "if(0 < 1);", errors: [{ message: "Unexpected constant condition.", type: "BinaryExpression" }] }, - { code: "if(0 || 1);", errors: [{ message: "Unexpected constant condition.", type: "LogicalExpression" }] }, - { code: "if(a, 1);", errors: [{ message: "Unexpected constant condition.", type: "SequenceExpression" }] }, - - { code: "while([]);", errors: [{ message: "Unexpected constant condition.", type: "ArrayExpression" }] }, - { code: "while(~!0);", errors: [{ message: "Unexpected constant condition.", type: "UnaryExpression" }] }, - { code: "while(x = 1);", errors: [{ message: "Unexpected constant condition.", type: "AssignmentExpression" }] }, - { code: "while(function(){});", errors: [{ message: "Unexpected constant condition.", type: "FunctionExpression" }] }, - { code: "while(true);", errors: [{ message: "Unexpected constant condition.", type: "Literal" }] }, - { code: "while(() => {});", errors: [{ message: "Unexpected constant condition.", type: "ArrowFunctionExpression" }] }, + { code: "for(;true;);", errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "do{}while(true)", errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "do{}while(t = -2)", errors: [{ messageId: "unexpected", type: "AssignmentExpression" }] }, + { code: "true ? 1 : 2;", errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "q = 0 ? 1 : 2;", errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "(q = 0) ? 1 : 2;", errors: [{ messageId: "unexpected", type: "AssignmentExpression" }] }, + { code: "if(-2);", errors: [{ messageId: "unexpected", type: "UnaryExpression" }] }, + { code: "if(true);", errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "if({});", errors: [{ messageId: "unexpected", type: "ObjectExpression" }] }, + { code: "if(0 < 1);", errors: [{ messageId: "unexpected", type: "BinaryExpression" }] }, + { code: "if(0 || 1);", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] }, + { code: "if(a, 1);", errors: [{ messageId: "unexpected", type: "SequenceExpression" }] }, + + { code: "while([]);", errors: [{ messageId: "unexpected", type: "ArrayExpression" }] }, + { code: "while(~!0);", errors: [{ messageId: "unexpected", type: "UnaryExpression" }] }, + { code: "while(x = 1);", errors: [{ messageId: "unexpected", type: "AssignmentExpression" }] }, + { code: "while(function(){});", errors: [{ messageId: "unexpected", type: "FunctionExpression" }] }, + { code: "while(true);", errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "while(() => {});", errors: [{ messageId: "unexpected", type: "ArrowFunctionExpression" }] }, // #5228 , typeof conditions - { code: "if(typeof x){}", errors: [{ message: "Unexpected constant condition.", type: "UnaryExpression" }] }, - { code: "if(typeof 'abc' === 'string'){}", errors: [{ message: "Unexpected constant condition.", type: "BinaryExpression" }] }, - { code: "if(a = typeof b){}", errors: [{ message: "Unexpected constant condition.", type: "AssignmentExpression" }] }, - { code: "if(a, typeof b){}", errors: [{ message: "Unexpected constant condition.", type: "SequenceExpression" }] }, - { code: "if(typeof 'a' == 'string' || typeof 'b' == 'string'){}", errors: [{ message: "Unexpected constant condition.", type: "LogicalExpression" }] }, - { code: "while(typeof x){}", errors: [{ message: "Unexpected constant condition.", type: "UnaryExpression" }] }, + { code: "if(typeof x){}", errors: [{ messageId: "unexpected", type: "UnaryExpression" }] }, + { code: "if(typeof 'abc' === 'string'){}", errors: [{ messageId: "unexpected", type: "BinaryExpression" }] }, + { code: "if(a = typeof b){}", errors: [{ messageId: "unexpected", type: "AssignmentExpression" }] }, + { code: "if(a, typeof b){}", errors: [{ messageId: "unexpected", type: "SequenceExpression" }] }, + { code: "if(typeof 'a' == 'string' || typeof 'b' == 'string'){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] }, + { code: "while(typeof x){}", errors: [{ messageId: "unexpected", type: "UnaryExpression" }] }, // #5726, void conditions - { code: "if(1 || void x);", errors: [{ message: "Unexpected constant condition.", type: "LogicalExpression" }] }, - { code: "if(void x);", errors: [{ message: "Unexpected constant condition.", type: "UnaryExpression" }] }, - { code: "if(y = void x);", errors: [{ message: "Unexpected constant condition.", type: "AssignmentExpression" }] }, - { code: "if(x, void x);", errors: [{ message: "Unexpected constant condition.", type: "SequenceExpression" }] }, - { code: "if(void x === void y);", errors: [{ message: "Unexpected constant condition.", type: "BinaryExpression" }] }, - { code: "if(void x && a);", errors: [{ message: "Unexpected constant condition.", type: "LogicalExpression" }] }, - { code: "if(a && void x);", errors: [{ message: "Unexpected constant condition.", type: "LogicalExpression" }] }, + { code: "if(1 || void x);", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] }, + { code: "if(void x);", errors: [{ messageId: "unexpected", type: "UnaryExpression" }] }, + { code: "if(y = void x);", errors: [{ messageId: "unexpected", type: "AssignmentExpression" }] }, + { code: "if(x, void x);", errors: [{ messageId: "unexpected", type: "SequenceExpression" }] }, + { code: "if(void x === void y);", errors: [{ messageId: "unexpected", type: "BinaryExpression" }] }, + { code: "if(void x && a);", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] }, + { code: "if(a && void x);", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] }, // #5693 - { code: "if(false && abc==='str'){}", errors: [{ message: "Unexpected constant condition.", type: "LogicalExpression" }] }, - { code: "if(true || abc==='str'){}", errors: [{ message: "Unexpected constant condition.", type: "LogicalExpression" }] }, - { code: "if(abc==='str' || true){}", errors: [{ message: "Unexpected constant condition.", type: "LogicalExpression" }] }, - { code: "if(abc==='str' || true || def ==='str'){}", errors: [{ message: "Unexpected constant condition.", type: "LogicalExpression" }] }, - { code: "if(false || true){}", errors: [{ message: "Unexpected constant condition.", type: "LogicalExpression" }] }, - { code: "if(typeof abc==='str' || true){}", errors: [{ message: "Unexpected constant condition.", type: "LogicalExpression" }] }, + { code: "if(false && abc==='str'){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] }, + { code: "if(true || abc==='str'){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] }, + { code: "if(abc==='str' || true){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] }, + { code: "if(abc==='str' || true || def ==='str'){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] }, + { code: "if(false || true){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] }, + { code: "if(typeof abc==='str' || true){}", errors: [{ messageId: "unexpected", type: "LogicalExpression" }] }, { code: "function* foo(){while(true){} yield 'foo';}", - errors: [{ message: "Unexpected constant condition.", type: "Literal" }] + errors: [{ messageId: "unexpected", type: "Literal" }] }, { code: "function* foo(){while(true){if (true) {yield 'foo';}}}", - errors: [{ message: "Unexpected constant condition.", type: "Literal" }] + errors: [{ messageId: "unexpected", type: "Literal" }] }, { code: "function* foo(){while(true){yield 'foo';} while(true) {}}", - errors: [{ message: "Unexpected constant condition.", type: "Literal" }] + errors: [{ messageId: "unexpected", type: "Literal" }] }, { code: "var a = function* foo(){while(true){} yield 'foo';}", - errors: [{ message: "Unexpected constant condition.", type: "Literal" }] + errors: [{ messageId: "unexpected", type: "Literal" }] }, { code: "while (true) { function* foo() {yield;}}", - errors: [{ message: "Unexpected constant condition.", type: "Literal" }] + errors: [{ messageId: "unexpected", type: "Literal" }] }, { code: "function* foo(){if (true) {yield 'foo';}}", - errors: [{ message: "Unexpected constant condition.", type: "Literal" }] + errors: [{ messageId: "unexpected", type: "Literal" }] }, { code: "function* foo() {for (let foo = yield; true;) {}}", - errors: [{ message: "Unexpected constant condition.", type: "Literal" }] + errors: [{ messageId: "unexpected", type: "Literal" }] }, { code: "function* foo() {for (foo = yield; true;) {}}", - errors: [{ message: "Unexpected constant condition.", type: "Literal" }] + errors: [{ messageId: "unexpected", type: "Literal" }] }, { code: "function foo() {while (true) {function* bar() {while (true) {yield;}}}}", - errors: [{ message: "Unexpected constant condition.", type: "Literal" }] + errors: [{ messageId: "unexpected", type: "Literal" }] }, { code: "function* foo() { for (let foo = 1 + 2 + 3 + (yield); true; baz) {}}", - errors: [{ message: "Unexpected constant condition.", type: "Literal" }] + errors: [{ messageId: "unexpected", type: "Literal" }] } ] }); diff --git a/tests/lib/rules/no-continue.js b/tests/lib/rules/no-continue.js index 16ed522829f..12e5baf69d3 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 caa052335db..ebadafc3001 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" }] } ] }); diff --git a/tests/lib/rules/no-debugger.js b/tests/lib/rules/no-debugger.js index 9edf059c41e..d977505999f 100644 --- a/tests/lib/rules/no-debugger.js +++ b/tests/lib/rules/no-debugger.js @@ -26,12 +26,12 @@ ruleTester.run("no-debugger", rule, { { code: "debugger", output: "", - errors: [{ message: "Unexpected 'debugger' statement.", type: "DebuggerStatement" }] + errors: [{ messageId: "unexpected", type: "DebuggerStatement" }] }, { code: "if (foo) debugger", output: null, - errors: [{ message: "Unexpected 'debugger' statement.", type: "DebuggerStatement" }] + errors: [{ messageId: "unexpected", type: "DebuggerStatement" }] } ] }); diff --git a/tests/lib/rules/no-delete-var.js b/tests/lib/rules/no-delete-var.js index 7e94c7f9ea9..ec284923e33 100644 --- a/tests/lib/rules/no-delete-var.js +++ b/tests/lib/rules/no-delete-var.js @@ -23,6 +23,6 @@ ruleTester.run("no-delete-var", rule, { "delete x.prop;" ], invalid: [ - { code: "delete x", errors: [{ message: "Variables should not be deleted.", type: "UnaryExpression" }] } + { code: "delete x", errors: [{ messageId: "unexpected", type: "UnaryExpression" }] } ] }); diff --git a/tests/lib/rules/no-div-regex.js b/tests/lib/rules/no-div-regex.js index 46881b363c6..fbad6a61886 100644 --- a/tests/lib/rules/no-div-regex.js +++ b/tests/lib/rules/no-div-regex.js @@ -24,6 +24,6 @@ ruleTester.run("no-div-regex", rule, { "var f = function() { return /\\=foo/; };" ], invalid: [ - { code: "var f = function() { return /=foo/; };", errors: [{ message: "A regular expression literal can be confused with '/='.", type: "Literal" }] } + { code: "var f = function() { return /=foo/; };", errors: [{ messageId: "unexpected", type: "Literal" }] } ] }); diff --git a/tests/lib/rules/no-dupe-args.js b/tests/lib/rules/no-dupe-args.js index b323fbe6ba0..829a6d81e65 100644 --- a/tests/lib/rules/no-dupe-args.js +++ b/tests/lib/rules/no-dupe-args.js @@ -27,13 +27,13 @@ ruleTester.run("no-dupe-args", rule, { { code: "function foo([[a, b], [c, d]]) {}", parserOptions: { ecmaVersion: 6 } } ], invalid: [ - { code: "function a(a, b, b) {}", errors: [{ message: "Duplicate param 'b'." }] }, - { code: "function a(a, a, a) {}", errors: [{ message: "Duplicate param 'a'." }] }, - { code: "function a(a, b, a) {}", errors: [{ message: "Duplicate param 'a'." }] }, - { code: "function a(a, b, a, b) {}", errors: [{ message: "Duplicate param 'a'." }, { message: "Duplicate param 'b'." }] }, - { code: "var a = function(a, b, b) {}", errors: [{ message: "Duplicate param 'b'." }] }, - { code: "var a = function(a, a, a) {}", errors: [{ message: "Duplicate param 'a'." }] }, - { code: "var a = function(a, b, a) {}", errors: [{ message: "Duplicate param 'a'." }] }, - { code: "var a = function(a, b, a, b) {}", errors: [{ message: "Duplicate param 'a'." }, { message: "Duplicate param 'b'." }] } + { code: "function a(a, b, b) {}", errors: [{ messageId: "unexpected", data: { name: "b" } }] }, + { code: "function a(a, a, a) {}", errors: [{ messageId: "unexpected", data: { name: "a" } }] }, + { code: "function a(a, b, a) {}", errors: [{ messageId: "unexpected", data: { name: "a" } }] }, + { code: "function a(a, b, a, b) {}", errors: [{ messageId: "unexpected", data: { name: "a" } }, { messageId: "unexpected", data: { name: "b" } }] }, + { code: "var a = function(a, b, b) {}", errors: [{ messageId: "unexpected", data: { name: "b" } }] }, + { code: "var a = function(a, a, a) {}", errors: [{ messageId: "unexpected", data: { name: "a" } }] }, + { code: "var a = function(a, b, a) {}", errors: [{ messageId: "unexpected", data: { name: "a" } }] }, + { code: "var a = function(a, b, a, b) {}", errors: [{ messageId: "unexpected", data: { name: "a" } }, { messageId: "unexpected", data: { name: "b" } }] } ] }); diff --git a/tests/lib/rules/no-dupe-class-members.js b/tests/lib/rules/no-dupe-class-members.js index 24eb2e53701..0c79dfb6242 100644 --- a/tests/lib/rules/no-dupe-class-members.js +++ b/tests/lib/rules/no-dupe-class-members.js @@ -35,50 +35,50 @@ ruleTester.run("no-dupe-class-members", rule, { { code: "class A { foo() {} foo() {} }", errors: [ - { type: "MethodDefinition", line: 1, column: 20, message: "Duplicate name 'foo'." } + { type: "MethodDefinition", line: 1, column: 20, messageId: "unexpected", data: { name: "foo" } } ] }, { code: "!class A { foo() {} foo() {} };", errors: [ - { type: "MethodDefinition", line: 1, column: 21, message: "Duplicate name 'foo'." } + { type: "MethodDefinition", line: 1, column: 21, messageId: "unexpected", data: { name: "foo" } } ] }, { code: "class A { 'foo'() {} 'foo'() {} }", errors: [ - { type: "MethodDefinition", line: 1, column: 22, message: "Duplicate name 'foo'." } + { type: "MethodDefinition", line: 1, column: 22, messageId: "unexpected", data: { name: "foo" } } ] }, { code: "class A { 10() {} 1e1() {} }", errors: [ - { type: "MethodDefinition", line: 1, column: 19, message: "Duplicate name '10'." } + { type: "MethodDefinition", line: 1, column: 19, messageId: "unexpected", data: { name: "10" } } ] }, { code: "class A { foo() {} foo() {} foo() {} }", errors: [ - { type: "MethodDefinition", line: 1, column: 20, message: "Duplicate name 'foo'." }, - { type: "MethodDefinition", line: 1, column: 29, message: "Duplicate name 'foo'." } + { type: "MethodDefinition", line: 1, column: 20, messageId: "unexpected", data: { name: "foo" } }, + { type: "MethodDefinition", line: 1, column: 29, messageId: "unexpected", data: { name: "foo" } } ] }, { code: "class A { static foo() {} static foo() {} }", errors: [ - { type: "MethodDefinition", line: 1, column: 27, message: "Duplicate name 'foo'." } + { type: "MethodDefinition", line: 1, column: 27, messageId: "unexpected", data: { name: "foo" } } ] }, { code: "class A { foo() {} get foo() {} }", errors: [ - { type: "MethodDefinition", line: 1, column: 20, message: "Duplicate name 'foo'." } + { type: "MethodDefinition", line: 1, column: 20, messageId: "unexpected", data: { name: "foo" } } ] }, { code: "class A { set foo(value) {} foo() {} }", errors: [ - { type: "MethodDefinition", line: 1, column: 29, message: "Duplicate name 'foo'." } + { type: "MethodDefinition", line: 1, column: 29, messageId: "unexpected", data: { name: "foo" } } ] } ] diff --git a/tests/lib/rules/no-dupe-keys.js b/tests/lib/rules/no-dupe-keys.js index d06f20c5788..c8ca43b54d4 100644 --- a/tests/lib/rules/no-dupe-keys.js +++ b/tests/lib/rules/no-dupe-keys.js @@ -30,13 +30,13 @@ ruleTester.run("no-dupe-keys", rule, { { code: "var {a, a} = obj", parserOptions: { ecmaVersion: 6 } } ], invalid: [ - { code: "var x = { a: b, ['a']: b };", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Duplicate key 'a'.", type: "ObjectExpression" }] }, - { code: "var x = { y: 1, y: 2 };", errors: [{ message: "Duplicate key 'y'.", type: "ObjectExpression" }] }, - { code: "var foo = { 0x1: 1, 1: 2};", errors: [{ message: "Duplicate key '1'.", type: "ObjectExpression" }] }, - { code: "var x = { \"z\": 1, z: 2 };", errors: [{ message: "Duplicate key 'z'.", type: "ObjectExpression" }] }, - { code: "var foo = {\n bar: 1,\n bar: 1,\n}", errors: [{ message: "Duplicate key 'bar'.", line: 3, column: 3 }] }, - { code: "var x = { a: 1, get a() {} };", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Duplicate key 'a'.", type: "ObjectExpression" }] }, - { code: "var x = { a: 1, set a(value) {} };", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Duplicate key 'a'.", type: "ObjectExpression" }] }, - { code: "var x = { a: 1, b: { a: 2 }, get b() {} };", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Duplicate key 'b'.", type: "ObjectExpression" }] } + { code: "var x = { a: b, ['a']: b };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] }, + { code: "var x = { y: 1, y: 2 };", errors: [{ messageId: "unexpected", data: { name: "y" }, type: "ObjectExpression" }] }, + { code: "var foo = { 0x1: 1, 1: 2};", errors: [{ messageId: "unexpected", data: { name: "1" }, type: "ObjectExpression" }] }, + { code: "var x = { \"z\": 1, z: 2 };", errors: [{ messageId: "unexpected", data: { name: "z" }, type: "ObjectExpression" }] }, + { code: "var foo = {\n bar: 1,\n bar: 1,\n}", errors: [{ messageId: "unexpected", data: { name: "bar" }, line: 3, column: 3 }] }, + { code: "var x = { a: 1, get a() {} };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] }, + { code: "var x = { a: 1, set a(value) {} };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "a" }, type: "ObjectExpression" }] }, + { code: "var x = { a: 1, b: { a: 2 }, get b() {} };", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", data: { name: "b" }, type: "ObjectExpression" }] } ] }); diff --git a/tests/lib/rules/no-duplicate-case.js b/tests/lib/rules/no-duplicate-case.js index c265dca1030..c01085e0420 100644 --- a/tests/lib/rules/no-duplicate-case.js +++ b/tests/lib/rules/no-duplicate-case.js @@ -35,63 +35,63 @@ ruleTester.run("no-duplicate-case", rule, { { code: "var a = 1; switch (a) {case 1: break; case 1: break; case 2: break; default: break;}", errors: [{ - message: "Duplicate case label.", + messageId: "unexpected", type: "SwitchCase" }] }, { code: "var a = '1'; switch (a) {case '1': break; case '1': break; case '2': break; default: break;}", errors: [{ - message: "Duplicate case label.", + messageId: "unexpected", type: "SwitchCase" }] }, { code: "var a = 1, one = 1; switch (a) {case one: break; case one: break; case 2: break; default: break;}", errors: [{ - message: "Duplicate case label.", + messageId: "unexpected", type: "SwitchCase" }] }, { code: "var a = 1, p = {p: {p1: 1, p2: 1}}; switch (a) {case p.p.p1: break; case p.p.p1: break; default: break;}", errors: [{ - message: "Duplicate case label.", + messageId: "unexpected", type: "SwitchCase" }] }, { code: "var a = 1, f = function(b) { return b ? { p1: 1 } : { p1: 2 }; }; switch (a) {case f(true).p1: break; case f(true).p1: break; default: break;}", errors: [{ - message: "Duplicate case label.", + messageId: "unexpected", type: "SwitchCase" }] }, { code: "var a = 1, f = function(s) { return { p1: s } }; switch (a) {case f(a + 1).p1: break; case f(a + 1).p1: break; default: break;}", errors: [{ - message: "Duplicate case label.", + messageId: "unexpected", type: "SwitchCase" }] }, { code: "var a = 1, f = function(s) { return { p1: s } }; switch (a) {case f(a === 1 ? 2 : 3).p1: break; case f(a === 1 ? 2 : 3).p1: break; default: break;}", errors: [{ - message: "Duplicate case label.", + messageId: "unexpected", type: "SwitchCase" }] }, { code: "var a = 1, f1 = function() { return { p1: 1 } }; switch (a) {case f1().p1: break; case f1().p1: break; default: break;}", errors: [{ - message: "Duplicate case label.", + messageId: "unexpected", type: "SwitchCase" }] }, { code: "var a = [1, 2]; switch(a.toString()){case ([1, 2]).toString():break; case ([1, 2]).toString():break; default:break;}", errors: [{ - message: "Duplicate case label.", + messageId: "unexpected", type: "SwitchCase" }] } diff --git a/tests/lib/rules/no-else-return.js b/tests/lib/rules/no-else-return.js index f88407151f2..6111b55da65 100644 --- a/tests/lib/rules/no-else-return.js +++ b/tests/lib/rules/no-else-return.js @@ -60,128 +60,128 @@ ruleTester.run("no-else-return", rule, { { code: "function foo1() { if (true) { return x; } else { return y; } }", output: "function foo1() { if (true) { return x; } return y; }", - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo2() { if (true) { var x = bar; return x; } else { var y = baz; return y; } }", output: "function foo2() { if (true) { var x = bar; return x; } var y = baz; return y; }", - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo3() { if (true) return x; else return y; }", output: "function foo3() { if (true) return x; return y; }", - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "ReturnStatement" }] + errors: [{ messageId: "unexpected", type: "ReturnStatement" }] }, { code: "function foo4() { if (true) { if (false) return x; else return y; } else { return z; } }", output: "function foo4() { if (true) { if (false) return x; return y; } else { return z; } }", // Other case is fixed in the second pass. - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "ReturnStatement" }, { message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "ReturnStatement" }, { messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo5() { if (true) { if (false) { if (true) return x; else { w = y; } } else { w = x; } } else { return z; } }", output: "function foo5() { if (true) { if (false) { if (true) return x; w = y; } else { w = x; } } else { return z; } }", - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo6() { if (true) { if (false) { if (true) return x; else return y; } } else { return z; } }", output: "function foo6() { if (true) { if (false) { if (true) return x; return y; } } else { return z; } }", - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "ReturnStatement" }] + errors: [{ messageId: "unexpected", type: "ReturnStatement" }] }, { code: "function foo7() { if (true) { if (false) { if (true) return x; else return y; } return w; } else { return z; } }", output: "function foo7() { if (true) { if (false) { if (true) return x; return y; } return w; } else { return z; } }", // Other case is fixed in the second pass. errors: [ - { message: "Unnecessary 'else' after 'return'.", type: "ReturnStatement" }, - { message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" } + { messageId: "unexpected", type: "ReturnStatement" }, + { messageId: "unexpected", type: "BlockStatement" } ] }, { code: "function foo8() { if (true) { if (false) { if (true) return x; else return y; } else { w = x; } } else { return z; } }", output: "function foo8() { if (true) { if (false) { if (true) return x; return y; } else { w = x; } } else { return z; } }", // Other case is fixed in the second pass. errors: [ - { message: "Unnecessary 'else' after 'return'.", type: "ReturnStatement" }, - { message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" } + { messageId: "unexpected", type: "ReturnStatement" }, + { messageId: "unexpected", type: "BlockStatement" } ] }, { code: "function foo9() {if (x) { return true; } else if (y) { return true; } else { notAReturn(); } }", output: "function foo9() {if (x) { return true; } else if (y) { return true; } notAReturn(); }", - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo9a() {if (x) { return true; } else if (y) { return true; } else { notAReturn(); } }", output: "function foo9a() {if (x) { return true; } if (y) { return true; } else { notAReturn(); } }", options: [{ allowElseIf: false }], - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "IfStatement" }] + errors: [{ messageId: "unexpected", type: "IfStatement" }] }, { code: "function foo9b() {if (x) { return true; } if (y) { return true; } else { notAReturn(); } }", output: "function foo9b() {if (x) { return true; } if (y) { return true; } notAReturn(); }", options: [{ allowElseIf: false }], - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo10() { if (foo) return bar; else (foo).bar(); }", output: "function foo10() { if (foo) return bar; (foo).bar(); }", - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "ExpressionStatement" }] + errors: [{ messageId: "unexpected", type: "ExpressionStatement" }] }, { code: "function foo11() { if (foo) return bar \nelse { [1, 2, 3].map(foo) } }", output: null, - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo12() { if (foo) return bar \nelse { baz() } \n[1, 2, 3].map(foo) }", output: null, - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo13() { if (foo) return bar; \nelse { [1, 2, 3].map(foo) } }", output: "function foo13() { if (foo) return bar; \n [1, 2, 3].map(foo) }", - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo14() { if (foo) return bar \nelse { baz(); } \n[1, 2, 3].map(foo) }", output: "function foo14() { if (foo) return bar \n baz(); \n[1, 2, 3].map(foo) }", - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo15() { if (foo) return bar; else { baz() } qaz() }", output: null, - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo16() { if (foo) return bar \nelse { baz() } qaz() }", output: null, - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo17() { if (foo) return bar \nelse { baz() } \nqaz() }", output: "function foo17() { if (foo) return bar \n baz() \nqaz() }", - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", type: "BlockStatement" }] }, { code: "function foo18() { if (foo) return function() {} \nelse [1, 2, 3].map(bar) }", output: null, - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "ExpressionStatement" }] + errors: [{ messageId: "unexpected", type: "ExpressionStatement" }] }, { code: "function foo19() { if (true) { return x; } else if (false) { return y; } }", output: "function foo19() { if (true) { return x; } if (false) { return y; } }", options: [{ allowElseIf: false }], - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "IfStatement" }] + errors: [{ messageId: "unexpected", type: "IfStatement" }] }, { code: "function foo20() {if (x) { return true; } else if (y) { notAReturn() } else { notAReturn(); } }", output: "function foo20() {if (x) { return true; } if (y) { notAReturn() } else { notAReturn(); } }", options: [{ allowElseIf: false }], - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "IfStatement" }] + errors: [{ messageId: "unexpected", type: "IfStatement" }] }, { code: "function foo21() { var x = true; if (x) { return x; } else if (x === false) { return false; } }", output: "function foo21() { var x = true; if (x) { return x; } if (x === false) { return false; } }", options: [{ allowElseIf: false }], - errors: [{ message: "Unnecessary 'else' after 'return'.", type: "IfStatement" }] + errors: [{ messageId: "unexpected", type: "IfStatement" }] } ] }); diff --git a/tests/lib/rules/no-empty-character-class.js b/tests/lib/rules/no-empty-character-class.js index d72eb3ca661..ce81e5488e6 100644 --- a/tests/lib/rules/no-empty-character-class.js +++ b/tests/lib/rules/no-empty-character-class.js @@ -33,12 +33,12 @@ ruleTester.run("no-empty-character-class", rule, { { code: "var foo = /[\\]]/uy;", parserOptions: { ecmaVersion: 6 } } ], invalid: [ - { code: "var foo = /^abc[]/;", errors: [{ message: "Empty class.", type: "Literal" }] }, - { code: "var foo = /foo[]bar/;", errors: [{ message: "Empty class.", type: "Literal" }] }, - { code: "if (foo.match(/^abc[]/)) {}", errors: [{ message: "Empty class.", type: "Literal" }] }, - { code: "if (/^abc[]/.test(foo)) {}", errors: [{ message: "Empty class.", type: "Literal" }] }, - { code: "var foo = /[]]/;", errors: [{ message: "Empty class.", type: "Literal" }] }, - { code: "var foo = /\\[[]/;", errors: [{ message: "Empty class.", type: "Literal" }] }, - { code: "var foo = /\\[\\[\\]a-z[]/;", errors: [{ message: "Empty class.", type: "Literal" }] } + { code: "var foo = /^abc[]/;", errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "var foo = /foo[]bar/;", errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "if (foo.match(/^abc[]/)) {}", errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "if (/^abc[]/.test(foo)) {}", errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "var foo = /[]]/;", errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "var foo = /\\[[]/;", errors: [{ messageId: "unexpected", type: "Literal" }] }, + { code: "var foo = /\\[\\[\\]a-z[]/;", errors: [{ messageId: "unexpected", type: "Literal" }] } ] }); diff --git a/tests/lib/rules/no-empty-function.js b/tests/lib/rules/no-empty-function.js index 5f65f992fbd..416a47da687 100644 --- a/tests/lib/rules/no-empty-function.js +++ b/tests/lib/rules/no-empty-function.js @@ -58,10 +58,12 @@ function toValidInvalid(patterns, item) { } ); + const error = item.message || { messageId: item.messageId, data: item.data }; + // Invalid Patterns. patterns.invalid.push({ code: item.code, - errors: [item.message], + errors: [error], parserOptions: { ecmaVersion: 6 } }); ALLOW_OPTIONS @@ -71,7 +73,7 @@ function toValidInvalid(patterns, item) { // non related "allow" option has no effect. patterns.invalid.push({ code: `${item.code} // allow: ${allow}`, - errors: [item.message], + errors: [error], options: [{ allow: [allow] }], parserOptions: { ecmaVersion: 6 } }); @@ -89,147 +91,176 @@ const ruleTester = new RuleTester(); ruleTester.run("no-empty-function", rule, [ { code: "function foo() {}", - message: "Unexpected empty function 'foo'.", + messageId: "unexpected", + data: { name: "function 'foo'" }, allow: "functions" }, { code: "var foo = function() {};", - message: "Unexpected empty function.", + messageId: "unexpected", + data: { name: "function" }, allow: "functions" }, { code: "var obj = {foo: function() {}};", - message: "Unexpected empty method 'foo'.", + messageId: "unexpected", + data: { name: "method 'foo'" }, allow: "functions" }, { code: "var foo = () => {};", - message: "Unexpected empty arrow function.", + messageId: "unexpected", + data: { name: "arrow function" }, allow: "arrowFunctions" }, { code: "function* foo() {}", - message: "Unexpected empty generator function 'foo'.", + messageId: "unexpected", + data: { name: "generator function 'foo'" }, allow: "generatorFunctions" }, { code: "var foo = function*() {};", - message: "Unexpected empty generator function.", + messageId: "unexpected", + data: { name: "generator function" }, allow: "generatorFunctions" }, { code: "var obj = {foo: function*() {}};", - message: "Unexpected empty generator method 'foo'.", + messageId: "unexpected", + data: { name: "generator method 'foo'" }, allow: "generatorFunctions" }, { code: "var obj = {foo() {}};", - message: "Unexpected empty method 'foo'.", + messageId: "unexpected", + data: { name: "method 'foo'" }, allow: "methods" }, { code: "class A {foo() {}}", - message: "Unexpected empty method 'foo'.", + messageId: "unexpected", + data: { name: "method 'foo'" }, allow: "methods" }, { code: "class A {static foo() {}}", - message: "Unexpected empty static method 'foo'.", + messageId: "unexpected", + data: { name: "static method 'foo'" }, allow: "methods" }, { code: "var A = class {foo() {}};", - message: "Unexpected empty method 'foo'.", + messageId: "unexpected", + data: { name: "method 'foo'" }, allow: "methods" }, { code: "var A = class {static foo() {}};", - message: "Unexpected empty static method 'foo'.", + messageId: "unexpected", + data: { name: "static method 'foo'" }, allow: "methods" }, { code: "var obj = {*foo() {}};", - message: "Unexpected empty generator method 'foo'.", + messageId: "unexpected", + data: { name: "generator method 'foo'" }, allow: "generatorMethods" }, { code: "class A {*foo() {}}", - message: "Unexpected empty generator method 'foo'.", + messageId: "unexpected", + data: { name: "generator method 'foo'" }, allow: "generatorMethods" }, { code: "class A {static *foo() {}}", - message: "Unexpected empty static generator method 'foo'.", + messageId: "unexpected", + data: { name: "static generator method 'foo'" }, allow: "generatorMethods" }, { code: "var A = class {*foo() {}};", - message: "Unexpected empty generator method 'foo'.", + messageId: "unexpected", + data: { name: "generator method 'foo'" }, allow: "generatorMethods" }, { code: "var A = class {static *foo() {}};", - message: "Unexpected empty static generator method 'foo'.", + messageId: "unexpected", + data: { name: "static generator method 'foo'" }, allow: "generatorMethods" }, { code: "var obj = {get foo() {}};", - message: "Unexpected empty getter 'foo'.", + messageId: "unexpected", + data: { name: "getter 'foo'" }, allow: "getters" }, { code: "class A {get foo() {}}", - message: "Unexpected empty getter 'foo'.", + messageId: "unexpected", + data: { name: "getter 'foo'" }, allow: "getters" }, { code: "class A {static get foo() {}}", - message: "Unexpected empty static getter 'foo'.", + messageId: "unexpected", + data: { name: "static getter 'foo'" }, allow: "getters" }, { code: "var A = class {get foo() {}};", - message: "Unexpected empty getter 'foo'.", + messageId: "unexpected", + data: { name: "getter 'foo'" }, allow: "getters" }, { code: "var A = class {static get foo() {}};", - message: "Unexpected empty static getter 'foo'.", + messageId: "unexpected", + data: { name: "static getter 'foo'" }, allow: "getters" }, { code: "var obj = {set foo(value) {}};", - message: "Unexpected empty setter 'foo'.", + messageId: "unexpected", + data: { name: "setter 'foo'" }, allow: "setters" }, { code: "class A {set foo(value) {}}", - message: "Unexpected empty setter 'foo'.", + messageId: "unexpected", + data: { name: "setter 'foo'" }, allow: "setters" }, { code: "class A {static set foo(value) {}}", - message: "Unexpected empty static setter 'foo'.", + messageId: "unexpected", + data: { name: "static setter 'foo'" }, allow: "setters" }, { code: "var A = class {set foo(value) {}};", - message: "Unexpected empty setter 'foo'.", + messageId: "unexpected", + data: { name: "setter 'foo'" }, allow: "setters" }, { code: "var A = class {static set foo(value) {}};", - message: "Unexpected empty static setter 'foo'.", + messageId: "unexpected", + data: { name: "static setter 'foo'" }, allow: "setters" }, { code: "class A {constructor() {}}", - message: "Unexpected empty constructor.", + messageId: "unexpected", + data: { name: "constructor" }, allow: "constructors" }, { code: "var A = class {constructor() {}};", - message: "Unexpected empty constructor.", + messageId: "unexpected", + data: { name: "constructor" }, allow: "constructors" } ].reduce(toValidInvalid, { diff --git a/tests/lib/rules/no-empty-pattern.js b/tests/lib/rules/no-empty-pattern.js index c3762e55e12..64b32977a6e 100644 --- a/tests/lib/rules/no-empty-pattern.js +++ b/tests/lib/rules/no-empty-pattern.js @@ -35,7 +35,8 @@ ruleTester.run("no-empty-pattern", rule, { code: "var {} = foo", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Unexpected empty object pattern.", + messageId: "unexpected", + data: { type: "object" }, type: "ObjectPattern" }] }, @@ -43,7 +44,8 @@ ruleTester.run("no-empty-pattern", rule, { code: "var [] = foo", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Unexpected empty array pattern.", + messageId: "unexpected", + data: { type: "array" }, type: "ArrayPattern" }] }, @@ -51,7 +53,8 @@ ruleTester.run("no-empty-pattern", rule, { code: "var {a: {}} = foo", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Unexpected empty object pattern.", + messageId: "unexpected", + data: { type: "object" }, type: "ObjectPattern" }] }, @@ -59,7 +62,8 @@ ruleTester.run("no-empty-pattern", rule, { code: "var {a, b: {}} = foo", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Unexpected empty object pattern.", + messageId: "unexpected", + data: { type: "object" }, type: "ObjectPattern" }] }, @@ -67,7 +71,8 @@ ruleTester.run("no-empty-pattern", rule, { code: "var {a: []} = foo", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Unexpected empty array pattern.", + messageId: "unexpected", + data: { type: "array" }, type: "ArrayPattern" }] }, @@ -75,7 +80,8 @@ ruleTester.run("no-empty-pattern", rule, { code: "function foo({}) {}", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Unexpected empty object pattern.", + messageId: "unexpected", + data: { type: "object" }, type: "ObjectPattern" }] }, @@ -83,7 +89,8 @@ ruleTester.run("no-empty-pattern", rule, { code: "function foo([]) {}", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Unexpected empty array pattern.", + messageId: "unexpected", + data: { type: "array" }, type: "ArrayPattern" }] }, @@ -91,7 +98,8 @@ ruleTester.run("no-empty-pattern", rule, { code: "function foo({a: {}}) {}", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Unexpected empty object pattern.", + messageId: "unexpected", + data: { type: "object" }, type: "ObjectPattern" }] }, @@ -99,7 +107,8 @@ ruleTester.run("no-empty-pattern", rule, { code: "function foo({a: []}) {}", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Unexpected empty array pattern.", + messageId: "unexpected", + data: { type: "array" }, type: "ArrayPattern" }] } diff --git a/tests/lib/rules/no-empty.js b/tests/lib/rules/no-empty.js index 61741f007bd..8706b276f95 100644 --- a/tests/lib/rules/no-empty.js +++ b/tests/lib/rules/no-empty.js @@ -44,36 +44,36 @@ ruleTester.run("no-empty", rule, { { code: "try { foo(); } catch (ex) {} finally { bar(); }", options: [{ allowEmptyCatch: true }] } ], invalid: [ - { code: "try {} catch (ex) {throw ex}", errors: [{ message: "Empty block statement.", type: "BlockStatement" }] }, - { code: "try { foo() } catch (ex) {}", errors: [{ message: "Empty block statement.", type: "BlockStatement" }] }, - { code: "try { foo() } catch (ex) {throw ex} finally {}", errors: [{ message: "Empty block statement.", type: "BlockStatement" }] }, - { code: "if (foo) {}", errors: [{ message: "Empty block statement.", type: "BlockStatement" }] }, - { code: "while (foo) {}", errors: [{ message: "Empty block statement.", type: "BlockStatement" }] }, - { code: "for (;foo;) {}", errors: [{ message: "Empty block statement.", type: "BlockStatement" }] }, - { code: "switch(foo) {}", errors: [{ message: "Empty switch statement.", type: "SwitchStatement" }] }, + { code: "try {} catch (ex) {throw ex}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] }, + { code: "try { foo() } catch (ex) {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] }, + { code: "try { foo() } catch (ex) {throw ex} finally {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] }, + { code: "if (foo) {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] }, + { code: "while (foo) {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] }, + { code: "for (;foo;) {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] }, + { code: "switch(foo) {}", errors: [{ messageId: "unexpected", data: { type: "switch" }, type: "SwitchStatement" }] }, { code: "try {} catch (ex) {}", options: [{ allowEmptyCatch: true }], - errors: [{ message: "Empty block statement.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] }, { code: "try { foo(); } catch (ex) {} finally {}", options: [{ allowEmptyCatch: true }], - errors: [{ message: "Empty block statement.", type: "BlockStatement" }] + errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] }, { code: "try {} catch (ex) {} finally {}", options: [{ allowEmptyCatch: true }], errors: [ - { message: "Empty block statement.", type: "BlockStatement" }, - { message: "Empty block statement.", type: "BlockStatement" } + { messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }, + { messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" } ] }, { code: "try { foo(); } catch (ex) {} finally {}", errors: [ - { message: "Empty block statement.", type: "BlockStatement" }, - { message: "Empty block statement.", type: "BlockStatement" } + { messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }, + { messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" } ] } ] diff --git a/tests/lib/rules/no-eq-null.js b/tests/lib/rules/no-eq-null.js index 23d992dc58f..709913c4230 100644 --- a/tests/lib/rules/no-eq-null.js +++ b/tests/lib/rules/no-eq-null.js @@ -18,16 +18,14 @@ const rule = require("../../../lib/rules/no-eq-null"), const ruleTester = new RuleTester(); -const MESSAGE = "Use '===' to compare with null."; - ruleTester.run("no-eq-null", rule, { valid: [ "if (x === null) { }", "if (null === f()) { }" ], invalid: [ - { code: "if (x == null) { }", errors: [{ message: MESSAGE, type: "BinaryExpression" }] }, - { code: "if (x != null) { }", errors: [{ message: MESSAGE, type: "BinaryExpression" }] }, - { code: "do {} while (null == x)", errors: [{ message: MESSAGE, type: "BinaryExpression" }] } + { code: "if (x == null) { }", errors: [{ messageId: "unexpected", type: "BinaryExpression" }] }, + { code: "if (x != null) { }", errors: [{ messageId: "unexpected", type: "BinaryExpression" }] }, + { code: "do {} while (null == x)", errors: [{ messageId: "unexpected", type: "BinaryExpression" }] } ] }); diff --git a/tests/lib/rules/no-eval.js b/tests/lib/rules/no-eval.js index 4ad32137cdf..d31c726b946 100644 --- a/tests/lib/rules/no-eval.js +++ b/tests/lib/rules/no-eval.js @@ -63,27 +63,27 @@ ruleTester.run("no-eval", rule, { invalid: [ // Direct eval - { code: "eval(foo)", errors: [{ message: "eval can be harmful.", type: "CallExpression" }] }, - { code: "eval('foo')", errors: [{ message: "eval can be harmful.", type: "CallExpression" }] }, - { code: "function foo(eval) { eval('foo') }", errors: [{ message: "eval can be harmful.", type: "CallExpression" }] }, - { code: "eval(foo)", options: [{ allowIndirect: true }], errors: [{ message: "eval can be harmful.", type: "CallExpression" }] }, - { code: "eval('foo')", options: [{ allowIndirect: true }], errors: [{ message: "eval can be harmful.", type: "CallExpression" }] }, - { code: "function foo(eval) { eval('foo') }", options: [{ allowIndirect: true }], errors: [{ message: "eval can be harmful.", type: "CallExpression" }] }, + { code: "eval(foo)", errors: [{ messageId: "unexpected", type: "CallExpression" }] }, + { code: "eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression" }] }, + { code: "function foo(eval) { eval('foo') }", errors: [{ messageId: "unexpected", type: "CallExpression" }] }, + { code: "eval(foo)", options: [{ allowIndirect: true }], errors: [{ messageId: "unexpected", type: "CallExpression" }] }, + { code: "eval('foo')", options: [{ allowIndirect: true }], errors: [{ messageId: "unexpected", type: "CallExpression" }] }, + { code: "function foo(eval) { eval('foo') }", options: [{ allowIndirect: true }], errors: [{ messageId: "unexpected", type: "CallExpression" }] }, // Indirect eval - { code: "(0, eval)('foo')", errors: [{ message: "eval can be harmful.", type: "Identifier" }] }, - { code: "(0, window.eval)('foo')", errors: [{ message: "eval can be harmful.", type: "MemberExpression" }], env: { browser: true } }, - { code: "(0, window['eval'])('foo')", errors: [{ message: "eval can be harmful.", type: "MemberExpression" }], env: { browser: true } }, - { code: "var EVAL = eval; EVAL('foo')", errors: [{ message: "eval can be harmful.", type: "Identifier" }] }, - { code: "var EVAL = this.eval; EVAL('foo')", errors: [{ message: "eval can be harmful.", type: "MemberExpression" }] }, - { code: "(function(exe){ exe('foo') })(eval);", errors: [{ message: "eval can be harmful.", type: "Identifier" }] }, - { code: "window.eval('foo')", errors: [{ message: "eval can be harmful.", type: "CallExpression" }], env: { browser: true } }, - { code: "window.window.eval('foo')", errors: [{ message: "eval can be harmful.", type: "CallExpression" }], env: { browser: true } }, - { code: "window.window['eval']('foo')", errors: [{ message: "eval can be harmful.", type: "CallExpression" }], env: { browser: true } }, - { code: "global.eval('foo')", errors: [{ message: "eval can be harmful.", type: "CallExpression" }], env: { node: true } }, - { code: "global.global.eval('foo')", errors: [{ message: "eval can be harmful.", type: "CallExpression" }], env: { node: true } }, - { code: "global.global[`eval`]('foo')", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "eval can be harmful.", type: "CallExpression" }], env: { node: true } }, - { code: "this.eval('foo')", errors: [{ message: "eval can be harmful.", type: "CallExpression" }] }, - { code: "function foo() { this.eval('foo') }", errors: [{ message: "eval can be harmful.", type: "CallExpression" }] } + { code: "(0, eval)('foo')", errors: [{ messageId: "unexpected", type: "Identifier" }] }, + { code: "(0, window.eval)('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression" }], env: { browser: true } }, + { code: "(0, window['eval'])('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression" }], env: { browser: true } }, + { code: "var EVAL = eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "Identifier" }] }, + { code: "var EVAL = this.eval; EVAL('foo')", errors: [{ messageId: "unexpected", type: "MemberExpression" }] }, + { code: "(function(exe){ exe('foo') })(eval);", errors: [{ messageId: "unexpected", type: "Identifier" }] }, + { code: "window.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression" }], env: { browser: true } }, + { code: "window.window.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression" }], env: { browser: true } }, + { code: "window.window['eval']('foo')", errors: [{ messageId: "unexpected", type: "CallExpression" }], env: { browser: true } }, + { code: "global.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression" }], env: { node: true } }, + { code: "global.global.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression" }], env: { node: true } }, + { code: "global.global[`eval`]('foo')", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "CallExpression" }], env: { node: true } }, + { code: "this.eval('foo')", errors: [{ messageId: "unexpected", type: "CallExpression" }] }, + { code: "function foo() { this.eval('foo') }", errors: [{ messageId: "unexpected", type: "CallExpression" }] } ] }); diff --git a/tests/lib/rules/no-ex-assign.js b/tests/lib/rules/no-ex-assign.js index ba753ea9ab7..76ff6fb015d 100644 --- a/tests/lib/rules/no-ex-assign.js +++ b/tests/lib/rules/no-ex-assign.js @@ -25,10 +25,10 @@ ruleTester.run("no-ex-assign", rule, { "function foo() { try { } catch (e) { return false; } }" ], invalid: [ - { code: "try { } catch (e) { e = 10; }", errors: [{ message: "Do not assign to the exception parameter.", type: "Identifier" }] }, - { code: "try { } catch (ex) { ex = 10; }", errors: [{ message: "Do not assign to the exception parameter.", type: "Identifier" }] }, - { code: "try { } catch (ex) { [ex] = []; }", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Do not assign to the exception parameter.", type: "Identifier" }] }, - { code: "try { } catch (ex) { ({x: ex = 0} = {}); }", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Do not assign to the exception parameter.", type: "Identifier" }] }, - { code: "try { } catch ({message}) { message = 10; }", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Do not assign to the exception parameter.", type: "Identifier" }] } + { code: "try { } catch (e) { e = 10; }", errors: [{ messageId: "unexpected", type: "Identifier" }] }, + { code: "try { } catch (ex) { ex = 10; }", errors: [{ messageId: "unexpected", type: "Identifier" }] }, + { code: "try { } catch (ex) { [ex] = []; }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, + { code: "try { } catch (ex) { ({x: ex = 0} = {}); }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Identifier" }] }, + { code: "try { } catch ({message}) { message = 10; }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpected", type: "Identifier" }] } ] }); diff --git a/tests/lib/rules/no-extend-native.js b/tests/lib/rules/no-extend-native.js index ec5449a87e3..05923d6b2c4 100644 --- a/tests/lib/rules/no-extend-native.js +++ b/tests/lib/rules/no-extend-native.js @@ -52,43 +52,50 @@ ruleTester.run("no-extend-native", rule, { invalid: [{ code: "Object.prototype.p = 0", errors: [{ - message: "Object prototype is read only, properties should not be added.", + messageId: "unexpected", + data: { builtin: "Object" }, type: "AssignmentExpression" }] }, { code: "Function.prototype['p'] = 0", errors: [{ - message: "Function prototype is read only, properties should not be added.", + messageId: "unexpected", + data: { builtin: "Function" }, type: "AssignmentExpression" }] }, { code: "String['prototype'].p = 0", errors: [{ - message: "String prototype is read only, properties should not be added.", + messageId: "unexpected", + data: { builtin: "String" }, type: "AssignmentExpression" }] }, { code: "Number['prototype']['p'] = 0", errors: [{ - message: "Number prototype is read only, properties should not be added.", + messageId: "unexpected", + data: { builtin: "Number" }, type: "AssignmentExpression" }] }, { code: "Object.defineProperty(Array.prototype, 'p', {value: 0})", errors: [{ - message: "Array prototype is read only, properties should not be added.", + messageId: "unexpected", + data: { builtin: "Array" }, type: "CallExpression" }] }, { code: "Object.defineProperties(Array.prototype, {p: {value: 0}})", errors: [{ - message: "Array prototype is read only, properties should not be added.", + messageId: "unexpected", + data: { builtin: "Array" }, type: "CallExpression" }] }, { code: "Object.defineProperties(Array.prototype, {p: {value: 0}, q: {value: 0}})", errors: [{ - message: "Array prototype is read only, properties should not be added.", + messageId: "unexpected", + data: { builtin: "Array" }, type: "CallExpression" }] }, @@ -96,18 +103,21 @@ ruleTester.run("no-extend-native", rule, { code: "Number['prototype']['p'] = 0", options: [{ exceptions: ["Object"] }], errors: [{ - message: "Number prototype is read only, properties should not be added.", + messageId: "unexpected", + data: { builtin: "Number" }, type: "AssignmentExpression" }] }, { code: "Object.prototype.p = 0; Object.prototype.q = 0", errors: [{ - message: "Object prototype is read only, properties should not be added.", + messageId: "unexpected", + data: { builtin: "Object" }, type: "AssignmentExpression", column: 1 }, { - message: "Object prototype is read only, properties should not be added.", + messageId: "unexpected", + data: { builtin: "Object" }, type: "AssignmentExpression", column: 25 }] @@ -115,7 +125,8 @@ ruleTester.run("no-extend-native", rule, { { code: "function foo() { Object.prototype.p = 0 }", errors: [{ - message: "Object prototype is read only, properties should not be added.", + messageId: "unexpected", + data: { builtin: "Object" }, type: "AssignmentExpression" }] }] diff --git a/tests/lib/rules/no-extra-bind.js b/tests/lib/rules/no-extra-bind.js index 1aced94560d..4dfec87ac6c 100644 --- a/tests/lib/rules/no-extra-bind.js +++ b/tests/lib/rules/no-extra-bind.js @@ -16,7 +16,7 @@ const rule = require("../../../lib/rules/no-extra-bind"), //------------------------------------------------------------------------------ const ruleTester = new RuleTester(); -const errors = [{ message: "The function binding is unnecessary.", type: "CallExpression" }]; +const errors = [{ messageId: "unexpected", type: "CallExpression" }]; ruleTester.run("no-extra-bind", rule, { valid: [ @@ -73,7 +73,7 @@ ruleTester.run("no-extra-bind", rule, { { code: "var a = function() { (function(){ (function(){ this.d }.bind(c)) }) }.bind(b)", output: "var a = function() { (function(){ (function(){ this.d }.bind(c)) }) }", - errors: [{ message: "The function binding is unnecessary.", type: "CallExpression", column: 71 }] + errors: [{ messageId: "unexpected", type: "CallExpression", column: 71 }] } ] }); diff --git a/tests/lib/rules/no-extra-boolean-cast.js b/tests/lib/rules/no-extra-boolean-cast.js index c929167d617..1db0cfb6f7a 100644 --- a/tests/lib/rules/no-extra-boolean-cast.js +++ b/tests/lib/rules/no-extra-boolean-cast.js @@ -39,7 +39,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "if (!!foo) {}", output: "if (foo) {}", errors: [{ - message: "Redundant double negation.", + messageId: "unexpectedNegation", type: "UnaryExpression" }] }, @@ -47,7 +47,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "do {} while (!!foo)", output: "do {} while (foo)", errors: [{ - message: "Redundant double negation.", + messageId: "unexpectedNegation", type: "UnaryExpression" }] }, @@ -55,7 +55,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "while (!!foo) {}", output: "while (foo) {}", errors: [{ - message: "Redundant double negation.", + messageId: "unexpectedNegation", type: "UnaryExpression" }] }, @@ -63,7 +63,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!!foo ? bar : baz", output: "foo ? bar : baz", errors: [{ - message: "Redundant double negation.", + messageId: "unexpectedNegation", type: "UnaryExpression" }] }, @@ -71,7 +71,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "for (; !!foo;) {}", output: "for (; foo;) {}", errors: [{ - message: "Redundant double negation.", + messageId: "unexpectedNegation", type: "UnaryExpression" }] }, @@ -79,7 +79,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!!!foo", output: "!foo", errors: [{ - message: "Redundant double negation.", + messageId: "unexpectedNegation", type: "UnaryExpression" }] }, @@ -87,7 +87,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "Boolean(!!foo)", output: "Boolean(foo)", errors: [{ - message: "Redundant double negation.", + messageId: "unexpectedNegation", type: "UnaryExpression" }] }, @@ -95,7 +95,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "new Boolean(!!foo)", output: "new Boolean(foo)", errors: [{ - message: "Redundant double negation.", + messageId: "unexpectedNegation", type: "UnaryExpression" }] }, @@ -103,7 +103,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "if (Boolean(foo)) {}", output: "if (foo) {}", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -111,7 +111,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "do {} while (Boolean(foo))", output: "do {} while (foo)", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -119,7 +119,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "while (Boolean(foo)) {}", output: "while (foo) {}", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -127,7 +127,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "Boolean(foo) ? bar : baz", output: "foo ? bar : baz", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -135,7 +135,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "for (; Boolean(foo);) {}", output: "for (; foo;) {}", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -143,7 +143,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!Boolean(foo)", output: "!foo", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -151,7 +151,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!Boolean(foo && bar)", output: "!(foo && bar)", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -159,7 +159,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!Boolean(foo + bar)", output: "!(foo + bar)", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -167,7 +167,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!Boolean(+foo)", output: "!+foo", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -175,7 +175,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!Boolean(foo())", output: "!foo()", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -183,7 +183,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!Boolean(foo = bar)", output: "!(foo = bar)", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -192,7 +192,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { output: null, parserOptions: { ecmaVersion: 2015 }, errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -200,7 +200,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!Boolean(foo, bar());", output: null, errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -208,7 +208,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!Boolean((foo, bar()));", output: "!(foo, bar());", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -216,7 +216,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!Boolean();", output: "true;", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] }, @@ -224,7 +224,7 @@ ruleTester.run("no-extra-boolean-cast", rule, { code: "!(Boolean());", output: "true;", errors: [{ - message: "Redundant Boolean call.", + messageId: "unexpectedCall", type: "CallExpression" }] } diff --git a/tests/lib/rules/no-extra-label.js b/tests/lib/rules/no-extra-label.js index 87a28344709..14cc57b9944 100644 --- a/tests/lib/rules/no-extra-label.js +++ b/tests/lib/rules/no-extra-label.js @@ -40,53 +40,53 @@ ruleTester.run("no-extra-label", rule, { { code: "A: while (a) break A;", output: "A: while (a) break;", - errors: ["This label 'A' is unnecessary."] + errors: [{ messageId: "unexpected", data: { name: "A" } }] }, { code: "A: while (a) { B: { continue A; } }", output: "A: while (a) { B: { continue; } }", - errors: ["This label 'A' is unnecessary."] + errors: [{ messageId: "unexpected", data: { name: "A" } }] }, { code: "X: while (x) { A: while (a) { B: { break A; break B; continue X; } } }", output: "X: while (x) { A: while (a) { B: { break; break B; continue X; } } }", - errors: ["This label 'A' is unnecessary."] + errors: [{ messageId: "unexpected", data: { name: "A" } }] }, { code: "A: do { break A; } while (a);", output: "A: do { break; } while (a);", - errors: ["This label 'A' is unnecessary."] + errors: [{ messageId: "unexpected", data: { name: "A" } }] }, { code: "A: for (;;) { break A; }", output: "A: for (;;) { break; }", - errors: ["This label 'A' is unnecessary."] + errors: [{ messageId: "unexpected", data: { name: "A" } }] }, { code: "A: for (a in obj) { break A; }", output: "A: for (a in obj) { break; }", - errors: ["This label 'A' is unnecessary."] + errors: [{ messageId: "unexpected", data: { name: "A" } }] }, { code: "A: for (a of ary) { break A; }", output: "A: for (a of ary) { break; }", parserOptions: { ecmaVersion: 6 }, - errors: ["This label 'A' is unnecessary."] + errors: [{ messageId: "unexpected", data: { name: "A" } }] }, { code: "A: switch (a) { case 0: break A; }", output: "A: switch (a) { case 0: break; }", - errors: ["This label 'A' is unnecessary."] + errors: [{ messageId: "unexpected", data: { name: "A" } }] }, { code: "X: while (x) { A: switch (a) { case 0: break A; } }", output: "X: while (x) { A: switch (a) { case 0: break; } }", - errors: ["This label 'A' is unnecessary."] + errors: [{ messageId: "unexpected", data: { name: "A" } }] }, { code: "X: switch (a) { case 0: A: while (b) break A; }", output: "X: switch (a) { case 0: A: while (b) break; }", - errors: ["This label 'A' is unnecessary."] + errors: [{ messageId: "unexpected", data: { name: "A" } }] }, { code: `\ @@ -105,7 +105,7 @@ ruleTester.run("no-extra-label", rule, { } } `, - errors: [{ message: "This label 'A' is unnecessary.", type: "Identifier", line: 2 }] + errors: [{ messageId: "unexpected", data: { name: "A" }, type: "Identifier", line: 2 }] } ] }); diff --git a/tests/lib/rules/no-extra-parens.js b/tests/lib/rules/no-extra-parens.js index cab241a0a3e..3df00d516b4 100644 --- a/tests/lib/rules/no-extra-parens.js +++ b/tests/lib/rules/no-extra-parens.js @@ -31,7 +31,7 @@ function invalid(code, output, type, line, config) { parserOptions: config.parserOptions || {}, errors: [ { - message: "Gratuitous parentheses around expression.", + messageId: "unexpected", type } ], @@ -709,7 +709,7 @@ ruleTester.run("no-extra-parens", rule, { options: ["all", { returnAssign: false }], errors: [ { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "LogicalExpression" } ] @@ -719,7 +719,7 @@ ruleTester.run("no-extra-parens", rule, { output: "function a(b) { return (b = c) || (d = e); }", errors: [ { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "LogicalExpression" } ] @@ -729,7 +729,7 @@ ruleTester.run("no-extra-parens", rule, { output: "function a(b) { return b = 1; }", errors: [ { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "AssignmentExpression" } ] @@ -739,11 +739,11 @@ ruleTester.run("no-extra-parens", rule, { output: "function a(b) { return c ? d = b : e = b; }", errors: [ { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "AssignmentExpression" }, { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "AssignmentExpression" } ] @@ -755,7 +755,7 @@ ruleTester.run("no-extra-parens", rule, { errors: [ { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "LogicalExpression" } ] @@ -765,7 +765,7 @@ ruleTester.run("no-extra-parens", rule, { output: "b => (b = c) || (d = e);", errors: [ { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "LogicalExpression" } ] @@ -775,7 +775,7 @@ ruleTester.run("no-extra-parens", rule, { output: "b => b = 1;", errors: [ { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "AssignmentExpression" } ] @@ -785,11 +785,11 @@ ruleTester.run("no-extra-parens", rule, { output: "b => c ? d = b : e = b;", errors: [ { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "AssignmentExpression" }, { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "AssignmentExpression" } ] @@ -800,7 +800,7 @@ ruleTester.run("no-extra-parens", rule, { options: ["all", { returnAssign: false }], errors: [ { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "LogicalExpression" } ] @@ -810,7 +810,7 @@ ruleTester.run("no-extra-parens", rule, { output: "b => { return (b = c) || (d = e) };", errors: [ { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "LogicalExpression" } ] @@ -820,7 +820,7 @@ ruleTester.run("no-extra-parens", rule, { output: "b => { return b = 1 };", errors: [ { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "AssignmentExpression" } ] @@ -830,11 +830,11 @@ ruleTester.run("no-extra-parens", rule, { output: "b => { return c ? d = b : e = b; }", errors: [ { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "AssignmentExpression" }, { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "AssignmentExpression" } ] @@ -846,11 +846,11 @@ ruleTester.run("no-extra-parens", rule, { output: "async function a() { await a + await b; }", errors: [ { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "AwaitExpression" }, { - message: "Gratuitous parentheses around expression.", + messgeId: "unexpected", type: "AwaitExpression" } ] @@ -924,7 +924,7 @@ ruleTester.run("no-extra-parens", rule, { options: ["all", { enforceForArrowConditionals: true }], errors: [ { - message: "Gratuitous parentheses around expression." + messgeId: "unexpected" } ] }, @@ -936,7 +936,7 @@ ruleTester.run("no-extra-parens", rule, { options: ["all", { enforceForArrowConditionals: false }], errors: [ { - message: "Gratuitous parentheses around expression." + messgeId: "unexpected" } ] }, diff --git a/tests/lib/rules/no-extra-semi.js b/tests/lib/rules/no-extra-semi.js index 036cb1f4b2c..dc465253448 100644 --- a/tests/lib/rules/no-extra-semi.js +++ b/tests/lib/rules/no-extra-semi.js @@ -47,68 +47,68 @@ ruleTester.run("no-extra-semi", rule, { { code: "var x = 5;;", output: "var x = 5;", - errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }] + errors: [{ messgeId: "unexpected", type: "EmptyStatement" }] }, { code: "function foo(){};", output: "function foo(){}", - errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }] + errors: [{ messgeId: "unexpected", type: "EmptyStatement" }] }, { code: "for(;;);;", output: "for(;;);", - errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }] + errors: [{ messgeId: "unexpected", type: "EmptyStatement" }] }, { code: "while(0);;", output: "while(0);", - errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }] + errors: [{ messgeId: "unexpected", type: "EmptyStatement" }] }, { code: "do;while(0);;", output: "do;while(0);", - errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }] + errors: [{ messgeId: "unexpected", type: "EmptyStatement" }] }, { code: "for(a in b);;", output: "for(a in b);", - errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }] + errors: [{ messgeId: "unexpected", type: "EmptyStatement" }] }, { code: "for(a of b);;", output: "for(a of b);", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }] + errors: [{ messgeId: "unexpected", type: "EmptyStatement" }] }, { code: "if(true);;", output: "if(true);", - errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }] + errors: [{ messgeId: "unexpected", type: "EmptyStatement" }] }, { code: "if(true){} else;;", output: "if(true){} else;", - errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }] + errors: [{ messgeId: "unexpected", type: "EmptyStatement" }] }, { code: "if(true){;} else {;}", output: "if(true){} else {}", - errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }, { message: "Unnecessary semicolon.", type: "EmptyStatement" }] + errors: [{ messgeId: "unexpected", type: "EmptyStatement" }, { messgeId: "unexpected", type: "EmptyStatement" }] }, { code: "foo:;;", output: "foo:;", - errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }] + errors: [{ messgeId: "unexpected", type: "EmptyStatement" }] }, { code: "with(foo);;", output: "with(foo);", - errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }] + errors: [{ messgeId: "unexpected", type: "EmptyStatement" }] }, { code: "with(foo){;}", output: "with(foo){}", - errors: [{ message: "Unnecessary semicolon.", type: "EmptyStatement" }] + errors: [{ messgeId: "unexpected", type: "EmptyStatement" }] }, // Class body. @@ -116,47 +116,47 @@ ruleTester.run("no-extra-semi", rule, { code: "class A { ; }", output: "class A { }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unnecessary semicolon.", type: "Punctuator", column: 11 }] + errors: [{ messgeId: "unexpected", type: "Punctuator", column: 11 }] }, { code: "class A { /*a*/; }", output: "class A { /*a*/ }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unnecessary semicolon.", type: "Punctuator", column: 16 }] + errors: [{ messgeId: "unexpected", type: "Punctuator", column: 16 }] }, { code: "class A { ; a() {} }", output: "class A { a() {} }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unnecessary semicolon.", type: "Punctuator", column: 11 }] + errors: [{ messgeId: "unexpected", type: "Punctuator", column: 11 }] }, { code: "class A { a() {}; }", output: "class A { a() {} }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unnecessary semicolon.", type: "Punctuator", column: 17 }] + errors: [{ messgeId: "unexpected", type: "Punctuator", column: 17 }] }, { code: "class A { a() {}; b() {} }", output: "class A { a() {} b() {} }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unnecessary semicolon.", type: "Punctuator", column: 17 }] + errors: [{ messgeId: "unexpected", type: "Punctuator", column: 17 }] }, { code: "class A {; a() {}; b() {}; }", output: "class A { a() {} b() {} }", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Unnecessary semicolon.", type: "Punctuator", column: 10 }, - { message: "Unnecessary semicolon.", type: "Punctuator", column: 18 }, - { message: "Unnecessary semicolon.", type: "Punctuator", column: 26 } + { messgeId: "unexpected", type: "Punctuator", column: 10 }, + { messgeId: "unexpected", type: "Punctuator", column: 18 }, + { messgeId: "unexpected", type: "Punctuator", column: 26 } ] }, { code: "class A { a() {}; get b() {} }", output: "class A { a() {} get b() {} }", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Unnecessary semicolon.", type: "Punctuator", column: 17 }] + errors: [{ messgeId: "unexpected", type: "Punctuator", column: 17 }] } ] });