diff --git a/lib/rules/global-require.js b/lib/rules/global-require.js
index 6576cfb6a1f..4af3a6a4669 100644
--- a/lib/rules/global-require.js
+++ b/lib/rules/global-require.js
@@ -57,7 +57,10 @@ module.exports = {
url: "https://eslint.org/docs/rules/global-require"
},
- schema: []
+ schema: [],
+ messages: {
+ unexpected: "Unexpected require()."
+ }
},
create(context) {
@@ -69,7 +72,7 @@ module.exports = {
const isGoodRequire = context.getAncestors().every(parent => ACCEPTABLE_PARENTS.indexOf(parent.type) > -1);
if (!isGoodRequire) {
- context.report({ node, message: "Unexpected require()." });
+ context.report({ node, messageId: "unexpected" });
}
}
}
diff --git a/lib/rules/guard-for-in.js b/lib/rules/guard-for-in.js
index 6e8452a4844..2c0976d997b 100644
--- a/lib/rules/guard-for-in.js
+++ b/lib/rules/guard-for-in.js
@@ -20,7 +20,10 @@ module.exports = {
url: "https://eslint.org/docs/rules/guard-for-in"
},
- schema: []
+ schema: [],
+ messages: {
+ wrap: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype."
+ }
},
create(context) {
@@ -65,7 +68,7 @@ module.exports = {
}
}
- context.report({ node, message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype." });
+ context.report({ node, messageId: "wrap" });
}
};
diff --git a/lib/rules/handle-callback-err.js b/lib/rules/handle-callback-err.js
index 5845aff4bc6..2966aff2e61 100644
--- a/lib/rules/handle-callback-err.js
+++ b/lib/rules/handle-callback-err.js
@@ -24,7 +24,10 @@ module.exports = {
{
type: "string"
}
- ]
+ ],
+ messages: {
+ expected: "Expected error to be handled."
+ }
},
create(context) {
@@ -77,7 +80,7 @@ module.exports = {
if (firstParameter && matchesConfiguredErrorName(firstParameter.name)) {
if (firstParameter.references.length === 0) {
- context.report({ node, message: "Expected error to be handled." });
+ context.report({ node, messageId: "expected" });
}
}
}
diff --git a/lib/rules/id-blacklist.js b/lib/rules/id-blacklist.js
index 7b8facbabe0..53be62e68a3 100644
--- a/lib/rules/id-blacklist.js
+++ b/lib/rules/id-blacklist.js
@@ -27,6 +27,9 @@ module.exports = {
type: "string"
},
uniqueItems: true
+ },
+ messages: {
+ blacklisted: "Identifier '{{name}}' is blacklisted."
}
},
@@ -72,7 +75,7 @@ module.exports = {
function report(node) {
context.report({
node,
- message: "Identifier '{{name}}' is blacklisted.",
+ messageId: "blacklisted",
data: {
name: node.name
}
diff --git a/lib/rules/id-length.js b/lib/rules/id-length.js
index d72eb08876a..1f9c696e2a9 100644
--- a/lib/rules/id-length.js
+++ b/lib/rules/id-length.js
@@ -44,7 +44,11 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ tooShort: "Identifier name '{{name}}' is too short (< {{min}}).",
+ tooLong: "Identifier name '{{name}}' is too long (> {{max}})."
+ }
},
create(context) {
@@ -107,9 +111,7 @@ module.exports = {
if (isValidExpression && (isValidExpression === true || isValidExpression(parent, node))) {
context.report({
node,
- message: isShort
- ? "Identifier name '{{name}}' is too short (< {{min}})."
- : "Identifier name '{{name}}' is too long (> {{max}}).",
+ messageId: isShort ? "tooShort" : "tooLong",
data: { name, min: minLength, max: maxLength }
});
}
diff --git a/lib/rules/id-match.js b/lib/rules/id-match.js
index 4755c779ca9..5dc86f8dbfd 100644
--- a/lib/rules/id-match.js
+++ b/lib/rules/id-match.js
@@ -38,7 +38,10 @@ module.exports = {
}
}
}
- ]
+ ],
+ messages: {
+ notMatch: "Identifier '{{name}}' does not match the pattern '{{pattern}}'."
+ }
},
create(context) {
@@ -116,7 +119,7 @@ module.exports = {
if (!reported.has(node)) {
context.report({
node,
- message: "Identifier '{{name}}' does not match the pattern '{{pattern}}'.",
+ messageId: "notMatch",
data: {
name: node.name,
pattern
diff --git a/lib/rules/implicit-arrow-linebreak.js b/lib/rules/implicit-arrow-linebreak.js
index fb7d603a35a..ad0d70da66c 100644
--- a/lib/rules/implicit-arrow-linebreak.js
+++ b/lib/rules/implicit-arrow-linebreak.js
@@ -30,7 +30,11 @@ module.exports = {
{
enum: ["beside", "below"]
}
- ]
+ ],
+ messages: {
+ expected: "Expected a linebreak before this expression.",
+ unexpected: "Expected no linebreak before this expression."
+ }
},
create(context) {
@@ -210,13 +214,13 @@ module.exports = {
if (tokenBefore.loc.end.line === fixerTarget.loc.start.line && option === "below") {
context.report({
node: fixerTarget,
- message: "Expected a linebreak before this expression.",
+ messageId: "expected",
fix: fixer => fixer.insertTextBefore(fixerTarget, "\n")
});
} else if (tokenBefore.loc.end.line !== fixerTarget.loc.start.line && option === "beside") {
context.report({
node: fixerTarget,
- message: "Expected no linebreak before this expression.",
+ messageId: "unexpected",
fix: autoFixBesides(tokenBefore, fixerTarget, node)
});
}
diff --git a/lib/rules/indent-legacy.js b/lib/rules/indent-legacy.js
index cfb807e34e0..2a712c520a2 100644
--- a/lib/rules/indent-legacy.js
+++ b/lib/rules/indent-legacy.js
@@ -169,7 +169,10 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ expected: "Expected indentation of {{expected}} but found {{actual}}."
+ }
},
create(context) {
@@ -268,7 +271,7 @@ module.exports = {
* @param {int} actualTabs The actual number of indentation tabs that were found on this line
* @returns {string} An error message for this line
*/
- function createErrorMessage(expectedAmount, actualSpaces, actualTabs) {
+ function createErrorMessageData(expectedAmount, actualSpaces, actualTabs) {
const expectedStatement = `${expectedAmount} ${indentType}${expectedAmount === 1 ? "" : "s"}`; // e.g. "2 tabs"
const foundSpacesWord = `space${actualSpaces === 1 ? "" : "s"}`; // e.g. "space"
const foundTabsWord = `tab${actualTabs === 1 ? "" : "s"}`; // e.g. "tabs"
@@ -288,8 +291,10 @@ module.exports = {
} else {
foundStatement = "0";
}
-
- return `Expected indentation of ${expectedStatement} but found ${foundStatement}.`;
+ return {
+ expected: expectedStatement,
+ actual: foundStatement
+ };
}
/**
@@ -318,7 +323,8 @@ module.exports = {
context.report({
node,
loc,
- message: createErrorMessage(needed, gottenSpaces, gottenTabs),
+ messageId: "expected",
+ data: createErrorMessageData(needed, gottenSpaces, gottenTabs),
fix: fixer => fixer.replaceTextRange(textRange, desiredIndent)
});
}
diff --git a/lib/rules/indent.js b/lib/rules/indent.js
index af7e2b147a0..c30d1f1e7bc 100644
--- a/lib/rules/indent.js
+++ b/lib/rules/indent.js
@@ -599,7 +599,10 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ wrongIndentation: "Expected indentation of {{expected}} but found {{actual}}."
+ }
},
create(context) {
@@ -671,7 +674,7 @@ module.exports = {
* @param {int} actualTabs The actual number of indentation tabs that were found on this line
* @returns {string} An error message for this line
*/
- function createErrorMessage(expectedAmount, actualSpaces, actualTabs) {
+ function createErrorMessageData(expectedAmount, actualSpaces, actualTabs) {
const expectedStatement = `${expectedAmount} ${indentType}${expectedAmount === 1 ? "" : "s"}`; // e.g. "2 tabs"
const foundSpacesWord = `space${actualSpaces === 1 ? "" : "s"}`; // e.g. "space"
const foundTabsWord = `tab${actualTabs === 1 ? "" : "s"}`; // e.g. "tabs"
@@ -689,8 +692,10 @@ module.exports = {
} else {
foundStatement = "0";
}
-
- return `Expected indentation of ${expectedStatement} but found ${foundStatement}.`;
+ return {
+ expected: expectedStatement,
+ actual: foundStatement
+ };
}
/**
@@ -706,7 +711,8 @@ module.exports = {
context.report({
node: token,
- message: createErrorMessage(neededIndent.length, numSpaces, numTabs),
+ messageId: "wrongIndentation",
+ data: createErrorMessageData(neededIndent.length, numSpaces, numTabs),
loc: {
start: { line: token.loc.start.line, column: 0 },
end: { line: token.loc.start.line, column: token.loc.start.column }
diff --git a/lib/rules/init-declarations.js b/lib/rules/init-declarations.js
index 755090917f9..65197358e60 100644
--- a/lib/rules/init-declarations.js
+++ b/lib/rules/init-declarations.js
@@ -85,6 +85,10 @@ module.exports = {
maxItems: 2
}
]
+ },
+ messages: {
+ initialized: "Variable '{{idName}}' should be initialized on declaration.",
+ notInitialized: "Variable '{{idName}}' should not be initialized on declaration."
}
},
@@ -111,23 +115,18 @@ module.exports = {
id = declaration.id,
initialized = isInitialized(declaration),
isIgnoredForLoop = params.ignoreForLoopInit && isForLoop(node.parent);
-
- if (id.type !== "Identifier") {
- continue;
- }
+ let messageId = "";
if (mode === MODE_ALWAYS && !initialized) {
- context.report({
- node: declaration,
- message: "Variable '{{idName}}' should be initialized on declaration.",
- data: {
- idName: id.name
- }
- });
+ messageId = "initialized";
} else if (mode === MODE_NEVER && kind !== "const" && initialized && !isIgnoredForLoop) {
+ messageId = "notInitialized";
+ }
+
+ if (id.type === "Identifier" && messageId) {
context.report({
node: declaration,
- message: "Variable '{{idName}}' should not be initialized on declaration.",
+ messageId,
data: {
idName: id.name
}
diff --git a/lib/rules/jsx-quotes.js b/lib/rules/jsx-quotes.js
index 603d55330b5..372dc2f42e7 100644
--- a/lib/rules/jsx-quotes.js
+++ b/lib/rules/jsx-quotes.js
@@ -53,7 +53,10 @@ module.exports = {
{
enum: ["prefer-single", "prefer-double"]
}
- ]
+ ],
+ messages: {
+ unexpected: "Unexpected usage of {{description}}."
+ }
},
create(context) {
@@ -77,7 +80,7 @@ module.exports = {
if (attributeValue && astUtils.isStringLiteral(attributeValue) && !usesExpectedQuotes(attributeValue)) {
context.report({
node: attributeValue,
- message: "Unexpected usage of {{description}}.",
+ messageId: "unexpected",
data: {
description: setting.description
},
diff --git a/lib/rules/key-spacing.js b/lib/rules/key-spacing.js
index 2d1315fde09..c52a74d499f 100644
--- a/lib/rules/key-spacing.js
+++ b/lib/rules/key-spacing.js
@@ -121,11 +121,6 @@ function initOptions(toOptions, fromOptions) {
// Rule Definition
//------------------------------------------------------------------------------
-const messages = {
- key: "{{error}} space after {{computed}}key '{{key}}'.",
- value: "{{error}} space before value for {{computed}}key '{{key}}'."
-};
-
module.exports = {
meta: {
type: "layout",
@@ -297,7 +292,13 @@ module.exports = {
additionalProperties: false
}
]
- }]
+ }],
+ messages: {
+ extraKey: "Extra space after {{computed}}key '{{key}}'.",
+ extraValue: "Extra space before value for {{computed}}key '{{key}}'.",
+ missingKey: "Missing space after {{computed}}key '{{key}}'.",
+ missingValue: "Missing space before value for {{computed}}key '{{key}}'."
+ }
},
create(context) {
@@ -460,12 +461,19 @@ module.exports = {
}
}
+ let messageId = "";
+
+ if (isExtra) {
+ messageId = side === "key" ? "extraKey" : "extraValue";
+ } else {
+ messageId = side === "key" ? "missingKey" : "missingValue";
+ }
+
context.report({
node: property[side],
loc: locStart,
- message: messages[side],
+ messageId,
data: {
- error: isExtra ? "Extra" : "Missing",
computed: property.computed ? "computed " : "",
key: getKey(property)
},
diff --git a/lib/rules/keyword-spacing.js b/lib/rules/keyword-spacing.js
index 790d7b031d8..833092e4160 100644
--- a/lib/rules/keyword-spacing.js
+++ b/lib/rules/keyword-spacing.js
@@ -100,7 +100,13 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ expectedBefore: "Expected space(s) before \"{{value}}\".",
+ expectedAfter: "Expected space(s) after \"{{value}}\".",
+ unexpectedBefore: "Unexpected space(s) before \"{{value}}\".",
+ unexpectedAfter: "Unexpected space(s) after \"{{value}}\"."
+ }
},
create(context) {
@@ -124,7 +130,7 @@ module.exports = {
) {
context.report({
loc: token.loc.start,
- message: "Expected space(s) before \"{{value}}\".",
+ messageId: "expectedBefore",
data: token,
fix(fixer) {
return fixer.insertTextBefore(token, " ");
@@ -151,7 +157,7 @@ module.exports = {
) {
context.report({
loc: token.loc.start,
- message: "Unexpected space(s) before \"{{value}}\".",
+ messageId: "unexpectedBefore",
data: token,
fix(fixer) {
return fixer.removeRange([prevToken.range[1], token.range[0]]);
@@ -178,7 +184,7 @@ module.exports = {
) {
context.report({
loc: token.loc.start,
- message: "Expected space(s) after \"{{value}}\".",
+ messageId: "expectedAfter",
data: token,
fix(fixer) {
return fixer.insertTextAfter(token, " ");
@@ -205,7 +211,7 @@ module.exports = {
) {
context.report({
loc: token.loc.start,
- message: "Unexpected space(s) after \"{{value}}\".",
+ messageId: "unexpectedAfter",
data: token,
fix(fixer) {
return fixer.removeRange([token.range[1], nextToken.range[0]]);
diff --git a/lib/rules/line-comment-position.js b/lib/rules/line-comment-position.js
index 7c791d5f277..6d0ac6d2ba8 100644
--- a/lib/rules/line-comment-position.js
+++ b/lib/rules/line-comment-position.js
@@ -47,7 +47,11 @@ module.exports = {
}
]
}
- ]
+ ],
+ messages: {
+ above: "Expected comment to be above code.",
+ beside: "Expected comment to be beside code."
+ }
},
create(context) {
@@ -100,14 +104,14 @@ module.exports = {
if (isOnSameLine) {
context.report({
node,
- message: "Expected comment to be above code."
+ messageId: "above"
});
}
} else {
if (!isOnSameLine) {
context.report({
node,
- message: "Expected comment to be beside code."
+ messageId: "beside"
});
}
}
diff --git a/lib/rules/linebreak-style.js b/lib/rules/linebreak-style.js
index 5345d53f288..4523d6f58a1 100644
--- a/lib/rules/linebreak-style.js
+++ b/lib/rules/linebreak-style.js
@@ -32,14 +32,14 @@ module.exports = {
{
enum: ["unix", "windows"]
}
- ]
+ ],
+ messages: {
+ expectedLF: "Expected linebreaks to be 'LF' but found 'CRLF'.",
+ expectedCRLF: "Expected linebreaks to be 'CRLF' but found 'LF'."
+ }
},
create(context) {
-
- const EXPECTED_LF_MSG = "Expected linebreaks to be 'LF' but found 'CRLF'.",
- EXPECTED_CRLF_MSG = "Expected linebreaks to be 'CRLF' but found 'LF'.";
-
const sourceCode = context.getSourceCode();
//--------------------------------------------------------------------------
@@ -89,7 +89,7 @@ module.exports = {
line: i,
column: sourceCode.lines[i - 1].length
},
- message: expectedLF ? EXPECTED_LF_MSG : EXPECTED_CRLF_MSG,
+ messageId: expectedLF ? "expectedLF" : "expectedCRLF",
fix: createFix(range, expectedLFChars)
});
}
diff --git a/lib/rules/lines-around-comment.js b/lib/rules/lines-around-comment.js
index 30175cd3663..62bef94831d 100644
--- a/lib/rules/lines-around-comment.js
+++ b/lib/rules/lines-around-comment.js
@@ -112,7 +112,11 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ after: "Expected line after comment.",
+ before: "Expected line before comment."
+ }
},
create(context) {
@@ -350,7 +354,7 @@ module.exports = {
context.report({
node: token,
- message: "Expected line before comment.",
+ messageId: "before",
fix(fixer) {
return fixer.insertTextBeforeRange(range, "\n");
}
@@ -362,7 +366,7 @@ module.exports = {
!(astUtils.isCommentToken(nextTokenOrComment) && astUtils.isTokenOnSameLine(token, nextTokenOrComment))) {
context.report({
node: token,
- message: "Expected line after comment.",
+ messageId: "after",
fix(fixer) {
return fixer.insertTextAfter(token, "\n");
}
diff --git a/lib/rules/lines-around-directive.js b/lib/rules/lines-around-directive.js
index 02bbe13b4fc..c2e5fd75aaa 100644
--- a/lib/rules/lines-around-directive.js
+++ b/lib/rules/lines-around-directive.js
@@ -45,6 +45,10 @@ module.exports = {
}],
fixable: "whitespace",
+ messages: {
+ expected: "Expected newline {{location}} \"{{value}}\" directive.",
+ unexpected: "Unexpected newline {{location}} \"{{value}}\" directive."
+ },
deprecated: true,
replacedBy: ["padding-line-between-statements"]
},
@@ -109,9 +113,8 @@ module.exports = {
function reportError(node, location, expected) {
context.report({
node,
- message: "{{expected}} newline {{location}} \"{{value}}\" directive.",
+ messageId: expected ? "expected" : "unexpected",
data: {
- expected: expected ? "Expected" : "Unexpected",
value: node.expression.value,
location
},
diff --git a/lib/rules/lines-between-class-members.js b/lib/rules/lines-between-class-members.js
index 5c1e69277a5..2937d24f81f 100644
--- a/lib/rules/lines-between-class-members.js
+++ b/lib/rules/lines-between-class-members.js
@@ -36,7 +36,11 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ never: "Unexpected blank line between class members.",
+ always: "Expected blank line between class members."
+ }
},
create(context) {
@@ -46,9 +50,6 @@ module.exports = {
options[0] = context.options[0] || "always";
options[1] = context.options[1] || { exceptAfterSingleLine: false };
- const ALWAYS_MESSAGE = "Expected blank line between class members.";
- const NEVER_MESSAGE = "Unexpected blank line between class members.";
-
const sourceCode = context.getSourceCode();
/**
@@ -127,7 +128,7 @@ module.exports = {
(options[0] === "never" && isPadded)) {
context.report({
node: body[i + 1],
- message: isPadded ? NEVER_MESSAGE : ALWAYS_MESSAGE,
+ messageId: isPadded ? "never" : "always",
fix(fixer) {
return isPadded
? fixer.replaceTextRange([curLast.range[1], nextFirst.range[0]], "\n")
diff --git a/lib/rules/max-depth.js b/lib/rules/max-depth.js
index 34d58b0d31e..500e9318817 100644
--- a/lib/rules/max-depth.js
+++ b/lib/rules/max-depth.js
@@ -43,7 +43,10 @@ module.exports = {
}
]
}
- ]
+ ],
+ messages: {
+ tooDeeply: "Blocks are nested too deeply ({{depth}})."
+ }
},
create(context) {
@@ -94,7 +97,7 @@ module.exports = {
const len = ++functionStack[functionStack.length - 1];
if (len > maxDepth) {
- context.report({ node, message: "Blocks are nested too deeply ({{depth}}).", data: { depth: len } });
+ context.report({ node, messageId: "tooDeeply", data: { depth: len } });
}
}
diff --git a/lib/rules/max-len.js b/lib/rules/max-len.js
index 13dd72160cc..d74373e9ea8 100644
--- a/lib/rules/max-len.js
+++ b/lib/rules/max-len.js
@@ -78,7 +78,11 @@ module.exports = {
OPTIONS_OR_INTEGER_SCHEMA,
OPTIONS_OR_INTEGER_SCHEMA,
OPTIONS_SCHEMA
- ]
+ ],
+ messages: {
+ max: "Line {{lineNumber}} exceeds the maximum line length of {{maxLength}}.",
+ maxComment: "Line {{lineNumber}} exceeds the maximum comment line length of {{maxCommentLength}}."
+ }
},
create(context) {
@@ -341,7 +345,7 @@ module.exports = {
context.report({
node,
loc: { line: lineNumber, column: 0 },
- message: "Line {{lineNumber}} exceeds the maximum comment line length of {{maxCommentLength}}.",
+ messageId: "maxComment",
data: {
lineNumber: i + 1,
maxCommentLength
@@ -352,7 +356,7 @@ module.exports = {
context.report({
node,
loc: { line: lineNumber, column: 0 },
- message: "Line {{lineNumber}} exceeds the maximum line length of {{maxLength}}.",
+ messageId: "max",
data: {
lineNumber: i + 1,
maxLength
diff --git a/lib/rules/max-lines-per-function.js b/lib/rules/max-lines-per-function.js
index 8c64a20bcc3..d1e4597a221 100644
--- a/lib/rules/max-lines-per-function.js
+++ b/lib/rules/max-lines-per-function.js
@@ -80,7 +80,10 @@ module.exports = {
schema: [
OPTIONS_OR_INTEGER_SCHEMA
- ]
+ ],
+ messages: {
+ exceed: "{{name}} has too many lines ({{lineCount}}). Maximum allowed is {{maxLines}}."
+ }
},
create(context) {
@@ -201,7 +204,7 @@ module.exports = {
context.report({
node,
- message: "{{name}} has too many lines ({{lineCount}}). Maximum allowed is {{maxLines}}.",
+ messageId: "exceed",
data: { name, lineCount, maxLines }
});
}
diff --git a/lib/rules/max-lines.js b/lib/rules/max-lines.js
index 730e05ab41c..da7ddd8a88f 100644
--- a/lib/rules/max-lines.js
+++ b/lib/rules/max-lines.js
@@ -51,7 +51,10 @@ module.exports = {
}
]
}
- ]
+ ],
+ messages: {
+ exceed: "File must be at most {{max}} lines long. It's {{actual}} lines long."
+ }
},
create(context) {
@@ -134,7 +137,7 @@ module.exports = {
if (lines.length > max) {
context.report({
loc: { line: 1, column: 0 },
- message: "File must be at most {{max}} lines long. It's {{actual}} lines long.",
+ messageId: "exceed",
data: {
max,
actual: lines.length
diff --git a/lib/rules/max-nested-callbacks.js b/lib/rules/max-nested-callbacks.js
index d4ecb4e2a5c..754fa168d39 100644
--- a/lib/rules/max-nested-callbacks.js
+++ b/lib/rules/max-nested-callbacks.js
@@ -43,7 +43,10 @@ module.exports = {
}
]
}
- ]
+ ],
+ messages: {
+ exceed: "Too many nested callbacks ({{num}}). Maximum allowed is {{max}}."
+ }
},
create(context) {
@@ -86,7 +89,7 @@ module.exports = {
if (callbackStack.length > THRESHOLD) {
const opts = { num: callbackStack.length, max: THRESHOLD };
- context.report({ node, message: "Too many nested callbacks ({{num}}). Maximum allowed is {{max}}.", data: opts });
+ context.report({ node, messageId: "exceed", data: opts });
}
}
diff --git a/lib/rules/max-params.js b/lib/rules/max-params.js
index f678974acf3..e082ec8e980 100644
--- a/lib/rules/max-params.js
+++ b/lib/rules/max-params.js
@@ -51,7 +51,10 @@ module.exports = {
}
]
}
- ]
+ ],
+ messages: {
+ exceed: "{{name}} has too many parameters ({{count}}). Maximum allowed is {{max}}."
+ }
},
create(context) {
@@ -80,7 +83,7 @@ module.exports = {
context.report({
loc: astUtils.getFunctionHeadLoc(node, sourceCode),
node,
- message: "{{name}} has too many parameters ({{count}}). Maximum allowed is {{max}}.",
+ messageId: "exceed",
data: {
name: lodash.upperFirst(astUtils.getFunctionNameWithKind(node)),
count: node.params.length,
diff --git a/lib/rules/max-statements-per-line.js b/lib/rules/max-statements-per-line.js
index f3fb8e9d5cf..b834cedc03f 100644
--- a/lib/rules/max-statements-per-line.js
+++ b/lib/rules/max-statements-per-line.js
@@ -36,15 +36,17 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ exceed: "This line has {{numberOfStatementsOnThisLine}} {{statements}}. Maximum allowed is {{maxStatementsPerLine}}."
+ }
},
create(context) {
const sourceCode = context.getSourceCode(),
options = context.options[0] || {},
- maxStatementsPerLine = typeof options.max !== "undefined" ? options.max : 1,
- message = "This line has {{numberOfStatementsOnThisLine}} {{statements}}. Maximum allowed is {{maxStatementsPerLine}}.";
+ maxStatementsPerLine = typeof options.max !== "undefined" ? options.max : 1;
let lastStatementLine = 0,
numberOfStatementsOnThisLine = 0,
@@ -65,7 +67,7 @@ module.exports = {
if (firstExtraStatement) {
context.report({
node: firstExtraStatement,
- message,
+ messageId: "exceed",
data: {
numberOfStatementsOnThisLine,
maxStatementsPerLine,
diff --git a/lib/rules/max-statements.js b/lib/rules/max-statements.js
index e32dedad632..b33ca429824 100644
--- a/lib/rules/max-statements.js
+++ b/lib/rules/max-statements.js
@@ -60,7 +60,10 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ exceed: "{{name}} has too many statements ({{count}}). Maximum allowed is {{max}}."
+ }
},
create(context) {
@@ -99,7 +102,7 @@ module.exports = {
context.report({
node,
- message: "{{name}} has too many statements ({{count}}). Maximum allowed is {{max}}.",
+ messageId: "exceed",
data: { name, count, max }
});
}
diff --git a/lib/rules/multiline-comment-style.js b/lib/rules/multiline-comment-style.js
index 73eab7c5741..e262c255869 100644
--- a/lib/rules/multiline-comment-style.js
+++ b/lib/rules/multiline-comment-style.js
@@ -22,20 +22,21 @@ module.exports = {
},
fixable: "whitespace",
- schema: [{ enum: ["starred-block", "separate-lines", "bare-block"] }]
+ schema: [{ enum: ["starred-block", "separate-lines", "bare-block"] }],
+ messages: {
+ expectedBlock: "Expected a block comment instead of consecutive line comments.",
+ startNewline: "Expected a linebreak after '/*'.",
+ endNewline: "Expected a linebreak before '*/'.",
+ missingStar: "Expected a '*' at the start of this line.",
+ alignment: "Expected this line to be aligned with the start of the comment.",
+ expectedLines: "Expected multiple line comments instead of a block comment."
+ }
},
create(context) {
const sourceCode = context.getSourceCode();
const option = context.options[0] || "starred-block";
- const EXPECTED_BLOCK_ERROR = "Expected a block comment instead of consecutive line comments.";
- const START_NEWLINE_ERROR = "Expected a linebreak after '/*'.";
- const END_NEWLINE_ERROR = "Expected a linebreak before '*/'.";
- const MISSING_STAR_ERROR = "Expected a '*' at the start of this line.";
- const ALIGNMENT_ERROR = "Expected this line to be aligned with the start of the comment.";
- const EXPECTED_LINES_ERROR = "Expected multiple line comments instead of a block comment.";
-
//----------------------------------------------------------------------
// Helpers
//----------------------------------------------------------------------
@@ -127,7 +128,7 @@ module.exports = {
start: commentGroup[0].loc.start,
end: commentGroup[commentGroup.length - 1].loc.end
},
- message: EXPECTED_BLOCK_ERROR,
+ messageId: "expectedBlock",
fix(fixer) {
const range = [commentGroup[0].range[0], commentGroup[commentGroup.length - 1].range[1]];
const starredBlock = `/*${convertToStarredBlock(commentGroup[0], commentLines)}*/`;
@@ -150,7 +151,7 @@ module.exports = {
start: block.loc.start,
end: { line: block.loc.start.line, column: block.loc.start.column + 2 }
},
- message: START_NEWLINE_ERROR,
+ messageId: "startNewline",
fix: fixer => fixer.insertTextAfterRange([start, start + 2], `\n${expectedLinePrefix}`)
});
}
@@ -161,7 +162,7 @@ module.exports = {
start: { line: block.loc.end.line, column: block.loc.end.column - 2 },
end: block.loc.end
},
- message: END_NEWLINE_ERROR,
+ messageId: "endNewline",
fix: fixer => fixer.replaceTextRange([block.range[1] - 2, block.range[1]], `\n${expectedLinePrefix}/`)
});
}
@@ -175,9 +176,9 @@ module.exports = {
start: { line: lineNumber, column: 0 },
end: { line: lineNumber, column: sourceCode.lines[lineNumber - 1].length }
},
- message: /^\s*\*/.test(lineText)
- ? ALIGNMENT_ERROR
- : MISSING_STAR_ERROR,
+ messageId: /^\s*\*/.test(lineText)
+ ? "alignment"
+ : "missingStar",
fix(fixer) {
const lineStartIndex = sourceCode.getIndexFromLoc({ line: lineNumber, column: 0 });
const linePrefixLength = lineText.match(/^\s*\*? ?/)[0].length;
@@ -209,7 +210,7 @@ module.exports = {
start: block.loc.start,
end: { line: block.loc.start.line, column: block.loc.start.column + 2 }
},
- message: EXPECTED_LINES_ERROR,
+ messageId: "expectedLines",
fix(fixer) {
return fixer.replaceText(block, convertToSeparateLines(block, commentLines.filter(line => line)));
}
@@ -228,7 +229,7 @@ module.exports = {
start: commentGroup[0].loc.start,
end: commentGroup[commentGroup.length - 1].loc.end
},
- message: EXPECTED_BLOCK_ERROR,
+ messageId: "expectedBlock",
fix(fixer) {
const range = [commentGroup[0].range[0], commentGroup[commentGroup.length - 1].range[1]];
const block = convertToBlock(commentGroup[0], commentLines.filter(line => line));
@@ -249,7 +250,7 @@ module.exports = {
start: block.loc.start,
end: { line: block.loc.start.line, column: block.loc.start.column + 2 }
},
- message: EXPECTED_BLOCK_ERROR,
+ messageId: "expectedBlock",
fix(fixer) {
return fixer.replaceText(block, convertToBlock(block, commentLines.filter(line => line)));
}
diff --git a/lib/rules/multiline-ternary.js b/lib/rules/multiline-ternary.js
index d1d577a4ffa..83378dcd86e 100644
--- a/lib/rules/multiline-ternary.js
+++ b/lib/rules/multiline-ternary.js
@@ -26,7 +26,13 @@ module.exports = {
{
enum: ["always", "always-multiline", "never"]
}
- ]
+ ],
+ messages: {
+ expectedTestCons: "Expected newline between test and consequent of ternary expression.",
+ expectedConsAlt: "Expected newline between consequent and alternate of ternary expression.",
+ unexpectedTestCons: "Unexpected newline between test and consequent of ternary expression.",
+ unexpectedConsAlt: "Unexpected newline between consequent and alternate of ternary expression."
+ }
},
create(context) {
@@ -49,11 +55,7 @@ module.exports = {
function reportError(node, parentNode, expected) {
context.report({
node,
- message: "{{expected}} newline between {{typeOfError}} of ternary expression.",
- data: {
- expected: expected ? "Expected" : "Unexpected",
- typeOfError: node === parentNode.test ? "test and consequent" : "consequent and alternate"
- }
+ messageId: `${expected ? "expected" : "unexpected"}${node === parentNode.test ? "TestCons" : "ConsAlt"}`
});
}
diff --git a/lib/rules/new-cap.js b/lib/rules/new-cap.js
index 834f4605ed2..4a01dcfa7f3 100644
--- a/lib/rules/new-cap.js
+++ b/lib/rules/new-cap.js
@@ -117,7 +117,11 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ upper: "A function with a name starting with an uppercase letter should only be used as a constructor.",
+ lower: "A constructor name should not start with a lowercase letter."
+ }
},
create(context) {
@@ -219,19 +223,19 @@ module.exports = {
}
/**
- * Reports the given message for the given node. The location will be the start of the property or the callee.
+ * Reports the given messageId for the given node. The location will be the start of the property or the callee.
* @param {ASTNode} node CallExpression or NewExpression node.
- * @param {string} message The message to report.
+ * @param {string} messageId The messageId to report.
* @returns {void}
*/
- function report(node, message) {
+ function report(node, messageId) {
let callee = node.callee;
if (callee.type === "MemberExpression") {
callee = callee.property;
}
- context.report({ node, loc: callee.loc.start, message });
+ context.report({ node, loc: callee.loc.start, messageId });
}
//--------------------------------------------------------------------------
@@ -248,7 +252,7 @@ module.exports = {
const isAllowed = capitalization !== "lower" || isCapAllowed(newIsCapExceptions, node, constructorName, newIsCapExceptionPattern);
if (!isAllowed) {
- report(node, "A constructor name should not start with a lowercase letter.");
+ report(node, "lower");
}
}
};
@@ -264,7 +268,7 @@ module.exports = {
const isAllowed = capitalization !== "upper" || isCapAllowed(capIsNewExceptions, node, calleeName, capIsNewExceptionPattern);
if (!isAllowed) {
- report(node, "A function with a name starting with an uppercase letter should only be used as a constructor.");
+ report(node, "upper");
}
}
};
diff --git a/lib/rules/new-parens.js b/lib/rules/new-parens.js
index 0637a8fbca2..edd3c1e1c2e 100644
--- a/lib/rules/new-parens.js
+++ b/lib/rules/new-parens.js
@@ -30,8 +30,11 @@ module.exports = {
url: "https://eslint.org/docs/rules/new-parens"
},
+ fixable: "code",
schema: [],
- fixable: "code"
+ messages: {
+ missing: "Missing '()' invoking a constructor."
+ }
},
create(context) {
@@ -50,7 +53,7 @@ module.exports = {
if (!hasParens) {
context.report({
node,
- message: "Missing '()' invoking a constructor.",
+ messageId: "missing",
fix: fixer => fixer.insertTextAfter(node, "()")
});
}
diff --git a/lib/rules/newline-after-var.js b/lib/rules/newline-after-var.js
index 83fd420d733..036cefc22ca 100644
--- a/lib/rules/newline-after-var.js
+++ b/lib/rules/newline-after-var.js
@@ -26,14 +26,16 @@ module.exports = {
recommended: false,
url: "https://eslint.org/docs/rules/newline-after-var"
},
-
schema: [
{
enum: ["never", "always"]
}
],
-
fixable: "whitespace",
+ messages: {
+ expected: "Expected blank line after variable declarations.",
+ unexpected: "Unexpected blank line after variable declarations."
+ },
deprecated: true,
@@ -41,10 +43,6 @@ module.exports = {
},
create(context) {
-
- const ALWAYS_MESSAGE = "Expected blank line after variable declarations.",
- NEVER_MESSAGE = "Unexpected blank line after variable declarations.";
-
const sourceCode = context.getSourceCode();
// Default `mode` to "always".
@@ -214,7 +212,7 @@ module.exports = {
if (mode === "never" && noNextLineToken && !hasNextLineComment) {
context.report({
node,
- message: NEVER_MESSAGE,
+ messageId: "unexpected",
data: { identifier: node.name },
fix(fixer) {
const linesBetween = sourceCode.getText().slice(lastToken.range[1], nextToken.range[0]).split(astUtils.LINEBREAK_MATCHER);
@@ -233,7 +231,7 @@ module.exports = {
) {
context.report({
node,
- message: ALWAYS_MESSAGE,
+ messageId: "expected",
data: { identifier: node.name },
fix(fixer) {
if ((noNextLineToken ? getLastCommentLineOfBlock(nextLineNum) : lastToken.loc.end.line) === nextToken.loc.start.line) {
diff --git a/lib/rules/newline-before-return.js b/lib/rules/newline-before-return.js
index 6a0ec8d5eb7..816ddba72b2 100644
--- a/lib/rules/newline-before-return.js
+++ b/lib/rules/newline-before-return.js
@@ -22,6 +22,10 @@ module.exports = {
fixable: "whitespace",
schema: [],
+ messages: {
+ expected: "Expected newline before return statement."
+ },
+
deprecated: true,
replacedBy: ["padding-line-between-statements"]
},
@@ -196,7 +200,7 @@ module.exports = {
if (!isFirstNode(node) && !hasNewlineBefore(node)) {
context.report({
node,
- message: "Expected newline before return statement.",
+ messageId: "expected",
fix(fixer) {
if (canFix(node)) {
const tokenBefore = sourceCode.getTokenBefore(node);
diff --git a/lib/rules/newline-per-chained-call.js b/lib/rules/newline-per-chained-call.js
index 9d993137682..0bf2365de5a 100644
--- a/lib/rules/newline-per-chained-call.js
+++ b/lib/rules/newline-per-chained-call.js
@@ -35,7 +35,10 @@ module.exports = {
}
},
additionalProperties: false
- }]
+ }],
+ messages: {
+ expected: "Expected line break before `{{callee}}`."
+ }
},
create(context) {
@@ -91,7 +94,7 @@ module.exports = {
context.report({
node: callee.property,
loc: callee.property.loc.start,
- message: "Expected line break before `{{callee}}`.",
+ messageId: "expected",
data: {
callee: getPropertyText(callee)
},
diff --git a/lib/rules/no-async-promise-executor.js b/lib/rules/no-async-promise-executor.js
index fc65f539a3e..af15509ed4d 100644
--- a/lib/rules/no-async-promise-executor.js
+++ b/lib/rules/no-async-promise-executor.js
@@ -20,7 +20,10 @@ module.exports = {
},
fixable: null,
- schema: []
+ schema: [],
+ messages: {
+ async: "Promise executor functions should not be async."
+ }
},
create(context) {
@@ -28,7 +31,7 @@ module.exports = {
"NewExpression[callee.name='Promise'][arguments.0.async=true]"(node) {
context.report({
node: context.getSourceCode().getFirstToken(node.arguments[0], token => token.value === "async"),
- message: "Promise executor functions should not be async."
+ messageId: "async"
});
}
};
diff --git a/lib/rules/no-duplicate-imports.js b/lib/rules/no-duplicate-imports.js
index 1d5bdfdc1a2..7d35b41b4d4 100644
--- a/lib/rules/no-duplicate-imports.js
+++ b/lib/rules/no-duplicate-imports.js
@@ -29,18 +29,17 @@ function getValue(node) {
* @param {ASTNode} node - A node to get.
* @param {string} value - The name of the imported or exported module.
* @param {string[]} array - The array containing other imports or exports in the file.
- * @param {string} message - A message to be reported after the name of the module
+ * @param {string} messageId - A messageId to be reported after the name of the module
*
* @returns {void} No return value
*/
-function checkAndReport(context, node, value, array, message) {
+function checkAndReport(context, node, value, array, messageId) {
if (array.indexOf(value) !== -1) {
context.report({
node,
- message: "'{{module}}' {{message}}",
+ messageId,
data: {
- module: value,
- message
+ module: value
}
});
}
@@ -66,10 +65,10 @@ function handleImports(context, includeExports, importsInFile, exportsInFile) {
const value = getValue(node);
if (value) {
- checkAndReport(context, node, value, importsInFile, "import is duplicated.");
+ checkAndReport(context, node, value, importsInFile, "import");
if (includeExports) {
- checkAndReport(context, node, value, exportsInFile, "import is duplicated as export.");
+ checkAndReport(context, node, value, exportsInFile, "importAs");
}
importsInFile.push(value);
@@ -91,8 +90,8 @@ function handleExports(context, importsInFile, exportsInFile) {
const value = getValue(node);
if (value) {
- checkAndReport(context, node, value, exportsInFile, "export is duplicated.");
- checkAndReport(context, node, value, importsInFile, "export is duplicated as import.");
+ checkAndReport(context, node, value, exportsInFile, "export");
+ checkAndReport(context, node, value, importsInFile, "exportAs");
exportsInFile.push(value);
}
@@ -118,7 +117,13 @@ module.exports = {
}
},
additionalProperties: false
- }]
+ }],
+ messages: {
+ import: "'{{module}}' import is duplicated.",
+ importAs: "'{{module}}' import is duplicated as export.",
+ export: "'{{module}}' export is duplicated.",
+ exportAs: "'{{module}}' export is duplicated as import."
+ }
},
create(context) {
diff --git a/lib/rules/no-fallthrough.js b/lib/rules/no-fallthrough.js
index b7fa221050d..79cbe81c0bb 100644
--- a/lib/rules/no-fallthrough.js
+++ b/lib/rules/no-fallthrough.js
@@ -74,7 +74,11 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ case: "Expected a 'break' statement before 'case'.",
+ default: "Expected a 'break' statement before 'default'."
+ }
},
create(context) {
@@ -111,8 +115,7 @@ module.exports = {
*/
if (fallthroughCase && !hasFallthroughComment(node, context, fallthroughCommentPattern)) {
context.report({
- message: "Expected a 'break' statement before '{{type}}'.",
- data: { type: node.test ? "case" : "default" },
+ messageId: node.test ? "case" : "default",
node
});
}
diff --git a/lib/rules/no-floating-decimal.js b/lib/rules/no-floating-decimal.js
index c835d6a545f..de5a521525f 100644
--- a/lib/rules/no-floating-decimal.js
+++ b/lib/rules/no-floating-decimal.js
@@ -27,7 +27,11 @@ module.exports = {
},
schema: [],
- fixable: "code"
+ fixable: "code",
+ messages: {
+ leading: "A leading decimal point can be confused with a dot.",
+ trailing: "A trailing decimal point can be confused with a dot."
+ }
},
create(context) {
@@ -40,7 +44,7 @@ module.exports = {
if (node.raw.startsWith(".")) {
context.report({
node,
- message: "A leading decimal point can be confused with a dot.",
+ messageId: "leading",
fix(fixer) {
const tokenBefore = sourceCode.getTokenBefore(node);
const needsSpaceBefore = tokenBefore &&
@@ -54,7 +58,7 @@ module.exports = {
if (node.raw.indexOf(".") === node.raw.length - 1) {
context.report({
node,
- message: "A trailing decimal point can be confused with a dot.",
+ messageId: "trailing",
fix: fixer => fixer.insertTextAfter(node, "0")
});
}
diff --git a/lib/rules/no-undef.js b/lib/rules/no-undef.js
index f923644eca1..e6cd152761f 100644
--- a/lib/rules/no-undef.js
+++ b/lib/rules/no-undef.js
@@ -44,7 +44,10 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ undef: "'{{name}}' is not defined."
+ }
},
create(context) {
@@ -64,7 +67,7 @@ module.exports = {
context.report({
node: identifier,
- message: "'{{name}}' is not defined.",
+ messageId: "undef",
data: identifier
});
});
diff --git a/lib/rules/no-unexpected-multiline.js b/lib/rules/no-unexpected-multiline.js
index 3bed96fc77d..35c2140bae6 100644
--- a/lib/rules/no-unexpected-multiline.js
+++ b/lib/rules/no-unexpected-multiline.js
@@ -25,16 +25,17 @@ module.exports = {
url: "https://eslint.org/docs/rules/no-unexpected-multiline"
},
- schema: []
+ schema: [],
+ messages: {
+ function: "Unexpected newline between function and ( of function call.",
+ property: "Unexpected newline between object and [ of property access.",
+ taggedTemplate: "Unexpected newline between template tag and template literal.",
+ division: "Unexpected newline between numerator and division operator."
+ }
},
create(context) {
- const FUNCTION_MESSAGE = "Unexpected newline between function and ( of function call.";
- const PROPERTY_MESSAGE = "Unexpected newline between object and [ of property access.";
- const TAGGED_TEMPLATE_MESSAGE = "Unexpected newline between template tag and template literal.";
- const DIVISION_MESSAGE = "Unexpected newline between numerator and division operator.";
-
const REGEX_FLAG_MATCHER = /^[gimsuy]+$/;
const sourceCode = context.getSourceCode();
@@ -43,16 +44,16 @@ module.exports = {
* Check to see if there is a newline between the node and the following open bracket
* line's expression
* @param {ASTNode} node The node to check.
- * @param {string} msg The error message to use.
+ * @param {string} messageId The error messageId to use.
* @returns {void}
* @private
*/
- function checkForBreakAfter(node, msg) {
+ function checkForBreakAfter(node, messageId) {
const openParen = sourceCode.getTokenAfter(node, astUtils.isNotClosingParenToken);
const nodeExpressionEnd = sourceCode.getTokenBefore(openParen);
if (openParen.loc.start.line !== nodeExpressionEnd.loc.end.line) {
- context.report({ node, loc: openParen.loc.start, message: msg, data: { char: openParen.value } });
+ context.report({ node, loc: openParen.loc.start, messageId, data: { char: openParen.value } });
}
}
@@ -66,21 +67,21 @@ module.exports = {
if (!node.computed) {
return;
}
- checkForBreakAfter(node.object, PROPERTY_MESSAGE);
+ checkForBreakAfter(node.object, "property");
},
TaggedTemplateExpression(node) {
if (node.tag.loc.end.line === node.quasi.loc.start.line) {
return;
}
- context.report({ node, loc: node.loc.start, message: TAGGED_TEMPLATE_MESSAGE });
+ context.report({ node, loc: node.loc.start, messageId: "taggedTemplate" });
},
CallExpression(node) {
if (node.arguments.length === 0) {
return;
}
- checkForBreakAfter(node.callee, FUNCTION_MESSAGE);
+ checkForBreakAfter(node.callee, "function");
},
"BinaryExpression[operator='/'] > BinaryExpression[operator='/'].left"(node) {
@@ -92,7 +93,7 @@ module.exports = {
REGEX_FLAG_MATCHER.test(tokenAfterOperator.value) &&
secondSlash.range[1] === tokenAfterOperator.range[0]
) {
- checkForBreakAfter(node.left, DIVISION_MESSAGE);
+ checkForBreakAfter(node.left, "division");
}
}
};
diff --git a/lib/rules/no-unsafe-negation.js b/lib/rules/no-unsafe-negation.js
index 3a0402eb0d5..3b5b367e42e 100644
--- a/lib/rules/no-unsafe-negation.js
+++ b/lib/rules/no-unsafe-negation.js
@@ -51,7 +51,10 @@ module.exports = {
},
schema: [],
- fixable: "code"
+ fixable: "code",
+ messages: {
+ unexpected: "Unexpected negating the left operand of '{{operator}}' operator."
+ }
},
create(context) {
@@ -66,8 +69,8 @@ module.exports = {
context.report({
node,
loc: node.left.loc,
- message: "Unexpected negating the left operand of '{{operator}}' operator.",
- data: node,
+ messageId: "unexpected",
+ data: { operator: node.operator },
fix(fixer) {
const negationToken = sourceCode.getFirstToken(node.left);
diff --git a/lib/rules/no-unused-labels.js b/lib/rules/no-unused-labels.js
index c9e097df458..1ba1d05d5c6 100644
--- a/lib/rules/no-unused-labels.js
+++ b/lib/rules/no-unused-labels.js
@@ -21,7 +21,12 @@ module.exports = {
},
schema: [],
- fixable: "code"
+
+ fixable: "code",
+
+ messages: {
+ unused: "'{{name}}:' is defined but never used."
+ }
},
create(context) {
@@ -53,7 +58,7 @@ module.exports = {
if (!scopeInfo.used) {
context.report({
node: node.label,
- message: "'{{name}}:' is defined but never used.",
+ messageId: "unused",
data: node.label,
fix(fixer) {
diff --git a/lib/rules/operator-assignment.js b/lib/rules/operator-assignment.js
index 8bb01737dd6..94e85927344 100644
--- a/lib/rules/operator-assignment.js
+++ b/lib/rules/operator-assignment.js
@@ -104,7 +104,11 @@ module.exports = {
}
],
- fixable: "code"
+ fixable: "code",
+ messages: {
+ replaced: "Assignment can be replaced with operator assignment.",
+ unexpected: "Unexpected operator assignment shorthand."
+ }
},
create(context) {
@@ -138,7 +142,7 @@ module.exports = {
if (same(left, expr.left)) {
context.report({
node,
- message: "Assignment can be replaced with operator assignment.",
+ messageId: "replaced",
fix(fixer) {
if (canBeFixed(left)) {
const equalsToken = getOperatorToken(node);
@@ -160,7 +164,7 @@ module.exports = {
*/
context.report({
node,
- message: "Assignment can be replaced with operator assignment."
+ messageId: "replaced"
});
}
}
@@ -175,7 +179,7 @@ module.exports = {
if (node.operator !== "=") {
context.report({
node,
- message: "Unexpected operator assignment shorthand.",
+ messageId: "unexpected",
fix(fixer) {
if (canBeFixed(node.left)) {
const operatorToken = getOperatorToken(node);
diff --git a/lib/rules/prefer-const.js b/lib/rules/prefer-const.js
index a40ad353950..5f75376c95c 100644
--- a/lib/rules/prefer-const.js
+++ b/lib/rules/prefer-const.js
@@ -350,7 +350,10 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ useConst: "'{{name}}' is never reassigned. Use 'const' instead."
+ }
},
create(context) {
@@ -445,7 +448,7 @@ module.exports = {
nodesToReport.forEach(node => {
context.report({
node,
- message: "'{{name}}' is never reassigned. Use 'const' instead.",
+ messageId: "useConst",
data: node,
fix: shouldFix ? fixer => fixer.replaceText(sourceCode.getFirstToken(varDeclParent), "const") : null
});
diff --git a/lib/rules/space-unary-ops.js b/lib/rules/space-unary-ops.js
index b56fa4f2fac..046be22bec8 100644
--- a/lib/rules/space-unary-ops.js
+++ b/lib/rules/space-unary-ops.js
@@ -46,7 +46,15 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ unexpectedBefore: "Unexpected space before unary operator '{{operator}}'.",
+ unexpectedAfter: "Unexpected space after unary operator '{{operator}}'.",
+ unexpectedAfterWord: "Unexpected space after unary word operator '{{word}}'.",
+ wordOperator: "Unary word operator '{{word}}' must be followed by whitespace.",
+ operator: "Unary operator '{{operator}}' must be followed by whitespace.",
+ beforeUnaryExpressions: "Space is required before unary expressions '{{token}}'."
+ }
},
create(context) {
@@ -98,7 +106,7 @@ module.exports = {
if (secondToken.range[0] === firstToken.range[1]) {
context.report({
node,
- message: "Unary word operator '{{word}}' must be followed by whitespace.",
+ messageId: "wordOperator",
data: {
word
},
@@ -122,7 +130,7 @@ module.exports = {
if (secondToken.range[0] > firstToken.range[1]) {
context.report({
node,
- message: "Unexpected space after unary word operator '{{word}}'.",
+ messageId: "unexpectedAfterWord",
data: {
word
},
@@ -198,7 +206,7 @@ module.exports = {
if (firstToken.range[1] === secondToken.range[0]) {
context.report({
node,
- message: "Unary operator '{{operator}}' must be followed by whitespace.",
+ messageId: "operator",
data: {
operator: firstToken.value
},
@@ -211,7 +219,7 @@ module.exports = {
if (firstToken.range[1] === secondToken.range[0]) {
context.report({
node,
- message: "Space is required before unary expressions '{{token}}'.",
+ messageId: "beforeUnaryExpressions",
data: {
token: secondToken.value
},
@@ -235,7 +243,7 @@ module.exports = {
if (secondToken.range[0] > firstToken.range[1]) {
context.report({
node,
- message: "Unexpected space after unary operator '{{operator}}'.",
+ messageId: "unexpectedAfter",
data: {
operator: firstToken.value
},
@@ -251,7 +259,7 @@ module.exports = {
if (secondToken.range[0] > firstToken.range[1]) {
context.report({
node,
- message: "Unexpected space before unary operator '{{operator}}'.",
+ messageId: "unexpectedBefore",
data: {
operator: secondToken.value
},
diff --git a/lib/rules/strict.js b/lib/rules/strict.js
index bec1baf4653..a826731260b 100644
--- a/lib/rules/strict.js
+++ b/lib/rules/strict.js
@@ -15,19 +15,6 @@ const astUtils = require("../util/ast-utils");
// Helpers
//------------------------------------------------------------------------------
-const messages = {
- function: "Use the function form of 'use strict'.",
- global: "Use the global form of 'use strict'.",
- multiple: "Multiple 'use strict' directives.",
- never: "Strict mode is not permitted.",
- unnecessary: "Unnecessary 'use strict' directive.",
- module: "'use strict' is unnecessary inside of modules.",
- implied: "'use strict' is unnecessary when implied strict mode is enabled.",
- unnecessaryInClasses: "'use strict' is unnecessary inside of classes.",
- nonSimpleParameterList: "'use strict' directive inside a function with non-simple parameter list throws a syntax error since ES2016.",
- wrap: "Wrap {{name}} in a function with 'use strict' directive."
-};
-
/**
* Gets all of the Use Strict Directives in the Directive Prologue of a group of
* statements.
@@ -95,7 +82,19 @@ module.exports = {
}
],
- fixable: "code"
+ fixable: "code",
+ messages: {
+ function: "Use the function form of 'use strict'.",
+ global: "Use the global form of 'use strict'.",
+ multiple: "Multiple 'use strict' directives.",
+ never: "Strict mode is not permitted.",
+ unnecessary: "Unnecessary 'use strict' directive.",
+ module: "'use strict' is unnecessary inside of modules.",
+ implied: "'use strict' is unnecessary when implied strict mode is enabled.",
+ unnecessaryInClasses: "'use strict' is unnecessary inside of classes.",
+ nonSimpleParameterList: "'use strict' directive inside a function with non-simple parameter list throws a syntax error since ES2016.",
+ wrap: "Wrap {{name}} in a function with 'use strict' directive."
+ }
},
create(context) {
@@ -134,36 +133,36 @@ module.exports = {
* @param {ASTNode[]} nodes Nodes.
* @param {string} start Index to start from.
* @param {string} end Index to end before.
- * @param {string} message Message to display.
+ * @param {string} messageId Message to display.
* @param {boolean} fix `true` if the directive should be fixed (i.e. removed)
* @returns {void}
*/
- function reportSlice(nodes, start, end, message, fix) {
+ function reportSlice(nodes, start, end, messageId, fix) {
nodes.slice(start, end).forEach(node => {
- context.report({ node, message, fix: fix ? getFixFunction(node) : null });
+ context.report({ node, messageId, fix: fix ? getFixFunction(node) : null });
});
}
/**
* Report all nodes in an array with a given message.
* @param {ASTNode[]} nodes Nodes.
- * @param {string} message Message to display.
+ * @param {string} messageId Message id to display.
* @param {boolean} fix `true` if the directive should be fixed (i.e. removed)
* @returns {void}
*/
- function reportAll(nodes, message, fix) {
- reportSlice(nodes, 0, nodes.length, message, fix);
+ function reportAll(nodes, messageId, fix) {
+ reportSlice(nodes, 0, nodes.length, messageId, fix);
}
/**
* Report all nodes in an array, except the first, with a given message.
* @param {ASTNode[]} nodes Nodes.
- * @param {string} message Message to display.
+ * @param {string} messageId Message id to display.
* @param {boolean} fix `true` if the directive should be fixed (i.e. removed)
* @returns {void}
*/
- function reportAllExceptFirst(nodes, message, fix) {
- reportSlice(nodes, 1, nodes.length, message, fix);
+ function reportAllExceptFirst(nodes, messageId, fix) {
+ reportSlice(nodes, 1, nodes.length, messageId, fix);
}
/**
@@ -181,21 +180,21 @@ module.exports = {
if (isStrict) {
if (!isSimpleParameterList(node.params)) {
- context.report({ node: useStrictDirectives[0], message: messages.nonSimpleParameterList });
+ context.report({ node: useStrictDirectives[0], messageId: "nonSimpleParameterList" });
} else if (isParentStrict) {
- context.report({ node: useStrictDirectives[0], message: messages.unnecessary, fix: getFixFunction(useStrictDirectives[0]) });
+ context.report({ node: useStrictDirectives[0], messageId: "unnecessary", fix: getFixFunction(useStrictDirectives[0]) });
} else if (isInClass) {
- context.report({ node: useStrictDirectives[0], message: messages.unnecessaryInClasses, fix: getFixFunction(useStrictDirectives[0]) });
+ context.report({ node: useStrictDirectives[0], messageId: "unnecessaryInClasses", fix: getFixFunction(useStrictDirectives[0]) });
}
- reportAllExceptFirst(useStrictDirectives, messages.multiple, true);
+ reportAllExceptFirst(useStrictDirectives, "multiple", true);
} else if (isParentGlobal) {
if (isSimpleParameterList(node.params)) {
- context.report({ node, message: messages.function });
+ context.report({ node, messageId: "function" });
} else {
context.report({
node,
- message: messages.wrap,
+ messageId: "wrap",
data: { name: astUtils.getFunctionNameWithKind(node) }
});
}
@@ -228,10 +227,10 @@ module.exports = {
enterFunctionInFunctionMode(node, useStrictDirectives);
} else if (useStrictDirectives.length > 0) {
if (isSimpleParameterList(node.params)) {
- reportAll(useStrictDirectives, messages[mode], shouldFix(mode));
+ reportAll(useStrictDirectives, mode, shouldFix(mode));
} else {
- context.report({ node: useStrictDirectives[0], message: messages.nonSimpleParameterList });
- reportAllExceptFirst(useStrictDirectives, messages.multiple, true);
+ context.report({ node: useStrictDirectives[0], messageId: "nonSimpleParameterList" });
+ reportAllExceptFirst(useStrictDirectives, "multiple", true);
}
}
}
@@ -246,11 +245,11 @@ module.exports = {
if (mode === "global") {
if (node.body.length > 0 && useStrictDirectives.length === 0) {
- context.report({ node, message: messages.global });
+ context.report({ node, messageId: "global" });
}
- reportAllExceptFirst(useStrictDirectives, messages.multiple, true);
+ reportAllExceptFirst(useStrictDirectives, "multiple", true);
} else {
- reportAll(useStrictDirectives, messages[mode], shouldFix(mode));
+ reportAll(useStrictDirectives, mode, shouldFix(mode));
}
},
FunctionDeclaration: enterFunction,
diff --git a/lib/rules/switch-colon-spacing.js b/lib/rules/switch-colon-spacing.js
index e94b3292106..9c7c0d589e0 100644
--- a/lib/rules/switch-colon-spacing.js
+++ b/lib/rules/switch-colon-spacing.js
@@ -36,8 +36,13 @@ module.exports = {
additionalProperties: false
}
],
-
- fixable: "whitespace"
+ fixable: "whitespace",
+ messages: {
+ expectedBefore: "Expected space(s) before this colon.",
+ expectedAfter: "Expected space(s) after this colon.",
+ unexpectedBefore: "Unexpected space(s) before this colon.",
+ unexpectedAfter: "Unexpected space(s) after this colon."
+ }
},
create(context) {
@@ -118,8 +123,7 @@ module.exports = {
context.report({
node,
loc: colonToken.loc,
- message: "{{verb}} space(s) before this colon.",
- data: { verb: beforeSpacing ? "Expected" : "Unexpected" },
+ messageId: beforeSpacing ? "expectedBefore" : "unexpectedBefore",
fix: fixer => fix(fixer, beforeToken, colonToken, beforeSpacing)
});
}
@@ -127,8 +131,7 @@ module.exports = {
context.report({
node,
loc: colonToken.loc,
- message: "{{verb}} space(s) after this colon.",
- data: { verb: afterSpacing ? "Expected" : "Unexpected" },
+ messageId: afterSpacing ? "expectedAfter" : "unexpectedAfter",
fix: fixer => fix(fixer, colonToken, afterToken, afterSpacing)
});
}
diff --git a/lib/rules/symbol-description.js b/lib/rules/symbol-description.js
index 7bb4e2dec69..f2e7e16b7a5 100644
--- a/lib/rules/symbol-description.js
+++ b/lib/rules/symbol-description.js
@@ -26,8 +26,11 @@ module.exports = {
recommended: false,
url: "https://eslint.org/docs/rules/symbol-description"
},
-
- schema: []
+ fixable: null,
+ schema: [],
+ messages: {
+ expected: "Expected Symbol to have a description."
+ }
},
create(context) {
@@ -43,7 +46,7 @@ module.exports = {
if (node.arguments.length === 0) {
context.report({
node,
- message: "Expected Symbol to have a description."
+ messageId: "expected"
});
}
}
diff --git a/lib/rules/template-curly-spacing.js b/lib/rules/template-curly-spacing.js
index ea801cbe5d2..84957d47594 100644
--- a/lib/rules/template-curly-spacing.js
+++ b/lib/rules/template-curly-spacing.js
@@ -37,13 +37,19 @@ module.exports = {
schema: [
{ enum: ["always", "never"] }
- ]
+ ],
+ messages: {
+ expectedBefore: "Expected space(s) before '}'.",
+ expectedAfter: "Expected space(s) after '${'.",
+ unexpectedBefore: "Unexpected space(s) before '}'.",
+ unexpectedAfter: "Unexpected space(s) after '${'."
+ }
},
create(context) {
const sourceCode = context.getSourceCode();
const always = context.options[0] === "always";
- const prefix = always ? "Expected" : "Unexpected";
+ const prefix = always ? "expected" : "unexpected";
/**
* Checks spacing before `}` of a given token.
@@ -60,10 +66,7 @@ module.exports = {
) {
context.report({
loc: token.loc.start,
- message: "{{prefix}} space(s) before '}'.",
- data: {
- prefix
- },
+ messageId: `${prefix}Before`,
fix(fixer) {
if (always) {
return fixer.insertTextBefore(token, " ");
@@ -95,10 +98,7 @@ module.exports = {
line: token.loc.end.line,
column: token.loc.end.column - 2
},
- message: "{{prefix}} space(s) after '${'.",
- data: {
- prefix
- },
+ messageId: `${prefix}After`,
fix(fixer) {
if (always) {
return fixer.insertTextAfter(token, " ");
diff --git a/lib/rules/template-tag-spacing.js b/lib/rules/template-tag-spacing.js
index f258cde3d88..9eb6d86077d 100644
--- a/lib/rules/template-tag-spacing.js
+++ b/lib/rules/template-tag-spacing.js
@@ -24,7 +24,11 @@ module.exports = {
schema: [
{ enum: ["always", "never"] }
- ]
+ ],
+ messages: {
+ unexpected: "Unexpected space between template tag and template literal.",
+ missing: "Missing space between template tag and template literal."
+ }
},
create(context) {
@@ -46,7 +50,7 @@ module.exports = {
context.report({
node,
loc: tagToken.loc.start,
- message: "Unexpected space between template tag and template literal.",
+ messageId: "unexpected",
fix(fixer) {
const comments = sourceCode.getCommentsBefore(node.quasi);
@@ -65,7 +69,7 @@ module.exports = {
context.report({
node,
loc: tagToken.loc.start,
- message: "Missing space between template tag and template literal.",
+ messageId: "missing",
fix(fixer) {
return fixer.insertTextAfter(tagToken, " ");
}
diff --git a/lib/rules/unicode-bom.js b/lib/rules/unicode-bom.js
index 20f48e22b3c..39642f85193 100644
--- a/lib/rules/unicode-bom.js
+++ b/lib/rules/unicode-bom.js
@@ -25,7 +25,11 @@ module.exports = {
{
enum: ["always", "never"]
}
- ]
+ ],
+ messages: {
+ expected: "Expected Unicode BOM (Byte Order Mark).",
+ unexpected: "Unexpected Unicode BOM (Byte Order Mark)."
+ }
},
create(context) {
@@ -46,7 +50,7 @@ module.exports = {
context.report({
node,
loc: location,
- message: "Expected Unicode BOM (Byte Order Mark).",
+ messageId: "expected",
fix(fixer) {
return fixer.insertTextBeforeRange([0, 1], "\uFEFF");
}
@@ -55,7 +59,7 @@ module.exports = {
context.report({
node,
loc: location,
- message: "Unexpected Unicode BOM (Byte Order Mark).",
+ messageId: "unexpected",
fix(fixer) {
return fixer.removeRange([-1, 0]);
}
diff --git a/lib/rules/use-isnan.js b/lib/rules/use-isnan.js
index 343ca045444..c8adefd608a 100644
--- a/lib/rules/use-isnan.js
+++ b/lib/rules/use-isnan.js
@@ -20,7 +20,10 @@ module.exports = {
url: "https://eslint.org/docs/rules/use-isnan"
},
- schema: []
+ schema: [],
+ messages: {
+ useIsNaN: "Use the isNaN function to compare with NaN."
+ }
},
create(context) {
@@ -28,7 +31,7 @@ module.exports = {
return {
BinaryExpression(node) {
if (/^(?:[<>]|[!=]=)=?$/.test(node.operator) && (node.left.name === "NaN" || node.right.name === "NaN")) {
- context.report({ node, message: "Use the isNaN function to compare with NaN." });
+ context.report({ node, messageId: "useIsNaN" });
}
}
};
diff --git a/lib/rules/valid-jsdoc.js b/lib/rules/valid-jsdoc.js
index b40a20f6b4b..515ba78b1d4 100644
--- a/lib/rules/valid-jsdoc.js
+++ b/lib/rules/valid-jsdoc.js
@@ -65,6 +65,22 @@ module.exports = {
],
fixable: "code",
+ messages: {
+ unexpectedTag: "Unexpected @{{title}} tag; function has no return statement.",
+ expected: "Expected JSDoc for '{{name}}' but found '{{jsdocName}}'.",
+ use: "Use @{{name}} instead.",
+ useType: "Use '{{expectedTypeName}}' instead of '{{currentTypeName}}'.",
+ syntaxError: "JSDoc syntax error.",
+ missingBrace: "JSDoc type missing brace.",
+ missingParamDesc: "Missing JSDoc parameter description for '{{name}}'.",
+ missingParamType: "Missing JSDoc parameter type for '{{name}}'.",
+ missingReturnType: "Missing JSDoc return type.",
+ missingReturnDesc: "Missing JSDoc return description.",
+ missingReturn: "Missing JSDoc @{{returns}} for function.",
+ missingParam: "Missing JSDoc for parameter '{{name}}'.",
+ duplicateParam: "Duplicate JSDoc parameter '{{name}}'.",
+ unsatisfiedDesc: "JSDoc description does not satisfy the regex pattern."
+ },
deprecated: true,
replacedBy: []
@@ -231,7 +247,7 @@ module.exports = {
typeToCheck.expectedTypeName !== typeToCheck.currentType.name) {
context.report({
node: jsdocNode,
- message: "Use '{{expectedTypeName}}' instead of '{{currentTypeName}}'.",
+ messageId: "useType",
loc: getAbsoluteRange(jsdocNode, typeToCheck.currentType),
data: {
currentTypeName: typeToCheck.currentType.name,
@@ -280,9 +296,9 @@ module.exports = {
} catch (ex) {
if (/braces/i.test(ex.message)) {
- context.report({ node: jsdocNode, message: "JSDoc type missing brace." });
+ context.report({ node: jsdocNode, messageId: "missingBrace" });
} else {
- context.report({ node: jsdocNode, message: "JSDoc syntax error." });
+ context.report({ node: jsdocNode, messageId: "syntaxError" });
}
return;
@@ -332,7 +348,7 @@ module.exports = {
context.report({
node: jsdocNode,
- message: "Use @{{name}} instead.",
+ messageId: "use",
loc: {
start: entireTagRange.start,
end: {
@@ -363,7 +379,7 @@ module.exports = {
if (requireParamType && !param.type) {
context.report({
node: jsdocNode,
- message: "Missing JSDoc parameter type for '{{name}}'.",
+ messageId: "missingParamType",
loc: getAbsoluteRange(jsdocNode, param),
data: { name: param.name }
});
@@ -371,7 +387,7 @@ module.exports = {
if (!param.description && requireParamDescription) {
context.report({
node: jsdocNode,
- message: "Missing JSDoc parameter description for '{{name}}'.",
+ messageId: "missingParamDesc",
loc: getAbsoluteRange(jsdocNode, param),
data: { name: param.name }
});
@@ -379,7 +395,7 @@ module.exports = {
if (paramTagsByName[param.name]) {
context.report({
node: jsdocNode,
- message: "Duplicate JSDoc parameter '{{name}}'.",
+ messageId: "duplicateParam",
loc: getAbsoluteRange(jsdocNode, param),
data: { name: param.name }
});
@@ -392,7 +408,7 @@ module.exports = {
if (!requireReturn && !functionData.returnPresent && (returnsTag.type === null || !isValidReturnType(returnsTag)) && !isAbstract) {
context.report({
node: jsdocNode,
- message: "Unexpected @{{title}} tag; function has no return statement.",
+ messageId: "unexpectedTag",
loc: getAbsoluteRange(jsdocNode, returnsTag),
data: {
title: returnsTag.title
@@ -400,11 +416,11 @@ module.exports = {
});
} else {
if (requireReturnType && !returnsTag.type) {
- context.report({ node: jsdocNode, message: "Missing JSDoc return type." });
+ context.report({ node: jsdocNode, messageId: "missingReturnType" });
}
if (!isValidReturnType(returnsTag) && !returnsTag.description && requireReturnDescription) {
- context.report({ node: jsdocNode, message: "Missing JSDoc return description." });
+ context.report({ node: jsdocNode, messageId: "missingReturnDesc" });
}
}
}
@@ -416,7 +432,7 @@ module.exports = {
if (requireReturn || (functionData.returnPresent && !node.async)) {
context.report({
node: jsdocNode,
- message: "Missing JSDoc @{{returns}} for function.",
+ messageId: "missingReturn",
data: {
returns: prefer.returns || "returns"
}
@@ -440,7 +456,7 @@ module.exports = {
if (jsdocParamNames[paramsIndex] && (name !== jsdocParamNames[paramsIndex])) {
context.report({
node: jsdocNode,
- message: "Expected JSDoc for '{{name}}' but found '{{jsdocName}}'.",
+ messageId: "expected",
loc: getAbsoluteRange(jsdocNode, paramTagsByName[jsdocParamNames[paramsIndex]]),
data: {
name,
@@ -450,7 +466,7 @@ module.exports = {
} else if (!paramTagsByName[name] && !isOverride) {
context.report({
node: jsdocNode,
- message: "Missing JSDoc for parameter '{{name}}'.",
+ messageId: "missingParam",
data: {
name
}
@@ -464,7 +480,7 @@ module.exports = {
const regex = new RegExp(options.matchDescription);
if (!regex.test(jsdoc.description)) {
- context.report({ node: jsdocNode, message: "JSDoc description does not satisfy the regex pattern." });
+ context.report({ node: jsdocNode, messageId: "unsatisfiedDesc" });
}
}
diff --git a/lib/rules/valid-typeof.js b/lib/rules/valid-typeof.js
index e3245e8f306..7fa2b89bd05 100644
--- a/lib/rules/valid-typeof.js
+++ b/lib/rules/valid-typeof.js
@@ -29,7 +29,11 @@ module.exports = {
},
additionalProperties: false
}
- ]
+ ],
+ messages: {
+ invalidValue: "Invalid typeof comparison value.",
+ notString: "Typeof comparisons should be to string literals."
+ }
},
create(context) {
@@ -65,10 +69,10 @@ module.exports = {
const value = sibling.type === "Literal" ? sibling.value : sibling.quasis[0].value.cooked;
if (VALID_TYPES.indexOf(value) === -1) {
- context.report({ node: sibling, message: "Invalid typeof comparison value." });
+ context.report({ node: sibling, messageId: "invalidValue" });
}
} else if (requireStringLiterals && !isTypeofExpression(sibling)) {
- context.report({ node: sibling, message: "Typeof comparisons should be to string literals." });
+ context.report({ node: sibling, messageId: "notString" });
}
}
}
diff --git a/lib/rules/vars-on-top.js b/lib/rules/vars-on-top.js
index d69c223388f..92d483b6ecc 100644
--- a/lib/rules/vars-on-top.js
+++ b/lib/rules/vars-on-top.js
@@ -20,11 +20,13 @@ module.exports = {
url: "https://eslint.org/docs/rules/vars-on-top"
},
- schema: []
+ schema: [],
+ messages: {
+ top: "All 'var' declarations must be at the top of the function scope."
+ }
},
create(context) {
- const errorMessage = "All 'var' declarations must be at the top of the function scope.";
//--------------------------------------------------------------------------
// Helpers
@@ -103,7 +105,7 @@ module.exports = {
*/
function globalVarCheck(node, parent) {
if (!isVarOnTop(node, parent.body)) {
- context.report({ node, message: errorMessage });
+ context.report({ node, messageId: "top" });
}
}
@@ -118,7 +120,7 @@ module.exports = {
if (!(/Function/.test(grandParent.type) &&
parent.type === "BlockStatement" &&
isVarOnTop(node, parent.body))) {
- context.report({ node, message: errorMessage });
+ context.report({ node, messageId: "top" });
}
}
diff --git a/lib/rules/wrap-iife.js b/lib/rules/wrap-iife.js
index ce272235b4f..628ebf532e0 100644
--- a/lib/rules/wrap-iife.js
+++ b/lib/rules/wrap-iife.js
@@ -41,7 +41,12 @@ module.exports = {
}
],
- fixable: "code"
+ fixable: "code",
+ messages: {
+ wrapInvocation: "Wrap an immediate function invocation in parentheses.",
+ wrapExpression: "Wrap only the function expression in parens.",
+ moveInvocation: "Move the invocation into the parens that contain the function."
+ }
},
create(context) {
@@ -99,7 +104,7 @@ module.exports = {
if (!callExpressionWrapped && !functionExpressionWrapped) {
context.report({
node,
- message: "Wrap an immediate function invocation in parentheses.",
+ messageId: "wrapInvocation",
fix(fixer) {
const nodeToSurround = style === "inside" ? innerNode : node;
@@ -109,7 +114,7 @@ module.exports = {
} else if (style === "inside" && !functionExpressionWrapped) {
context.report({
node,
- message: "Wrap only the function expression in parens.",
+ messageId: "wrapExpression",
fix(fixer) {
/*
@@ -129,7 +134,7 @@ module.exports = {
} else if (style === "outside" && !callExpressionWrapped) {
context.report({
node,
- message: "Move the invocation into the parens that contain the function.",
+ messageId: "moveInvocation",
fix(fixer) {
/*
diff --git a/lib/rules/yield-star-spacing.js b/lib/rules/yield-star-spacing.js
index e7712a51dbf..20b8e9ea91e 100644
--- a/lib/rules/yield-star-spacing.js
+++ b/lib/rules/yield-star-spacing.js
@@ -38,7 +38,13 @@ module.exports = {
}
]
}
- ]
+ ],
+ messages: {
+ missingBefore: "Missing space before *.",
+ missingAfter: "Missing space after *.",
+ unexpectedBefore: "Unexpected space before *.",
+ unexpectedAfter: "Unexpected space after *."
+ }
},
create(context) {
@@ -70,16 +76,17 @@ module.exports = {
const after = leftToken.value === "*";
const spaceRequired = mode[side];
const node = after ? leftToken : rightToken;
- const type = spaceRequired ? "Missing" : "Unexpected";
- const message = "{{type}} space {{side}} *.";
+ let messageId = "";
+
+ if (spaceRequired) {
+ messageId = side === "before" ? "missingBefore" : "missingAfter";
+ } else {
+ messageId = side === "before" ? "unexpectedBefore" : "unexpectedAfter";
+ }
context.report({
node,
- message,
- data: {
- type,
- side
- },
+ messageId,
fix(fixer) {
if (spaceRequired) {
if (after) {
diff --git a/lib/rules/yoda.js b/lib/rules/yoda.js
index 8789c001ef9..83c435a4f74 100644
--- a/lib/rules/yoda.js
+++ b/lib/rules/yoda.js
@@ -179,7 +179,10 @@ module.exports = {
}
],
- fixable: "code"
+ fixable: "code",
+ messages: {
+ expected: "Expected literal to be on the {{expectedSide}} side of {{operator}}."
+ }
},
create(context) {
@@ -297,7 +300,7 @@ module.exports = {
) {
context.report({
node,
- message: "Expected literal to be on the {{expectedSide}} side of {{operator}}.",
+ messageId: "expected",
data: {
operator: node.operator,
expectedSide: always ? "left" : "right"
diff --git a/tests/lib/cli-engine.js b/tests/lib/cli-engine.js
index 9a57e86dfd1..fd961cb6353 100644
--- a/tests/lib/cli-engine.js
+++ b/tests/lib/cli-engine.js
@@ -481,6 +481,7 @@ describe("CLIEngine", () => {
{
ruleId: "no-undef",
severity: 2,
+ messageId: "undef",
message: "'foo' is not defined.",
line: 1,
column: 11,
@@ -1643,6 +1644,7 @@ describe("CLIEngine", () => {
line: 1,
endColumn: 21,
endLine: 1,
+ messageId: "undef",
message: "'foo' is not defined.",
nodeType: "Identifier",
ruleId: "no-undef",
diff --git a/tests/lib/rules/global-require.js b/tests/lib/rules/global-require.js
index d1f28d2cc87..a18c7874a6e 100644
--- a/tests/lib/rules/global-require.js
+++ b/tests/lib/rules/global-require.js
@@ -33,87 +33,46 @@ const valid = [
{ code: "var someFunc = require('./someFunc'); someFunc(function(require) { return('bananas'); });" }
];
-const message = "Unexpected require().";
-const type = "CallExpression";
+const error = { messageId: "unexpected", type: "CallExpression" };
const invalid = [
// block statements
{
code: "if (process.env.NODE_ENV === 'DEVELOPMENT') {\n\trequire('debug');\n}",
- errors: [{
- line: 2,
- column: 2,
- message,
- type
- }]
+ errors: [error]
},
{
code: "var x; if (y) { x = require('debug'); }",
- errors: [{
- line: 1,
- column: 21,
- message,
- type
- }]
+ errors: [error]
},
{
code: "var x; if (y) { x = require('debug').baz; }",
- errors: [{
- line: 1,
- column: 21,
- message,
- type
- }]
+ errors: [error]
},
{
code: "function x() { require('y') }",
- errors: [{
- line: 1,
- column: 16,
- message,
- type
- }]
+ errors: [error]
},
{
code: "try { require('x'); } catch (e) { console.log(e); }",
- errors: [{
- line: 1,
- column: 7,
- message,
- type
- }]
+ errors: [error]
},
// non-block statements
{
code: "var getModule = x => require(x);",
parserOptions: { ecmaVersion: 6 },
- errors: [{
- line: 1,
- column: 22,
- message,
- type
- }]
+ errors: [error]
},
{
code: "var x = (x => require(x))('weird')",
parserOptions: { ecmaVersion: 6 },
- errors: [{
- line: 1,
- column: 15,
- message,
- type
- }]
+ errors: [error]
},
{
code: "switch(x) { case '1': require('1'); break; }",
- errors: [{
- line: 1,
- column: 23,
- message,
- type
- }]
+ errors: [error]
}
];
diff --git a/tests/lib/rules/guard-for-in.js b/tests/lib/rules/guard-for-in.js
index d3a41134068..0cfdaa9795f 100644
--- a/tests/lib/rules/guard-for-in.js
+++ b/tests/lib/rules/guard-for-in.js
@@ -17,6 +17,7 @@ const rule = require("../../../lib/rules/guard-for-in"),
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
+const error = { messageId: "wrap", type: "ForInStatement" };
ruleTester.run("guard-for-in", rule, {
valid: [
@@ -28,11 +29,11 @@ ruleTester.run("guard-for-in", rule, {
"for (var x in o) { if (x) { continue; } f(); }"
],
invalid: [
- { code: "for (var x in o) { if (x) { f(); continue; } g(); }", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement" }] },
- { code: "for (var x in o) { if (x) { continue; f(); } g(); }", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement" }] },
- { code: "for (var x in o) { if (x) { f(); } g(); }", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement" }] },
- { code: "for (var x in o) { if (x) f(); g(); }", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement" }] },
- { code: "for (var x in o) { foo() }", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement" }] },
- { code: "for (var x in o) foo();", errors: [{ message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.", type: "ForInStatement" }] }
+ { code: "for (var x in o) { if (x) { f(); continue; } g(); }", errors: [error] },
+ { code: "for (var x in o) { if (x) { continue; f(); } g(); }", errors: [error] },
+ { code: "for (var x in o) { if (x) { f(); } g(); }", errors: [error] },
+ { code: "for (var x in o) { if (x) f(); g(); }", errors: [error] },
+ { code: "for (var x in o) { foo() }", errors: [error] },
+ { code: "for (var x in o) foo();", errors: [error] }
]
});
diff --git a/tests/lib/rules/handle-callback-err.js b/tests/lib/rules/handle-callback-err.js
index c70aed57e41..0dcacbfb5e0 100644
--- a/tests/lib/rules/handle-callback-err.js
+++ b/tests/lib/rules/handle-callback-err.js
@@ -18,9 +18,8 @@ const rule = require("../../../lib/rules/handle-callback-err"),
const ruleTester = new RuleTester();
-const expectedErrorMessage = "Expected error to be handled.";
-const expectedFunctionDeclarationError = { message: expectedErrorMessage, type: "FunctionDeclaration" };
-const expectedFunctionExpressionError = { message: expectedErrorMessage, type: "FunctionExpression" };
+const expectedFunctionDeclarationError = { messageId: "expected", type: "FunctionDeclaration" };
+const expectedFunctionExpressionError = { messageId: "expected", type: "FunctionExpression" };
ruleTester.run("handle-callback-err", rule, {
valid: [
@@ -58,7 +57,7 @@ ruleTester.run("handle-callback-err", rule, {
{ code: "function test(err) {errorLookingWord();}", errors: [expectedFunctionDeclarationError] },
{ code: "function test(err) {try{} catch(err) {}}", errors: [expectedFunctionDeclarationError] },
{ code: "function test(err, callback) { foo(function(err, callback) {}); }", errors: [expectedFunctionDeclarationError, expectedFunctionExpressionError] },
- { code: "var test = (err) => {};", parserOptions: { ecmaVersion: 6 }, errors: [{ message: expectedErrorMessage, type: "ArrowFunctionExpression" }] },
+ { code: "var test = (err) => {};", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "expected" }] },
{ code: "var test = function(err) {};", errors: [expectedFunctionExpressionError] },
{ code: "var test = function test(err, data) {};", errors: [expectedFunctionExpressionError] },
{ code: "var test = function test(err) {/* if(err){} */};", errors: [expectedFunctionExpressionError] },
diff --git a/tests/lib/rules/id-blacklist.js b/tests/lib/rules/id-blacklist.js
index 9f347f81f54..5f1397ada0f 100644
--- a/tests/lib/rules/id-blacklist.js
+++ b/tests/lib/rules/id-blacklist.js
@@ -17,6 +17,7 @@ const rule = require("../../../lib/rules/id-blacklist"),
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
+const error = { messageId: "blacklisted", type: "Identifier" };
ruleTester.run("id-blacklist", rule, {
valid: [
@@ -102,200 +103,140 @@ ruleTester.run("id-blacklist", rule, {
code: "foo = \"bar\"",
options: ["foo"],
errors: [
- {
- message: "Identifier 'foo' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "bar = \"bar\"",
options: ["bar"],
errors: [
- {
- message: "Identifier 'bar' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "foo = \"bar\"",
options: ["f", "fo", "foo", "bar"],
errors: [
- {
- message: "Identifier 'foo' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "function foo(){}",
options: ["f", "fo", "foo", "bar"],
errors: [
- {
- message: "Identifier 'foo' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "foo.bar()",
options: ["f", "fo", "foo", "b", "ba", "baz"],
errors: [
- {
- message: "Identifier 'foo' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "var foo = bar.baz;",
options: ["f", "fo", "foo", "b", "ba", "barr", "bazz"],
errors: [
- {
- message: "Identifier 'foo' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "var foo = bar.baz;",
options: ["f", "fo", "fooo", "b", "ba", "bar", "bazz"],
errors: [
- {
- message: "Identifier 'bar' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "if (foo.bar) {}",
options: ["f", "fo", "foo", "b", "ba", "barr", "bazz", "bingg"],
errors: [
- {
- message: "Identifier 'foo' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "var obj = { key: foo.bar };",
options: ["obj"],
errors: [
- {
- message: "Identifier 'obj' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "var obj = { key: foo.bar };",
options: ["key"],
errors: [
- {
- message: "Identifier 'key' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "var obj = { key: foo.bar };",
options: ["foo"],
errors: [
- {
- message: "Identifier 'foo' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "var arr = [foo.bar];",
options: ["arr"],
errors: [
- {
- message: "Identifier 'arr' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "var arr = [foo.bar];",
options: ["foo"],
errors: [
- {
- message: "Identifier 'foo' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "[foo.bar]",
options: ["f", "fo", "foo", "b", "ba", "barr", "bazz", "bingg"],
errors: [
- {
- message: "Identifier 'foo' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "if (foo.bar === bar.baz) { [bing.baz] }",
options: ["f", "fo", "foo", "b", "ba", "barr", "bazz", "bingg"],
errors: [
- {
- message: "Identifier 'foo' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "if (foo.bar === bar.baz) { [foo.bar] }",
options: ["f", "fo", "fooo", "b", "ba", "bar", "bazz", "bingg"],
errors: [
- {
- message: "Identifier 'bar' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "var myArray = new Array(); var myDate = new Date();",
options: ["array", "date", "myDate", "myarray", "new", "var"],
errors: [
- {
- message: "Identifier 'myDate' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "var myArray = new Array(); var myDate = new Date();",
options: ["array", "date", "mydate", "myArray", "new", "var"],
errors: [
- {
- message: "Identifier 'myArray' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "foo.bar = 1",
options: ["bar"],
errors: [
- {
- message: "Identifier 'bar' is blacklisted.",
- type: "Identifier"
- }
+ error
]
},
{
code: "foo.bar.baz = 1",
options: ["bar", "baz"],
errors: [
- {
- message: "Identifier 'baz' is blacklisted.",
- type: "Identifier"
- }
+ error
]
}
]
diff --git a/tests/lib/rules/id-length.js b/tests/lib/rules/id-length.js
index a4e36cd74d6..1c657576180 100644
--- a/tests/lib/rules/id-length.js
+++ b/tests/lib/rules/id-length.js
@@ -17,6 +17,8 @@ const rule = require("../../../lib/rules/id-length"),
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
+const tooShortError = { messageId: "tooShort", type: "Identifier" };
+const tooLongError = { messageId: "tooLong", type: "Identifier" };
ruleTester.run("id-length", rule, {
valid: [
@@ -64,116 +66,116 @@ ruleTester.run("id-length", rule, {
{ code: "({ prop: obj.xxxxx } = {});", options: [{ max: 4, properties: "never" }], parserOptions: { ecmaVersion: 6 } }
],
invalid: [
- { code: "var x = 1;", errors: [{ message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }] },
- { code: "var x;", errors: [{ message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }] },
- { code: "obj.e = document.body;", errors: [{ message: "Identifier name 'e' is too short (< 2).", type: "Identifier" }] },
- { code: "function x() {};", errors: [{ message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }] },
- { code: "function xyz(a) {};", errors: [{ message: "Identifier name 'a' is too short (< 2).", type: "Identifier" }] },
- { code: "var obj = { a: 1, bc: 2 };", errors: [{ message: "Identifier name 'a' is too short (< 2).", type: "Identifier" }] },
- { code: "try { blah(); } catch (e) { /* pass */ }", errors: [{ message: "Identifier name 'e' is too short (< 2).", type: "Identifier" }] },
- { code: "var handler = function (e) {};", errors: [{ message: "Identifier name 'e' is too short (< 2).", type: "Identifier" }] },
- { code: "for (var i=0; i < 10; i++) { console.log(i); }", errors: [{ message: "Identifier name 'i' is too short (< 2).", type: "Identifier" }] },
- { code: "var j=0; while (j > -10) { console.log(--j); }", errors: [{ message: "Identifier name 'j' is too short (< 2).", type: "Identifier" }] },
+ { code: "var x = 1;", errors: [tooShortError] },
+ { code: "var x;", errors: [tooShortError] },
+ { code: "obj.e = document.body;", errors: [tooShortError] },
+ { code: "function x() {};", errors: [tooShortError] },
+ { code: "function xyz(a) {};", errors: [tooShortError] },
+ { code: "var obj = { a: 1, bc: 2 };", errors: [tooShortError] },
+ { code: "try { blah(); } catch (e) { /* pass */ }", errors: [tooShortError] },
+ { code: "var handler = function (e) {};", errors: [tooShortError] },
+ { code: "for (var i=0; i < 10; i++) { console.log(i); }", errors: [tooShortError] },
+ { code: "var j=0; while (j > -10) { console.log(--j); }", errors: [tooShortError] },
{
code: "var _$xt_$ = Foo(42)",
options: [{ min: 2, max: 4 }],
errors: [
- { message: "Identifier name '_$xt_$' is too long (> 4).", type: "Identifier" }
+ tooLongError
]
},
{
code: "var _$x$_t$ = Foo(42)",
options: [{ min: 2, max: 4 }],
errors: [
- { message: "Identifier name '_$x$_t$' is too long (> 4).", type: "Identifier" }
+ tooLongError
]
},
{
code: "(a) => { a * a };",
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Identifier name 'a' is too short (< 2).", type: "Identifier" }
+ tooShortError
]
},
{
code: "function foo(x = 0) { }",
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }
+ tooShortError
]
},
{
code: "class x { }",
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }
+ tooShortError
]
},
{
code: "class Foo { x() {} }",
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }
+ tooShortError
]
},
{
code: "function foo(...x) { }",
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }
+ tooShortError
]
},
{
code: "var { x} = {};",
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" },
- { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }
+ tooShortError,
+ tooShortError
]
},
{
code: "var { x: a} = {};",
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }
+ tooShortError
]
},
{
code: "var { a: [x]} = {};",
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Identifier name 'a' is too short (< 2).", type: "Identifier" }
+ tooShortError
]
},
{
code: "import x from 'y';",
parserOptions: { sourceType: "module" },
errors: [
- { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }
+ tooShortError
]
},
{
code: "export var x = 0;",
parserOptions: { sourceType: "module" },
errors: [
- { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }
+ tooShortError
]
},
{
code: "({ a: obj.x.y.z } = {});",
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Identifier name 'a' is too short (< 2).", type: "Identifier" },
- { message: "Identifier name 'z' is too short (< 2).", type: "Identifier" }
+ tooShortError,
+ tooShortError
]
},
{
code: "({ prop: obj.x } = {});",
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }
+ tooShortError
]
},
- { code: "var x = 1;", options: [{ properties: "never" }], errors: [{ message: "Identifier name 'x' is too short (< 2).", type: "Identifier" }] }
+ { code: "var x = 1;", options: [{ properties: "never" }], errors: [tooShortError] }
]
});
diff --git a/tests/lib/rules/id-match.js b/tests/lib/rules/id-match.js
index c3a12f6afb6..d500155c272 100644
--- a/tests/lib/rules/id-match.js
+++ b/tests/lib/rules/id-match.js
@@ -17,6 +17,7 @@ const rule = require("../../../lib/rules/id-match"),
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
+const error = { messageId: "notMatch", type: "Identifier" };
ruleTester.run("id-match", rule, {
valid: [
@@ -193,41 +194,24 @@ ruleTester.run("id-match", rule, {
onlyDeclarations: true
}
],
- errors: [
- {
- message: "Identifier '__foo' does not match the pattern '^[a-z]+$'.",
- type: "Identifier"
- }
- ]
+ errors: [error]
},
{
code: "first_name = \"Matthieu\"",
options: ["^[a-z]+$"],
- errors: [
- {
- message: "Identifier 'first_name' does not match the pattern '^[a-z]+$'.",
- type: "Identifier"
- }
- ]
+ errors: [error]
},
{
code: "first_name = \"Matthieu\"",
options: ["^z"],
errors: [
- {
- message: "Identifier 'first_name' does not match the pattern '^z'.",
- type: "Identifier"
- }
+ error
]
},
{
code: "Last_Name = \"Larcher\"",
options: ["^[a-z]+(_[A-Z][a-z])*$"],
- errors: [
- {
- message: "Identifier 'Last_Name' does not match the pattern '^[a-z]+(_[A-Z][a-z])*$'.",
- type: "Identifier"
- }
+ errors: [error
]
},
{
@@ -245,11 +229,7 @@ ruleTester.run("id-match", rule, {
{
code: "function no_under21(){}",
options: ["^[^_]+$"],
- errors: [
- {
- message: "Identifier 'no_under21' does not match the pattern '^[^_]+$'.",
- type: "Identifier"
- }
+ errors: [error
]
},
{
@@ -257,11 +237,7 @@ ruleTester.run("id-match", rule, {
options: ["^[^_]+$", {
properties: true
}],
- errors: [
- {
- message: "Identifier 'no_under22' does not match the pattern '^[^_]+$'.",
- type: "Identifier"
- }
+ errors: [error
]
},
{
@@ -269,11 +245,7 @@ ruleTester.run("id-match", rule, {
options: ["^[^_]+$", {
properties: true
}],
- errors: [
- {
- message: "Identifier 'no_under23' does not match the pattern '^[^_]+$'.",
- type: "Identifier"
- }
+ errors: [error
]
},
{
@@ -281,11 +253,7 @@ ruleTester.run("id-match", rule, {
options: ["^[^_]+$", {
properties: true
}],
- errors: [
- {
- message: "Identifier 'no_under24' does not match the pattern '^[^_]+$'.",
- type: "Identifier"
- }
+ errors: [error
]
},
{
@@ -293,11 +261,7 @@ ruleTester.run("id-match", rule, {
options: ["^[^_]+$", {
properties: true
}],
- errors: [
- {
- message: "Identifier 'no_under25' does not match the pattern '^[^_]+$'.",
- type: "Identifier"
- }
+ errors: [error
]
},
{
@@ -305,11 +269,7 @@ ruleTester.run("id-match", rule, {
options: ["^[^_]+$", {
properties: true
}],
- errors: [
- {
- message: "Identifier 'no_under26' does not match the pattern '^[^_]+$'.",
- type: "Identifier"
- }
+ errors: [error
]
},
{
@@ -317,11 +277,7 @@ ruleTester.run("id-match", rule, {
options: ["^[^_]+$", {
properties: true
}],
- errors: [
- {
- message: "Identifier 'no_under27' does not match the pattern '^[^_]+$'.",
- type: "Identifier"
- }
+ errors: [error
]
},
{
@@ -329,11 +285,7 @@ ruleTester.run("id-match", rule, {
options: ["^[^_]+$", {
properties: true
}],
- errors: [
- {
- message: "Identifier 'no_under28' does not match the pattern '^[^_]+$'.",
- type: "Identifier"
- }
+ errors: [error
]
},
{
@@ -341,11 +293,7 @@ ruleTester.run("id-match", rule, {
options: ["^[^_]+$", {
properties: true
}],
- errors: [
- {
- message: "Identifier 'no_under29' does not match the pattern '^[^_]+$'.",
- type: "Identifier"
- }
+ errors: [error
]
},
{
@@ -355,8 +303,8 @@ ruleTester.run("id-match", rule, {
}],
errors: [
{
- message: "Identifier 'no_under30' does not match the pattern '^[^_]+$'.",
- type: "Identifier"
+ messageId: "notMatch",
+ data: { name: "no_under30", pattern: "^[^_]+$" }
}
]
},
diff --git a/tests/lib/rules/implicit-arrow-linebreak.js b/tests/lib/rules/implicit-arrow-linebreak.js
index f07182c1b5c..0ed7213dc9c 100644
--- a/tests/lib/rules/implicit-arrow-linebreak.js
+++ b/tests/lib/rules/implicit-arrow-linebreak.js
@@ -11,8 +11,8 @@
const rule = require("../../../lib/rules/implicit-arrow-linebreak");
const RuleTester = require("../../../lib/testers/rule-tester");
-const EXPECTED_LINEBREAK = { message: "Expected a linebreak before this expression." };
-const UNEXPECTED_LINEBREAK = { message: "Expected no linebreak before this expression." };
+const EXPECTED_LINEBREAK = { messageId: "expected" };
+const UNEXPECTED_LINEBREAK = { messageId: "unexpected" };
//------------------------------------------------------------------------------
// Tests
diff --git a/tests/lib/rules/indent-legacy.js b/tests/lib/rules/indent-legacy.js
index 3e3a216849b..1eb506d4188 100644
--- a/tests/lib/rules/indent-legacy.js
+++ b/tests/lib/rules/indent-legacy.js
@@ -40,18 +40,17 @@ function expectedErrors(providedIndentType, providedErrors) {
indentType = providedIndentType;
}
- return errors.map(err => {
- let message;
-
- if (typeof err[1] === "string" && typeof err[2] === "string") {
- message = `Expected indentation of ${err[1]} but found ${err[2]}.`;
- } else {
- const chars = indentType + (err[1] === 1 ? "" : "s");
-
- message = `Expected indentation of ${err[1]} ${chars} but found ${err[2]}.`;
- }
- return { message, type: err[3], line: err[0] };
- });
+ return errors.map(err => ({
+ messageId: "expected",
+ data: {
+ expected: typeof err[1] === "string" && typeof err[2] === "string"
+ ? err[1]
+ : `${err[1]} ${indentType}${err[1] === 1 ? "" : "s"}`,
+ actual: err[2]
+ },
+ type: err[3],
+ line: err[0]
+ }));
}
const ruleTester = new RuleTester();
diff --git a/tests/lib/rules/indent.js b/tests/lib/rules/indent.js
index 2690830b919..7571d3aaf7e 100644
--- a/tests/lib/rules/indent.js
+++ b/tests/lib/rules/indent.js
@@ -41,18 +41,17 @@ function expectedErrors(providedIndentType, providedErrors) {
indentType = providedIndentType;
}
- return errors.map(err => {
- let message;
-
- if (typeof err[1] === "string" && typeof err[2] === "string") {
- message = `Expected indentation of ${err[1]} but found ${err[2]}.`;
- } else {
- const chars = indentType + (err[1] === 1 ? "" : "s");
-
- message = `Expected indentation of ${err[1]} ${chars} but found ${err[2]}.`;
- }
- return { message, type: err[3], line: err[0], endLine: err[0], column: 1, endColumn: parseInt(err[2], 10) + 1 };
- });
+ return errors.map(err => ({
+ messageId: "wrongIndentation",
+ data: {
+ expected: typeof err[1] === "string" && typeof err[2] === "string"
+ ? err[1]
+ : `${err[1]} ${indentType}${err[1] === 1 ? "" : "s"}`,
+ actual: err[2]
+ },
+ type: err[3],
+ line: err[0]
+ }));
}
/**
diff --git a/tests/lib/rules/init-declarations.js b/tests/lib/rules/init-declarations.js
index 01acca476a6..ac0af4a1847 100644
--- a/tests/lib/rules/init-declarations.js
+++ b/tests/lib/rules/init-declarations.js
@@ -110,7 +110,8 @@ ruleTester.run("init-declarations", rule, {
options: ["always"],
errors: [
{
- message: "Variable 'foo' should be initialized on declaration.",
+ messageId: "initialized",
+ data: { idName: "foo" },
type: "VariableDeclarator"
}
]
@@ -120,7 +121,8 @@ ruleTester.run("init-declarations", rule, {
options: ["always"],
errors: [
{
- message: "Variable 'foo' should be initialized on declaration.",
+ messageId: "initialized",
+ data: { idName: "foo" },
type: "VariableDeclarator"
}
]
@@ -131,11 +133,13 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'foo' should be initialized on declaration.",
+ messageId: "initialized",
+ data: { idName: "foo" },
type: "VariableDeclarator"
},
{
- message: "Variable 'baz' should be initialized on declaration.",
+ messageId: "initialized",
+ data: { idName: "baz" },
type: "VariableDeclarator"
}
]
@@ -146,7 +150,8 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'bar' should be initialized on declaration.",
+ messageId: "initialized",
+ data: { idName: "bar" },
type: "VariableDeclarator"
}
]
@@ -157,7 +162,8 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'foo' should be initialized on declaration.",
+ messageId: "initialized",
+ data: { idName: "foo" },
type: "VariableDeclarator"
}
]
@@ -168,7 +174,8 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'a' should be initialized on declaration.",
+ messageId: "initialized",
+ data: { idName: "a" },
type: "VariableDeclarator"
}
]
@@ -179,7 +186,8 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'b' should be initialized on declaration.",
+ messageId: "initialized",
+ data: { idName: "b" },
type: "VariableDeclarator"
}
]
@@ -190,11 +198,13 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'a' should be initialized on declaration.",
+ messageId: "initialized",
+ data: { idName: "a" },
type: "VariableDeclarator"
},
{
- message: "Variable 'c' should be initialized on declaration.",
+ messageId: "initialized",
+ data: { idName: "c" },
type: "VariableDeclarator"
}
]
@@ -205,7 +215,8 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'foo' should not be initialized on declaration.",
+ messageId: "notInitialized",
+ data: { idName: "foo" },
type: "VariableDeclarator"
}
]
@@ -216,7 +227,8 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'foo' should not be initialized on declaration.",
+ messageId: "notInitialized",
+ data: { idName: "foo" },
type: "VariableDeclarator"
}
]
@@ -227,11 +239,13 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'bar' should not be initialized on declaration.",
+ messageId: "notInitialized",
+ data: { idName: "bar" },
type: "VariableDeclarator"
},
{
- message: "Variable 'baz' should not be initialized on declaration.",
+ messageId: "notInitialized",
+ data: { idName: "baz" },
type: "VariableDeclarator"
}
]
@@ -242,7 +256,9 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'bar' should not be initialized on declaration.",
+ messageId: "notInitialized",
+ data: { idName: "bar" },
+
type: "VariableDeclarator"
}
]
@@ -253,7 +269,8 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'a' should not be initialized on declaration.",
+ messageId: "notInitialized",
+ data: { idName: "a" },
type: "VariableDeclarator"
}
]
@@ -264,7 +281,8 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'a' should not be initialized on declaration.",
+ messageId: "notInitialized",
+ data: { idName: "a" },
type: "VariableDeclarator"
}
]
@@ -275,7 +293,8 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'c' should not be initialized on declaration.",
+ messageId: "notInitialized",
+ data: { idName: "c" },
type: "VariableDeclarator"
}
]
@@ -285,7 +304,8 @@ ruleTester.run("init-declarations", rule, {
options: ["never"],
errors: [
{
- message: "Variable 'i' should not be initialized on declaration.",
+ messageId: "notInitialized",
+ data: { idName: "i" },
type: "VariableDeclarator"
}
]
@@ -295,7 +315,8 @@ ruleTester.run("init-declarations", rule, {
options: ["never"],
errors: [
{
- message: "Variable 'foo' should not be initialized on declaration.",
+ messageId: "notInitialized",
+ data: { idName: "foo" },
type: "VariableDeclarator"
}
]
@@ -306,7 +327,8 @@ ruleTester.run("init-declarations", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
{
- message: "Variable 'foo' should not be initialized on declaration.",
+ messageId: "notInitialized",
+ data: { idName: "foo" },
type: "VariableDeclarator"
}
]
diff --git a/tests/lib/rules/jsx-quotes.js b/tests/lib/rules/jsx-quotes.js
index 772f31bd9bf..f537df84c71 100644
--- a/tests/lib/rules/jsx-quotes.js
+++ b/tests/lib/rules/jsx-quotes.js
@@ -12,106 +12,72 @@
const rule = require("../../../lib/rules/jsx-quotes"),
RuleTester = require("../../../lib/testers/rule-tester");
-const ruleTester = new RuleTester();
+const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } } });
ruleTester.run("jsx-quotes", rule, {
valid: [
- {
- code: "",
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
- },
- {
- code: "",
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
- },
+ "",
+ "",
{
code: "",
- options: ["prefer-single"],
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
+ options: ["prefer-single"]
},
{
code: "",
- options: ["prefer-single"],
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
- },
- {
- code: "\"",
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
+ options: ["prefer-single"]
},
+ "\"",
{
code: "'",
- options: ["prefer-single"],
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
- },
- {
- code: "",
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
+ options: ["prefer-single"]
},
+ "",
{
code: "",
- options: ["prefer-single"],
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
- },
- {
- code: "",
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
- },
- {
- code: "",
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
+ options: ["prefer-single"]
},
+ "",
+ "",
{
code: "",
- options: ["prefer-single"],
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
- },
- {
- code: "",
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
+ options: ["prefer-single"]
},
+ "",
{
code: "",
- options: ["prefer-single"],
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
+ options: ["prefer-single"]
},
- {
- code: "",
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }
- }
+ ""
],
invalid: [
{
code: "",
output: "",
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } },
errors: [
- { message: "Unexpected usage of singlequote.", line: 1, column: 10, type: "Literal" }
+ { messageId: "unexpected", data: { description: "singlequote" }, line: 1, column: 10, type: "Literal" }
]
},
{
code: "",
output: "",
options: ["prefer-single"],
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } },
errors: [
- { message: "Unexpected usage of doublequote.", line: 1, column: 10, type: "Literal" }
+ { messageId: "unexpected", data: { description: "doublequote" }, line: 1, column: 10, type: "Literal" }
]
},
{
code: "",
output: "",
options: ["prefer-single"],
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } },
errors: [
- { message: "Unexpected usage of doublequote.", line: 1, column: 10, type: "Literal" }
+ { messageId: "unexpected", data: { description: "doublequote" }, line: 1, column: 10, type: "Literal" }
]
},
{
code: "",
output: "",
- parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } },
errors: [
- { message: "Unexpected usage of singlequote.", line: 1, column: 10, type: "Literal" }
+ { messageId: "unexpected", data: { description: "singlequote" }, line: 1, column: 10, type: "Literal" }
]
}
]
diff --git a/tests/lib/rules/key-spacing.js b/tests/lib/rules/key-spacing.js
index 2ed67e08e9f..61ce37afd5c 100644
--- a/tests/lib/rules/key-spacing.js
+++ b/tests/lib/rules/key-spacing.js
@@ -766,13 +766,13 @@ ruleTester.run("key-spacing", rule, {
beforeColon: false,
afterColon: false
}],
- errors: [{ message: "Extra space before value for key 'key'.", type: "Identifier", line: 1, column: 49 }]
+ errors: [{ messageId: "extraValue", data: { computed: "", key: "key" }, type: "Identifier", line: 1, column: 49 }]
}, {
code: "var obj = { [ (a + b) ]:value };",
output: "var obj = { [ (a + b) ]: value };",
options: [{}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: "Missing space before value for computed key 'a + b'.", type: "Identifier", line: 1, column: 25 }]
+ errors: [{ messageId: "missingValue", data: { computed: "computed ", key: "a + b" }, type: "Identifier", line: 1, column: 25 }]
}, {
code: "fn({ foo:bar, 'key' :value });",
output: "fn({ foo:bar, 'key':value });",
@@ -780,7 +780,7 @@ ruleTester.run("key-spacing", rule, {
beforeColon: false,
afterColon: false
}],
- errors: [{ message: "Extra space after key 'key'.", type: "Literal", line: 1, column: 15 }]
+ errors: [{ messageId: "extraKey", data: { computed: "", key: "key" }, type: "Literal", line: 1, column: 15 }]
}, {
code: "var obj = {prop :(42)};",
output: "var obj = {prop : (42)};",
@@ -788,7 +788,7 @@ ruleTester.run("key-spacing", rule, {
beforeColon: true,
afterColon: true
}],
- errors: [{ message: "Missing space before value for key 'prop'.", type: "Literal", line: 1, column: 18 }]
+ errors: [{ messageId: "missingValue", data: { computed: "", key: "prop" }, type: "Literal", line: 1, column: 18 }]
}, {
code: "({'a' : foo, b: bar() }).b();",
output: "({'a' : foo, b : bar() }).b();",
@@ -796,7 +796,7 @@ ruleTester.run("key-spacing", rule, {
beforeColon: true,
afterColon: true
}],
- errors: [{ message: "Missing space after key 'b'.", type: "Identifier", line: 1, column: 14 }]
+ errors: [{ messageId: "missingKey", data: { computed: "", key: "b" }, type: "Identifier", line: 1, column: 14 }]
}, {
code: "({'a' :foo(), b: bar() }).b();",
output: "({'a' : foo(), b : bar() }).b();",
@@ -805,10 +805,10 @@ ruleTester.run("key-spacing", rule, {
afterColon: true
}],
errors: [
- { message: "Extra space after key 'a'.", type: "Literal", line: 1, column: 3 },
- { message: "Missing space before value for key 'a'.", type: "CallExpression", line: 1, column: 9 },
- { message: "Missing space after key 'b'.", type: "Identifier", line: 1, column: 16 },
- { message: "Extra space before value for key 'b'.", type: "CallExpression", line: 1, column: 20 }
+ { messageId: "extraKey", data: { computed: "", key: "a" }, type: "Literal", line: 1, column: 3 },
+ { messageId: "missingValue", data: { computed: "", key: "a" }, type: "CallExpression", line: 1, column: 9 },
+ { messageId: "missingKey", data: { computed: "", key: "b" }, type: "Identifier", line: 1, column: 16 },
+ { messageId: "extraValue", data: { computed: "", key: "b" }, type: "CallExpression", line: 1, column: 20 }
]
}, {
code: "bar = { key:value };",
@@ -817,7 +817,7 @@ ruleTester.run("key-spacing", rule, {
beforeColon: false,
afterColon: true
}],
- errors: [{ message: "Missing space before value for key 'key'.", type: "Identifier", line: 1, column: 13 }]
+ errors: [{ messageId: "missingValue", data: { computed: "", key: "key" }, type: "Identifier", line: 1, column: 13 }]
}, {
code: [
"obj = {",
@@ -837,9 +837,9 @@ ruleTester.run("key-spacing", rule, {
align: "colon"
}],
errors: [
- { message: "Missing space after key 'key'.", type: "Identifier", line: 2, column: 5 },
- { message: "Extra space before value for key 'key'.", type: "Identifier", line: 2, column: 12 },
- { message: "Missing space before value for key 'foobar'.", type: "CallExpression", line: 3, column: 12 }
+ { messageId: "missingKey", data: { computed: "", key: "key" }, type: "Identifier", line: 2, column: 5 },
+ { messageId: "extraValue", data: { computed: "", key: "key" }, type: "Identifier", line: 2, column: 12 },
+ { messageId: "missingValue", data: { computed: "", key: "foobar" }, type: "CallExpression", line: 3, column: 12 }
]
}, {
code: [
@@ -864,9 +864,9 @@ ruleTester.run("key-spacing", rule, {
afterColon: false
}],
errors: [
- { message: "Extra space before value for key 'a'.", type: "Identifier", line: 2, column: 11 },
- { message: "Missing space after key 'foo'.", type: "Identifier", line: 3, column: 5 },
- { message: "Extra space after key 'b'.", type: "Identifier", line: 4, column: 5 }
+ { messageId: "extraValue", data: { computed: "", key: "a" }, type: "Identifier", line: 2, column: 11 },
+ { messageId: "missingKey", data: { computed: "", key: "foo" }, type: "Identifier", line: 3, column: 5 },
+ { messageId: "extraKey", data: { computed: "", key: "b" }, type: "Identifier", line: 4, column: 5 }
]
}, {
code: [
@@ -892,10 +892,10 @@ ruleTester.run("key-spacing", rule, {
}],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Extra space before value for key 'a'.", type: "CallExpression", line: 2, column: 11 },
- { message: "Extra space after key 'b'.", type: "Literal", line: 3, column: 5 },
- { message: "Missing space before value for key 'foo'.", type: "Identifier", line: 4, column: 9 },
- { message: "Extra space after computed key 'a'.", type: "Identifier", line: 6, column: 7 }
+ { messageId: "extraValue", data: { computed: "", key: "a" }, type: "CallExpression", line: 2, column: 11 },
+ { messageId: "extraKey", data: { computed: "", key: "b" }, type: "Literal", line: 3, column: 5 },
+ { messageId: "missingValue", data: { computed: "", key: "foo" }, type: "Identifier", line: 4, column: 9 },
+ { messageId: "extraKey", data: { computed: "computed ", key: "a" }, type: "Identifier", line: 6, column: 7 }
]
}, {
code: [
@@ -920,8 +920,8 @@ ruleTester.run("key-spacing", rule, {
afterColon: false
}],
errors: [
- { message: "Missing space after key 'a'.", type: "Identifier", line: 2, column: 5 },
- { message: "Extra space before value for key 'bar'.", type: "CallExpression", line: 5, column: 11 }
+ { messageId: "missingKey", data: { computed: "", key: "a" }, type: "Identifier", line: 2, column: 5 },
+ { messageId: "extraValue", data: { computed: "", key: "bar" }, type: "CallExpression", line: 5, column: 11 }
]
}, {
code: [
@@ -946,9 +946,9 @@ ruleTester.run("key-spacing", rule, {
align: "colon"
}],
errors: [
- { message: "Missing space after key 'a'.", type: "Identifier", line: 2, column: 5 },
- { message: "Missing space after key 'e'.", type: "Identifier", line: 5, column: 5 },
- { message: "Missing space before value for key 'fg'.", type: "Literal", line: 6, column: 8 }
+ { messageId: "missingKey", data: { computed: "", key: "a" }, type: "Identifier", line: 2, column: 5 },
+ { messageId: "missingKey", data: { computed: "", key: "e" }, type: "Identifier", line: 5, column: 5 },
+ { messageId: "missingValue", data: { computed: "", key: "fg" }, type: "Literal", line: 6, column: 8 }
]
}, {
code: [
@@ -970,8 +970,8 @@ ruleTester.run("key-spacing", rule, {
afterColon: false
}],
errors: [
- { message: "Extra space before value for key 'key'.", type: "Identifier", line: 3, column: 9 },
- { message: "Extra space after key 'key2'.", type: "Identifier", line: 4, column: 5 }
+ { messageId: "extraValue", data: { computed: "", key: "key" }, type: "Identifier", line: 3, column: 9 },
+ { messageId: "extraKey", data: { computed: "", key: "key2" }, type: "Identifier", line: 4, column: 5 }
]
}, {
code: [
@@ -998,27 +998,27 @@ ruleTester.run("key-spacing", rule, {
align: "value"
}],
errors: [
- { message: "Missing space before value for key 'key1'.", type: "Literal" },
- { message: "Missing space before value for key 'key12'.", type: "Literal" }
+ { messageId: "missingValue", data: { computed: "", key: "key1" }, type: "Literal" },
+ { messageId: "missingValue", data: { computed: "", key: "key12" }, type: "Literal" }
]
}, {
code: "foo = { key:(1+2) };",
output: "foo = { key: (1+2) };",
errors: [
- { message: "Missing space before value for key 'key'.", line: 1, column: 13, type: "BinaryExpression" }
+ { messageId: "missingValue", data: { computed: "", key: "key" }, line: 1, column: 13, type: "BinaryExpression" }
]
}, {
code: "foo = { key:( ( (1+2) ) ) };",
output: "foo = { key: ( ( (1+2) ) ) };",
errors: [
- { message: "Missing space before value for key 'key'.", line: 1, column: 13, type: "BinaryExpression" }
+ { messageId: "missingValue", data: { computed: "", key: "key" }, line: 1, column: 13, type: "BinaryExpression" }
]
}, {
code: "var obj = {a : 'foo', bar: 'bam'};",
output: "var obj = {a: 'foo', bar: 'bam'};",
options: [{ align: "colon" }],
errors: [
- { message: "Extra space after key 'a'.", line: 1, column: 12, type: "Identifier" }
+ { messageId: "extraKey", data: { computed: "", key: "a" }, line: 1, column: 12, type: "Identifier" }
]
}, {
code: [
@@ -1035,7 +1035,7 @@ ruleTester.run("key-spacing", rule, {
].join("\n"),
options: [{ align: "colon" }],
errors: [
- { message: "Extra space after key 'b'.", line: 3, column: 5, type: "Identifier" }
+ { messageId: "extraKey", data: { computed: "", key: "b" }, line: 3, column: 5, type: "Identifier" }
]
}, {
code: [
@@ -1052,7 +1052,7 @@ ruleTester.run("key-spacing", rule, {
].join("\n"),
options: [{ align: "colon", beforeColon: true }],
errors: [
- { message: "Missing space after key 'b'.", line: 3, column: 11, type: "Identifier" }
+ { messageId: "missingKey", data: { computed: "", key: "b" }, line: 3, column: 11, type: "Identifier" }
]
}, {
code: [
@@ -1068,7 +1068,7 @@ ruleTester.run("key-spacing", rule, {
afterColon: true
}],
errors: [
- { message: "Extra space before value for key 'key'.", line: 2, column: 8, type: "Identifier" }
+ { messageId: "extraValue", data: { computed: "", key: "key" }, line: 2, column: 8, type: "Identifier" }
]
}, {
code: [
@@ -1088,7 +1088,7 @@ ruleTester.run("key-spacing", rule, {
options: [{ align: "value" }],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Missing space before value for key 'baz'.", line: 4, column: 10, type: "Literal" }
+ { messageId: "missingValue", data: { computed: "", key: "baz" }, line: 4, column: 10, type: "Literal" }
]
}, {
code: [
@@ -1108,7 +1108,7 @@ ruleTester.run("key-spacing", rule, {
options: [{ align: "value" }],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Extra space before value for key 'foobar'.", line: 2, column: 14, type: "Literal" }
+ { messageId: "extraValue", data: { computed: "", key: "foobar" }, line: 2, column: 14, type: "Literal" }
]
}, {
code: [
@@ -1128,7 +1128,7 @@ ruleTester.run("key-spacing", rule, {
options: [{ align: "value" }],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Missing space before value for key 'baz'.", line: 4, column: 10, type: "Literal" }
+ { messageId: "missingValue", data: { computed: "", key: "baz" }, line: 4, column: 10, type: "Literal" }
]
}, {
code: [
@@ -1148,7 +1148,7 @@ ruleTester.run("key-spacing", rule, {
options: [{ align: "value" }],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Extra space before value for key 'foobar'.", line: 2, column: 14, type: "Literal" }
+ { messageId: "extraValue", data: { computed: "", key: "foobar" }, line: 2, column: 14, type: "Literal" }
]
}, {
code: [
@@ -1172,7 +1172,7 @@ ruleTester.run("key-spacing", rule, {
options: [{ align: "value" }],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Extra space before value for key 'baz'.", line: 6, column: 13, type: "Literal" }
+ { messageId: "extraValue", data: { computed: "", key: "baz" }, line: 6, column: 13, type: "Literal" }
]
}, {
code: [
@@ -1189,7 +1189,7 @@ ruleTester.run("key-spacing", rule, {
].join("\n"),
options: [{ align: "colon" }],
errors: [
- { message: "Missing space after key 'foo'.", line: 2, column: 5, type: "Identifier" }
+ { messageId: "missingKey", data: { computed: "", key: "foo" }, line: 2, column: 5, type: "Identifier" }
]
}, {
code: [
@@ -1206,7 +1206,7 @@ ruleTester.run("key-spacing", rule, {
].join("\n"),
options: [{ align: "colon" }],
errors: [
- { message: "Extra space before value for key 'cats'.", line: 3, column: 12, type: "Identifier" }
+ { messageId: "extraValue", data: { computed: "", key: "cats" }, line: 3, column: 12, type: "Identifier" }
]
}, {
code: [
@@ -1221,7 +1221,7 @@ ruleTester.run("key-spacing", rule, {
].join("\n"),
options: [{ align: "colon" }],
errors: [
- { message: "Missing space after key 'foo'.", line: 1, column: 13, type: "Identifier" }
+ { messageId: "missingKey", data: { computed: "", key: "foo" }, line: 1, column: 13, type: "Identifier" }
]
}, {
code: [
@@ -1236,7 +1236,7 @@ ruleTester.run("key-spacing", rule, {
].join("\n"),
options: [{ align: "colon" }],
errors: [
- { message: "Extra space after key 'foo'.", line: 1, column: 13, type: "Identifier" }
+ { messageId: "extraKey", data: { computed: "", key: "foo" }, line: 1, column: 13, type: "Identifier" }
]
}, {
code: [
@@ -1251,7 +1251,7 @@ ruleTester.run("key-spacing", rule, {
].join("\n"),
options: [{ align: "colon" }],
errors: [
- { message: "Missing space before value for key 'foo'.", line: 1, column: 18, type: "Identifier" }
+ { messageId: "missingValue", data: { computed: "", key: "foo" }, line: 1, column: 18, type: "Identifier" }
]
}, {
code: [
@@ -1266,7 +1266,7 @@ ruleTester.run("key-spacing", rule, {
].join("\n"),
options: [{ align: "colon" }],
errors: [
- { message: "Extra space before value for key 'foo'.", line: 1, column: 20, type: "Identifier" }
+ { messageId: "extraValue", data: { computed: "", key: "foo" }, line: 1, column: 20, type: "Identifier" }
]
}, {
code: [
@@ -1281,7 +1281,7 @@ ruleTester.run("key-spacing", rule, {
].join("\n"),
options: [{ align: "colon" }],
errors: [
- { message: "Extra space before value for key 'cats'.", line: 2, column: 20, type: "Identifier" }
+ { messageId: "extraValue", data: { computed: "", key: "cats" }, line: 2, column: 20, type: "Identifier" }
]
},
@@ -1320,8 +1320,8 @@ ruleTester.run("key-spacing", rule, {
options: [{ align: "colon" }],
parserOptions: { ecmaVersion: 2018 },
errors: [
- { message: "Missing space after key 'a'.", line: 3, column: 5, type: "Identifier" },
- { message: "Extra space after key 'f'.", line: 12, column: 5, type: "Identifier" }
+ { messageId: "missingKey", data: { computed: "", key: "a" }, line: 3, column: 5, type: "Identifier" },
+ { messageId: "extraKey", data: { computed: "", key: "f" }, line: 12, column: 5, type: "Identifier" }
]
},
@@ -1343,7 +1343,7 @@ ruleTester.run("key-spacing", rule, {
align: "colon"
}],
errors: [
- { message: "Extra space after key 'a'.", line: 2, column: 5, type: "Identifier" }
+ { messageId: "extraKey", data: { computed: "", key: "a" }, line: 2, column: 5, type: "Identifier" }
]
}, {
code: [
@@ -1362,7 +1362,7 @@ ruleTester.run("key-spacing", rule, {
align: "value"
}],
errors: [
- { message: "Extra space after key 'c'.", line: 3, column: 5, type: "Identifier" }
+ { messageId: "extraKey", data: { computed: "", key: "c" }, line: 3, column: 5, type: "Identifier" }
]
}, {
code: [
@@ -1385,7 +1385,7 @@ ruleTester.run("key-spacing", rule, {
align: "colon"
}],
errors: [
- { message: "Missing space after key 'a'.", line: 2, column: 5, type: "Identifier" }
+ { messageId: "missingKey", data: { computed: "", key: "a" }, line: 2, column: 5, type: "Identifier" }
]
}, {
code: [
@@ -1419,7 +1419,7 @@ ruleTester.run("key-spacing", rule, {
}
}],
errors: [
- { message: "Extra space before value for key 'a1'.", line: 6, column: 17, type: "Literal" }
+ { messageId: "extraValue", data: { computed: "", key: "a1" }, line: 6, column: 17, type: "Literal" }
]
}, {
code: [
@@ -1452,7 +1452,7 @@ ruleTester.run("key-spacing", rule, {
}
}],
errors: [
- { message: "Missing space after key 'a2'.", line: 6, column: 11, type: "Identifier" }
+ { messageId: "missingKey", data: { computed: "", key: "a2" }, line: 6, column: 11, type: "Identifier" }
]
}, {
code: [
@@ -1476,7 +1476,7 @@ ruleTester.run("key-spacing", rule, {
mode: "minimum"
}],
errors: [
- { message: "Missing space before value for key 'ex'.", line: 4, column: 7, type: "Identifier" }
+ { messageId: "missingValue", data: { computed: "", key: "ex" }, line: 4, column: 7, type: "Identifier" }
]
}, {
code: [
@@ -1500,7 +1500,7 @@ ruleTester.run("key-spacing", rule, {
mode: "minimum"
}],
errors: [
- { message: "Extra space after key 'ex'.", line: 4, column: 4, type: "Identifier" }
+ { messageId: "extraKey", data: { computed: "", key: "ex" }, line: 4, column: 4, type: "Identifier" }
]
}, {
code: [
@@ -1526,8 +1526,8 @@ ruleTester.run("key-spacing", rule, {
}
}],
errors: [
- { message: "Missing space after key 'aInv'.", line: 2, column: 5, type: "Identifier" },
- { message: "Missing space before value for key 'aInv'.", line: 2, column: 11, type: "Literal" }
+ { messageId: "missingKey", data: { computed: "", key: "aInv" }, line: 2, column: 5, type: "Identifier" },
+ { messageId: "missingValue", data: { computed: "", key: "aInv" }, line: 2, column: 11, type: "Literal" }
]
},
@@ -1538,8 +1538,8 @@ ruleTester.run("key-spacing", rule, {
options: [{ align: "colon" }],
parserOptions: { ecmaVersion: 2018 },
errors: [
- { message: "Missing space before value for key 'a'.", line: 1, column: 6, type: "Identifier" },
- { message: "Extra space after key 'c'.", line: 1, column: 20, type: "Identifier" }
+ { messageId: "missingValue", data: { computed: "", key: "a" }, line: 1, column: 6, type: "Identifier" },
+ { messageId: "extraKey", data: { computed: "", key: "c" }, line: 1, column: 20, type: "Identifier" }
]
},
@@ -1569,10 +1569,10 @@ ruleTester.run("key-spacing", rule, {
}],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Missing space after key 'longName'.", line: 2, column: 5, type: "Identifier" },
- { message: "Missing space before value for key 'longName'.", line: 2, column: 14, type: "Literal" },
- { message: "Missing space before value for key 'small'.", line: 3, column: 15, type: "Literal" },
- { message: "Missing space after key 'xs'.", line: 4, column: 5, type: "Identifier" }
+ { messageId: "missingKey", data: { computed: "", key: "longName" }, line: 2, column: 5, type: "Identifier" },
+ { messageId: "missingValue", data: { computed: "", key: "longName" }, line: 2, column: 14, type: "Literal" },
+ { messageId: "missingValue", data: { computed: "", key: "small" }, line: 3, column: 15, type: "Literal" },
+ { messageId: "missingKey", data: { computed: "", key: "xs" }, line: 4, column: 5, type: "Identifier" }
]
}, {
code: [
@@ -1617,11 +1617,11 @@ ruleTester.run("key-spacing", rule, {
}],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Missing space before value for key 'func'.", line: 2, column: 10, type: "FunctionExpression" },
- { message: "Missing space after key 'longName'.", line: 5, column: 5, type: "Identifier" },
- { message: "Missing space after key 'small'.", line: 6, column: 5, type: "Identifier" },
- { message: "Extra space after key 'xs'.", line: 7, column: 5, type: "Identifier" },
- { message: "Extra space after key 'singleLine'.", line: 11, column: 5, type: "Identifier" }
+ { messageId: "missingValue", data: { computed: "", key: "func" }, line: 2, column: 10, type: "FunctionExpression" },
+ { messageId: "missingKey", data: { computed: "", key: "longName" }, line: 5, column: 5, type: "Identifier" },
+ { messageId: "missingKey", data: { computed: "", key: "small" }, line: 6, column: 5, type: "Identifier" },
+ { messageId: "extraKey", data: { computed: "", key: "xs" }, line: 7, column: 5, type: "Identifier" },
+ { messageId: "extraKey", data: { computed: "", key: "singleLine" }, line: 11, column: 5, type: "Identifier" }
]
}, {
code: [
@@ -1666,12 +1666,12 @@ ruleTester.run("key-spacing", rule, {
}],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Missing space before value for key 'func'.", line: 2, column: 10, type: "FunctionExpression" },
- { message: "Missing space after key 'small'.", line: 6, column: 5, type: "Identifier" },
- { message: "Extra space after key 'xs'.", line: 7, column: 5, type: "Identifier" },
- { message: "Extra space before value for key 'xs'.", line: 7, column: 21, type: "Literal" },
- { message: "Extra space before value for key 'func2'.", line: 8, column: 16, type: "FunctionExpression" },
- { message: "Extra space after key 'singleLine'.", line: 11, column: 5, type: "Identifier" }
+ { messageId: "missingValue", data: { computed: "", key: "func" }, line: 2, column: 10, type: "FunctionExpression" },
+ { messageId: "missingKey", data: { computed: "", key: "small" }, line: 6, column: 5, type: "Identifier" },
+ { messageId: "extraKey", data: { computed: "", key: "xs" }, line: 7, column: 5, type: "Identifier" },
+ { messageId: "extraValue", data: { computed: "", key: "xs" }, line: 7, column: 21, type: "Literal" },
+ { messageId: "extraValue", data: { computed: "", key: "func2" }, line: 8, column: 16, type: "FunctionExpression" },
+ { messageId: "extraKey", data: { computed: "", key: "singleLine" }, line: 11, column: 5, type: "Identifier" }
]
}, {
code: [
@@ -1708,8 +1708,8 @@ ruleTester.run("key-spacing", rule, {
}],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Extra space before value for key 'key2'.", line: 4, column: 14, type: "Literal" },
- { message: "Extra space before value for key 'key3'.", line: 5, column: 14, type: "Literal" }
+ { messageId: "extraValue", data: { computed: "", key: "key2" }, line: 4, column: 14, type: "Literal" },
+ { messageId: "extraValue", data: { computed: "", key: "key3" }, line: 5, column: 14, type: "Literal" }
]
}, {
code: [
@@ -1746,28 +1746,28 @@ ruleTester.run("key-spacing", rule, {
}],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Extra space before value for key 'key2'.", line: 4, column: 14, type: "Literal" },
- { message: "Extra space before value for key 'key3'.", line: 5, column: 14, type: "Literal" }
+ { messageId: "extraValue", data: { computed: "", key: "key2" }, line: 4, column: 14, type: "Literal" },
+ { messageId: "extraValue", data: { computed: "", key: "key3" }, line: 5, column: 14, type: "Literal" }
]
}, {
// https://github.com/eslint/eslint/issues/7603
code: "({ foo/* comment */ : bar })",
output: "({ foo/* comment */: bar })",
- errors: [{ message: "Extra space after key 'foo'.", line: 1, column: 7, type: "Identifier" }]
+ errors: [{ messageId: "extraKey", data: { computed: "", key: "foo" }, line: 1, column: 7, type: "Identifier" }]
}, {
code: "({ foo: /* comment */bar })",
output: "({ foo:/* comment */bar })",
options: [{ afterColon: false }],
- errors: [{ message: "Extra space before value for key 'foo'.", line: 1, column: 9, type: "Identifier" }]
+ errors: [{ messageId: "extraValue", data: { computed: "", key: "foo" }, line: 1, column: 9, type: "Identifier" }]
},
{
code: "({ foo/*comment*/:/*comment*/bar })",
output: "({ foo/*comment*/ : /*comment*/bar })",
options: [{ beforeColon: true, afterColon: true }],
errors: [
- { message: "Missing space after key 'foo'.", line: 1, column: 7, type: "Identifier" },
- { message: "Missing space before value for key 'foo'.", line: 1, column: 19, type: "Identifier" }
+ { messageId: "missingKey", data: { computed: "", key: "foo" }, line: 1, column: 7, type: "Identifier" },
+ { messageId: "missingValue", data: { computed: "", key: "foo" }, line: 1, column: 19, type: "Identifier" }
]
}]
});
diff --git a/tests/lib/rules/keyword-spacing.js b/tests/lib/rules/keyword-spacing.js
index cebd163673e..84c5d74a6fe 100644
--- a/tests/lib/rules/keyword-spacing.js
+++ b/tests/lib/rules/keyword-spacing.js
@@ -58,7 +58,7 @@ function override(keyword, value) {
* @returns {string[]} An error message.
*/
function expectedBefore(keyword) {
- return [`Expected space(s) before "${keyword}".`];
+ return [{ messageId: "expectedBefore", data: { value: keyword } }];
}
/**
@@ -68,7 +68,7 @@ function expectedBefore(keyword) {
* @returns {string[]} An error message.
*/
function expectedAfter(keyword) {
- return [`Expected space(s) after "${keyword}".`];
+ return [{ messageId: "expectedAfter", data: { value: keyword } }];
}
/**
@@ -80,8 +80,8 @@ function expectedAfter(keyword) {
*/
function expectedBeforeAndAfter(keyword) {
return [
- `Expected space(s) before "${keyword}".`,
- `Expected space(s) after "${keyword}".`
+ { messageId: "expectedBefore", data: { value: keyword } },
+ { messageId: "expectedAfter", data: { value: keyword } }
];
}
@@ -92,7 +92,7 @@ function expectedBeforeAndAfter(keyword) {
* @returns {string[]} An error message.
*/
function unexpectedBefore(keyword) {
- return [`Unexpected space(s) before "${keyword}".`];
+ return [{ messageId: "unexpectedBefore", data: { value: keyword } }];
}
/**
@@ -102,7 +102,7 @@ function unexpectedBefore(keyword) {
* @returns {string[]} An error message.
*/
function unexpectedAfter(keyword) {
- return [`Unexpected space(s) after "${keyword}".`];
+ return [{ messageId: "unexpectedAfter", data: { value: keyword } }];
}
/**
@@ -114,8 +114,8 @@ function unexpectedAfter(keyword) {
*/
function unexpectedBeforeAndAfter(keyword) {
return [
- `Unexpected space(s) before "${keyword}".`,
- `Unexpected space(s) after "${keyword}".`
+ { messageId: "unexpectedBefore", data: { value: keyword } },
+ { messageId: "unexpectedAfter", data: { value: keyword } }
];
}
diff --git a/tests/lib/rules/line-comment-position.js b/tests/lib/rules/line-comment-position.js
index 546ca1581b3..6dfe4856115 100644
--- a/tests/lib/rules/line-comment-position.js
+++ b/tests/lib/rules/line-comment-position.js
@@ -87,7 +87,7 @@ ruleTester.run("line-comment-position", rule, {
{
code: "1 + 1; // invalid comment",
errors: [{
- message: "Expected comment to be above code.",
+ messageId: "above",
type: "Line",
line: 1,
column: 8
@@ -96,7 +96,7 @@ ruleTester.run("line-comment-position", rule, {
{
code: "1 + 1; // globalization is a word",
errors: [{
- message: "Expected comment to be above code.",
+ messageId: "above",
type: "Line",
line: 1,
column: 8
@@ -106,7 +106,7 @@ ruleTester.run("line-comment-position", rule, {
code: "// jscs: disable\n1 + 1;",
options: [{ position: "beside", applyDefaultIgnorePatterns: false }],
errors: [{
- message: "Expected comment to be beside code.",
+ messageId: "beside",
type: "Line",
line: 1,
column: 1
@@ -116,7 +116,7 @@ ruleTester.run("line-comment-position", rule, {
code: "// jscs: disable\n1 + 1;",
options: [{ position: "beside", applyDefaultPatterns: false }],
errors: [{
- message: "Expected comment to be beside code.",
+ messageId: "beside",
type: "Line",
line: 1,
column: 1
@@ -126,7 +126,7 @@ ruleTester.run("line-comment-position", rule, {
code: "// jscs: disable\n1 + 1;",
options: [{ position: "beside", applyDefaultIgnorePatterns: false, applyDefaultPatterns: true }],
errors: [{
- message: "Expected comment to be beside code.",
+ messageId: "beside",
type: "Line",
line: 1,
column: 1
@@ -135,7 +135,7 @@ ruleTester.run("line-comment-position", rule, {
{
code: "1 + 1; // mentioning falls through",
errors: [{
- message: "Expected comment to be above code.",
+ messageId: "above",
type: "Line",
line: 1,
column: 8
@@ -145,7 +145,7 @@ ruleTester.run("line-comment-position", rule, {
code: "// invalid comment\n1 + 1;",
options: ["beside"],
errors: [{
- message: "Expected comment to be beside code.",
+ messageId: "beside",
type: "Line",
line: 1,
column: 1
@@ -155,7 +155,7 @@ ruleTester.run("line-comment-position", rule, {
code: "// pragma\n// invalid\n1 + 1;",
options: [{ position: "beside", ignorePattern: "pragma" }],
errors: [{
- message: "Expected comment to be beside code.",
+ messageId: "beside",
type: "Line",
line: 2,
column: 1
@@ -165,7 +165,7 @@ ruleTester.run("line-comment-position", rule, {
code: "1 + 1; // linter\n2 + 2; // invalid comment",
options: [{ position: "above", ignorePattern: "linter" }],
errors: [{
- message: "Expected comment to be above code.",
+ messageId: "above",
type: "Line",
line: 2,
column: 8
diff --git a/tests/lib/rules/linebreak-style.js b/tests/lib/rules/linebreak-style.js
index bc92837359e..483ae9c8905 100644
--- a/tests/lib/rules/linebreak-style.js
+++ b/tests/lib/rules/linebreak-style.js
@@ -11,9 +11,6 @@
const rule = require("../../../lib/rules/linebreak-style"),
RuleTester = require("../../../lib/testers/rule-tester");
-const EXPECTED_LF_MSG = "Expected linebreaks to be 'LF' but found 'CRLF'.",
- EXPECTED_CRLF_MSG = "Expected linebreaks to be 'CRLF' but found 'LF'.";
-
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
@@ -49,7 +46,7 @@ ruleTester.run("linebreak-style", rule, {
errors: [{
line: 1,
column: 13,
- message: EXPECTED_LF_MSG
+ messageId: "expectedLF"
}]
},
{
@@ -59,7 +56,7 @@ ruleTester.run("linebreak-style", rule, {
errors: [{
line: 1,
column: 13,
- message: EXPECTED_LF_MSG
+ messageId: "expectedLF"
}]
},
{
@@ -69,7 +66,7 @@ ruleTester.run("linebreak-style", rule, {
errors: [{
line: 1,
column: 13,
- message: EXPECTED_CRLF_MSG
+ messageId: "expectedCRLF"
}]
},
{
@@ -78,12 +75,12 @@ ruleTester.run("linebreak-style", rule, {
errors: [{
line: 4,
column: 24,
- message: EXPECTED_LF_MSG
+ messageId: "expectedLF"
},
{
line: 6,
column: 3,
- message: EXPECTED_LF_MSG
+ messageId: "expectedLF"
}]
},
{
@@ -93,17 +90,17 @@ ruleTester.run("linebreak-style", rule, {
errors: [{
line: 3,
column: 1,
- message: EXPECTED_CRLF_MSG
+ messageId: "expectedCRLF"
},
{
line: 5,
column: 1,
- message: EXPECTED_CRLF_MSG
+ messageId: "expectedCRLF"
},
{
line: 6,
column: 17,
- message: EXPECTED_CRLF_MSG
+ messageId: "expectedCRLF"
}]
}
]
diff --git a/tests/lib/rules/lines-around-comment.js b/tests/lib/rules/lines-around-comment.js
index 07fea8ea8e2..bc16cb9bdf0 100644
--- a/tests/lib/rules/lines-around-comment.js
+++ b/tests/lib/rules/lines-around-comment.js
@@ -11,9 +11,6 @@
const rule = require("../../../lib/rules/lines-around-comment"),
RuleTester = require("../../../lib/testers/rule-tester");
-const afterMessage = "Expected line after comment.",
- beforeMessage = "Expected line before comment.";
-
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
@@ -860,7 +857,7 @@ ruleTester.run("lines-around-comment", rule, {
{
code: "bar()\n/** block block block\n * block \n */\nvar a = 1;",
output: "bar()\n\n/** block block block\n * block \n */\nvar a = 1;",
- errors: [{ message: beforeMessage, type: "Block" }]
+ errors: [{ messageId: "before", type: "Block" }]
},
// line comments
@@ -868,25 +865,25 @@ ruleTester.run("lines-around-comment", rule, {
code: "baz()\n// A line comment with no empty line after\nvar a = 1;",
output: "baz()\n// A line comment with no empty line after\n\nvar a = 1;",
options: [{ afterLineComment: true }],
- errors: [{ message: afterMessage, type: "Line" }]
+ errors: [{ messageId: "after", type: "Line" }]
},
{
code: "baz()\n// A line comment with no empty line after\nvar a = 1;",
output: "baz()\n\n// A line comment with no empty line after\nvar a = 1;",
options: [{ beforeLineComment: true, afterLineComment: false }],
- errors: [{ message: beforeMessage, type: "Line" }]
+ errors: [{ messageId: "before", type: "Line" }]
},
{
code: "// A line comment with no empty line after\nvar a = 1;",
output: "// A line comment with no empty line after\n\nvar a = 1;",
options: [{ beforeLineComment: true, afterLineComment: true }],
- errors: [{ message: afterMessage, type: "Line", line: 1, column: 1 }]
+ errors: [{ messageId: "after", type: "Line", line: 1, column: 1 }]
},
{
code: "baz()\n// A line comment with no empty line after\nvar a = 1;",
output: "baz()\n\n// A line comment with no empty line after\n\nvar a = 1;",
options: [{ beforeLineComment: true, afterLineComment: true }],
- errors: [{ message: beforeMessage, type: "Line", line: 2 }, { message: afterMessage, type: "Line", line: 2 }]
+ errors: [{ messageId: "before", type: "Line", line: 2 }, { messageId: "after", type: "Line", line: 2 }]
},
// block comments
@@ -894,15 +891,15 @@ ruleTester.run("lines-around-comment", rule, {
code: "bar()\n/**\n * block block block\n */\nvar a = 1;",
output: "bar()\n\n/**\n * block block block\n */\n\nvar a = 1;",
options: [{ afterBlockComment: true, beforeBlockComment: true }],
- errors: [{ message: beforeMessage, type: "Block", line: 2 }, { message: afterMessage, type: "Block", line: 2 }]
+ errors: [{ messageId: "before", type: "Block", line: 2 }, { messageId: "after", type: "Block", line: 2 }]
},
{
code: "bar()\n/* first block comment */ /* second block comment */\nvar a = 1;",
output: "bar()\n\n/* first block comment */ /* second block comment */\n\nvar a = 1;",
options: [{ afterBlockComment: true, beforeBlockComment: true }],
errors: [
- { message: beforeMessage, type: "Block", line: 2 },
- { message: afterMessage, type: "Block", line: 2 }
+ { messageId: "before", type: "Block", line: 2 },
+ { messageId: "after", type: "Block", line: 2 }
]
},
{
@@ -910,21 +907,21 @@ ruleTester.run("lines-around-comment", rule, {
output: "bar()\n\n/* first block comment */ /* second block\n comment */\n\nvar a = 1;",
options: [{ afterBlockComment: true, beforeBlockComment: true }],
errors: [
- { message: beforeMessage, type: "Block", line: 2 },
- { message: afterMessage, type: "Block", line: 2 }
+ { messageId: "before", type: "Block", line: 2 },
+ { messageId: "after", type: "Block", line: 2 }
]
},
{
code: "bar()\n/**\n * block block block\n */\nvar a = 1;",
output: "bar()\n/**\n * block block block\n */\n\nvar a = 1;",
options: [{ afterBlockComment: true, beforeBlockComment: false }],
- errors: [{ message: afterMessage, type: "Block", line: 2 }]
+ errors: [{ messageId: "after", type: "Block", line: 2 }]
},
{
code: "bar()\n/**\n * block block block\n */\nvar a = 1;",
output: "bar()\n\n/**\n * block block block\n */\nvar a = 1;",
options: [{ afterBlockComment: false, beforeBlockComment: true }],
- errors: [{ message: beforeMessage, type: "Block", line: 2 }]
+ errors: [{ messageId: "before", type: "Block", line: 2 }]
},
{
code: "var a,\n// line\nb;",
@@ -933,7 +930,7 @@ ruleTester.run("lines-around-comment", rule, {
beforeLineComment: true,
allowBlockStart: true
}],
- errors: [{ message: beforeMessage, type: "Line", line: 2 }]
+ errors: [{ messageId: "before", type: "Line", line: 2 }]
},
{
code: "function foo(){\nvar a = 1;\n// line at block start\nvar g = 1;\n}",
@@ -942,7 +939,7 @@ ruleTester.run("lines-around-comment", rule, {
beforeLineComment: true,
allowBlockStart: true
}],
- errors: [{ message: beforeMessage, type: "Line", line: 3 }]
+ errors: [{ messageId: "before", type: "Line", line: 3 }]
},
{
code: "var a,\n// line\nb;",
@@ -951,7 +948,7 @@ ruleTester.run("lines-around-comment", rule, {
afterLineComment: true,
allowBlockEnd: true
}],
- errors: [{ message: afterMessage, type: "Line", line: 2 }]
+ errors: [{ messageId: "after", type: "Line", line: 2 }]
},
{
code: "function foo(){\nvar a = 1;\n\n// line at block start\nvar g = 1;\n}",
@@ -960,7 +957,7 @@ ruleTester.run("lines-around-comment", rule, {
afterLineComment: true,
allowBlockEnd: true
}],
- errors: [{ message: afterMessage, type: "Line", line: 4 }]
+ errors: [{ messageId: "after", type: "Line", line: 4 }]
},
{
code: "switch ('foo'){\ncase 'foo':\n// line at switch case start\nbreak;\n}",
@@ -968,7 +965,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
beforeLineComment: true
}],
- errors: [{ message: beforeMessage, type: "Line", line: 3 }]
+ errors: [{ messageId: "before", type: "Line", line: 3 }]
},
{
code: "switch ('foo'){\ncase 'foo':\nbreak;\n\ndefault:\n// line at switch case start\nbreak;\n}",
@@ -976,7 +973,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
beforeLineComment: true
}],
- errors: [{ message: beforeMessage, type: "Line", line: 6 }]
+ errors: [{ messageId: "before", type: "Line", line: 6 }]
},
{
code: "while(true){\n// line at block start and end\n}",
@@ -985,7 +982,7 @@ ruleTester.run("lines-around-comment", rule, {
afterLineComment: true,
allowBlockStart: true
}],
- errors: [{ message: afterMessage, type: "Line", line: 2 }]
+ errors: [{ messageId: "after", type: "Line", line: 2 }]
},
{
code: "while(true){\n// line at block start and end\n}",
@@ -994,7 +991,7 @@ ruleTester.run("lines-around-comment", rule, {
beforeLineComment: true,
allowBlockEnd: true
}],
- errors: [{ message: beforeMessage, type: "Line", line: 2 }]
+ errors: [{ messageId: "before", type: "Line", line: 2 }]
},
{
code: "class A {\n// line at class start\nconstructor() {}\n}",
@@ -1003,7 +1000,7 @@ ruleTester.run("lines-around-comment", rule, {
beforeLineComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: beforeMessage, type: "Line", line: 2 }]
+ errors: [{ messageId: "before", type: "Line", line: 2 }]
},
{
code: "class A {\n// line at class start\nconstructor() {}\n}",
@@ -1014,7 +1011,7 @@ ruleTester.run("lines-around-comment", rule, {
beforeLineComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: beforeMessage, type: "Line", line: 2 }]
+ errors: [{ messageId: "before", type: "Line", line: 2 }]
},
{
code: "class B {\nconstructor() {}\n\n// line at class end\n}",
@@ -1023,7 +1020,7 @@ ruleTester.run("lines-around-comment", rule, {
afterLineComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: afterMessage, type: "Line", line: 4 }]
+ errors: [{ messageId: "after", type: "Line", line: 4 }]
},
{
code: "class B {\nconstructor() {}\n\n// line at class end\n}",
@@ -1034,7 +1031,7 @@ ruleTester.run("lines-around-comment", rule, {
allowClassEnd: false
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: afterMessage, type: "Line", line: 4 }]
+ errors: [{ messageId: "after", type: "Line", line: 4 }]
},
{
code: "switch ('foo'){\ncase 'foo':\nvar g = 1;\n\n// line at switch case end\n}",
@@ -1042,7 +1039,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
afterLineComment: true
}],
- errors: [{ message: afterMessage, type: "Line", line: 5 }]
+ errors: [{ messageId: "after", type: "Line", line: 5 }]
},
{
code: "switch ('foo'){\ncase 'foo':\nbreak;\n\ndefault:\nvar g = 1;\n\n// line at switch case end\n}",
@@ -1050,7 +1047,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
afterLineComment: true
}],
- errors: [{ message: afterMessage, type: "Line", line: 8 }]
+ errors: [{ messageId: "after", type: "Line", line: 8 }]
},
// object start comments
@@ -1069,7 +1066,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
beforeLineComment: true
}],
- errors: [{ message: beforeMessage, type: "Line", line: 2 }]
+ errors: [{ messageId: "before", type: "Line", line: 2 }]
},
{
code:
@@ -1092,7 +1089,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
beforeLineComment: true
}],
- errors: [{ message: beforeMessage, type: "Line", line: 3 }]
+ errors: [{ messageId: "before", type: "Line", line: 3 }]
},
{
code:
@@ -1109,7 +1106,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
beforeBlockComment: true
}],
- errors: [{ message: beforeMessage, type: "Block", line: 2 }]
+ errors: [{ messageId: "before", type: "Block", line: 2 }]
},
{
code:
@@ -1136,7 +1133,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
beforeLineComment: true
}],
- errors: [{ message: beforeMessage, type: "Block", line: 3 }]
+ errors: [{ messageId: "before", type: "Block", line: 3 }]
},
{
code:
@@ -1154,7 +1151,7 @@ ruleTester.run("lines-around-comment", rule, {
beforeLineComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: beforeMessage, type: "Line", line: 2 }]
+ errors: [{ messageId: "before", type: "Line", line: 2 }]
},
{
code:
@@ -1172,7 +1169,7 @@ ruleTester.run("lines-around-comment", rule, {
beforeLineComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: beforeMessage, type: "Line", line: 2 }]
+ errors: [{ messageId: "before", type: "Line", line: 2 }]
},
{
code:
@@ -1190,7 +1187,7 @@ ruleTester.run("lines-around-comment", rule, {
beforeBlockComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: beforeMessage, type: "Block", line: 2 }]
+ errors: [{ messageId: "before", type: "Block", line: 2 }]
},
{
code:
@@ -1208,7 +1205,7 @@ ruleTester.run("lines-around-comment", rule, {
beforeBlockComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: beforeMessage, type: "Block", line: 2 }]
+ errors: [{ messageId: "before", type: "Block", line: 2 }]
},
// object end comments
@@ -1227,7 +1224,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
afterLineComment: true
}],
- errors: [{ message: afterMessage, type: "Line", line: 3 }]
+ errors: [{ messageId: "after", type: "Line", line: 3 }]
},
{
code:
@@ -1250,7 +1247,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
afterLineComment: true
}],
- errors: [{ message: afterMessage, type: "Line", line: 5 }]
+ errors: [{ messageId: "after", type: "Line", line: 5 }]
},
{
code:
@@ -1269,7 +1266,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
afterBlockComment: true
}],
- errors: [{ message: afterMessage, type: "Block", line: 4 }]
+ errors: [{ messageId: "after", type: "Block", line: 4 }]
},
{
code:
@@ -1298,7 +1295,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
afterBlockComment: true
}],
- errors: [{ message: afterMessage, type: "Block", line: 6 }]
+ errors: [{ messageId: "after", type: "Block", line: 6 }]
},
{
code:
@@ -1316,7 +1313,7 @@ ruleTester.run("lines-around-comment", rule, {
afterLineComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: afterMessage, type: "Line", line: 3 }]
+ errors: [{ messageId: "after", type: "Line", line: 3 }]
},
{
code:
@@ -1334,7 +1331,7 @@ ruleTester.run("lines-around-comment", rule, {
afterLineComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: afterMessage, type: "Line", line: 3 }]
+ errors: [{ messageId: "after", type: "Line", line: 3 }]
},
{
code:
@@ -1354,7 +1351,7 @@ ruleTester.run("lines-around-comment", rule, {
afterBlockComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: afterMessage, type: "Block", line: 4 }]
+ errors: [{ messageId: "after", type: "Block", line: 4 }]
},
{
code:
@@ -1374,7 +1371,7 @@ ruleTester.run("lines-around-comment", rule, {
afterBlockComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: afterMessage, type: "Block", line: 4 }]
+ errors: [{ messageId: "after", type: "Block", line: 4 }]
},
// array start comments
@@ -1393,7 +1390,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
beforeLineComment: true
}],
- errors: [{ message: beforeMessage, type: "Line", line: 2 }]
+ errors: [{ messageId: "before", type: "Line", line: 2 }]
},
{
code:
@@ -1410,7 +1407,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
beforeBlockComment: true
}],
- errors: [{ message: beforeMessage, type: "Block", line: 2 }]
+ errors: [{ messageId: "before", type: "Block", line: 2 }]
},
{
code:
@@ -1428,7 +1425,7 @@ ruleTester.run("lines-around-comment", rule, {
beforeLineComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: beforeMessage, type: "Line", line: 2 }]
+ errors: [{ messageId: "before", type: "Line", line: 2 }]
},
{
code:
@@ -1446,7 +1443,7 @@ ruleTester.run("lines-around-comment", rule, {
beforeBlockComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: beforeMessage, type: "Block", line: 2 }]
+ errors: [{ messageId: "before", type: "Block", line: 2 }]
},
// array end comments
@@ -1465,7 +1462,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
afterLineComment: true
}],
- errors: [{ message: afterMessage, type: "Line", line: 3 }]
+ errors: [{ messageId: "after", type: "Line", line: 3 }]
},
{
code:
@@ -1484,7 +1481,7 @@ ruleTester.run("lines-around-comment", rule, {
options: [{
afterBlockComment: true
}],
- errors: [{ message: afterMessage, type: "Block", line: 4 }]
+ errors: [{ messageId: "after", type: "Block", line: 4 }]
},
{
code:
@@ -1502,7 +1499,7 @@ ruleTester.run("lines-around-comment", rule, {
afterLineComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: afterMessage, type: "Line", line: 3 }]
+ errors: [{ messageId: "after", type: "Line", line: 3 }]
},
{
code:
@@ -1522,7 +1519,7 @@ ruleTester.run("lines-around-comment", rule, {
afterBlockComment: true
}],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: afterMessage, type: "Block", line: 4 }]
+ errors: [{ messageId: "after", type: "Block", line: 4 }]
},
// ignorePattern
@@ -1549,69 +1546,69 @@ ruleTester.run("lines-around-comment", rule, {
applyDefaultIgnorePatterns: false
}],
errors: [
- { message: beforeMessage, type: "Block", line: 7 },
- { message: afterMessage, type: "Block", line: 7 }
+ { messageId: "before", type: "Block", line: 7 },
+ { messageId: "after", type: "Block", line: 7 }
]
},
{
code: "foo;\n/* eslint */",
output: "foo;\n\n/* eslint */",
options: [{ applyDefaultIgnorePatterns: false }],
- errors: [{ message: beforeMessage, type: "Block" }]
+ errors: [{ messageId: "before", type: "Block" }]
},
{
code: "foo;\n/* jshint */",
output: "foo;\n\n/* jshint */",
options: [{ applyDefaultIgnorePatterns: false }],
- errors: [{ message: beforeMessage, type: "Block" }]
+ errors: [{ messageId: "before", type: "Block" }]
},
{
code: "foo;\n/* jslint */",
output: "foo;\n\n/* jslint */",
options: [{ applyDefaultIgnorePatterns: false }],
- errors: [{ message: beforeMessage, type: "Block" }]
+ errors: [{ messageId: "before", type: "Block" }]
},
{
code: "foo;\n/* istanbul */",
output: "foo;\n\n/* istanbul */",
options: [{ applyDefaultIgnorePatterns: false }],
- errors: [{ message: beforeMessage, type: "Block" }]
+ errors: [{ messageId: "before", type: "Block" }]
},
{
code: "foo;\n/* global */",
output: "foo;\n\n/* global */",
options: [{ applyDefaultIgnorePatterns: false }],
- errors: [{ message: beforeMessage, type: "Block" }]
+ errors: [{ messageId: "before", type: "Block" }]
},
{
code: "foo;\n/* globals */",
output: "foo;\n\n/* globals */",
options: [{ applyDefaultIgnorePatterns: false }],
- errors: [{ message: beforeMessage, type: "Block" }]
+ errors: [{ messageId: "before", type: "Block" }]
},
{
code: "foo;\n/* exported */",
output: "foo;\n\n/* exported */",
options: [{ applyDefaultIgnorePatterns: false }],
- errors: [{ message: beforeMessage, type: "Block" }]
+ errors: [{ messageId: "before", type: "Block" }]
},
{
code: "foo;\n/* jscs */",
output: "foo;\n\n/* jscs */",
options: [{ applyDefaultIgnorePatterns: false }],
- errors: [{ message: beforeMessage, type: "Block" }]
+ errors: [{ messageId: "before", type: "Block" }]
},
{
code: "foo\n/* something else */",
output: "foo\n\n/* something else */",
options: [{ ignorePattern: "pragma" }],
- errors: [{ message: beforeMessage, type: "Block" }]
+ errors: [{ messageId: "before", type: "Block" }]
},
{
code: "foo\n/* eslint */",
output: "foo\n\n/* eslint */",
options: [{ applyDefaultIgnorePatterns: false }],
- errors: [{ message: beforeMessage, type: "Block" }]
+ errors: [{ messageId: "before", type: "Block" }]
},
// "fallthrough" patterns are not ignored by default
@@ -1619,7 +1616,7 @@ ruleTester.run("lines-around-comment", rule, {
code: "foo;\n/* fallthrough */",
output: "foo;\n\n/* fallthrough */",
options: [],
- errors: [{ message: beforeMessage, type: "Block" }]
+ errors: [{ messageId: "before", type: "Block" }]
}
]
diff --git a/tests/lib/rules/lines-around-directive.js b/tests/lib/rules/lines-around-directive.js
index b3ef8883ae8..4575cfab57e 100644
--- a/tests/lib/rules/lines-around-directive.js
+++ b/tests/lib/rules/lines-around-directive.js
@@ -18,6 +18,12 @@ const RuleTester = require("../../../lib/testers/rule-tester");
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
+const expectedBeforeStrictError = { messageId: "expected", data: { location: "before", value: "use strict" } };
+const expectedAfterStrictError = { messageId: "expected", data: { location: "after", value: "use strict" } };
+const expectedAfterAsmError = { messageId: "expected", data: { location: "after", value: "use asm" } };
+const unexpectedBeforeStrictError = { messageId: "unexpected", data: { location: "before", value: "use strict" } };
+const unexpectedAfterStrictError = { messageId: "unexpected", data: { location: "after", value: "use strict" } };
+const unexpectedAfterAsmError = { messageId: "unexpected", data: { location: "after", value: "use asm" } };
ruleTester.run("lines-around-directive", rule, {
valid: [
@@ -707,19 +713,19 @@ ruleTester.run("lines-around-directive", rule, {
code: "'use strict';\nvar foo;",
output: "'use strict';\n\nvar foo;",
options: ["always"],
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
},
{
code: "'use strict';\n//comment\nvar foo;",
output: "'use strict';\n\n//comment\nvar foo;",
options: ["always"],
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
},
{
code: "'use strict';\n/*\nmultiline comment\n*/\nvar foo;",
output: "'use strict';\n\n/*\nmultiline comment\n*/\nvar foo;",
options: ["always"],
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
},
// multiple directives
@@ -727,19 +733,19 @@ ruleTester.run("lines-around-directive", rule, {
code: "'use strict';\n'use asm';\nvar foo;",
output: "'use strict';\n'use asm';\n\nvar foo;",
options: ["always"],
- errors: ["Expected newline after \"use asm\" directive."]
+ errors: [expectedAfterAsmError]
},
{
code: "'use strict';\n'use asm';\n//comment\nvar foo;",
output: "'use strict';\n'use asm';\n\n//comment\nvar foo;",
options: ["always"],
- errors: ["Expected newline after \"use asm\" directive."]
+ errors: [expectedAfterAsmError]
},
{
code: "'use strict';\n'use asm';\n/*\nmultiline comment\n*/\nvar foo;",
output: "'use strict';\n'use asm';\n\n/*\nmultiline comment\n*/\nvar foo;",
options: ["always"],
- errors: ["Expected newline after \"use asm\" directive."]
+ errors: [expectedAfterAsmError]
},
/*
@@ -751,8 +757,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "#!/usr/bin/env node\n\n'use strict';\n\nvar foo;",
options: ["always"],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ expectedAfterStrictError
]
},
{
@@ -760,8 +766,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "#!/usr/bin/env node\n//comment\n\n'use strict';\n\nvar foo;",
options: ["always"],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ expectedAfterStrictError
]
},
{
@@ -769,8 +775,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "//comment\n\n'use strict';\n\nvar foo;",
options: ["always"],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ expectedAfterStrictError
]
},
{
@@ -778,8 +784,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "/*\nmultiline comment\n*/\n\n'use strict';\n\nvar foo;",
options: ["always"],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ expectedAfterStrictError
]
},
@@ -789,8 +795,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "#!/usr/bin/env node\n\n'use strict';\n'use asm';\n\nvar foo;",
options: ["always"],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ expectedAfterAsmError
]
},
{
@@ -798,8 +804,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "#!/usr/bin/env node\n//comment\n\n'use strict';\n'use asm';\n\nvar foo;",
options: ["always"],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ expectedAfterAsmError
]
},
{
@@ -807,8 +813,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "//comment\n\n'use strict';\n'use asm';\n\nvar foo;",
options: ["always"],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ expectedAfterAsmError
]
},
{
@@ -816,8 +822,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\n\nvar foo;",
options: ["always"],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ expectedAfterAsmError
]
},
@@ -829,14 +835,14 @@ ruleTester.run("lines-around-directive", rule, {
code: "function foo() {\n'use strict';\nvar bar;\n}",
output: "function foo() {\n'use strict';\n\nvar bar;\n}",
options: ["always"],
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
},
{
code: "() => {\n'use strict';\nvar foo;\n}",
output: "() => {\n'use strict';\n\nvar foo;\n}",
options: ["always"],
parserOptions: { ecmaVersion: 6 },
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
},
// multiple directives
@@ -844,14 +850,14 @@ ruleTester.run("lines-around-directive", rule, {
code: "function foo() {\n'use strict';\n'use asm';\nvar bar;\n}",
output: "function foo() {\n'use strict';\n'use asm';\n\nvar bar;\n}",
options: ["always"],
- errors: ["Expected newline after \"use asm\" directive."]
+ errors: [expectedAfterAsmError]
},
{
code: "() => {\n'use strict';\n'use asm';\nvar foo;\n}",
output: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}",
options: ["always"],
parserOptions: { ecmaVersion: 6 },
- errors: ["Expected newline after \"use asm\" directive."]
+ errors: [expectedAfterAsmError]
},
/*
@@ -863,8 +869,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n//comment\n\n'use strict';\n\nvar bar;\n}",
options: ["always"],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ expectedAfterStrictError
]
},
{
@@ -872,8 +878,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n/*\nmultiline comment\n*/\n\n'use strict';\n\nvar bar;\n}",
options: ["always"],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ expectedAfterStrictError
]
},
{
@@ -882,8 +888,8 @@ ruleTester.run("lines-around-directive", rule, {
options: ["always"],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ expectedAfterStrictError
]
},
{
@@ -892,8 +898,8 @@ ruleTester.run("lines-around-directive", rule, {
options: ["always"],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ expectedAfterStrictError
]
},
@@ -903,8 +909,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n//comment\n\n'use strict';\n'use asm';\n\nvar bar;\n}",
options: ["always"],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ expectedAfterAsmError
]
},
{
@@ -912,8 +918,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\n\nvar bar;\n}",
options: ["always"],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ expectedAfterAsmError
]
},
{
@@ -922,8 +928,8 @@ ruleTester.run("lines-around-directive", rule, {
options: ["always"],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ expectedAfterAsmError
]
},
{
@@ -932,8 +938,8 @@ ruleTester.run("lines-around-directive", rule, {
options: ["always"],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Expected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ expectedAfterAsmError
]
},
@@ -946,19 +952,19 @@ ruleTester.run("lines-around-directive", rule, {
code: "'use strict';\n\nvar foo;",
output: "'use strict';\nvar foo;",
options: ["never"],
- errors: ["Unexpected newline after \"use strict\" directive."]
+ errors: [unexpectedAfterStrictError]
},
{
code: "'use strict';\n\n//comment\nvar foo;",
output: "'use strict';\n//comment\nvar foo;",
options: ["never"],
- errors: ["Unexpected newline after \"use strict\" directive."]
+ errors: [unexpectedAfterStrictError]
},
{
code: "'use strict';\n\n/*\nmultiline comment\n*/\nvar foo;",
output: "'use strict';\n/*\nmultiline comment\n*/\nvar foo;",
options: ["never"],
- errors: ["Unexpected newline after \"use strict\" directive."]
+ errors: [unexpectedAfterStrictError]
},
// multiple directives
@@ -966,19 +972,19 @@ ruleTester.run("lines-around-directive", rule, {
code: "'use strict';\n'use asm';\n\nvar foo;",
output: "'use strict';\n'use asm';\nvar foo;",
options: ["never"],
- errors: ["Unexpected newline after \"use asm\" directive."]
+ errors: [unexpectedAfterAsmError]
},
{
code: "'use strict';\n'use asm';\n\n//comment\nvar foo;",
output: "'use strict';\n'use asm';\n//comment\nvar foo;",
options: ["never"],
- errors: ["Unexpected newline after \"use asm\" directive."]
+ errors: [unexpectedAfterAsmError]
},
{
code: "'use strict';\n'use asm';\n\n/*\nmultiline comment\n*/\nvar foo;",
output: "'use strict';\n'use asm';\n/*\nmultiline comment\n*/\nvar foo;",
options: ["never"],
- errors: ["Unexpected newline after \"use asm\" directive."]
+ errors: [unexpectedAfterAsmError]
},
/*
@@ -990,8 +996,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "#!/usr/bin/env node\n'use strict';\nvar foo;",
options: ["never"],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
{
@@ -999,8 +1005,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "#!/usr/bin/env node\n//comment\n'use strict';\nvar foo;",
options: ["never"],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
{
@@ -1008,8 +1014,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "//comment\n'use strict';\nvar foo;",
options: ["never"],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
{
@@ -1017,8 +1023,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "/*\nmultiline comment\n*/\n'use strict';\nvar foo;",
options: ["never"],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
@@ -1028,8 +1034,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "#!/usr/bin/env node\n'use strict';\n'use asm';\nvar foo;",
options: ["never"],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
{
@@ -1037,8 +1043,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "#!/usr/bin/env node\n//comment\n'use strict';\n'use asm';\nvar foo;",
options: ["never"],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
{
@@ -1046,8 +1052,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "//comment\n'use strict';\n'use asm';\nvar foo;",
options: ["never"],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
{
@@ -1055,8 +1061,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "/*\nmultiline comment\n*/\n'use strict';\n'use asm';\nvar foo;",
options: ["never"],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
@@ -1068,14 +1074,14 @@ ruleTester.run("lines-around-directive", rule, {
code: "function foo() {\n'use strict';\n\nvar bar;\n}",
output: "function foo() {\n'use strict';\nvar bar;\n}",
options: ["never"],
- errors: ["Unexpected newline after \"use strict\" directive."]
+ errors: [unexpectedAfterStrictError]
},
{
code: "() => {\n'use strict';\n\nvar foo;\n}",
output: "() => {\n'use strict';\nvar foo;\n}",
options: ["never"],
parserOptions: { ecmaVersion: 6 },
- errors: ["Unexpected newline after \"use strict\" directive."]
+ errors: [unexpectedAfterStrictError]
},
// multiple directives
@@ -1083,14 +1089,14 @@ ruleTester.run("lines-around-directive", rule, {
code: "function foo() {\n'use strict';\n'use asm';\n\nvar bar;\n}",
output: "function foo() {\n'use strict';\n'use asm';\nvar bar;\n}",
options: ["never"],
- errors: ["Unexpected newline after \"use asm\" directive."]
+ errors: [unexpectedAfterAsmError]
},
{
code: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}",
output: "() => {\n'use strict';\n'use asm';\nvar foo;\n}",
options: ["never"],
parserOptions: { ecmaVersion: 6 },
- errors: ["Unexpected newline after \"use asm\" directive."]
+ errors: [unexpectedAfterAsmError]
},
/*
@@ -1102,8 +1108,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n//comment\n'use strict';\nvar bar;\n}",
options: ["never"],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
{
@@ -1111,8 +1117,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n/*\nmultiline comment\n*/\n'use strict';\nvar bar;\n}",
options: ["never"],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
{
@@ -1121,8 +1127,8 @@ ruleTester.run("lines-around-directive", rule, {
options: ["never"],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
{
@@ -1131,8 +1137,8 @@ ruleTester.run("lines-around-directive", rule, {
options: ["never"],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
@@ -1142,8 +1148,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n//comment\n'use strict';\n'use asm';\nvar bar;\n}",
options: ["never"],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
{
@@ -1151,8 +1157,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n/*\nmultiline comment\n*/\n'use strict';\n'use asm';\nvar bar;\n}",
options: ["never"],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
{
@@ -1161,8 +1167,8 @@ ruleTester.run("lines-around-directive", rule, {
options: ["never"],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
{
@@ -1171,8 +1177,8 @@ ruleTester.run("lines-around-directive", rule, {
options: ["never"],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
@@ -1186,19 +1192,19 @@ ruleTester.run("lines-around-directive", rule, {
code: "'use strict';\nvar foo;",
output: "'use strict';\n\nvar foo;",
options: [{ before: "never", after: "always" }],
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
},
{
code: "'use strict';\n//comment\nvar foo;",
output: "'use strict';\n\n//comment\nvar foo;",
options: [{ before: "never", after: "always" }],
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
},
{
code: "'use strict';\n/*\nmultiline comment\n*/\nvar foo;",
output: "'use strict';\n\n/*\nmultiline comment\n*/\nvar foo;",
options: [{ before: "never", after: "always" }],
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
},
// multiple directives
@@ -1206,19 +1212,19 @@ ruleTester.run("lines-around-directive", rule, {
code: "'use strict';\n'use asm';\nvar foo;",
output: "'use strict';\n'use asm';\n\nvar foo;",
options: [{ before: "never", after: "always" }],
- errors: ["Expected newline after \"use asm\" directive."]
+ errors: [expectedAfterAsmError]
},
{
code: "'use strict';\n'use asm';\n//comment\nvar foo;",
output: "'use strict';\n'use asm';\n\n//comment\nvar foo;",
options: [{ before: "never", after: "always" }],
- errors: ["Expected newline after \"use asm\" directive."]
+ errors: [expectedAfterAsmError]
},
{
code: "'use strict';\n'use asm';\n/*\nmultiline comment\n*/\nvar foo;",
output: "'use strict';\n'use asm';\n\n/*\nmultiline comment\n*/\nvar foo;",
options: [{ before: "never", after: "always" }],
- errors: ["Expected newline after \"use asm\" directive."]
+ errors: [expectedAfterAsmError]
},
/*
@@ -1230,8 +1236,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "#!/usr/bin/env node\n'use strict';\n\nvar foo;",
options: [{ before: "never", after: "always" }],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterStrictError
]
},
{
@@ -1239,8 +1245,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "//comment\n'use strict';\n\nvar foo;",
options: [{ before: "never", after: "always" }],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterStrictError
]
},
{
@@ -1248,8 +1254,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "/*\nmultiline comment\n*/\n'use strict';\n\nvar foo;",
options: [{ before: "never", after: "always" }],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterStrictError
]
},
@@ -1259,8 +1265,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "#!/usr/bin/env node\n'use strict';\n'use asm';\n\nvar foo;",
options: [{ before: "never", after: "always" }],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterAsmError
]
},
{
@@ -1268,8 +1274,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "//comment\n'use strict';\n'use asm';\n\nvar foo;",
options: [{ before: "never", after: "always" }],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterAsmError
]
},
{
@@ -1277,8 +1283,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "/*\nmultiline comment\n*/\n'use strict';\n'use asm';\n\nvar foo;",
options: [{ before: "never", after: "always" }],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterAsmError
]
},
@@ -1290,27 +1296,27 @@ ruleTester.run("lines-around-directive", rule, {
code: "function foo() {\n'use strict';\nvar bar;\n}",
output: "function foo() {\n'use strict';\n\nvar bar;\n}",
options: [{ before: "never", after: "always" }],
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
},
{
code: "function foo() {\n\n'use strict';\nvar bar;\n}",
output: "function foo() {\n\n'use strict';\n\nvar bar;\n}",
options: [{ before: "never", after: "always" }],
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
},
{
code: "() => {\n'use strict';\nvar foo;\n}",
output: "() => {\n'use strict';\n\nvar foo;\n}",
options: [{ before: "never", after: "always" }],
parserOptions: { ecmaVersion: 6 },
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
},
{
code: "() => {\n\n'use strict';\nvar foo;\n}",
output: "() => {\n\n'use strict';\n\nvar foo;\n}",
options: [{ before: "never", after: "always" }],
parserOptions: { ecmaVersion: 6 },
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
},
// multiple directives
@@ -1318,27 +1324,27 @@ ruleTester.run("lines-around-directive", rule, {
code: "function foo() {\n'use strict';\n'use asm';\nvar bar;\n}",
output: "function foo() {\n'use strict';\n'use asm';\n\nvar bar;\n}",
options: [{ before: "never", after: "always" }],
- errors: ["Expected newline after \"use asm\" directive."]
+ errors: [expectedAfterAsmError]
},
{
code: "function foo() {\n\n'use strict';\n'use asm';\nvar bar;\n}",
output: "function foo() {\n\n'use strict';\n'use asm';\n\nvar bar;\n}",
options: [{ before: "never", after: "always" }],
- errors: ["Expected newline after \"use asm\" directive."]
+ errors: [expectedAfterAsmError]
},
{
code: "() => {\n'use strict';\n'use asm';\nvar foo;\n}",
output: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}",
options: [{ before: "never", after: "always" }],
parserOptions: { ecmaVersion: 6 },
- errors: ["Expected newline after \"use asm\" directive."]
+ errors: [expectedAfterAsmError]
},
{
code: "() => {\n\n'use strict';\n'use asm';\nvar foo;\n}",
output: "() => {\n\n'use strict';\n'use asm';\n\nvar foo;\n}",
options: [{ before: "never", after: "always" }],
parserOptions: { ecmaVersion: 6 },
- errors: ["Expected newline after \"use asm\" directive."]
+ errors: [expectedAfterAsmError]
},
/*
@@ -1350,8 +1356,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n//comment\n'use strict';\n\nvar bar;\n}",
options: [{ before: "never", after: "always" }],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterStrictError
]
},
{
@@ -1359,8 +1365,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n/*\nmultiline comment\n*/\n'use strict';\n\nvar bar;\n}",
options: [{ before: "never", after: "always" }],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterStrictError
]
},
{
@@ -1369,8 +1375,8 @@ ruleTester.run("lines-around-directive", rule, {
options: [{ before: "never", after: "always" }],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterStrictError
]
},
{
@@ -1379,8 +1385,8 @@ ruleTester.run("lines-around-directive", rule, {
options: [{ before: "never", after: "always" }],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use strict\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterStrictError
]
},
@@ -1390,8 +1396,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n//comment\n'use strict';\n'use asm';\n\nvar bar;\n}",
options: [{ before: "never", after: "always" }],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterAsmError
]
},
{
@@ -1399,8 +1405,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n/*\nmultiline comment\n*/\n'use strict';\n'use asm';\n\nvar bar;\n}",
options: [{ before: "never", after: "always" }],
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterAsmError
]
},
{
@@ -1409,8 +1415,8 @@ ruleTester.run("lines-around-directive", rule, {
options: [{ before: "never", after: "always" }],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterAsmError
]
},
{
@@ -1419,8 +1425,8 @@ ruleTester.run("lines-around-directive", rule, {
options: [{ before: "never", after: "always" }],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Unexpected newline before \"use strict\" directive.",
- "Expected newline after \"use asm\" directive."
+ unexpectedBeforeStrictError,
+ expectedAfterAsmError
]
},
@@ -1433,19 +1439,19 @@ ruleTester.run("lines-around-directive", rule, {
code: "'use strict';\n\nvar foo;",
output: "'use strict';\nvar foo;",
options: [{ before: "always", after: "never" }],
- errors: ["Unexpected newline after \"use strict\" directive."]
+ errors: [unexpectedAfterStrictError]
},
{
code: "'use strict';\n\n//comment\nvar foo;",
output: "'use strict';\n//comment\nvar foo;",
options: [{ before: "always", after: "never" }],
- errors: ["Unexpected newline after \"use strict\" directive."]
+ errors: [unexpectedAfterStrictError]
},
{
code: "'use strict';\n\n/*\nmultiline comment\n*/\nvar foo;",
output: "'use strict';\n/*\nmultiline comment\n*/\nvar foo;",
options: [{ before: "always", after: "never" }],
- errors: ["Unexpected newline after \"use strict\" directive."]
+ errors: [unexpectedAfterStrictError]
},
// multiple directives
@@ -1453,19 +1459,19 @@ ruleTester.run("lines-around-directive", rule, {
code: "'use strict';\n'use asm';\n\nvar foo;",
output: "'use strict';\n'use asm';\nvar foo;",
options: [{ before: "always", after: "never" }],
- errors: ["Unexpected newline after \"use asm\" directive."]
+ errors: [unexpectedAfterAsmError]
},
{
code: "'use strict';\n'use asm';\n\n//comment\nvar foo;",
output: "'use strict';\n'use asm';\n//comment\nvar foo;",
options: [{ before: "always", after: "never" }],
- errors: ["Unexpected newline after \"use asm\" directive."]
+ errors: [unexpectedAfterAsmError]
},
{
code: "'use strict';\n'use asm';\n\n/*\nmultiline comment\n*/\nvar foo;",
output: "'use strict';\n'use asm';\n/*\nmultiline comment\n*/\nvar foo;",
options: [{ before: "always", after: "never" }],
- errors: ["Unexpected newline after \"use asm\" directive."]
+ errors: [unexpectedAfterAsmError]
},
/*
@@ -1477,8 +1483,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "#!/usr/bin/env node\n\n'use strict';\nvar foo;",
options: [{ before: "always", after: "never" }],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
{
@@ -1486,8 +1492,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "//comment\n\n'use strict';\nvar foo;",
options: [{ before: "always", after: "never" }],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
{
@@ -1495,8 +1501,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "/*\nmultiline comment\n*/\n\n'use strict';\nvar foo;",
options: [{ before: "always", after: "never" }],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
@@ -1506,8 +1512,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "#!/usr/bin/env node\n\n'use strict';\n'use asm';\nvar foo;",
options: [{ before: "always", after: "never" }],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
{
@@ -1515,8 +1521,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "//comment\n\n'use strict';\n'use asm';\nvar foo;",
options: [{ before: "always", after: "never" }],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
{
@@ -1524,8 +1530,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\nvar foo;",
options: [{ before: "always", after: "never" }],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
@@ -1537,27 +1543,27 @@ ruleTester.run("lines-around-directive", rule, {
code: "function foo() {\n'use strict';\n\nvar bar;\n}",
output: "function foo() {\n'use strict';\nvar bar;\n}",
options: [{ before: "always", after: "never" }],
- errors: ["Unexpected newline after \"use strict\" directive."]
+ errors: [unexpectedAfterStrictError]
},
{
code: "function foo() {\n\n'use strict';\n\nvar bar;\n}",
output: "function foo() {\n\n'use strict';\nvar bar;\n}",
options: [{ before: "always", after: "never" }],
- errors: ["Unexpected newline after \"use strict\" directive."]
+ errors: [unexpectedAfterStrictError]
},
{
code: "() => {\n'use strict';\n\nvar foo;\n}",
output: "() => {\n'use strict';\nvar foo;\n}",
options: [{ before: "always", after: "never" }],
parserOptions: { ecmaVersion: 6 },
- errors: ["Unexpected newline after \"use strict\" directive."]
+ errors: [unexpectedAfterStrictError]
},
{
code: "() => {\n\n'use strict';\n\nvar foo;\n}",
output: "() => {\n\n'use strict';\nvar foo;\n}",
options: [{ before: "always", after: "never" }],
parserOptions: { ecmaVersion: 6 },
- errors: ["Unexpected newline after \"use strict\" directive."]
+ errors: [unexpectedAfterStrictError]
},
// multiple directives
@@ -1565,27 +1571,27 @@ ruleTester.run("lines-around-directive", rule, {
code: "function foo() {\n'use strict';\n'use asm';\n\nvar bar;\n}",
output: "function foo() {\n'use strict';\n'use asm';\nvar bar;\n}",
options: [{ before: "always", after: "never" }],
- errors: ["Unexpected newline after \"use asm\" directive."]
+ errors: [unexpectedAfterAsmError]
},
{
code: "function foo() {\n\n'use strict';\n'use asm';\n\nvar bar;\n}",
output: "function foo() {\n\n'use strict';\n'use asm';\nvar bar;\n}",
options: [{ before: "always", after: "never" }],
- errors: ["Unexpected newline after \"use asm\" directive."]
+ errors: [unexpectedAfterAsmError]
},
{
code: "() => {\n'use strict';\n'use asm';\n\nvar foo;\n}",
output: "() => {\n'use strict';\n'use asm';\nvar foo;\n}",
options: [{ before: "always", after: "never" }],
parserOptions: { ecmaVersion: 6 },
- errors: ["Unexpected newline after \"use asm\" directive."]
+ errors: [unexpectedAfterAsmError]
},
{
code: "() => {\n\n'use strict';\n'use asm';\n\nvar foo;\n}",
output: "() => {\n\n'use strict';\n'use asm';\nvar foo;\n}",
options: [{ before: "always", after: "never" }],
parserOptions: { ecmaVersion: 6 },
- errors: ["Unexpected newline after \"use asm\" directive."]
+ errors: [unexpectedAfterAsmError]
},
/*
@@ -1597,8 +1603,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n//comment\n\n'use strict';\nvar bar;\n}",
options: [{ before: "always", after: "never" }],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
{
@@ -1606,8 +1612,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n/*\nmultiline comment\n*/\n\n'use strict';\nvar bar;\n}",
options: [{ before: "always", after: "never" }],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
{
@@ -1616,8 +1622,8 @@ ruleTester.run("lines-around-directive", rule, {
options: [{ before: "always", after: "never" }],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
{
@@ -1626,8 +1632,8 @@ ruleTester.run("lines-around-directive", rule, {
options: [{ before: "always", after: "never" }],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use strict\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterStrictError
]
},
@@ -1637,8 +1643,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n//comment\n\n'use strict';\n'use asm';\nvar bar;\n}",
options: [{ before: "always", after: "never" }],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
{
@@ -1646,8 +1652,8 @@ ruleTester.run("lines-around-directive", rule, {
output: "function foo() {\n/*\nmultiline comment\n*/\n\n'use strict';\n'use asm';\nvar bar;\n}",
options: [{ before: "always", after: "never" }],
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
{
@@ -1656,8 +1662,8 @@ ruleTester.run("lines-around-directive", rule, {
options: [{ before: "always", after: "never" }],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
{
@@ -1666,8 +1672,8 @@ ruleTester.run("lines-around-directive", rule, {
options: [{ before: "always", after: "never" }],
parserOptions: { ecmaVersion: 6 },
errors: [
- "Expected newline before \"use strict\" directive.",
- "Unexpected newline after \"use asm\" directive."
+ expectedBeforeStrictError,
+ unexpectedAfterAsmError
]
},
@@ -1677,19 +1683,19 @@ ruleTester.run("lines-around-directive", rule, {
code: "'use strict'\n\n;foo();",
output: "'use strict'\n;foo();",
options: [{ before: "never", after: "never" }],
- errors: ["Unexpected newline after \"use strict\" directive."]
+ errors: [unexpectedAfterStrictError]
},
{
code: "'use strict'\n;foo();",
output: "'use strict'\n\n;foo();",
options: [{ before: "never", after: "always" }],
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
},
{
code: "'use strict'\n;\nfoo();",
output: "'use strict'\n\n;\nfoo();",
options: [{ before: "never", after: "always" }],
- errors: ["Expected newline after \"use strict\" directive."]
+ errors: [expectedAfterStrictError]
}
]
});
diff --git a/tests/lib/rules/lines-between-class-members.js b/tests/lib/rules/lines-between-class-members.js
index 443a41f2fd0..d8b75ee576f 100644
--- a/tests/lib/rules/lines-between-class-members.js
+++ b/tests/lib/rules/lines-between-class-members.js
@@ -15,9 +15,8 @@ const RuleTester = require("../../../lib/testers/rule-tester");
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
-
-const ALWAYS_MESSAGE = "Expected blank line between class members.";
-const NEVER_MESSAGE = "Unexpected blank line between class members.";
+const alwaysError = { messageId: "always" };
+const neverError = { messageId: "never" };
//------------------------------------------------------------------------------
// Tests
@@ -63,17 +62,17 @@ ruleTester.run("lines-between-class-members", rule, {
code: "class foo{ bar(){}\nbaz(){}}",
output: "class foo{ bar(){}\n\nbaz(){}}",
options: ["always"],
- errors: [{ message: ALWAYS_MESSAGE }]
+ errors: [alwaysError]
}, {
code: "class foo{ bar(){}\n\nbaz(){}}",
output: "class foo{ bar(){}\nbaz(){}}",
options: ["never"],
- errors: [{ message: NEVER_MESSAGE }]
+ errors: [neverError]
}, {
code: "class foo{ bar(){\n}\nbaz(){}}",
output: "class foo{ bar(){\n}\n\nbaz(){}}",
options: ["always", { exceptAfterSingleLine: true }],
- errors: [{ message: ALWAYS_MESSAGE }]
+ errors: [alwaysError]
}
]
});
diff --git a/tests/lib/rules/max-depth.js b/tests/lib/rules/max-depth.js
index f9899cbad9f..086abec58f8 100644
--- a/tests/lib/rules/max-depth.js
+++ b/tests/lib/rules/max-depth.js
@@ -29,15 +29,15 @@ ruleTester.run("max-depth", rule, {
{ code: "function foo() { if (true) { if (false) { if (true) { } } } }", options: [{ max: 3 }] }
],
invalid: [
- { code: "function foo() { if (true) { if (false) { if (true) { } } } }", options: [2], errors: [{ message: "Blocks are nested too deeply (3).", type: "IfStatement" }] },
- { code: "var foo = () => { if (true) { if (false) { if (true) { } } } }", options: [2], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Blocks are nested too deeply (3).", type: "IfStatement" }] },
- { code: "function foo() { if (true) {} else { for(;;) {} } }", options: [1], errors: [{ message: "Blocks are nested too deeply (2).", type: "ForStatement" }] },
- { code: "function foo() { while (true) { if (true) {} } }", options: [1], errors: [{ message: "Blocks are nested too deeply (2).", type: "IfStatement" }] },
- { code: "function foo() { for (let x of foo) { if (true) {} } }", options: [1], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Blocks are nested too deeply (2).", type: "IfStatement" }] },
- { code: "function foo() { while (true) { if (true) { if (false) { } } } }", options: [1], errors: [{ message: "Blocks are nested too deeply (2).", type: "IfStatement" }, { message: "Blocks are nested too deeply (3).", type: "IfStatement" }] },
- { code: "function foo() { if (true) { if (false) { if (true) { if (false) { if (true) { } } } } } }", errors: [{ message: "Blocks are nested too deeply (5).", type: "IfStatement" }] },
+ { code: "function foo() { if (true) { if (false) { if (true) { } } } }", options: [2], errors: [{ messageId: "tooDeeply", data: { depth: 3 }, type: "IfStatement" }] },
+ { code: "var foo = () => { if (true) { if (false) { if (true) { } } } }", options: [2], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "tooDeeply", data: { depth: 3 }, type: "IfStatement" }] },
+ { code: "function foo() { if (true) {} else { for(;;) {} } }", options: [1], errors: [{ messageId: "tooDeeply", data: { depth: 2 }, type: "ForStatement" }] },
+ { code: "function foo() { while (true) { if (true) {} } }", options: [1], errors: [{ messageId: "tooDeeply", data: { depth: 2 }, type: "IfStatement" }] },
+ { code: "function foo() { for (let x of foo) { if (true) {} } }", options: [1], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "tooDeeply", data: { depth: 2 }, type: "IfStatement" }] },
+ { code: "function foo() { while (true) { if (true) { if (false) { } } } }", options: [1], errors: [{ messageId: "tooDeeply", data: { depth: 2 }, type: "IfStatement" }, { messageId: "tooDeeply", data: { depth: 3 }, type: "IfStatement" }] },
+ { code: "function foo() { if (true) { if (false) { if (true) { if (false) { if (true) { } } } } } }", errors: [{ messageId: "tooDeeply", data: { depth: 5 }, type: "IfStatement" }] },
// object property options
- { code: "function foo() { if (true) { if (false) { if (true) { } } } }", options: [{ max: 2 }], errors: [{ message: "Blocks are nested too deeply (3).", type: "IfStatement" }] }
+ { code: "function foo() { if (true) { if (false) { if (true) { } } } }", options: [{ max: 2 }], errors: [{ messageId: "tooDeeply", data: { depth: 3 }, type: "IfStatement" }] }
]
});
diff --git a/tests/lib/rules/max-len.js b/tests/lib/rules/max-len.js
index caa5f3d5639..a7080f47708 100644
--- a/tests/lib/rules/max-len.js
+++ b/tests/lib/rules/max-len.js
@@ -186,7 +186,8 @@ ruleTester.run("max-len", rule, {
code: "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvar i = 1;",
errors: [
{
- message: "Line 1 exceeds the maximum line length of 80.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 80 },
type: "Program",
line: 1,
column: 1
@@ -198,7 +199,8 @@ ruleTester.run("max-len", rule, {
options: [10, 4],
errors: [
{
- message: "Line 1 exceeds the maximum line length of 10.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 10 },
type: "Program",
line: 1,
column: 1
@@ -210,7 +212,8 @@ ruleTester.run("max-len", rule, {
options: [15, 4],
errors: [
{
- message: "Line 1 exceeds the maximum line length of 15.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 15 },
type: "Program",
line: 1,
column: 1
@@ -222,13 +225,15 @@ ruleTester.run("max-len", rule, {
options: [15, 4],
errors: [
{
- message: "Line 1 exceeds the maximum line length of 15.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 15 },
type: "Program",
line: 1,
column: 1
},
{
- message: "Line 2 exceeds the maximum line length of 15.",
+ messageId: "max",
+ data: { lineNumber: 2, maxLength: 15 },
type: "Program",
line: 2,
column: 1
@@ -240,7 +245,8 @@ ruleTester.run("max-len", rule, {
options: [20, 4, { ignoreComments: true }],
errors: [
{
- message: "Line 1 exceeds the maximum line length of 20.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 20 },
type: "Program",
line: 1,
column: 1
@@ -254,7 +260,8 @@ ruleTester.run("max-len", rule, {
options: [20, 4, { ignorePattern: "fizzbuzz" }],
errors: [
{
- message: "Line 1 exceeds the maximum line length of 20.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 20 },
type: "Program",
line: 1,
column: 1
@@ -266,7 +273,8 @@ ruleTester.run("max-len", rule, {
options: [10, 4, { ignoreComments: true }],
errors: [
{
- message: "Line 1 exceeds the maximum line length of 10.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 10 },
type: "Program",
line: 1,
column: 1
@@ -278,7 +286,8 @@ ruleTester.run("max-len", rule, {
options: [40, 4], // ignoreComments is disabled
errors: [
{
- message: "Line 1 exceeds the maximum line length of 40.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 40 },
type: "Program",
line: 1,
column: 1
@@ -290,7 +299,8 @@ ruleTester.run("max-len", rule, {
options: [40, 4], // ignoreUrls is disabled
errors: [
{
- message: "Line 1 exceeds the maximum line length of 40.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 40 },
type: "Program",
line: 1,
column: 1
@@ -301,7 +311,8 @@ ruleTester.run("max-len", rule, {
options: [40, 4], // ignorePattern is disabled
errors: [
{
- message: "Line 1 exceeds the maximum line length of 40.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 40 },
type: "Program",
line: 1,
column: 1
@@ -312,7 +323,8 @@ ruleTester.run("max-len", rule, {
options: [80, 4, { comments: 20 }],
errors: [
{
- message: "Line 1 exceeds the maximum comment line length of 20.",
+ messageId: "maxComment",
+ data: { lineNumber: 1, maxCommentLength: 20 },
type: "Program",
line: 1,
column: 1
@@ -323,7 +335,8 @@ ruleTester.run("max-len", rule, {
options: [40, 4, { comments: 80 }],
errors: [
{
- message: "Line 1 exceeds the maximum comment line length of 80.",
+ messageId: "maxComment",
+ data: { lineNumber: 1, maxCommentLength: 80 },
type: "Program",
line: 1,
column: 1
@@ -334,7 +347,8 @@ ruleTester.run("max-len", rule, {
options: [{ code: 20 }],
errors: [
{
- message: "Line 1 exceeds the maximum line length of 20.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 20 },
type: "Program",
line: 1,
column: 1
@@ -345,7 +359,8 @@ ruleTester.run("max-len", rule, {
options: [40, 4, { ignoreTrailingComments: true }],
errors: [
{
- message: "Line 1 exceeds the maximum line length of 40.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 40 },
type: "Program",
line: 1,
column: 1
@@ -361,7 +376,8 @@ ruleTester.run("max-len", rule, {
options: [40, 4, { comments: 28 }],
errors: [
{
- message: "Line 2 exceeds the maximum comment line length of 28.",
+ messageId: "maxComment",
+ data: { lineNumber: 2, maxCommentLength: 28 },
type: "Program",
line: 2,
column: 1
@@ -374,7 +390,8 @@ ruleTester.run("max-len", rule, {
options: [40, 4, { comments: 32 }],
errors: [
{
- message: "Line 2 exceeds the maximum comment line length of 32.",
+ messageId: "maxComment",
+ data: { lineNumber: 2, maxCommentLength: 32 },
type: "Program",
line: 2,
column: 1
@@ -388,13 +405,15 @@ ruleTester.run("max-len", rule, {
options: [40, 4, { comments: 28 }],
errors: [
{
- message: "Line 2 exceeds the maximum comment line length of 28.",
+ messageId: "maxComment",
+ data: { lineNumber: 2, maxCommentLength: 28 },
type: "Program",
line: 2,
column: 1
},
{
- message: "Line 3 exceeds the maximum comment line length of 28.",
+ messageId: "maxComment",
+ data: { lineNumber: 3, maxCommentLength: 28 },
type: "Program",
line: 3,
column: 1
@@ -408,13 +427,15 @@ ruleTester.run("max-len", rule, {
options: [40, 4, { comments: 32 }],
errors: [
{
- message: "Line 2 exceeds the maximum comment line length of 32.",
+ messageId: "maxComment",
+ data: { lineNumber: 2, maxCommentLength: 32 },
type: "Program",
line: 2,
column: 1
},
{
- message: "Line 3 exceeds the maximum comment line length of 32.",
+ messageId: "maxComment",
+ data: { lineNumber: 3, maxCommentLength: 32 },
type: "Program",
line: 3,
column: 1
@@ -428,13 +449,15 @@ ruleTester.run("max-len", rule, {
options: [39, 4, { comments: 35 }],
errors: [
{
- message: "Line 2 exceeds the maximum line length of 39.",
+ messageId: "max",
+ data: { lineNumber: 2, maxLength: 39 },
type: "Program",
line: 2,
column: 1
},
{
- message: "Line 3 exceeds the maximum comment line length of 35.",
+ messageId: "maxComment",
+ data: { lineNumber: 3, maxCommentLength: 35 },
type: "Program",
line: 3,
column: 1
@@ -448,13 +471,15 @@ ruleTester.run("max-len", rule, {
options: [42, 4, { comments: 32 }],
errors: [
{
- message: "Line 2 exceeds the maximum comment line length of 32.",
+ messageId: "maxComment",
+ data: { lineNumber: 2, maxCommentLength: 32 },
type: "Program",
line: 2,
column: 1
},
{
- message: "Line 3 exceeds the maximum line length of 42.",
+ messageId: "max",
+ data: { lineNumber: 3, maxLength: 42 },
type: "Program",
line: 3,
column: 1
@@ -469,7 +494,8 @@ ruleTester.run("max-len", rule, {
options: [20, { ignoreComments: true }],
errors: [
{
- message: "Line 2 exceeds the maximum line length of 20.",
+ messageId: "max",
+ data: { lineNumber: 2, maxLength: 20 },
type: "Program",
line: 2,
column: 1
@@ -483,7 +509,8 @@ ruleTester.run("max-len", rule, {
options: [29, { ignoreStrings: false, ignoreTemplateLiterals: true }],
errors: [
{
- message: "Line 2 exceeds the maximum line length of 29.",
+ messageId: "max",
+ data: { lineNumber: 2, maxLength: 29 },
type: "Program",
line: 2,
column: 1
@@ -495,7 +522,8 @@ ruleTester.run("max-len", rule, {
options: [29, { ignoreStrings: false, ignoreRegExpLiterals: false }],
errors: [
{
- message: "Line 2 exceeds the maximum line length of 29.",
+ messageId: "max",
+ data: { lineNumber: 2, maxLength: 29 },
type: "Program",
line: 2,
column: 1
@@ -507,7 +535,8 @@ ruleTester.run("max-len", rule, {
options: [29, { ignoreStrings: false, ignoreRegExpLiterals: true }],
errors: [
{
- message: "Line 2 exceeds the maximum line length of 29.",
+ messageId: "max",
+ data: { lineNumber: 2, maxLength: 29 },
type: "Program",
line: 2,
column: 1
@@ -519,7 +548,8 @@ ruleTester.run("max-len", rule, {
options: [29, { ignoreStrings: false, ignoreTemplateLiterals: true }],
errors: [
{
- message: "Line 2 exceeds the maximum line length of 29.",
+ messageId: "max",
+ data: { lineNumber: 2, maxLength: 29 },
type: "Program",
line: 2,
column: 1
@@ -532,7 +562,8 @@ ruleTester.run("max-len", rule, {
parserOptions,
errors: [
{
- message: "Line 2 exceeds the maximum line length of 29.",
+ messageId: "max",
+ data: { lineNumber: 2, maxLength: 29 },
type: "Program",
line: 2,
column: 1
@@ -545,13 +576,15 @@ ruleTester.run("max-len", rule, {
parserOptions,
errors: [
{
- message: "Line 2 exceeds the maximum line length of 29.",
+ messageId: "max",
+ data: { lineNumber: 2, maxLength: 29 },
type: "Program",
line: 2,
column: 1
},
{
- message: "Line 3 exceeds the maximum line length of 29.",
+ messageId: "max",
+ data: { lineNumber: 3, maxLength: 29 },
type: "Program",
line: 3,
column: 1
@@ -564,7 +597,8 @@ ruleTester.run("max-len", rule, {
parserOptions: { ecmaFeatures: { jsx: true } },
errors: [
{
- message: "Line 1 exceeds the maximum line length of 29.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 29 },
type: "Program",
line: 1,
column: 1
@@ -578,7 +612,8 @@ ruleTester.run("max-len", rule, {
options: [10],
errors: [
{
- message: "Line 1 exceeds the maximum line length of 10.",
+ messageId: "max",
+ data: { lineNumber: 1, maxLength: 10 },
type: "Program",
line: 1,
column: 1
diff --git a/tests/lib/rules/max-lines-per-function.js b/tests/lib/rules/max-lines-per-function.js
index 8bf8250f338..9046a140635 100644
--- a/tests/lib/rules/max-lines-per-function.js
+++ b/tests/lib/rules/max-lines-per-function.js
@@ -174,7 +174,7 @@ if ( x === y ) {
code: "function name() {\n}",
options: [1],
errors: [
- "function 'name' has too many lines (2). Maximum allowed is 1."
+ { messageId: "exceed", data: { name: "function 'name'", lineCount: 2, maxLines: 1 } }
]
},
@@ -183,7 +183,7 @@ if ( x === y ) {
code: "var func = function() {\n}",
options: [1],
errors: [
- "function has too many lines (2). Maximum allowed is 1."
+ { messageId: "exceed", data: { name: "function", lineCount: 2, maxLines: 1 } }
]
},
@@ -192,7 +192,7 @@ if ( x === y ) {
code: "const bar = () => {\nconst x = 2 + 1;\nreturn x;\n}",
options: [3],
errors: [
- "arrow function has too many lines (4). Maximum allowed is 3."
+ { messageId: "exceed", data: { name: "arrow function", lineCount: 4, maxLines: 3 } }
]
},
@@ -201,7 +201,7 @@ if ( x === y ) {
code: "const bar = () =>\n 2",
options: [1],
errors: [
- "arrow function has too many lines (2). Maximum allowed is 1."
+ { messageId: "exceed", data: { name: "arrow function", lineCount: 2, maxLines: 1 } }
]
},
@@ -210,7 +210,7 @@ if ( x === y ) {
code: "function name() {\nvar x = 5;\n\t\n \n\nvar x = 2;\n}",
options: [{ max: 6, skipComments: false, skipBlankLines: false }],
errors: [
- "function 'name' has too many lines (7). Maximum allowed is 6."
+ { messageId: "exceed", data: { name: "function 'name'", lineCount: 7, maxLines: 6 } }
]
},
@@ -219,7 +219,7 @@ if ( x === y ) {
code: "function name() {\r\nvar x = 5;\r\n\t\r\n \r\n\r\nvar x = 2;\r\n}",
options: [{ max: 6, skipComments: true, skipBlankLines: false }],
errors: [
- "function 'name' has too many lines (7). Maximum allowed is 6."
+ { messageId: "exceed", data: { name: "function 'name'", lineCount: 7, maxLines: 6 } }
]
},
@@ -228,7 +228,7 @@ if ( x === y ) {
code: "function name() {\nvar x = 5;\n\t\n \n\nvar x = 2;\n}",
options: [{ max: 2, skipComments: true, skipBlankLines: true }],
errors: [
- "function 'name' has too many lines (4). Maximum allowed is 2."
+ { messageId: "exceed", data: { name: "function 'name'", lineCount: 4, maxLines: 2 } }
]
},
@@ -237,7 +237,7 @@ if ( x === y ) {
code: "function name() {\r\nvar x = 5;\r\n\t\r\n \r\n\r\nvar x = 2;\r\n}",
options: [{ max: 2, skipComments: true, skipBlankLines: true }],
errors: [
- "function 'name' has too many lines (4). Maximum allowed is 2."
+ { messageId: "exceed", data: { name: "function 'name'", lineCount: 4, maxLines: 2 } }
]
},
@@ -246,7 +246,7 @@ if ( x === y ) {
code: "function name() { // end of line comment\nvar x = 5; /* mid line comment */\n\t// single line comment taking up whole line\n\t\n \n\nvar x = 2;\n}",
options: [{ max: 6, skipComments: true, skipBlankLines: false }],
errors: [
- "function 'name' has too many lines (7). Maximum allowed is 6."
+ { messageId: "exceed", data: { name: "function 'name'", lineCount: 7, maxLines: 6 } }
]
},
@@ -255,7 +255,7 @@ if ( x === y ) {
code: "function name() { // end of line comment\nvar x = 5; /* mid line comment */\n\t// single line comment taking up whole line\n\t\n \n\nvar x = 2;\n}",
options: [{ max: 1, skipComments: true, skipBlankLines: true }],
errors: [
- "function 'name' has too many lines (4). Maximum allowed is 1."
+ { messageId: "exceed", data: { name: "function 'name'", lineCount: 4, maxLines: 1 } }
]
},
@@ -264,7 +264,7 @@ if ( x === y ) {
code: "function name() { // end of line comment\nvar x = 5; /* mid line comment */\n\t// single line comment taking up whole line\n\t\n \n\nvar x = 2;\n}",
options: [{ max: 1, skipComments: false, skipBlankLines: true }],
errors: [
- "function 'name' has too many lines (5). Maximum allowed is 1."
+ { messageId: "exceed", data: { name: "function 'name'", lineCount: 5, maxLines: 1 } }
]
},
@@ -279,7 +279,7 @@ if ( x === y ) {
}`,
options: [{ max: 2, skipComments: true, skipBlankLines: false }],
errors: [
- "function 'foo' has too many lines (7). Maximum allowed is 2."
+ { messageId: "exceed", data: { name: "function 'foo'", lineCount: 7, maxLines: 2 } }
]
},
@@ -294,7 +294,7 @@ function
()`,
options: [{ max: 2, skipComments: true, skipBlankLines: false, IIFEs: true }],
errors: [
- "function has too many lines (4). Maximum allowed is 2."
+ { messageId: "exceed", data: { name: "function", lineCount: 4, maxLines: 2 } }
]
},
@@ -312,7 +312,7 @@ if ( x === y ) {
}`,
options: [{ max: 9, skipComments: true, skipBlankLines: false }],
errors: [
- "function 'parent' has too many lines (10). Maximum allowed is 9."
+ { messageId: "exceed", data: { name: "function 'parent'", lineCount: 10, maxLines: 9 } }
]
},
@@ -330,8 +330,8 @@ if ( x === y ) {
}`,
options: [{ max: 2, skipComments: true, skipBlankLines: false }],
errors: [
- "function 'parent' has too many lines (10). Maximum allowed is 2.",
- "function 'nested' has too many lines (4). Maximum allowed is 2."
+ { messageId: "exceed", data: { name: "function 'parent'", lineCount: 10, maxLines: 2 } },
+ { messageId: "exceed", data: { name: "function 'nested'", lineCount: 4, maxLines: 2 } }
]
},
@@ -346,7 +346,7 @@ if ( x === y ) {
}`,
options: [{ max: 2, skipComments: true, skipBlankLines: false }],
errors: [
- "method 'method' has too many lines (5). Maximum allowed is 2."
+ { messageId: "exceed", data: { name: "method 'method'", lineCount: 5, maxLines: 2 } }
]
},
@@ -361,7 +361,7 @@ if ( x === y ) {
}`,
options: [{ max: 2, skipComments: true, skipBlankLines: false }],
errors: [
- "static method 'foo' has too many lines (5). Maximum allowed is 2."
+ { messageId: "exceed", data: { name: "static method 'foo'", lineCount: 5, maxLines: 2 } }
]
},
@@ -376,7 +376,7 @@ if ( x === y ) {
}`,
options: [{ max: 2, skipComments: true, skipBlankLines: false }],
errors: [
- "getter 'foo' has too many lines (5). Maximum allowed is 2."
+ { messageId: "exceed", data: { name: "getter 'foo'", lineCount: 5, maxLines: 2 } }
]
},
@@ -391,7 +391,7 @@ if ( x === y ) {
}`,
options: [{ max: 2, skipComments: true, skipBlankLines: false }],
errors: [
- "setter 'foo' has too many lines (5). Maximum allowed is 2."
+ { messageId: "exceed", data: { name: "setter 'foo'", lineCount: 5, maxLines: 2 } }
]
},
@@ -409,7 +409,7 @@ if ( x === y ) {
}`,
options: [{ max: 2, skipComments: true, skipBlankLines: false }],
errors: [
- "static method has too many lines (8). Maximum allowed is 2."
+ { messageId: "exceed", data: { name: "static method", lineCount: 8, maxLines: 2 } }
]
},
@@ -424,7 +424,7 @@ if ( x === y ) {
}());`,
options: [{ max: 2, skipComments: true, skipBlankLines: false, IIFEs: true }],
errors: [
- "function has too many lines (7). Maximum allowed is 2."
+ { messageId: "exceed", data: { name: "function", lineCount: 7, maxLines: 2 } }
]
}
]
diff --git a/tests/lib/rules/max-lines.js b/tests/lib/rules/max-lines.js
index 199a6bfd451..8324b51e1ff 100644
--- a/tests/lib/rules/max-lines.js
+++ b/tests/lib/rules/max-lines.js
@@ -19,16 +19,6 @@ const rule = require("../../../lib/rules/max-lines"),
const ruleTester = new RuleTester();
-/**
- * Returns the error message with the specified max number of lines
- * @param {number} limitLines Maximum number of lines
- * @param {number} actualLines Actual number of lines
- * @returns {string} error message
- */
-function errorMessage(limitLines, actualLines) {
- return `File must be at most ${limitLines} lines long. It's ${actualLines} lines long.`;
-}
-
ruleTester.run("max-lines", rule, {
valid: [
"var x;",
@@ -89,17 +79,17 @@ ruleTester.run("max-lines", rule, {
{
code: "var xyz;\nvar xyz;\nvar xyz;",
options: [2],
- errors: [{ message: errorMessage(2, 3) }]
+ errors: [{ messageId: "exceed", data: { max: 2, actual: 3 } }]
},
{
code: "/* a multiline comment\n that goes to many lines*/\nvar xy;\nvar xy;",
options: [2],
- errors: [{ message: errorMessage(2, 4) }]
+ errors: [{ messageId: "exceed", data: { max: 2, actual: 4 } }]
},
{
code: "//a single line comment\nvar xy;\nvar xy;",
options: [2],
- errors: [{ message: errorMessage(2, 3) }]
+ errors: [{ messageId: "exceed", data: { max: 2, actual: 3 } }]
},
{
code: [
@@ -110,7 +100,7 @@ ruleTester.run("max-lines", rule, {
"var y;"
].join("\n"),
options: [{ max: 2 }],
- errors: [{ message: errorMessage(2, 5) }]
+ errors: [{ messageId: "exceed", data: { max: 2, actual: 5 } }]
},
{
code: [
@@ -124,7 +114,7 @@ ruleTester.run("max-lines", rule, {
" long comment*/"
].join("\n"),
options: [{ max: 2, skipComments: true }],
- errors: [{ message: errorMessage(2, 4) }]
+ errors: [{ messageId: "exceed", data: { max: 2, actual: 4 } }]
},
{
code: [
@@ -133,7 +123,7 @@ ruleTester.run("max-lines", rule, {
"var z;"
].join("\n"),
options: [{ max: 2, skipComments: true }],
- errors: [{ message: errorMessage(2, 3) }]
+ errors: [{ messageId: "exceed", data: { max: 2, actual: 3 } }]
},
{
code: [
@@ -143,7 +133,7 @@ ruleTester.run("max-lines", rule, {
"var z;"
].join("\n"),
options: [{ max: 2, skipComments: true }],
- errors: [{ message: errorMessage(2, 3) }]
+ errors: [{ messageId: "exceed", data: { max: 2, actual: 3 } }]
},
{
code: [
@@ -157,7 +147,7 @@ ruleTester.run("max-lines", rule, {
" long comment*/"
].join("\n"),
options: [{ max: 2, skipBlankLines: true }],
- errors: [{ message: errorMessage(2, 6) }]
+ errors: [{ messageId: "exceed", data: { max: 2, actual: 6 } }]
}
]
});
diff --git a/tests/lib/rules/max-nested-callbacks.js b/tests/lib/rules/max-nested-callbacks.js
index 752051ef664..af17ab3b6d6 100644
--- a/tests/lib/rules/max-nested-callbacks.js
+++ b/tests/lib/rules/max-nested-callbacks.js
@@ -52,35 +52,35 @@ ruleTester.run("max-nested-callbacks", rule, {
{
code: "foo(function() { bar(thing, function(data) { baz(function() {}); }); });",
options: [2],
- errors: [{ message: "Too many nested callbacks (3). Maximum allowed is 2.", type: "FunctionExpression" }]
+ errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "FunctionExpression" }]
},
{
code: "foo(function() { bar(thing, (data) => { baz(function() {}); }); });",
options: [2],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: "Too many nested callbacks (3). Maximum allowed is 2.", type: "FunctionExpression" }]
+ errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "FunctionExpression" }]
},
{
code: "foo(() => { bar(thing, (data) => { baz( () => {}); }); });",
options: [2],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: "Too many nested callbacks (3). Maximum allowed is 2.", type: "ArrowFunctionExpression" }]
+ errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "ArrowFunctionExpression" }]
},
{
code: "foo(function() { if (isTrue) { bar(function(data) { baz(function() {}); }); } });",
options: [2],
- errors: [{ message: "Too many nested callbacks (3). Maximum allowed is 2.", type: "FunctionExpression" }]
+ errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "FunctionExpression" }]
},
{
code: nestFunctions(11),
- errors: [{ message: "Too many nested callbacks (11). Maximum allowed is 10.", type: "FunctionExpression" }]
+ errors: [{ messageId: "exceed", data: { num: 11, max: 10 }, type: "FunctionExpression" }]
},
// object property options
{
code: "foo(function() { bar(thing, function(data) { baz(function() {}); }); });",
options: [{ max: 2 }],
- errors: [{ message: "Too many nested callbacks (3). Maximum allowed is 2.", type: "FunctionExpression" }]
+ errors: [{ messageId: "exceed", data: { num: 3, max: 2 }, type: "FunctionExpression" }]
}
]
});
diff --git a/tests/lib/rules/max-params.js b/tests/lib/rules/max-params.js
index 959f5d7b8e2..bdbc8efa0ba 100644
--- a/tests/lib/rules/max-params.js
+++ b/tests/lib/rules/max-params.js
@@ -33,14 +33,16 @@ ruleTester.run("max-params", rule, {
code: "function test(a, b, c) {}",
options: [2],
errors: [{
- message: "Function 'test' has too many parameters (3). Maximum allowed is 2.",
+ messageId: "exceed",
+ data: { name: "Function 'test'", count: 3, max: 2.0 },
type: "FunctionDeclaration"
}]
},
{
code: "function test(a, b, c, d) {}",
errors: [{
- message: "Function 'test' has too many parameters (4). Maximum allowed is 3.",
+ messageId: "exceed",
+ data: { name: "Function 'test'", count: 4, max: 3.0 },
type: "FunctionDeclaration"
}]
},
@@ -48,7 +50,8 @@ ruleTester.run("max-params", rule, {
code: "var test = function(a, b, c, d) {};",
options: [3],
errors: [{
- message: "Function has too many parameters (4). Maximum allowed is 3.",
+ messageId: "exceed",
+ data: { name: "Function", count: 4, max: 3.0 },
type: "FunctionExpression"
}]
},
@@ -57,7 +60,8 @@ ruleTester.run("max-params", rule, {
options: [3],
parserOptions: { ecmaVersion: 6 },
errors: [{
- message: "Arrow function has too many parameters (4). Maximum allowed is 3.",
+ messageId: "exceed",
+ data: { name: "Arrow function", count: 4, max: 3.0 },
type: "ArrowFunctionExpression"
}]
},
@@ -65,7 +69,8 @@ ruleTester.run("max-params", rule, {
code: "(function(a, b, c, d) {});",
options: [3],
errors: [{
- message: "Function has too many parameters (4). Maximum allowed is 3.",
+ messageId: "exceed",
+ data: { name: "Function", count: 4, max: 3.0 },
type: "FunctionExpression"
}]
},
@@ -73,7 +78,8 @@ ruleTester.run("max-params", rule, {
code: "var test = function test(a, b, c) {};",
options: [1],
errors: [{
- message: "Function 'test' has too many parameters (3). Maximum allowed is 1.",
+ messageId: "exceed",
+ data: { name: "Function 'test'", count: 3, max: 1.0 },
type: "FunctionExpression"
}]
},
@@ -83,7 +89,8 @@ ruleTester.run("max-params", rule, {
code: "function test(a, b, c) {}",
options: [{ max: 2 }],
errors: [{
- message: "Function 'test' has too many parameters (3). Maximum allowed is 2.",
+ messageId: "exceed",
+ data: { name: "Function 'test'", count: 3, max: 2.0 },
type: "FunctionDeclaration"
}]
},
diff --git a/tests/lib/rules/max-statements-per-line.js b/tests/lib/rules/max-statements-per-line.js
index dd70ec67948..000ea50757d 100644
--- a/tests/lib/rules/max-statements-per-line.js
+++ b/tests/lib/rules/max-statements-per-line.js
@@ -114,47 +114,47 @@ ruleTester.run("max-statements-per-line", rule, {
}
],
invalid: [
- { code: "var foo; var bar;", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "var bar = 1; var foo = 3;", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "var bar = 1; var baz = 2;", errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "var bar = 1; var baz = 2;", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "if (condition) var bar = 1; if (condition) var baz = 2;", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "if (condition) var bar = 1; else var baz = 1;", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "if (condition) { } if (condition) { }", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "if (condition) { var bar = 1; } else { }", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "if (condition) { } else { var bar = 1; }", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "if (condition) { var bar = 1; } else { var bar = 1; }", options: [{ max: 1 }], errors: [{ message: "This line has 3 statements. Maximum allowed is 1." }] },
- { code: "for (var i = 0; i < length; ++i) { var bar = 1; }", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "switch (discriminant) { default: break; }", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "function foo() { var bar = 1; }", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "function foo() { if (condition) var bar = 1; }", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "function foo() { if (condition) { var bar = 1; } }", options: [{ max: 1 }], errors: [{ message: "This line has 3 statements. Maximum allowed is 1." }] },
- { code: "(function() { var bar = 1; })();", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "var foo = function foo() { var bar = 1; };", options: [{ max: 1 }], errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "var foo = { prop: () => { var bar = 1; } };", options: [{ max: 1 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "var bar = 1; var baz = 2; var qux = 3;", options: [{ max: 2 }], errors: [{ message: "This line has 3 statements. Maximum allowed is 2." }] },
- { code: "if (condition) { var bar = 1; var baz = 2; }", options: [{ max: 2 }], errors: [{ message: "This line has 3 statements. Maximum allowed is 2." }] },
- { code: "if (condition) { var bar = 1; } else { var bar = 1; }", options: [{ max: 2 }], errors: [{ message: "This line has 3 statements. Maximum allowed is 2." }] },
- { code: "if (condition) { var bar = 1; var baz = 2; } else { var bar = 1; var baz = 2; }", options: [{ max: 2 }], errors: [{ message: "This line has 5 statements. Maximum allowed is 2." }] },
- { code: "for (var i = 0; i < length; ++i) { var bar = 1; var baz = 2; }", options: [{ max: 2 }], errors: [{ message: "This line has 3 statements. Maximum allowed is 2." }] },
- { code: "switch (discriminant) { case 'test': break; default: break; }", options: [{ max: 2 }], errors: [{ message: "This line has 3 statements. Maximum allowed is 2." }] },
- { code: "function foo() { var bar = 1; var baz = 2; }", options: [{ max: 2 }], errors: [{ message: "This line has 3 statements. Maximum allowed is 2." }] },
- { code: "function foo() { if (condition) { var bar = 1; } }", options: [{ max: 2 }], errors: [{ message: "This line has 3 statements. Maximum allowed is 2." }] },
- { code: "(function() { var bar = 1; var baz = 2; })();", options: [{ max: 2 }], errors: [{ message: "This line has 3 statements. Maximum allowed is 2." }] },
- { code: "var foo = function foo() { var bar = 1; var baz = 2; };", options: [{ max: 2 }], errors: [{ message: "This line has 3 statements. Maximum allowed is 2." }] },
- { code: "var foo = { prop: () => { var bar = 1; var baz = 2; } };", options: [{ max: 2 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has 3 statements. Maximum allowed is 2." }] },
- { code: "var bar = 1; var baz = 2; var qux = 3; var waldo = 4;", options: [{ max: 3 }], errors: [{ message: "This line has 4 statements. Maximum allowed is 3." }] },
- { code: "if (condition) { var bar = 1; var baz = 2; var qux = 3; }", options: [{ max: 3 }], errors: [{ message: "This line has 4 statements. Maximum allowed is 3." }] },
- { code: "if (condition) { var bar = 1; var baz = 2; } else { var bar = 1; var baz = 2; }", options: [{ max: 3 }], errors: [{ message: "This line has 5 statements. Maximum allowed is 3." }] },
- { code: "switch (discriminant) { case 'test': var bar = 1; break; default: var bar = 1; break; }", options: [{ max: 3 }], errors: [{ message: "This line has 5 statements. Maximum allowed is 3." }] },
- { code: "let bar = bar => { a; }, baz = baz => { b; }, qux = qux => { c; };", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has 4 statements. Maximum allowed is 3." }] },
- { code: "(bar => { a; }) ? (baz => { b; }) : (qux => { c; });", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has 4 statements. Maximum allowed is 3." }] },
- { code: "bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; };", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has 5 statements. Maximum allowed is 4." }] },
- { code: "[bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; }];", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has 5 statements. Maximum allowed is 4." }] },
- { code: "foo(bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; });", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has 5 statements. Maximum allowed is 4." }] },
- { code: "({ bar: bar => { a; }, baz: baz => { b; }, qux: qux => { c; }, quux: quux => { d; }});", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "This line has 5 statements. Maximum allowed is 4." }] },
- { code: "a; if (b) { c; d; }\nz;", options: [{ max: 2 }], errors: [{ message: "This line has 4 statements. Maximum allowed is 2." }] },
- { code: "export default function foo() { console.log('test') }", options: [{ max: 1 }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] },
- { code: "export function foo() { console.log('test') }", options: [{ max: 1 }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ message: "This line has 2 statements. Maximum allowed is 1." }] }
+ { code: "var foo; var bar;", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "var bar = 1; var foo = 3;", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "var bar = 1; var baz = 2;", errors: [{ messageId: "exceed" }] },
+ { code: "var bar = 1; var baz = 2;", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "if (condition) var bar = 1; if (condition) var baz = 2;", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "if (condition) var bar = 1; else var baz = 1;", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "if (condition) { } if (condition) { }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "if (condition) { var bar = 1; } else { }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "if (condition) { } else { var bar = 1; }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "if (condition) { var bar = 1; } else { var bar = 1; }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "for (var i = 0; i < length; ++i) { var bar = 1; }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "switch (discriminant) { default: break; }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "function foo() { var bar = 1; }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "function foo() { if (condition) var bar = 1; }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "function foo() { if (condition) { var bar = 1; } }", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "(function() { var bar = 1; })();", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "var foo = function foo() { var bar = 1; };", options: [{ max: 1 }], errors: [{ messageId: "exceed" }] },
+ { code: "var foo = { prop: () => { var bar = 1; } };", options: [{ max: 1 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed" }] },
+ { code: "var bar = 1; var baz = 2; var qux = 3;", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] },
+ { code: "if (condition) { var bar = 1; var baz = 2; }", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] },
+ { code: "if (condition) { var bar = 1; } else { var bar = 1; }", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] },
+ { code: "if (condition) { var bar = 1; var baz = 2; } else { var bar = 1; var baz = 2; }", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 2.0 } }] },
+ { code: "for (var i = 0; i < length; ++i) { var bar = 1; var baz = 2; }", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] },
+ { code: "switch (discriminant) { case 'test': break; default: break; }", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] },
+ { code: "function foo() { var bar = 1; var baz = 2; }", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] },
+ { code: "function foo() { if (condition) { var bar = 1; } }", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] },
+ { code: "(function() { var bar = 1; var baz = 2; })();", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] },
+ { code: "var foo = function foo() { var bar = 1; var baz = 2; };", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] },
+ { code: "var foo = { prop: () => { var bar = 1; var baz = 2; } };", options: [{ max: 2 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 3, statements: "statements", maxStatementsPerLine: 2.0 } }] },
+ { code: "var bar = 1; var baz = 2; var qux = 3; var waldo = 4;", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }] },
+ { code: "if (condition) { var bar = 1; var baz = 2; var qux = 3; }", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }] },
+ { code: "if (condition) { var bar = 1; var baz = 2; } else { var bar = 1; var baz = 2; }", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 3.0 } }] },
+ { code: "switch (discriminant) { case 'test': var bar = 1; break; default: var bar = 1; break; }", options: [{ max: 3 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 3.0 } }] },
+ { code: "let bar = bar => { a; }, baz = baz => { b; }, qux = qux => { c; };", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }] },
+ { code: "(bar => { a; }) ? (baz => { b; }) : (qux => { c; });", options: [{ max: 3 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 3.0 } }] },
+ { code: "bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; };", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }] },
+ { code: "[bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; }];", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }] },
+ { code: "foo(bar => { a; }, baz => { b; }, qux => { c; }, quux => { d; });", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }] },
+ { code: "({ bar: bar => { a; }, baz: baz => { b; }, qux: qux => { c; }, quux: quux => { d; }});", options: [{ max: 4 }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 5, statements: "statements", maxStatementsPerLine: 4.0 } }] },
+ { code: "a; if (b) { c; d; }\nz;", options: [{ max: 2 }], errors: [{ messageId: "exceed", data: { numberOfStatementsOnThisLine: 4, statements: "statements", maxStatementsPerLine: 2.0 } }] },
+ { code: "export default function foo() { console.log('test') }", options: [{ max: 1 }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "exceed" }] },
+ { code: "export function foo() { console.log('test') }", options: [{ max: 1 }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ messageId: "exceed" }] }
]
});
diff --git a/tests/lib/rules/max-statements.js b/tests/lib/rules/max-statements.js
index 173e3411f75..53567448f56 100644
--- a/tests/lib/rules/max-statements.js
+++ b/tests/lib/rules/max-statements.js
@@ -39,78 +39,78 @@ ruleTester.run("max-statements", rule, {
{
code: "function foo() { var bar = 1; var baz = 2; var qux = 3; }",
options: [2],
- errors: [{ message: "Function 'foo' has too many statements (3). Maximum allowed is 2." }]
+ errors: [{ messageId: "exceed", data: { name: "Function 'foo'", count: "3", max: 2 } }]
},
{
code: "var foo = () => { var bar = 1; var baz = 2; var qux = 3; };",
options: [2],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: "Arrow function has too many statements (3). Maximum allowed is 2." }]
+ errors: [{ messageId: "exceed", data: { name: "Arrow function", count: "3", max: 2 } }]
},
{
code: "var foo = function() { var bar = 1; var baz = 2; var qux = 3; };",
options: [2],
- errors: [{ message: "Function has too many statements (3). Maximum allowed is 2." }]
+ errors: [{ messageId: "exceed", data: { name: "Function", count: "3", max: 2 } }]
},
{
code: "function foo() { var bar = 1; if (true) { while (false) { var qux = null; } } return 3; }",
options: [4],
- errors: [{ message: "Function 'foo' has too many statements (5). Maximum allowed is 4." }]
+ errors: [{ messageId: "exceed", data: { name: "Function 'foo'", count: "5", max: 4 } }]
},
{
code: "function foo() { var bar = 1; if (true) { for (;;) { var qux = null; } } return 3; }",
options: [4],
- errors: [{ message: "Function 'foo' has too many statements (5). Maximum allowed is 4." }]
+ errors: [{ messageId: "exceed", data: { name: "Function 'foo'", count: "5", max: 4 } }]
},
{
code: "function foo() { var bar = 1; if (true) { for (;;) { var qux = null; } } else { quxx(); } return 3; }",
options: [5],
- errors: [{ message: "Function 'foo' has too many statements (6). Maximum allowed is 5." }]
+ errors: [{ messageId: "exceed", data: { name: "Function 'foo'", count: "6", max: 5 } }]
},
{
code: "function foo() { var x = 5; function bar() { var y = 6; } bar(); z = 10; baz(); }",
options: [3],
- errors: [{ message: "Function 'foo' has too many statements (5). Maximum allowed is 3." }]
+ errors: [{ messageId: "exceed", data: { name: "Function 'foo'", count: "5", max: 3 } }]
},
{
code: "function foo() { var x = 5; function bar() { var y = 6; } bar(); z = 10; baz(); }",
options: [4],
- errors: [{ message: "Function 'foo' has too many statements (5). Maximum allowed is 4." }]
+ errors: [{ messageId: "exceed", data: { name: "Function 'foo'", count: "5", max: 4 } }]
},
{
code: ";(function() { var bar = 1; return function () { var z; return 42; }; })()",
options: [1, { ignoreTopLevelFunctions: true }],
- errors: [{ message: "Function has too many statements (2). Maximum allowed is 1." }]
+ errors: [{ messageId: "exceed", data: { name: "Function", count: "2", max: 1 } }]
},
{
code: ";(function() { var bar = 1; var baz = 2; })(); (function() { var bar = 1; var baz = 2; })()",
options: [1, { ignoreTopLevelFunctions: true }],
errors: [
- { message: "Function has too many statements (2). Maximum allowed is 1." },
- { message: "Function has too many statements (2). Maximum allowed is 1." }
+ { messageId: "exceed", data: { name: "Function", count: "2", max: 1 } },
+ { messageId: "exceed", data: { name: "Function", count: "2", max: 1 } }
]
},
{
code: "define(['foo', 'qux'], function(foo, qux) { var bar = 1; var baz = 2; return function () { var z; return 42; }; })",
options: [1, { ignoreTopLevelFunctions: true }],
- errors: [{ message: "Function has too many statements (2). Maximum allowed is 1." }]
+ errors: [{ messageId: "exceed", data: { name: "Function", count: "2", max: 1 } }]
},
{
code: "function foo() { var a; var b; var c; var x; var y; var z; bar(); baz(); qux(); quxx(); foo(); }",
- errors: [{ message: "Function 'foo' has too many statements (11). Maximum allowed is 10." }]
+ errors: [{ messageId: "exceed", data: { name: "Function 'foo'", count: "11", max: 10 } }]
},
// object property options
{
code: "var foo = { thing: function() { var bar = 1; var baz = 2; var baz2; } }",
options: [2],
- errors: [{ message: "Method 'thing' has too many statements (3). Maximum allowed is 2." }]
+ errors: [{ messageId: "exceed", data: { name: "Method 'thing'", count: "3", max: 2 } }]
},
{
code: "var foo = { thing() { var bar = 1; var baz = 2; var baz2; } }",
options: [2],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: "Method 'thing' has too many statements (3). Maximum allowed is 2." }]
+ errors: [{ messageId: "exceed", data: { name: "Method 'thing'", count: "3", max: 2 } }]
},
/*
@@ -119,7 +119,7 @@ ruleTester.run("max-statements", rule, {
* code: "var foo = { ['thing']() { var bar = 1; var baz = 2; var baz2; } }",
* options: [2],
* parserOptions: { ecmaVersion: 6 },
- * errors: [{ message: "Method ''thing'' has too many statements (3). Maximum allowed is 2." }]
+ * errors: [{ messageId: "exceed", data: {name: "Method ''thing''", count: "3", max: 2} }]
* },
*/
@@ -127,12 +127,12 @@ ruleTester.run("max-statements", rule, {
code: "var foo = { thing: () => { var bar = 1; var baz = 2; var baz2; } }",
options: [2],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: "Arrow function 'thing' has too many statements (3). Maximum allowed is 2." }]
+ errors: [{ messageId: "exceed", data: { name: "Arrow function 'thing'", count: "3", max: 2 } }]
},
{
code: "var foo = { thing: function() { var bar = 1; var baz = 2; var baz2; } }",
options: [{ max: 2 }],
- errors: [{ message: "Method 'thing' has too many statements (3). Maximum allowed is 2." }]
+ errors: [{ messageId: "exceed", data: { name: "Method 'thing'", count: "3", max: 2 } }]
}
]
});
diff --git a/tests/lib/rules/multiline-comment-style.js b/tests/lib/rules/multiline-comment-style.js
index 7f0cb42509b..be5c292a9b4 100644
--- a/tests/lib/rules/multiline-comment-style.js
+++ b/tests/lib/rules/multiline-comment-style.js
@@ -16,13 +16,6 @@ const RuleTester = require("../../../lib/testers/rule-tester");
// Tests
//------------------------------------------------------------------------------
-const EXPECTED_BLOCK_ERROR = "Expected a block comment instead of consecutive line comments.";
-const START_NEWLINE_ERROR = "Expected a linebreak after '/*'.";
-const END_NEWLINE_ERROR = "Expected a linebreak before '*/'.";
-const MISSING_STAR_ERROR = "Expected a '*' at the start of this line.";
-const ALIGNMENT_ERROR = "Expected this line to be aligned with the start of the comment.";
-const EXPECTED_LINES_ERROR = "Expected multiple line comments instead of a block comment.";
-
const ruleTester = new RuleTester();
ruleTester.run("multiline-comment-style", rule, {
@@ -252,7 +245,7 @@ ruleTester.run("multiline-comment-style", rule, {
* line comments
*/
`,
- errors: [{ message: EXPECTED_BLOCK_ERROR, line: 2 }]
+ errors: [{ messageId: "expectedBlock", line: 2 }]
},
{
code: `
@@ -260,7 +253,7 @@ ruleTester.run("multiline-comment-style", rule, {
///bar
`,
output: null,
- errors: [{ message: EXPECTED_BLOCK_ERROR, line: 2 }]
+ errors: [{ messageId: "expectedBlock", line: 2 }]
},
{
code: `
@@ -281,7 +274,7 @@ ruleTester.run("multiline-comment-style", rule, {
* qux
*/
`,
- errors: [{ message: EXPECTED_BLOCK_ERROR, line: 2 }, { message: EXPECTED_BLOCK_ERROR, line: 5 }]
+ errors: [{ messageId: "expectedBlock", line: 2 }, { messageId: "expectedBlock", line: 5 }]
},
{
code: `
@@ -295,7 +288,7 @@ ruleTester.run("multiline-comment-style", rule, {
* is missing a newline at the start
*/
`,
- errors: [{ message: START_NEWLINE_ERROR, line: 2 }]
+ errors: [{ messageId: "startNewline", line: 2 }]
},
{
code: `
@@ -309,7 +302,7 @@ ruleTester.run("multiline-comment-style", rule, {
* is missing a newline at the start
*/
`,
- errors: [{ message: START_NEWLINE_ERROR, line: 2 }]
+ errors: [{ messageId: "startNewline", line: 2 }]
},
{
code: `
@@ -323,7 +316,7 @@ ruleTester.run("multiline-comment-style", rule, {
* is missing a newline at the end
*/
`,
- errors: [{ message: END_NEWLINE_ERROR, line: 4 }]
+ errors: [{ messageId: "endNewline", line: 4 }]
},
{
code: `
@@ -338,7 +331,7 @@ ruleTester.run("multiline-comment-style", rule, {
* is missing a '*' at the start
*/
`,
- errors: [{ message: MISSING_STAR_ERROR, line: 4 }]
+ errors: [{ messageId: "missingStar", line: 4 }]
},
{
code: `
@@ -353,7 +346,7 @@ ruleTester.run("multiline-comment-style", rule, {
* has a '*' with the wrong offset at the start
*/
`,
- errors: [{ message: ALIGNMENT_ERROR, line: 4 }]
+ errors: [{ messageId: "alignment", line: 4 }]
},
{
code: `
@@ -368,7 +361,7 @@ ruleTester.run("multiline-comment-style", rule, {
* has a '*' with the wrong offset at the start
*/
`,
- errors: [{ message: ALIGNMENT_ERROR, line: 4 }]
+ errors: [{ messageId: "alignment", line: 4 }]
},
{
code: `
@@ -383,7 +376,7 @@ ruleTester.run("multiline-comment-style", rule, {
* is misaligned
*/
`,
- errors: [{ message: ALIGNMENT_ERROR, line: 5 }]
+ errors: [{ messageId: "alignment", line: 5 }]
},
{
code: `
@@ -400,7 +393,7 @@ ruleTester.run("multiline-comment-style", rule, {
* is blank
*/
`,
- errors: [{ message: ALIGNMENT_ERROR, line: 4 }]
+ errors: [{ messageId: "alignment", line: 4 }]
},
{
code: `
@@ -417,7 +410,7 @@ ruleTester.run("multiline-comment-style", rule, {
* is blank
*/
`,
- errors: [{ message: ALIGNMENT_ERROR, line: 4 }]
+ errors: [{ messageId: "alignment", line: 4 }]
},
{
code: `
@@ -432,7 +425,7 @@ ruleTester.run("multiline-comment-style", rule, {
* is misaligned
*/ foo
`,
- errors: [{ message: ALIGNMENT_ERROR, line: 5 }]
+ errors: [{ messageId: "alignment", line: 5 }]
},
{
code: `
@@ -446,7 +439,7 @@ ruleTester.run("multiline-comment-style", rule, {
// bar
`,
options: ["separate-lines"],
- errors: [{ message: EXPECTED_LINES_ERROR, line: 2 }]
+ errors: [{ messageId: "expectedLines", line: 2 }]
},
{
code: `
@@ -462,7 +455,7 @@ ruleTester.run("multiline-comment-style", rule, {
// qux
`,
options: ["separate-lines"],
- errors: [{ message: EXPECTED_LINES_ERROR, line: 2 }]
+ errors: [{ messageId: "expectedLines", line: 2 }]
},
{
code: `
@@ -474,7 +467,7 @@ ruleTester.run("multiline-comment-style", rule, {
bar */
`,
options: ["bare-block"],
- errors: [{ message: EXPECTED_BLOCK_ERROR, line: 2 }]
+ errors: [{ messageId: "expectedBlock", line: 2 }]
},
{
code: `
@@ -488,7 +481,7 @@ ruleTester.run("multiline-comment-style", rule, {
bar */
`,
options: ["bare-block"],
- errors: [{ message: EXPECTED_BLOCK_ERROR, line: 2 }]
+ errors: [{ messageId: "expectedBlock", line: 2 }]
}
]
});
diff --git a/tests/lib/rules/multiline-ternary.js b/tests/lib/rules/multiline-ternary.js
index 30750246c04..9ffd001e395 100644
--- a/tests/lib/rules/multiline-ternary.js
+++ b/tests/lib/rules/multiline-ternary.js
@@ -17,10 +17,6 @@ const RuleTester = require("../../../lib/testers/rule-tester");
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
-const expectedTestConsMsg = "Expected newline between test and consequent of ternary expression.";
-const expectedConsAltMsg = "Expected newline between consequent and alternate of ternary expression.";
-const unexpectedTestConsMsg = "Unexpected newline between test and consequent of ternary expression.";
-const unexpectedConsAltMsg = "Unexpected newline between consequent and alternate of ternary expression.";
ruleTester.run("multiline-ternary", rule, {
valid: [
@@ -60,12 +56,12 @@ ruleTester.run("multiline-ternary", rule, {
{
code: "a ? b : c",
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 1,
column: 5
}]
@@ -73,7 +69,7 @@ ruleTester.run("multiline-ternary", rule, {
{
code: "a\n? b : c",
errors: [{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 3
}]
@@ -81,7 +77,7 @@ ruleTester.run("multiline-ternary", rule, {
{
code: "a ? b\n: c",
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
}]
@@ -89,22 +85,22 @@ ruleTester.run("multiline-ternary", rule, {
{
code: "a ? (b ? c : d) : e",
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 1,
column: 6
},
{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 6
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 1,
column: 10
}]
@@ -112,12 +108,12 @@ ruleTester.run("multiline-ternary", rule, {
{
code: "a ?\n(b ? c : d) :\ne",
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 2,
column: 2
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 6
}]
@@ -125,12 +121,12 @@ ruleTester.run("multiline-ternary", rule, {
{
code: "a ? (b\n? c\n: d) : e",
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 1,
column: 6
}]
@@ -138,12 +134,12 @@ ruleTester.run("multiline-ternary", rule, {
{
code: "a ?\n(b? c\n: d) : e",
errors: [{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 2
},
{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 2,
column: 2
}]
@@ -151,12 +147,12 @@ ruleTester.run("multiline-ternary", rule, {
{
code: "a ?\n(b\n? c : d) : e",
errors: [{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 2
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 3,
column: 3
}]
@@ -164,7 +160,7 @@ ruleTester.run("multiline-ternary", rule, {
{
code: "a ?\n(b\n? c\n : d) : e",
errors: [{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 2
}]
@@ -175,12 +171,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ? b : c",
options: ["always"],
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 1,
column: 5
}]
@@ -189,7 +185,7 @@ ruleTester.run("multiline-ternary", rule, {
code: "a\n? b : c",
options: ["always"],
errors: [{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 3
}]
@@ -198,7 +194,7 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ? b\n: c",
options: ["always"],
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
}]
@@ -207,22 +203,22 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ? (b ? c : d) : e",
options: ["always"],
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 1,
column: 6
},
{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 6
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 1,
column: 10
}]
@@ -231,12 +227,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ?\n(b ? c : d) :\ne",
options: ["always"],
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 2,
column: 2
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 6
}]
@@ -245,12 +241,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ? (b\n? c\n: d) : e",
options: ["always"],
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 1,
column: 6
}]
@@ -259,12 +255,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ?\n(b? c\n: d) : e",
options: ["always"],
errors: [{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 2
},
{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 2,
column: 2
}]
@@ -273,12 +269,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ?\n(b\n? c : d) : e",
options: ["always"],
errors: [{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 2
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 3,
column: 3
}]
@@ -287,7 +283,7 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ?\n(b\n? c\n : d) : e",
options: ["always"],
errors: [{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 2
}]
@@ -298,7 +294,7 @@ ruleTester.run("multiline-ternary", rule, {
code: "a\n? b : c",
options: ["always-multiline"],
errors: [{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 3
}]
@@ -307,7 +303,7 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ? b\n: c",
options: ["always-multiline"],
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
}]
@@ -316,12 +312,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a &&\nb ? c : d",
options: ["always-multiline"],
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 5
}]
@@ -330,12 +326,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ? b +\nc : d",
options: ["always-multiline"],
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 1,
column: 5
}]
@@ -344,12 +340,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ? b : c +\nd",
options: ["always-multiline"],
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 1,
column: 5
}]
@@ -358,7 +354,7 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ?\n(b ? c : d) : e",
options: ["always-multiline"],
errors: [{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 2
}]
@@ -367,7 +363,7 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ? (b ? c : d) :\ne",
options: ["always-multiline"],
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
}]
@@ -376,12 +372,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ? (b\n? c\n: d) : e",
options: ["always-multiline"],
errors: [{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 1,
column: 1
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 1,
column: 6
}]
@@ -390,12 +386,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ?\n(b ? c\n: d) : e",
options: ["always-multiline"],
errors: [{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 2
},
{
- message: expectedTestConsMsg,
+ messageId: "expectedTestCons",
line: 2,
column: 2
}]
@@ -404,12 +400,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ?\n(b\n? c : d) : e",
options: ["always-multiline"],
errors: [{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 2
},
{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 3,
column: 3
}]
@@ -418,7 +414,7 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ?\n(b\n? c\n : d) : e",
options: ["always-multiline"],
errors: [{
- message: expectedConsAltMsg,
+ messageId: "expectedConsAlt",
line: 2,
column: 2
}]
@@ -429,7 +425,7 @@ ruleTester.run("multiline-ternary", rule, {
code: "a\n? b : c",
options: ["never"],
errors: [{
- message: unexpectedTestConsMsg,
+ messageId: "unexpectedTestCons",
line: 1,
column: 1
}]
@@ -438,7 +434,7 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ? b\n: c",
options: ["never"],
errors: [{
- message: unexpectedConsAltMsg,
+ messageId: "unexpectedConsAlt",
line: 1,
column: 5
}]
@@ -447,12 +443,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ?\n(b ? c : d) :\ne",
options: ["never"],
errors: [{
- message: unexpectedTestConsMsg,
+ messageId: "unexpectedTestCons",
line: 1,
column: 1
},
{
- message: unexpectedConsAltMsg,
+ messageId: "unexpectedConsAlt",
line: 2,
column: 2
}]
@@ -461,12 +457,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ? (b\n? c\n: d) : e",
options: ["never"],
errors: [{
- message: unexpectedTestConsMsg,
+ messageId: "unexpectedTestCons",
line: 1,
column: 6
},
{
- message: unexpectedConsAltMsg,
+ messageId: "unexpectedConsAlt",
line: 2,
column: 3
}]
@@ -475,12 +471,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ?\n(b? c\n: d) : e",
options: ["never"],
errors: [{
- message: unexpectedTestConsMsg,
+ messageId: "unexpectedTestCons",
line: 1,
column: 1
},
{
- message: unexpectedConsAltMsg,
+ messageId: "unexpectedConsAlt",
line: 2,
column: 5
}]
@@ -489,12 +485,12 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ?\n(b\n? c : d) : e",
options: ["never"],
errors: [{
- message: unexpectedTestConsMsg,
+ messageId: "unexpectedTestCons",
line: 1,
column: 1
},
{
- message: unexpectedTestConsMsg,
+ messageId: "unexpectedTestCons",
line: 2,
column: 2
}]
@@ -503,17 +499,17 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ?\n(b\n? c\n : d) : e",
options: ["never"],
errors: [{
- message: unexpectedTestConsMsg,
+ messageId: "unexpectedTestCons",
line: 1,
column: 1
},
{
- message: unexpectedTestConsMsg,
+ messageId: "unexpectedTestCons",
line: 2,
column: 2
},
{
- message: unexpectedConsAltMsg,
+ messageId: "unexpectedConsAlt",
line: 3,
column: 3
}]
@@ -522,17 +518,17 @@ ruleTester.run("multiline-ternary", rule, {
code: "a ? (b\n? c\n: d)\n: e",
options: ["never"],
errors: [{
- message: unexpectedConsAltMsg,
+ messageId: "unexpectedConsAlt",
line: 1,
column: 6
},
{
- message: unexpectedTestConsMsg,
+ messageId: "unexpectedTestCons",
line: 1,
column: 6
},
{
- message: unexpectedConsAltMsg,
+ messageId: "unexpectedConsAlt",
line: 2,
column: 3
}]
@@ -541,22 +537,22 @@ ruleTester.run("multiline-ternary", rule, {
code: "a\n?\n(b\n?\nc\n:\nd)\n:\ne",
options: ["never"],
errors: [{
- message: unexpectedTestConsMsg,
+ messageId: "unexpectedTestCons",
line: 1,
column: 1
},
{
- message: unexpectedConsAltMsg,
+ messageId: "unexpectedConsAlt",
line: 3,
column: 2
},
{
- message: unexpectedTestConsMsg,
+ messageId: "unexpectedTestCons",
line: 3,
column: 2
},
{
- message: unexpectedConsAltMsg,
+ messageId: "unexpectedConsAlt",
line: 5,
column: 1
}]
diff --git a/tests/lib/rules/new-cap.js b/tests/lib/rules/new-cap.js
index 0e7b5c706a4..9be94764f17 100644
--- a/tests/lib/rules/new-cap.js
+++ b/tests/lib/rules/new-cap.js
@@ -73,20 +73,20 @@ ruleTester.run("new-cap", rule, {
{ code: "var x = foo.Bar(42);", options: [{ capIsNew: false, properties: false }] }
],
invalid: [
- { code: "var x = new c();", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression" }] },
- { code: "var x = new φ;", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression" }] },
- { code: "var x = new a.b.c;", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression" }] },
- { code: "var x = new a.b['c'];", errors: [{ message: "A constructor name should not start with a lowercase letter.", type: "NewExpression" }] },
- { code: "var b = Foo();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] },
- { code: "var b = a.Foo();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] },
- { code: "var b = a['Foo']();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] },
- { code: "var b = a.Date.UTC();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] },
- { code: "var b = UTC();", errors: [{ message: "A function with a name starting with an uppercase letter should only be used as a constructor.", type: "CallExpression" }] },
+ { code: "var x = new c();", errors: [{ messageId: "lower", type: "NewExpression" }] },
+ { code: "var x = new φ;", errors: [{ messageId: "lower", type: "NewExpression" }] },
+ { code: "var x = new a.b.c;", errors: [{ messageId: "lower", type: "NewExpression" }] },
+ { code: "var x = new a.b['c'];", errors: [{ messageId: "lower", type: "NewExpression" }] },
+ { code: "var b = Foo();", errors: [{ messageId: "upper", type: "CallExpression" }] },
+ { code: "var b = a.Foo();", errors: [{ messageId: "upper", type: "CallExpression" }] },
+ { code: "var b = a['Foo']();", errors: [{ messageId: "upper", type: "CallExpression" }] },
+ { code: "var b = a.Date.UTC();", errors: [{ messageId: "upper", type: "CallExpression" }] },
+ { code: "var b = UTC();", errors: [{ messageId: "upper", type: "CallExpression" }] },
{
code: "var a = B.C();",
errors: [
{
- message: "A function with a name starting with an uppercase letter should only be used as a constructor.",
+ messageId: "upper",
type: "CallExpression",
line: 1,
column: 11
@@ -97,7 +97,7 @@ ruleTester.run("new-cap", rule, {
code: "var a = B\n.C();",
errors: [
{
- message: "A function with a name starting with an uppercase letter should only be used as a constructor.",
+ messageId: "upper",
type: "CallExpression",
line: 2,
column: 2
@@ -108,7 +108,7 @@ ruleTester.run("new-cap", rule, {
code: "var a = new B.c();",
errors: [
{
- message: "A constructor name should not start with a lowercase letter.",
+ messageId: "lower",
type: "NewExpression",
line: 1,
column: 15
@@ -119,7 +119,7 @@ ruleTester.run("new-cap", rule, {
code: "var a = new B.\nc();",
errors: [
{
- message: "A constructor name should not start with a lowercase letter.",
+ messageId: "lower",
type: "NewExpression",
line: 2,
column: 1
@@ -130,7 +130,7 @@ ruleTester.run("new-cap", rule, {
code: "var a = new c();",
errors: [
{
- message: "A constructor name should not start with a lowercase letter.",
+ messageId: "lower",
type: "NewExpression",
line: 1,
column: 13
@@ -141,24 +141,24 @@ ruleTester.run("new-cap", rule, {
{
code: "var x = Foo.Bar(42);",
options: [{ capIsNewExceptions: ["Foo"] }],
- errors: [{ type: "CallExpression", message: "A function with a name starting with an uppercase letter should only be used as a constructor." }]
+ errors: [{ type: "CallExpression", messageId: "upper" }]
},
{
code: "var x = Bar.Foo(42);",
options: [{ capIsNewExceptionPattern: "^Foo\\.." }],
- errors: [{ type: "CallExpression", message: "A function with a name starting with an uppercase letter should only be used as a constructor." }]
+ errors: [{ type: "CallExpression", messageId: "upper" }]
},
{
code: "var x = new foo.bar(42);",
options: [{ newIsCapExceptions: ["foo"] }],
- errors: [{ type: "NewExpression", message: "A constructor name should not start with a lowercase letter." }]
+ errors: [{ type: "NewExpression", messageId: "lower" }]
},
{
code: "var x = new bar.foo(42);",
options: [{ newIsCapExceptionPattern: "^foo\\.." }],
- errors: [{ type: "NewExpression", message: "A constructor name should not start with a lowercase letter." }]
+ errors: [{ type: "NewExpression", messageId: "lower" }]
}
]
});
diff --git a/tests/lib/rules/new-parens.js b/tests/lib/rules/new-parens.js
index a93bcbd6f0d..d56cd079d44 100644
--- a/tests/lib/rules/new-parens.js
+++ b/tests/lib/rules/new-parens.js
@@ -16,6 +16,7 @@ const parser = require("../../fixtures/fixture-parser"),
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
+const error = { messageId: "missing", type: "NewExpression" };
const ruleTester = new RuleTester();
@@ -34,47 +35,44 @@ ruleTester.run("new-parens", rule, {
{
code: "var a = new Date;",
output: "var a = new Date();",
- errors: [{ message: "Missing '()' invoking a constructor.", type: "NewExpression" }]
+ errors: [error]
},
{
code: "var a = new Date",
output: "var a = new Date()",
- errors: [{ message: "Missing '()' invoking a constructor.", type: "NewExpression" }]
+ errors: [error]
},
{
code: "var a = new (Date);",
output: "var a = new (Date)();",
- errors: [{ message: "Missing '()' invoking a constructor.", type: "NewExpression" }]
+ errors: [error]
},
{
code: "var a = new (Date)",
output: "var a = new (Date)()",
- errors: [{ message: "Missing '()' invoking a constructor.", type: "NewExpression" }]
+ errors: [error]
},
{
code: "var a = (new Date)",
output: "var a = (new Date())",
- errors: [{
- message: "Missing '()' invoking a constructor.",
- type: "NewExpression"
- }]
+ errors: [error]
},
{
// This `()` is `CallExpression`'s. This is a call of the result of `new Date`.
code: "var a = (new Date)()",
output: "var a = (new Date())()",
- errors: [{ message: "Missing '()' invoking a constructor.", type: "NewExpression" }]
+ errors: [error]
},
{
code: "var a = new foo.Bar;",
output: "var a = new foo.Bar();",
- errors: [{ message: "Missing '()' invoking a constructor.", type: "NewExpression" }]
+ errors: [error]
},
{
code: "var a = (new Foo).bar;",
output: "var a = (new Foo()).bar;",
- errors: [{ message: "Missing '()' invoking a constructor.", type: "NewExpression" }]
+ errors: [error]
}
]
});
diff --git a/tests/lib/rules/newline-after-var.js b/tests/lib/rules/newline-after-var.js
index 8060227bef9..1a0d41763d2 100644
--- a/tests/lib/rules/newline-after-var.js
+++ b/tests/lib/rules/newline-after-var.js
@@ -94,12 +94,12 @@ const NO_BREAK = "var greet = 'hello';console.log(greet);",
NO_BLANK_BEFORE_CASE = "switch(a) {\ncase 0:\nvar foo;\ncase 1:}";
const ALWAYS_ERROR = {
- message: "Expected blank line after variable declarations.",
+ messageId: "expected",
type: "VariableDeclaration"
};
const NEVER_ERROR = {
- message: "Unexpected blank line after variable declarations.",
+ messageId: "unexpected",
type: "VariableDeclaration"
};
diff --git a/tests/lib/rules/newline-before-return.js b/tests/lib/rules/newline-before-return.js
index 591ccce19b3..100a4558e48 100644
--- a/tests/lib/rules/newline-before-return.js
+++ b/tests/lib/rules/newline-before-return.js
@@ -17,6 +17,7 @@ const rule = require("../../../lib/rules/newline-before-return"),
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
+const error = { messageId: "expected" };
ruleTester.run("newline-before-return", rule, {
valid: [
@@ -114,110 +115,110 @@ ruleTester.run("newline-before-return", rule, {
{
code: "function a() {\nvar b; return;\n}",
output: "function a() {\nvar b; \n\nreturn;\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nvar b;\nreturn;\n}",
output: "function a() {\nvar b;\n\nreturn;\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne();\nreturn d;\n}\n}",
output: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne();\n\nreturn d;\n}\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne(); return d;\n}\n}",
output: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne(); \n\nreturn d;\n}\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\n while (b) {\nc();\nreturn;\n}\n}",
output: "function a() {\n while (b) {\nc();\n\nreturn;\n}\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\ndo {\nc();\nreturn;\n} while (b);\n}",
output: "function a() {\ndo {\nc();\n\nreturn;\n} while (b);\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nfor (var b; b < c; b++) {\nc();\nreturn;\n}\n}",
output: "function a() {\nfor (var b; b < c; b++) {\nc();\n\nreturn;\n}\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nfor (b in c) {\nd();\nreturn;\n}\n}",
output: "function a() {\nfor (b in c) {\nd();\n\nreturn;\n}\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nfor (b of c) {\nd();\nreturn;\n}\n}",
output: "function a() {\nfor (b of c) {\nd();\n\nreturn;\n}\n}",
parserOptions: { ecmaVersion: 6 },
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nif (b) {\nc();\n}\n//comment\nreturn b;\n}",
output: null,
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\n/*comment\ncomment*/\nif (b) {\nc();\nreturn b;\n} else {\n//comment\n\nreturn d;\n}\n/*multi-line\ncomment*/\nreturn e;\n}",
output: "function a() {\n/*comment\ncomment*/\nif (b) {\nc();\n\nreturn b;\n} else {\n//comment\n\nreturn d;\n}\n/*multi-line\ncomment*/\nreturn e;\n}",
- errors: ["Expected newline before return statement.", "Expected newline before return statement."]
+ errors: [error, error]
},
{
code: "function a() {\nif (b) { return; } //comment\nreturn c;\n}",
output: "function a() {\nif (b) { return; } //comment\n\nreturn c;\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nif (b) { return; } /*multi-line\ncomment*/\nreturn c;\n}",
output: null,
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nif (b) { return; }\n/*multi-line\ncomment*/ return c;\n}",
output: null,
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nif (b) { return; } /*multi-line\ncomment*/ return c;\n}",
output: null,
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "var a;\nreturn;",
output: "var a;\n\nreturn;",
parserOptions: { ecmaFeatures: { globalReturn: true } },
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "var a; return;",
output: "var a; \n\nreturn;",
parserOptions: { ecmaFeatures: { globalReturn: true } },
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\n{\n//comment\n}\nreturn\n}",
output: "function a() {\n{\n//comment\n}\n\nreturn\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\n{\n//comment\n} return\n}",
output: "function a() {\n{\n//comment\n} \n\nreturn\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nvar c;\nwhile (b) {\n c = d; //comment\n}\nreturn c;\n}",
output: "function a() {\nvar c;\nwhile (b) {\n c = d; //comment\n}\n\nreturn c;\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nfor (var b; b < c; b++) {\nif (d) {\nbreak; //comment\n}\nreturn;\n}\n}",
output: "function a() {\nfor (var b; b < c; b++) {\nif (d) {\nbreak; //comment\n}\n\nreturn;\n}\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
/*
@@ -227,57 +228,57 @@ ruleTester.run("newline-before-return", rule, {
{
code: "function a() {\nvar b; /*multi-line\ncomment*/\nreturn c;\n}",
output: null,
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nvar b;\n/*multi-line\ncomment*/ return c;\n}",
output: null,
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nvar b; /*multi-line\ncomment*/ return c;\n}",
output: null,
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nvar b;\n//comment\nreturn;\n}",
output: null,
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nvar b; //comment\nreturn;\n}",
output: "function a() {\nvar b; //comment\n\nreturn;\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nvar b;\n/* comment */ return;\n}",
output: null,
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nvar b;\n//comment\n/* comment */ return;\n}",
output: null,
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nvar b; /* comment */ return;\n}",
output: null,
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nvar b; /* comment */\nreturn;\n}",
output: "function a() {\nvar b; /* comment */\n\nreturn;\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nvar b;\nreturn; //comment\n}",
output: "function a() {\nvar b;\n\nreturn; //comment\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
},
{
code: "function a() {\nvar b; return; //comment\n}",
output: "function a() {\nvar b; \n\nreturn; //comment\n}",
- errors: ["Expected newline before return statement."]
+ errors: [error]
}
]
});
diff --git a/tests/lib/rules/newline-per-chained-call.js b/tests/lib/rules/newline-per-chained-call.js
index ada18a70b79..4b46a4b8365 100644
--- a/tests/lib/rules/newline-per-chained-call.js
+++ b/tests/lib/rules/newline-per-chained-call.js
@@ -30,47 +30,47 @@ ruleTester.run("newline-per-chained-call", rule, {
code: "_\n.chain({}).map(foo).filter(bar).value();",
output: "_\n.chain({}).map(foo)\n.filter(bar)\n.value();",
errors: [{
- message: "Expected line break before `.filter`."
+ messageId: "expected", data: { callee: ".filter" }
}, {
- message: "Expected line break before `.value`."
+ messageId: "expected", data: { callee: ".value" }
}]
}, {
code: "_\n.chain({})\n.map(foo)\n.filter(bar).value();",
output: "_\n.chain({})\n.map(foo)\n.filter(bar)\n.value();",
errors: [{
- message: "Expected line break before `.value`."
+ messageId: "expected", data: { callee: ".value" }
}]
}, {
code: "a().b().c().e.d()",
output: "a().b()\n.c().e.d()",
errors: [{
- message: "Expected line break before `.c`."
+ messageId: "expected", data: { callee: ".c" }
}]
}, {
code: "a.b.c().e().d()",
output: "a.b.c().e()\n.d()",
errors: [{
- message: "Expected line break before `.d`."
+ messageId: "expected", data: { callee: ".d" }
}]
}, {
code: "_.chain({}).map(a).value(); ",
output: "_.chain({}).map(a)\n.value(); ",
errors: [{
- message: "Expected line break before `.value`."
+ messageId: "expected", data: { callee: ".value" }
}]
}, {
code: "var a = m1.m2();\n var b = m1.m2().m3().m4().m5();",
output: "var a = m1.m2();\n var b = m1.m2().m3()\n.m4()\n.m5();",
errors: [{
- message: "Expected line break before `.m4`."
+ messageId: "expected", data: { callee: ".m4" }
}, {
- message: "Expected line break before `.m5`."
+ messageId: "expected", data: { callee: ".m5" }
}]
}, {
code: "var a = m1.m2();\n var b = m1.m2().m3()\n.m4().m5();",
output: "var a = m1.m2();\n var b = m1.m2().m3()\n.m4()\n.m5();",
errors: [{
- message: "Expected line break before `.m5`."
+ messageId: "expected", data: { callee: ".m5" }
}]
}, {
code: "var a = m1().m2\n.m3().m4().m5().m6().m7();",
@@ -79,9 +79,9 @@ ruleTester.run("newline-per-chained-call", rule, {
ignoreChainWithDepth: 3
}],
errors: [{
- message: "Expected line break before `.m6`."
+ messageId: "expected", data: { callee: ".m6" }
}, {
- message: "Expected line break before `.m7`."
+ messageId: "expected", data: { callee: ".m7" }
}]
}, {
code: [
@@ -145,9 +145,9 @@ ruleTester.run("newline-per-chained-call", rule, {
".end();"
].join("\n"),
errors: [{
- message: "Expected line break before `.on`."
+ messageId: "expected", data: { callee: ".on" }
}, {
- message: "Expected line break before `.end`."
+ messageId: "expected", data: { callee: ".end" }
}]
}, {
code: [
@@ -163,34 +163,34 @@ ruleTester.run("newline-per-chained-call", rule, {
" 'method4']()"
].join("\n"),
errors: [{
- message: "Expected line break before `['method' + n]`."
+ messageId: "expected", data: { callee: "['method' + n]" }
}, {
- message: "Expected line break before `[aCondition ?`."
+ messageId: "expected", data: { callee: "[aCondition ?" }
}]
}, {
code: "foo.bar()['foo' + \u2029 + 'bar']()",
output: "foo.bar()\n['foo' + \u2029 + 'bar']()",
options: [{ ignoreChainWithDepth: 1 }],
- errors: [{ message: "Expected line break before `['foo' + `." }]
+ errors: [{ messageId: "expected", data: { callee: "['foo' + " } }]
}, {
code: "foo.bar()[(biz)]()",
output: "foo.bar()\n[(biz)]()",
options: [{ ignoreChainWithDepth: 1 }],
- errors: [{ message: "Expected line break before `[biz]`." }]
+ errors: [{ messageId: "expected", data: { callee: "[biz]" } }]
}, {
code: "(foo).bar().biz()",
output: "(foo).bar()\n.biz()",
options: [{ ignoreChainWithDepth: 1 }],
- errors: [{ message: "Expected line break before `.biz`." }]
+ errors: [{ messageId: "expected", data: { callee: ".biz" } }]
}, {
code: "foo.bar(). /* comment */ biz()",
output: "foo.bar()\n. /* comment */ biz()",
options: [{ ignoreChainWithDepth: 1 }],
- errors: [{ message: "Expected line break before `.biz`." }]
+ errors: [{ messageId: "expected", data: { callee: ".biz" } }]
}, {
code: "foo.bar() /* comment */ .biz()",
output: "foo.bar() /* comment */ \n.biz()",
options: [{ ignoreChainWithDepth: 1 }],
- errors: [{ message: "Expected line break before `.biz`." }]
+ errors: [{ messageId: "expected", data: { callee: ".biz" } }]
}]
});
diff --git a/tests/lib/rules/no-async-promise-executor.js b/tests/lib/rules/no-async-promise-executor.js
index d5bcd0ae998..3190be20d96 100644
--- a/tests/lib/rules/no-async-promise-executor.js
+++ b/tests/lib/rules/no-async-promise-executor.js
@@ -30,7 +30,7 @@ ruleTester.run("no-async-promise-executor", rule, {
{
code: "new Promise(async function foo(resolve, reject) {})",
errors: [{
- message: "Promise executor functions should not be async.",
+ messageId: "async",
line: 1,
column: 13,
endLine: 1,
@@ -40,7 +40,7 @@ ruleTester.run("no-async-promise-executor", rule, {
{
code: "new Promise(async (resolve, reject) => {})",
errors: [{
- message: "Promise executor functions should not be async.",
+ messageId: "async",
line: 1,
column: 13,
endLine: 1,
@@ -50,7 +50,7 @@ ruleTester.run("no-async-promise-executor", rule, {
{
code: "new Promise(((((async () => {})))))",
errors: [{
- message: "Promise executor functions should not be async.",
+ messageId: "async",
line: 1,
column: 17,
endLine: 1,
diff --git a/tests/lib/rules/no-duplicate-imports.js b/tests/lib/rules/no-duplicate-imports.js
index 24bc078f1f7..cdc22a17479 100644
--- a/tests/lib/rules/no-duplicate-imports.js
+++ b/tests/lib/rules/no-duplicate-imports.js
@@ -50,39 +50,39 @@ ruleTester.run("no-duplicate-imports", rule, {
invalid: [
{
code: "import \"fs\";\nimport \"fs\"",
- errors: [{ message: "'fs' import is duplicated.", type: "ImportDeclaration" }]
+ errors: [{ messageId: "import", data: { module: "fs" }, type: "ImportDeclaration" }]
},
{
code: "import { merge } from \"lodash-es\";import { find } from \"lodash-es\";",
- errors: [{ message: "'lodash-es' import is duplicated.", type: "ImportDeclaration" }]
+ errors: [{ messageId: "import", data: { module: "lodash-es" }, type: "ImportDeclaration" }]
},
{
code: "import { merge } from \"lodash-es\";import _ from \"lodash-es\";",
- errors: [{ message: "'lodash-es' import is duplicated.", type: "ImportDeclaration" }]
+ errors: [{ messageId: "import", data: { module: "lodash-es" }, type: "ImportDeclaration" }]
},
{
code: "export { os } from \"os\";\nexport { something } from \"os\";",
options: [{ includeExports: true }],
- errors: [{ message: "'os' export is duplicated.", type: "ExportNamedDeclaration" }]
+ errors: [{ messageId: "export", data: { module: "os" }, type: "ExportNamedDeclaration" }]
},
{
code: "import os from \"os\"; export { os as foobar } from \"os\";\nexport { something } from \"os\";",
options: [{ includeExports: true }],
errors: [
- { message: "'os' export is duplicated as import.", type: "ExportNamedDeclaration" },
- { message: "'os' export is duplicated.", type: "ExportNamedDeclaration" },
- { message: "'os' export is duplicated as import.", type: "ExportNamedDeclaration" }
+ { messageId: "exportAs", data: { module: "os" }, type: "ExportNamedDeclaration" },
+ { messageId: "export", data: { module: "os" }, type: "ExportNamedDeclaration" },
+ { messageId: "exportAs", data: { module: "os" }, type: "ExportNamedDeclaration" }
]
},
{
code: "import os from \"os\";\nexport { something } from \"os\";",
options: [{ includeExports: true }],
- errors: [{ message: "'os' export is duplicated as import.", type: "ExportNamedDeclaration" }]
+ errors: [{ messageId: "exportAs", data: { module: "os" }, type: "ExportNamedDeclaration" }]
},
{
code: "import os from \"os\";\nexport * from \"os\";",
options: [{ includeExports: true }],
- errors: [{ message: "'os' export is duplicated as import.", type: "ExportAllDeclaration" }]
+ errors: [{ messageId: "exportAs", data: { module: "os" }, type: "ExportAllDeclaration" }]
}
]
});
diff --git a/tests/lib/rules/no-fallthrough.js b/tests/lib/rules/no-fallthrough.js
index 4d8e4514ba3..738bfdfe0f1 100644
--- a/tests/lib/rules/no-fallthrough.js
+++ b/tests/lib/rules/no-fallthrough.js
@@ -17,7 +17,7 @@ const rule = require("../../../lib/rules/no-fallthrough"),
//------------------------------------------------------------------------------
const errorsDefault = [{
- message: "Expected a 'break' statement before 'default'.",
+ messageId: "default",
type: "SwitchCase"
}];
@@ -91,7 +91,7 @@ ruleTester.run("no-fallthrough", rule, {
code: "switch(foo) { case 0: a();\ncase 1: b() }",
errors: [
{
- message: "Expected a 'break' statement before 'case'.",
+ messageId: "case",
type: "SwitchCase",
line: 2,
column: 1
@@ -102,7 +102,7 @@ ruleTester.run("no-fallthrough", rule, {
code: "switch(foo) { case 0: a();\ndefault: b() }",
errors: [
{
- message: "Expected a 'break' statement before 'default'.",
+ messageId: "default",
type: "SwitchCase",
line: 2,
column: 1
@@ -148,7 +148,7 @@ ruleTester.run("no-fallthrough", rule, {
}],
errors: [
{
- message: "Expected a 'break' statement before 'case'.",
+ messageId: "case",
type: "SwitchCase",
line: 3,
column: 1
@@ -162,8 +162,8 @@ ruleTester.run("no-fallthrough", rule, {
}],
errors: [
{
- message: errorsDefault[0].message,
- type: errorsDefault[0].type,
+ messageId: "default",
+ type: "SwitchCase",
line: 4,
column: 1
}
diff --git a/tests/lib/rules/no-floating-decimal.js b/tests/lib/rules/no-floating-decimal.js
index 32ca50e4aa9..bf95f94f188 100644
--- a/tests/lib/rules/no-floating-decimal.js
+++ b/tests/lib/rules/no-floating-decimal.js
@@ -17,6 +17,8 @@ const rule = require("../../../lib/rules/no-floating-decimal"),
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
+const leadingError = { messageId: "leading", type: "Literal" };
+const trailingError = { messageId: "trailing", type: "Literal" };
ruleTester.run("no-floating-decimal", rule, {
valid: [
@@ -27,33 +29,33 @@ ruleTester.run("no-floating-decimal", rule, {
{
code: "var x = .5;",
output: "var x = 0.5;",
- errors: [{ message: "A leading decimal point can be confused with a dot.", type: "Literal" }]
+ errors: [leadingError]
},
{
code: "var x = -.5;",
output: "var x = -0.5;",
- errors: [{ message: "A leading decimal point can be confused with a dot.", type: "Literal" }]
+ errors: [leadingError]
},
{
code: "var x = 2.;",
output: "var x = 2.0;",
- errors: [{ message: "A trailing decimal point can be confused with a dot.", type: "Literal" }]
+ errors: [trailingError]
},
{
code: "var x = -2.;",
output: "var x = -2.0;",
- errors: [{ message: "A trailing decimal point can be confused with a dot.", type: "Literal" }]
+ errors: [trailingError]
},
{
code: "typeof.2",
output: "typeof 0.2",
- errors: [{ message: "A leading decimal point can be confused with a dot.", type: "Literal" }]
+ errors: [leadingError]
},
{
code: "for(foo of.2);",
output: "for(foo of 0.2);",
parserOptions: { ecmaVersion: 2015 },
- errors: [{ message: "A leading decimal point can be confused with a dot.", type: "Literal" }]
+ errors: [leadingError]
}
]
});
diff --git a/tests/lib/rules/no-undef.js b/tests/lib/rules/no-undef.js
index 2372b87d519..51007795a61 100644
--- a/tests/lib/rules/no-undef.js
+++ b/tests/lib/rules/no-undef.js
@@ -81,18 +81,18 @@ ruleTester.run("no-undef", rule, {
}
],
invalid: [
- { code: "a = 1;", errors: [{ message: "'a' is not defined.", type: "Identifier" }] },
- { code: "if (typeof anUndefinedVar === 'string') {}", options: [{ typeof: true }], errors: [{ message: "'anUndefinedVar' is not defined.", type: "Identifier" }] },
- { code: "var a = b;", errors: [{ message: "'b' is not defined.", type: "Identifier" }] },
- { code: "function f() { b; }", errors: [{ message: "'b' is not defined.", type: "Identifier" }] },
- { code: "window;", errors: [{ message: "'window' is not defined.", type: "Identifier" }] },
- { code: "require(\"a\");", errors: [{ message: "'require' is not defined.", type: "Identifier" }] },
- { code: "var React; React.render(
);", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, errors: [{ message: "'a' is not defined." }] },
- { code: "var React, App; React.render();", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, errors: [{ message: "'a' is not defined." }] },
- { code: "[a] = [0];", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' is not defined." }] },
- { code: "({a} = {});", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' is not defined." }] },
- { code: "({b: a} = {});", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'a' is not defined." }] },
- { code: "[obj.a, obj.b] = [0, 1];", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "'obj' is not defined." }, { message: "'obj' is not defined." }] },
+ { code: "a = 1;", errors: [{ messageId: "undef", data: { name: "a" }, type: "Identifier" }] },
+ { code: "if (typeof anUndefinedVar === 'string') {}", options: [{ typeof: true }], errors: [{ messageId: "undef", data: { name: "anUndefinedVar" }, type: "Identifier" }] },
+ { code: "var a = b;", errors: [{ messageId: "undef", data: { name: "b" }, type: "Identifier" }] },
+ { code: "function f() { b; }", errors: [{ messageId: "undef", data: { name: "b" }, type: "Identifier" }] },
+ { code: "window;", errors: [{ messageId: "undef", data: { name: "window" }, type: "Identifier" }] },
+ { code: "require(\"a\");", errors: [{ messageId: "undef", data: { name: "require" }, type: "Identifier" }] },
+ { code: "var React; React.render(
);", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, errors: [{ messageId: "undef", data: { name: "a" } }] },
+ { code: "var React, App; React.render();", parserOptions: { ecmaVersion: 6, ecmaFeatures: { jsx: true } }, errors: [{ messageId: "undef", data: { name: "a" } }] },
+ { code: "[a] = [0];", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "undef", data: { name: "a" } }] },
+ { code: "({a} = {});", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "undef", data: { name: "a" } }] },
+ { code: "({b: a} = {});", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "undef", data: { name: "a" } }] },
+ { code: "[obj.a, obj.b] = [0, 1];", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "undef", data: { name: "obj" } }, { messageId: "undef", data: { name: "obj" } }] },
// Experimental
{
@@ -100,7 +100,7 @@ ruleTester.run("no-undef", rule, {
parserOptions: {
ecmaVersion: 2018
},
- errors: [{ message: "'b' is not defined." }]
+ errors: [{ messageId: "undef", data: { name: "b" } }]
}
]
});
diff --git a/tests/lib/rules/no-unexpected-multiline.js b/tests/lib/rules/no-unexpected-multiline.js
index 0df8de5573f..6cd9f73105d 100644
--- a/tests/lib/rules/no-unexpected-multiline.js
+++ b/tests/lib/rules/no-unexpected-multiline.js
@@ -88,7 +88,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
{
code: "var a = b\n(x || y).doSomething()",
errors: [{
- message: "Unexpected newline between function and ( of function call.",
+ messageId: "function",
line: 2,
column: 1
@@ -99,7 +99,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
errors: [{
line: 2,
column: 1,
- message: "Unexpected newline between function and ( of function call."
+ messageId: "function"
}]
},
{
@@ -107,7 +107,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
errors: [{
line: 2,
column: 1,
- message: "Unexpected newline between function and ( of function call."
+ messageId: "function"
}]
},
{
@@ -115,7 +115,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
errors: [{
line: 2,
column: 1,
- message: "Unexpected newline between object and [ of property access."
+ messageId: "property"
}]
},
{
@@ -123,7 +123,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
errors: [{
line: 2,
column: 5,
- message: "Unexpected newline between function and ( of function call."
+ messageId: "function"
}]
},
{
@@ -131,7 +131,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
errors: [{
line: 2,
column: 3,
- message: "Unexpected newline between object and [ of property access."
+ messageId: "property"
}]
},
{
@@ -140,7 +140,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
errors: [{
line: 1,
column: 9,
- message: "Unexpected newline between template tag and template literal."
+ messageId: "taggedTemplate"
}]
},
{
@@ -149,7 +149,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
errors: [{
line: 2,
column: 1,
- message: "Unexpected newline between template tag and template literal."
+ messageId: "taggedTemplate"
}]
},
{
@@ -158,7 +158,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
errors: [{
line: 3,
column: 1,
- message: "Unexpected newline between template tag and template literal."
+ messageId: "taggedTemplate"
}]
},
{
@@ -169,7 +169,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
errors: [{
line: 3,
column: 17,
- message: "Unexpected newline between numerator and division operator."
+ messageId: "division"
}]
},
{
@@ -180,7 +180,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
errors: [{
line: 3,
column: 17,
- message: "Unexpected newline between numerator and division operator."
+ messageId: "division"
}]
},
{
@@ -191,7 +191,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
errors: [{
line: 3,
column: 17,
- message: "Unexpected newline between numerator and division operator."
+ messageId: "division"
}]
},
{
@@ -202,7 +202,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
errors: [{
line: 3,
column: 17,
- message: "Unexpected newline between numerator and division operator."
+ messageId: "division"
}]
},
{
@@ -213,7 +213,7 @@ ruleTester.run("no-unexpected-multiline", rule, {
errors: [{
line: 3,
column: 17,
- message: "Unexpected newline between numerator and division operator."
+ messageId: "division"
}]
}
]
diff --git a/tests/lib/rules/no-unsafe-negation.js b/tests/lib/rules/no-unsafe-negation.js
index 42c894b3e92..a66470784c6 100644
--- a/tests/lib/rules/no-unsafe-negation.js
+++ b/tests/lib/rules/no-unsafe-negation.js
@@ -17,6 +17,8 @@ const rule = require("../../../lib/rules/no-unsafe-negation"),
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
+const unexpectedInError = { messageId: "unexpected", data: { operator: "in" } };
+const unexpectedInstanceofError = { messageId: "unexpected", data: { operator: "instanceof" } };
ruleTester.run("no-unsafe-negation", rule, {
valid: [
@@ -33,32 +35,32 @@ ruleTester.run("no-unsafe-negation", rule, {
{
code: "!a in b",
output: "!(a in b)",
- errors: ["Unexpected negating the left operand of 'in' operator."]
+ errors: [unexpectedInError]
},
{
code: "(!a in b)",
output: "(!(a in b))",
- errors: ["Unexpected negating the left operand of 'in' operator."]
+ errors: [unexpectedInError]
},
{
code: "!(a) in b",
output: "!((a) in b)",
- errors: ["Unexpected negating the left operand of 'in' operator."]
+ errors: [unexpectedInError]
},
{
code: "!a instanceof b",
output: "!(a instanceof b)",
- errors: ["Unexpected negating the left operand of 'instanceof' operator."]
+ errors: [unexpectedInstanceofError]
},
{
code: "(!a instanceof b)",
output: "(!(a instanceof b))",
- errors: ["Unexpected negating the left operand of 'instanceof' operator."]
+ errors: [unexpectedInstanceofError]
},
{
code: "!(a) instanceof b",
output: "!((a) instanceof b)",
- errors: ["Unexpected negating the left operand of 'instanceof' operator."]
+ errors: [unexpectedInstanceofError]
}
]
});
diff --git a/tests/lib/rules/no-unused-labels.js b/tests/lib/rules/no-unused-labels.js
index 08e6f093bf0..8a8dd68aa08 100644
--- a/tests/lib/rules/no-unused-labels.js
+++ b/tests/lib/rules/no-unused-labels.js
@@ -32,47 +32,47 @@ ruleTester.run("no-unused-labels", rule, {
{
code: "A: var foo = 0;",
output: "var foo = 0;",
- errors: ["'A:' is defined but never used."]
+ errors: [{ messageId: "unused" }]
},
{
code: "A: { foo(); bar(); }",
output: "{ foo(); bar(); }",
- errors: ["'A:' is defined but never used."]
+ errors: [{ messageId: "unused" }]
},
{
code: "A: if (a) { foo(); bar(); }",
output: "if (a) { foo(); bar(); }",
- errors: ["'A:' is defined but never used."]
+ errors: [{ messageId: "unused" }]
},
{
code: "A: for (var i = 0; i < 10; ++i) { foo(); if (a) break; bar(); }",
output: "for (var i = 0; i < 10; ++i) { foo(); if (a) break; bar(); }",
- errors: ["'A:' is defined but never used."]
+ errors: [{ messageId: "unused" }]
},
{
code: "A: for (var i = 0; i < 10; ++i) { foo(); if (a) continue; bar(); }",
output: "for (var i = 0; i < 10; ++i) { foo(); if (a) continue; bar(); }",
- errors: ["'A:' is defined but never used."]
+ errors: [{ messageId: "unused" }]
},
{
code: "A: for (var i = 0; i < 10; ++i) { B: break A; }",
output: "A: for (var i = 0; i < 10; ++i) { break A; }",
- errors: ["'B:' is defined but never used."]
+ errors: [{ messageId: "unused", data: { name: "B" } }]
},
{
code: "A: { var A = 0; console.log(A); }",
output: "{ var A = 0; console.log(A); }",
- errors: ["'A:' is defined but never used."]
+ errors: [{ messageId: "unused" }]
},
{
code: "A: /* comment */ foo",
output: null,
- errors: ["'A:' is defined but never used."]
+ errors: [{ messageId: "unused" }]
},
{
code: "A /* comment */: foo",
output: null,
- errors: ["'A:' is defined but never used."]
+ errors: [{ messageId: "unused" }]
}
/*
diff --git a/tests/lib/rules/operator-assignment.js b/tests/lib/rules/operator-assignment.js
index 19fb03bd8af..0012cb81c65 100644
--- a/tests/lib/rules/operator-assignment.js
+++ b/tests/lib/rules/operator-assignment.js
@@ -18,8 +18,8 @@ const rule = require("../../../lib/rules/operator-assignment"),
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 7 } });
-const EXPECTED_OPERATOR_ASSIGNMENT = [{ message: "Assignment can be replaced with operator assignment.", type: "AssignmentExpression" }];
-const UNEXPECTED_OPERATOR_ASSIGNMENT = [{ message: "Unexpected operator assignment shorthand.", type: "AssignmentExpression" }];
+const EXPECTED_OPERATOR_ASSIGNMENT = [{ messageId: "replaced", type: "AssignmentExpression" }];
+const UNEXPECTED_OPERATOR_ASSIGNMENT = [{ messageId: "unexpected", type: "AssignmentExpression" }];
ruleTester.run("operator-assignment", rule, {
diff --git a/tests/lib/rules/prefer-const.js b/tests/lib/rules/prefer-const.js
index a16ac38c3b4..699feb6cfb2 100644
--- a/tests/lib/rules/prefer-const.js
+++ b/tests/lib/rules/prefer-const.js
@@ -179,74 +179,74 @@ ruleTester.run("prefer-const", rule, {
{
code: "let x = 1; foo(x);",
output: "const x = 1; foo(x);",
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }]
},
{
code: "for (let i in [1,2,3]) { foo(i); }",
output: "for (const i in [1,2,3]) { foo(i); }",
- errors: [{ message: "'i' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "i" }, type: "Identifier" }]
},
{
code: "for (let x of [1,2,3]) { foo(x); }",
output: "for (const x of [1,2,3]) { foo(x); }",
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }]
},
{
code: "let [x = -1, y] = [1,2]; y = 0;",
output: null,
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }]
},
{
code: "let {a: x = -1, b: y} = {a:1,b:2}; y = 0;",
output: null,
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }]
},
{
code: "(function() { let x = 1; foo(x); })();",
output: "(function() { const x = 1; foo(x); })();",
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }]
},
{
code: "(function() { for (let i in [1,2,3]) { foo(i); } })();",
output: "(function() { for (const i in [1,2,3]) { foo(i); } })();",
- errors: [{ message: "'i' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "i" }, type: "Identifier" }]
},
{
code: "(function() { for (let x of [1,2,3]) { foo(x); } })();",
output: "(function() { for (const x of [1,2,3]) { foo(x); } })();",
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }]
},
{
code: "(function() { let [x = -1, y] = [1,2]; y = 0; })();",
output: null,
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }]
},
{
code: "let f = (function() { let g = x; })(); f = 1;",
output: "let f = (function() { const g = x; })(); f = 1;",
- errors: [{ message: "'g' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "g" }, type: "Identifier" }]
},
{
code: "(function() { let {a: x = -1, b: y} = {a:1,b:2}; y = 0; })();",
output: null,
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }]
},
{
code: "let x = 0; { let x = 1; foo(x); } x = 0;",
output: "let x = 0; { const x = 1; foo(x); } x = 0;",
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }]
},
{
code: "for (let i = 0; i < 10; ++i) { let x = 1; foo(x); }",
output: "for (let i = 0; i < 10; ++i) { const x = 1; foo(x); }",
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }]
},
{
code: "for (let i in [1,2,3]) { let x = 1; foo(x); }",
output: "for (const i in [1,2,3]) { const x = 1; foo(x); }",
errors: [
- { message: "'i' is never reassigned. Use 'const' instead.", type: "Identifier" },
- { message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier" }
+ { messageId: "useConst", data: { name: "i" }, type: "Identifier" },
+ { messageId: "useConst", data: { name: "x" }, type: "Identifier" }
]
},
{
@@ -260,7 +260,7 @@ ruleTester.run("prefer-const", rule, {
].join("\n"),
output: null,
errors: [
- { message: "'a' is never reassigned. Use 'const' instead.", type: "Identifier" }
+ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }
]
},
{
@@ -274,60 +274,60 @@ ruleTester.run("prefer-const", rule, {
].join("\n"),
output: null,
errors: [
- { message: "'a' is never reassigned. Use 'const' instead.", type: "Identifier" }
+ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }
]
},
{
code: "let x; x = 0;",
output: null,
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier", column: 8 }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier", column: 8 }]
},
{
code: "switch (a) { case 0: let x; x = 0; }",
output: null,
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier", column: 29 }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier", column: 29 }]
},
{
code: "(function() { let x; x = 1; })();",
output: null,
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier", column: 22 }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier", column: 22 }]
},
{
code: "let {a = 0, b} = obj; b = 0; foo(a, b);",
output: null,
options: [{ destructuring: "any" }],
- errors: [{ message: "'a' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }]
},
{
code: "let {a: {b, c}} = {a: {b: 1, c: 2}}; b = 3;",
output: null,
options: [{ destructuring: "any" }],
- errors: [{ message: "'c' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "c" }, type: "Identifier" }]
},
{
code: "let {a: {b, c}} = {a: {b: 1, c: 2}}",
output: "const {a: {b, c}} = {a: {b: 1, c: 2}}",
options: [{ destructuring: "all" }],
errors: [
- { message: "'b' is never reassigned. Use 'const' instead.", type: "Identifier" },
- { message: "'c' is never reassigned. Use 'const' instead.", type: "Identifier" }
+ { messageId: "useConst", data: { name: "b" }, type: "Identifier" },
+ { messageId: "useConst", data: { name: "c" }, type: "Identifier" }
]
},
{
code: "let a, b; ({a = 0, b} = obj); b = 0; foo(a, b);",
output: null,
options: [{ destructuring: "any" }],
- errors: [{ message: "'a' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "a" }, type: "Identifier" }]
},
{
code: "let {a = 0, b} = obj; foo(a, b);",
output: "const {a = 0, b} = obj; foo(a, b);",
options: [{ destructuring: "all" }],
errors: [
- { message: "'a' is never reassigned. Use 'const' instead.", type: "Identifier" },
- { message: "'b' is never reassigned. Use 'const' instead.", type: "Identifier" }
+ { messageId: "useConst", data: { name: "a" }, type: "Identifier" },
+ { messageId: "useConst", data: { name: "b" }, type: "Identifier" }
]
},
{
@@ -335,7 +335,7 @@ ruleTester.run("prefer-const", rule, {
output: "const [a] = [1]",
options: [],
errors: [
- { message: "'a' is never reassigned. Use 'const' instead.", type: "Identifier" }
+ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }
]
},
{
@@ -343,7 +343,7 @@ ruleTester.run("prefer-const", rule, {
output: "const {a} = obj",
options: [],
errors: [
- { message: "'a' is never reassigned. Use 'const' instead.", type: "Identifier" }
+ { messageId: "useConst", data: { name: "a" }, type: "Identifier" }
]
},
{
@@ -351,8 +351,8 @@ ruleTester.run("prefer-const", rule, {
output: null,
options: [{ destructuring: "all" }],
errors: [
- { message: "'a' is never reassigned. Use 'const' instead.", type: "Identifier" },
- { message: "'b' is never reassigned. Use 'const' instead.", type: "Identifier" }
+ { messageId: "useConst", data: { name: "a" }, type: "Identifier" },
+ { messageId: "useConst", data: { name: "b" }, type: "Identifier" }
]
},
{
@@ -360,15 +360,15 @@ ruleTester.run("prefer-const", rule, {
output: null,
options: [{ destructuring: "any" }],
errors: [
- { message: "'a' is never reassigned. Use 'const' instead.", type: "Identifier" },
- { message: "'c' is never reassigned. Use 'const' instead.", type: "Identifier" }
+ { messageId: "useConst", data: { name: "a" }, type: "Identifier" },
+ { messageId: "useConst", data: { name: "c" }, type: "Identifier" }
]
},
{
code: "let {a = 0, b} = obj, c = a; b = a;",
output: null,
options: [{ destructuring: "all" }],
- errors: [{ message: "'c' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "c" }, type: "Identifier" }]
},
// https://github.com/eslint/eslint/issues/8187
@@ -377,13 +377,13 @@ ruleTester.run("prefer-const", rule, {
output: null,
options: [{ destructuring: "any" }],
parserOptions: { ecmaVersion: 2018 },
- errors: [{ message: "'name' is never reassigned. Use 'const' instead.", type: "Identifier", column: 7 }]
+ errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }]
},
{
code: "let { name, ...otherStuff } = obj; otherStuff = {};",
output: null,
options: [{ destructuring: "any" }],
- errors: [{ message: "'name' is never reassigned. Use 'const' instead.", type: "Identifier", column: 7 }],
+ errors: [{ messageId: "useConst", data: { name: "name" }, type: "Identifier", column: 7 }],
parser: fixtureParser("babel-eslint5/destructuring-object-spread")
},
@@ -391,7 +391,7 @@ ruleTester.run("prefer-const", rule, {
{
code: "let x; function foo() { bar(x); } x = 0;",
output: null,
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier", column: 5 }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier", column: 5 }]
},
// https://github.com/eslint/eslint/issues/5837
@@ -399,19 +399,19 @@ ruleTester.run("prefer-const", rule, {
code: "/*eslint use-x:error*/ let x = 1",
output: "/*eslint use-x:error*/ const x = 1",
parserOptions: { ecmaFeatures: { globalReturn: true } },
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }]
},
{
code: "/*eslint use-x:error*/ { let x = 1 }",
output: "/*eslint use-x:error*/ { const x = 1 }",
- errors: [{ message: "'x' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "x" }, type: "Identifier" }]
},
{
code: "let { foo, bar } = baz;",
output: "const { foo, bar } = baz;",
errors: [
- { message: "'foo' is never reassigned. Use 'const' instead.", type: "Identifier" },
- { message: "'bar' is never reassigned. Use 'const' instead.", type: "Identifier" }
+ { messageId: "useConst", data: { name: "foo" }, type: "Identifier" },
+ { messageId: "useConst", data: { name: "bar" }, type: "Identifier" }
]
},
@@ -419,14 +419,14 @@ ruleTester.run("prefer-const", rule, {
{
code: "const x = [1,2]; let [,y] = x;",
output: "const x = [1,2]; const [,y] = x;",
- errors: [{ message: "'y' is never reassigned. Use 'const' instead.", type: "Identifier" }]
+ errors: [{ messageId: "useConst", data: { name: "y" }, type: "Identifier" }]
},
{
code: "const x = [1,2,3]; let [y,,z] = x;",
output: "const x = [1,2,3]; const [y,,z] = x;",
errors: [
- { message: "'y' is never reassigned. Use 'const' instead.", type: "Identifier" },
- { message: "'z' is never reassigned. Use 'const' instead.", type: "Identifier" }
+ { messageId: "useConst", data: { name: "y" }, type: "Identifier" },
+ { messageId: "useConst", data: { name: "z" }, type: "Identifier" }
]
},
diff --git a/tests/lib/rules/space-unary-ops.js b/tests/lib/rules/space-unary-ops.js
index 11b2c96bfc1..0e6c0e1c351 100644
--- a/tests/lib/rules/space-unary-ops.js
+++ b/tests/lib/rules/space-unary-ops.js
@@ -259,7 +259,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "delete (foo.bar)",
options: [{ words: true }],
errors: [{
- message: "Unary word operator 'delete' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "delete" },
type: "UnaryExpression"
}]
},
@@ -268,7 +269,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "delete (foo[\"bar\"]);",
options: [{ words: true }],
errors: [{
- message: "Unary word operator 'delete' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "delete" },
type: "UnaryExpression"
}]
},
@@ -277,7 +279,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "delete(foo.bar)",
options: [{ words: false }],
errors: [{
- message: "Unexpected space after unary word operator 'delete'.",
+ messageId: "unexpectedAfterWord",
+ data: { word: "delete" },
type: "UnaryExpression"
}]
},
@@ -286,7 +289,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "new (Foo)",
options: [{ words: true }],
errors: [{
- message: "Unary word operator 'new' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "new" },
type: "NewExpression"
}]
},
@@ -295,7 +299,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "new(Foo)",
options: [{ words: false }],
errors: [{
- message: "Unexpected space after unary word operator 'new'.",
+ messageId: "unexpectedAfterWord",
+ data: { word: "new" },
type: "NewExpression"
}]
},
@@ -304,7 +309,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "new (Foo())",
options: [{ words: true }],
errors: [{
- message: "Unary word operator 'new' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "new" },
type: "NewExpression"
}]
},
@@ -313,7 +319,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "new[foo][0]",
options: [{ words: false }],
errors: [{
- message: "Unexpected space after unary word operator 'new'.",
+ messageId: "unexpectedAfterWord",
+ data: { word: "new" },
type: "NewExpression"
}]
},
@@ -323,7 +330,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "typeof (foo)",
options: [{ words: true }],
errors: [{
- message: "Unary word operator 'typeof' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "typeof" },
type: "UnaryExpression"
}]
},
@@ -332,7 +340,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "typeof(foo)",
options: [{ words: false }],
errors: [{
- message: "Unexpected space after unary word operator 'typeof'.",
+ messageId: "unexpectedAfterWord",
+ data: { word: "typeof" },
type: "UnaryExpression"
}]
},
@@ -341,7 +350,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "typeof [foo]",
options: [{ words: true }],
errors: [{
- message: "Unary word operator 'typeof' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "typeof" },
type: "UnaryExpression"
}]
},
@@ -350,7 +360,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "typeof[foo]",
options: [{ words: false }],
errors: [{
- message: "Unexpected space after unary word operator 'typeof'.",
+ messageId: "unexpectedAfterWord",
+ data: { word: "typeof" },
type: "UnaryExpression"
}]
},
@@ -359,7 +370,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "typeof {foo:true}",
options: [{ words: true }],
errors: [{
- message: "Unary word operator 'typeof' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "typeof" },
type: "UnaryExpression"
}]
},
@@ -368,7 +380,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "typeof{foo:true}",
options: [{ words: false }],
errors: [{
- message: "Unexpected space after unary word operator 'typeof'.",
+ messageId: "unexpectedAfterWord",
+ data: { word: "typeof" },
type: "UnaryExpression"
}]
},
@@ -377,7 +390,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "typeof !foo",
options: [{ words: true }],
errors: [{
- message: "Unary word operator 'typeof' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "typeof" },
type: "UnaryExpression"
}]
},
@@ -387,7 +401,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "void (0);",
options: [{ words: true }],
errors: [{
- message: "Unary word operator 'void' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "void" },
type: "UnaryExpression"
}]
},
@@ -396,7 +411,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "void (foo);",
options: [{ words: true }],
errors: [{
- message: "Unary word operator 'void' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "void" },
type: "UnaryExpression"
}]
},
@@ -405,7 +421,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "void [foo];",
options: [{ words: true }],
errors: [{
- message: "Unary word operator 'void' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "void" },
type: "UnaryExpression"
}]
},
@@ -414,7 +431,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "void {a:0};",
options: [{ words: true }],
errors: [{
- message: "Unary word operator 'void' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "void" },
type: "UnaryExpression"
}]
},
@@ -423,7 +441,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "void(foo)",
options: [{ words: false }],
errors: [{
- message: "Unexpected space after unary word operator 'void'.",
+ messageId: "unexpectedAfterWord",
+ data: { word: "void" },
type: "UnaryExpression"
}]
},
@@ -432,7 +451,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "void[foo]",
options: [{ words: false }],
errors: [{
- message: "Unexpected space after unary word operator 'void'.",
+ messageId: "unexpectedAfterWord",
+ data: { word: "void" },
type: "UnaryExpression"
}]
},
@@ -442,7 +462,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "!foo",
options: [{ nonwords: false }],
errors: [{
- message: "Unexpected space after unary operator '!'."
+ messageId: "unexpectedAfter",
+ data: { operator: "!" }
}]
},
{
@@ -450,7 +471,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "! foo",
options: [{ nonwords: true }],
errors: [{
- message: "Unary operator '!' must be followed by whitespace."
+ messageId: "operator",
+ data: { operator: "!" }
}]
},
@@ -459,7 +481,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "!!foo",
options: [{ nonwords: false }],
errors: [{
- message: "Unexpected space after unary operator '!'.",
+ messageId: "unexpectedAfter",
+ data: { operator: "!" },
type: "UnaryExpression",
line: 1,
column: 2
@@ -470,7 +493,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "!! foo",
options: [{ nonwords: true }],
errors: [{
- message: "Unary operator '!' must be followed by whitespace.",
+ messageId: "operator",
+ data: { operator: "!" },
type: "UnaryExpression",
line: 1,
column: 2
@@ -482,7 +506,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "-1",
options: [{ nonwords: false }],
errors: [{
- message: "Unexpected space after unary operator '-'.",
+ messageId: "unexpectedAfter",
+ data: { operator: "-" },
type: "UnaryExpression"
}]
},
@@ -491,7 +516,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "- 1",
options: [{ nonwords: true }],
errors: [{
- message: "Unary operator '-' must be followed by whitespace.",
+ messageId: "operator",
+ data: { operator: "-" },
type: "UnaryExpression"
}]
},
@@ -501,7 +527,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "foo ++",
options: [{ nonwords: true }],
errors: [{
- message: "Space is required before unary expressions '++'."
+ messageId: "beforeUnaryExpressions",
+ data: { token: "++" }
}]
},
{
@@ -509,7 +536,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "foo++",
options: [{ nonwords: false }],
errors: [{
- message: "Unexpected space before unary operator '++'."
+ messageId: "unexpectedBefore",
+ data: { operator: "++" }
}]
},
{
@@ -517,7 +545,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "++foo",
options: [{ nonwords: false }],
errors: [{
- message: "Unexpected space after unary operator '++'."
+ messageId: "unexpectedAfter",
+ data: { operator: "++" }
}]
},
{
@@ -525,7 +554,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "++ foo",
options: [{ nonwords: true }],
errors: [{
- message: "Unary operator '++' must be followed by whitespace."
+ messageId: "operator",
+ data: { operator: "++" }
}]
},
{
@@ -533,14 +563,16 @@ ruleTester.run("space-unary-ops", rule, {
output: "foo .bar ++",
options: [{ nonwords: true }],
errors: [{
- message: "Space is required before unary expressions '++'."
+ messageId: "beforeUnaryExpressions",
+ data: { token: "++" }
}]
},
{
code: "foo.bar --",
output: "foo.bar--",
errors: [{
- message: "Unexpected space before unary operator '--'."
+ messageId: "unexpectedBefore",
+ data: { operator: "--" }
}]
},
{
@@ -548,7 +580,8 @@ ruleTester.run("space-unary-ops", rule, {
output: null,
options: [{ nonwords: false }],
errors: [{
- message: "Unexpected space after unary operator '+'."
+ messageId: "unexpectedAfter",
+ data: { operator: "+" }
}]
},
{
@@ -556,7 +589,8 @@ ruleTester.run("space-unary-ops", rule, {
output: null,
options: [{ nonwords: false }],
errors: [{
- message: "Unexpected space after unary operator '+'."
+ messageId: "unexpectedAfter",
+ data: { operator: "+" }
}]
},
{
@@ -564,7 +598,8 @@ ruleTester.run("space-unary-ops", rule, {
output: null,
options: [{ nonwords: false }],
errors: [{
- message: "Unexpected space after unary operator '-'."
+ messageId: "unexpectedAfter",
+ data: { operator: "-" }
}]
},
{
@@ -572,7 +607,8 @@ ruleTester.run("space-unary-ops", rule, {
output: null,
options: [{ nonwords: false }],
errors: [{
- message: "Unexpected space after unary operator '-'."
+ messageId: "unexpectedAfter",
+ data: { operator: "-" }
}]
},
{
@@ -580,7 +616,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "+-foo",
options: [{ nonwords: false }],
errors: [{
- message: "Unexpected space after unary operator '+'."
+ messageId: "unexpectedAfter",
+ data: { operator: "+" }
}]
},
{
@@ -588,7 +625,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "function *foo() { yield (0) }",
parserOptions: { ecmaVersion: 6 },
errors: [{
- message: "Unary word operator 'yield' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "yield" },
type: "YieldExpression",
line: 1,
column: 19
@@ -600,7 +638,8 @@ ruleTester.run("space-unary-ops", rule, {
options: [{ words: false }],
parserOptions: { ecmaVersion: 6 },
errors: [{
- message: "Unexpected space after unary word operator 'yield'.",
+ messageId: "unexpectedAfterWord",
+ data: { word: "yield" },
type: "YieldExpression",
line: 1,
column: 19
@@ -611,7 +650,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "function *foo() { yield +0 }",
parserOptions: { ecmaVersion: 6 },
errors: [{
- message: "Unary word operator 'yield' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "yield" },
type: "YieldExpression",
line: 1,
column: 19
@@ -622,7 +662,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "foo ++",
options: [{ nonwords: true, overrides: { "++": true } }],
errors: [{
- message: "Space is required before unary expressions '++'."
+ messageId: "beforeUnaryExpressions",
+ data: { token: "++" }
}]
},
{
@@ -630,7 +671,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "foo ++",
options: [{ nonwords: false, overrides: { "++": true } }],
errors: [{
- message: "Space is required before unary expressions '++'."
+ messageId: "beforeUnaryExpressions",
+ data: { token: "++" }
}]
},
{
@@ -638,7 +680,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "++ foo",
options: [{ nonwords: true, overrides: { "++": true } }],
errors: [{
- message: "Unary operator '++' must be followed by whitespace."
+ messageId: "operator",
+ data: { operator: "++" }
}]
},
{
@@ -646,7 +689,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "++ foo",
options: [{ nonwords: false, overrides: { "++": true } }],
errors: [{
- message: "Unary operator '++' must be followed by whitespace."
+ messageId: "operator",
+ data: { operator: "++" }
}]
},
{
@@ -654,7 +698,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "! foo",
options: [{ nonwords: true, overrides: { "!": true } }],
errors: [{
- message: "Unary operator '!' must be followed by whitespace."
+ messageId: "operator",
+ data: { operator: "!" }
}]
},
{
@@ -662,7 +707,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "! foo",
options: [{ nonwords: false, overrides: { "!": true } }],
errors: [{
- message: "Unary operator '!' must be followed by whitespace."
+ messageId: "operator",
+ data: { operator: "!" }
}]
},
{
@@ -670,7 +716,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "new (Foo)",
options: [{ words: true, overrides: { new: true } }],
errors: [{
- message: "Unary word operator 'new' must be followed by whitespace."
+ messageId: "wordOperator",
+ data: { word: "new" }
}]
},
{
@@ -678,7 +725,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "new (Foo)",
options: [{ words: false, overrides: { new: true } }],
errors: [{
- message: "Unary word operator 'new' must be followed by whitespace."
+ messageId: "wordOperator",
+ data: { word: "new" }
}]
},
{
@@ -687,7 +735,8 @@ ruleTester.run("space-unary-ops", rule, {
options: [{ words: true, overrides: { yield: true } }],
parserOptions: { ecmaVersion: 6 },
errors: [{
- message: "Unary word operator 'yield' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "yield" },
type: "YieldExpression",
line: 1,
column: 19
@@ -699,7 +748,8 @@ ruleTester.run("space-unary-ops", rule, {
options: [{ words: false, overrides: { yield: true } }],
parserOptions: { ecmaVersion: 6 },
errors: [{
- message: "Unary word operator 'yield' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "yield" },
type: "YieldExpression",
line: 1,
column: 19
@@ -710,7 +760,8 @@ ruleTester.run("space-unary-ops", rule, {
output: "async function foo() { await {foo: 'bar'} }",
parserOptions: { ecmaVersion: 8 },
errors: [{
- message: "Unary word operator 'await' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "await" },
type: "AwaitExpression",
line: 1,
column: 24
@@ -722,7 +773,8 @@ ruleTester.run("space-unary-ops", rule, {
options: [{ words: false, overrides: { await: true } }],
parserOptions: { ecmaVersion: 8 },
errors: [{
- message: "Unary word operator 'await' must be followed by whitespace.",
+ messageId: "wordOperator",
+ data: { word: "await" },
type: "AwaitExpression",
line: 1,
column: 24
@@ -734,7 +786,8 @@ ruleTester.run("space-unary-ops", rule, {
options: [{ words: false }],
parserOptions: { ecmaVersion: 8 },
errors: [{
- message: "Unexpected space after unary word operator 'await'.",
+ messageId: "unexpectedAfterWord",
+ data: { word: "await" },
type: "AwaitExpression",
line: 1,
column: 24
@@ -746,7 +799,8 @@ ruleTester.run("space-unary-ops", rule, {
options: [{ words: true, overrides: { await: false } }],
parserOptions: { ecmaVersion: 8 },
errors: [{
- message: "Unexpected space after unary word operator 'await'.",
+ messageId: "unexpectedAfterWord",
+ data: { word: "await" },
type: "AwaitExpression",
line: 1,
column: 24
diff --git a/tests/lib/rules/strict.js b/tests/lib/rules/strict.js
index 6c75f74b872..50be450874b 100644
--- a/tests/lib/rules/strict.js
+++ b/tests/lib/rules/strict.js
@@ -95,36 +95,36 @@ ruleTester.run("strict", rule, {
output: null,
options: ["never"],
errors: [
- { message: "Strict mode is not permitted.", type: "ExpressionStatement" }
+ { messageId: "never", type: "ExpressionStatement" }
]
}, {
code: "function foo() { 'use strict'; return; }",
output: null,
options: ["never"],
errors: [
- { message: "Strict mode is not permitted.", type: "ExpressionStatement" }
+ { messageId: "never", type: "ExpressionStatement" }
]
}, {
code: "var foo = function() { 'use strict'; return; };",
output: null,
options: ["never"],
errors: [
- { message: "Strict mode is not permitted.", type: "ExpressionStatement" }
+ { messageId: "never", type: "ExpressionStatement" }
]
}, {
code: "function foo() { return function() { 'use strict'; return; }; }",
output: null,
options: ["never"],
errors: [
- { message: "Strict mode is not permitted.", type: "ExpressionStatement" }
+ { messageId: "never", type: "ExpressionStatement" }
]
}, {
code: "'use strict'; function foo() { \"use strict\"; return; }",
output: null,
options: ["never"],
errors: [
- { message: "Strict mode is not permitted.", type: "ExpressionStatement" },
- { message: "Strict mode is not permitted.", type: "ExpressionStatement" }
+ { messageId: "never", type: "ExpressionStatement" },
+ { messageId: "never", type: "ExpressionStatement" }
]
}, {
code: "\"use strict\"; foo();",
@@ -132,7 +132,7 @@ ruleTester.run("strict", rule, {
options: ["never"],
parserOptions: { sourceType: "module" },
errors: [
- { message: "'use strict' is unnecessary inside of modules.", type: "ExpressionStatement" }
+ { messageId: "module", type: "ExpressionStatement" }
]
}, {
code: "'use strict'; function foo() { 'use strict'; return; }",
@@ -140,8 +140,8 @@ ruleTester.run("strict", rule, {
options: ["never"],
parserOptions: { ecmaFeatures: { impliedStrict: true } },
errors: [
- { message: "'use strict' is unnecessary when implied strict mode is enabled.", type: "ExpressionStatement" },
- { message: "'use strict' is unnecessary when implied strict mode is enabled.", type: "ExpressionStatement" }
+ { messageId: "implied", type: "ExpressionStatement" },
+ { messageId: "implied", type: "ExpressionStatement" }
]
}, {
code: "'use strict'; function foo() { 'use strict'; return; }",
@@ -149,8 +149,8 @@ ruleTester.run("strict", rule, {
options: ["never"],
parserOptions: { sourceType: "module", ecmaFeatures: { impliedStrict: true } },
errors: [
- { message: "'use strict' is unnecessary inside of modules.", type: "ExpressionStatement" },
- { message: "'use strict' is unnecessary inside of modules.", type: "ExpressionStatement" }
+ { messageId: "module", type: "ExpressionStatement" },
+ { messageId: "module", type: "ExpressionStatement" }
]
},
@@ -160,23 +160,23 @@ ruleTester.run("strict", rule, {
output: null,
options: ["global"],
errors: [
- { message: "Use the global form of 'use strict'.", type: "Program" }
+ { messageId: "global", type: "Program" }
]
}, {
code: "function foo() { 'use strict'; return; }",
output: null,
options: ["global"],
errors: [
- { message: "Use the global form of 'use strict'.", type: "Program" },
- { message: "Use the global form of 'use strict'.", type: "ExpressionStatement" }
+ { messageId: "global", type: "Program" },
+ { messageId: "global", type: "ExpressionStatement" }
]
}, {
code: "var foo = function() { 'use strict'; return; }",
output: null,
options: ["global"],
errors: [
- { message: "Use the global form of 'use strict'.", type: "Program" },
- { message: "Use the global form of 'use strict'.", type: "ExpressionStatement" }
+ { messageId: "global", type: "Program" },
+ { messageId: "global", type: "ExpressionStatement" }
]
}, {
code: "var foo = () => { 'use strict'; return () => 1; }",
@@ -184,29 +184,29 @@ ruleTester.run("strict", rule, {
options: ["global"],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Use the global form of 'use strict'.", type: "Program" },
- { message: "Use the global form of 'use strict'.", type: "ExpressionStatement" }
+ { messageId: "global", type: "Program" },
+ { messageId: "global", type: "ExpressionStatement" }
]
}, {
code: "'use strict'; function foo() { 'use strict'; return; }",
output: null,
options: ["global"],
errors: [
- { message: "Use the global form of 'use strict'.", type: "ExpressionStatement" }
+ { messageId: "global", type: "ExpressionStatement" }
]
}, {
code: "'use strict'; var foo = function() { 'use strict'; return; };",
output: null,
options: ["global"],
errors: [
- { message: "Use the global form of 'use strict'.", type: "ExpressionStatement" }
+ { messageId: "global", type: "ExpressionStatement" }
]
}, {
code: "'use strict'; 'use strict'; foo();",
output: "'use strict'; foo();",
options: ["global"],
errors: [
- { message: "Multiple 'use strict' directives.", type: "ExpressionStatement" }
+ { messageId: "multiple", type: "ExpressionStatement" }
]
}, {
code: "'use strict'; foo();",
@@ -214,7 +214,7 @@ ruleTester.run("strict", rule, {
options: ["global"],
parserOptions: { sourceType: "module" },
errors: [
- { message: "'use strict' is unnecessary inside of modules.", type: "ExpressionStatement" }
+ { messageId: "module", type: "ExpressionStatement" }
]
}, {
code: "'use strict'; function foo() { 'use strict'; return; }",
@@ -222,8 +222,8 @@ ruleTester.run("strict", rule, {
options: ["global"],
parserOptions: { ecmaFeatures: { impliedStrict: true } },
errors: [
- { message: "'use strict' is unnecessary when implied strict mode is enabled.", type: "ExpressionStatement" },
- { message: "'use strict' is unnecessary when implied strict mode is enabled.", type: "ExpressionStatement" }
+ { messageId: "implied", type: "ExpressionStatement" },
+ { messageId: "implied", type: "ExpressionStatement" }
]
}, {
code: "'use strict'; function foo() { 'use strict'; return; }",
@@ -231,8 +231,8 @@ ruleTester.run("strict", rule, {
options: ["global"],
parserOptions: { sourceType: "module", ecmaFeatures: { impliedStrict: true } },
errors: [
- { message: "'use strict' is unnecessary inside of modules.", type: "ExpressionStatement" },
- { message: "'use strict' is unnecessary inside of modules.", type: "ExpressionStatement" }
+ { messageId: "module", type: "ExpressionStatement" },
+ { messageId: "module", type: "ExpressionStatement" }
]
},
@@ -242,28 +242,28 @@ ruleTester.run("strict", rule, {
output: null,
options: ["function"],
errors: [
- { message: "Use the function form of 'use strict'.", type: "ExpressionStatement" }
+ { messageId: "function", type: "ExpressionStatement" }
]
}, {
code: "'use strict'; (function() { 'use strict'; return true; }());",
output: null,
options: ["function"],
errors: [
- { message: "Use the function form of 'use strict'.", type: "ExpressionStatement" }
+ { messageId: "function", type: "ExpressionStatement" }
]
}, {
code: "(function() { 'use strict'; function f() { 'use strict'; return } return true; }());",
output: "(function() { 'use strict'; function f() { return } return true; }());",
options: ["function"],
errors: [
- { message: "Unnecessary 'use strict' directive.", type: "ExpressionStatement" }
+ { messageId: "unnecessary", type: "ExpressionStatement" }
]
}, {
code: "(function() { return true; }());",
output: null,
options: ["function"],
errors: [
- { message: "Use the function form of 'use strict'.", type: "FunctionExpression" }
+ { messageId: "function", type: "FunctionExpression" }
]
}, {
code: "(() => { return true; })();",
@@ -271,7 +271,7 @@ ruleTester.run("strict", rule, {
options: ["function"],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Use the function form of 'use strict'.", type: "ArrowFunctionExpression" }
+ { messageId: "function", type: "ArrowFunctionExpression" }
]
}, {
code: "(() => true)();",
@@ -279,29 +279,29 @@ ruleTester.run("strict", rule, {
options: ["function"],
parserOptions: { ecmaVersion: 6 },
errors: [
- { message: "Use the function form of 'use strict'.", type: "ArrowFunctionExpression" }
+ { messageId: "function", type: "ArrowFunctionExpression" }
]
}, {
code: "var foo = function() { foo(); 'use strict'; return; }; function bar() { foo(); 'use strict'; }",
output: null,
options: ["function"],
errors: [
- { message: "Use the function form of 'use strict'.", type: "FunctionExpression" },
- { message: "Use the function form of 'use strict'.", type: "FunctionDeclaration" }
+ { messageId: "function", type: "FunctionExpression" },
+ { messageId: "function", type: "FunctionDeclaration" }
]
}, {
code: "function foo() { 'use strict'; 'use strict'; return; }",
output: "function foo() { 'use strict'; return; }",
options: ["function"],
errors: [
- { message: "Multiple 'use strict' directives.", type: "ExpressionStatement" }
+ { messageId: "multiple", type: "ExpressionStatement" }
]
}, {
code: "var foo = function() { 'use strict'; 'use strict'; return; }",
output: "var foo = function() { 'use strict'; return; }",
options: ["function"],
errors: [
- { message: "Multiple 'use strict' directives.", type: "ExpressionStatement" }
+ { messageId: "multiple", type: "ExpressionStatement" }
]
}, {
code: "var foo = function() { 'use strict'; return; }",
@@ -309,7 +309,7 @@ ruleTester.run("strict", rule, {
options: ["function"],
parserOptions: { sourceType: "module" },
errors: [
- { message: "'use strict' is unnecessary inside of modules.", type: "ExpressionStatement" }
+ { messageId: "module", type: "ExpressionStatement" }
]
}, {
code: "'use strict'; function foo() { 'use strict'; return; }",
@@ -317,8 +317,8 @@ ruleTester.run("strict", rule, {
options: ["function"],
parserOptions: { ecmaFeatures: { impliedStrict: true } },
errors: [
- { message: "'use strict' is unnecessary when implied strict mode is enabled.", type: "ExpressionStatement" },
- { message: "'use strict' is unnecessary when implied strict mode is enabled.", type: "ExpressionStatement" }
+ { messageId: "implied", type: "ExpressionStatement" },
+ { messageId: "implied", type: "ExpressionStatement" }
]
}, {
code: "'use strict'; function foo() { 'use strict'; return; }",
@@ -326,52 +326,52 @@ ruleTester.run("strict", rule, {
options: ["function"],
parserOptions: { sourceType: "module", ecmaFeatures: { impliedStrict: true } },
errors: [
- { message: "'use strict' is unnecessary inside of modules.", type: "ExpressionStatement" },
- { message: "'use strict' is unnecessary inside of modules.", type: "ExpressionStatement" }
+ { messageId: "module", type: "ExpressionStatement" },
+ { messageId: "module", type: "ExpressionStatement" }
]
}, {
code: "function foo() { return function() { 'use strict'; return; }; }",
output: null,
options: ["function"],
errors: [
- { message: "Use the function form of 'use strict'.", type: "FunctionDeclaration" }
+ { messageId: "function", type: "FunctionDeclaration" }
]
}, {
code: "var foo = function() { function bar() { 'use strict'; return; } return; }",
output: null,
options: ["function"],
errors: [
- { message: "Use the function form of 'use strict'.", type: "FunctionExpression" }
+ { messageId: "function", type: "FunctionExpression" }
]
}, {
code: "function foo() { 'use strict'; return; } var bar = function() { return; };",
output: null,
options: ["function"],
errors: [
- { message: "Use the function form of 'use strict'.", type: "FunctionExpression" }
+ { messageId: "function", type: "FunctionExpression" }
]
}, {
code: "var foo = function() { 'use strict'; return; }; function bar() { return; };",
output: null,
options: ["function"],
errors: [
- { message: "Use the function form of 'use strict'.", type: "FunctionDeclaration" }
+ { messageId: "function", type: "FunctionDeclaration" }
]
}, {
code: "function foo() { 'use strict'; return function() { 'use strict'; 'use strict'; return; }; }",
output: "function foo() { 'use strict'; return function() { return; }; }",
options: ["function"],
errors: [
- { message: "Unnecessary 'use strict' directive.", type: "ExpressionStatement" },
- { message: "Multiple 'use strict' directives.", type: "ExpressionStatement" }
+ { messageId: "unnecessary", type: "ExpressionStatement" },
+ { messageId: "multiple", type: "ExpressionStatement" }
]
}, {
code: "var foo = function() { 'use strict'; function bar() { 'use strict'; 'use strict'; return; } }",
output: "var foo = function() { 'use strict'; function bar() { return; } }",
options: ["function"],
errors: [
- { message: "Unnecessary 'use strict' directive.", type: "ExpressionStatement" },
- { message: "Multiple 'use strict' directives.", type: "ExpressionStatement" }
+ { messageId: "unnecessary", type: "ExpressionStatement" },
+ { messageId: "multiple", type: "ExpressionStatement" }
]
},
{
@@ -379,7 +379,7 @@ ruleTester.run("strict", rule, {
output: null,
options: ["function"],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: "Use the function form of 'use strict'.", type: "ArrowFunctionExpression" }]
+ errors: [{ messageId: "function", type: "ArrowFunctionExpression" }]
},
// Classes
@@ -388,21 +388,21 @@ ruleTester.run("strict", rule, {
output: "class A { constructor() { } }",
options: ["function"],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: "'use strict' is unnecessary inside of classes.", type: "ExpressionStatement" }]
+ errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }]
},
{
code: "class A { foo() { \"use strict\"; } }",
output: "class A { foo() { } }",
options: ["function"],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: "'use strict' is unnecessary inside of classes.", type: "ExpressionStatement" }]
+ errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }]
},
{
code: "class A { foo() { function bar() { \"use strict\"; } } }",
output: "class A { foo() { function bar() { } } }",
options: ["function"],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: "'use strict' is unnecessary inside of classes.", type: "ExpressionStatement" }]
+ errors: [{ messageId: "unnecessaryInClasses", type: "ExpressionStatement" }]
},
@@ -412,8 +412,8 @@ ruleTester.run("strict", rule, {
output: null,
options: ["safe"],
errors: [
- { message: "Use the function form of 'use strict'.", type: "ExpressionStatement" },
- { message: "Use the function form of 'use strict'.", type: "FunctionDeclaration" }
+ { messageId: "function", type: "ExpressionStatement" },
+ { messageId: "function", type: "FunctionDeclaration" }
]
},
{
@@ -422,8 +422,8 @@ ruleTester.run("strict", rule, {
options: ["safe"],
parserOptions: { ecmaFeatures: { globalReturn: true } },
errors: [
- { message: "Use the global form of 'use strict'.", type: "Program" },
- { message: "Use the global form of 'use strict'.", type: "ExpressionStatement" }
+ { messageId: "global", type: "Program" },
+ { messageId: "global", type: "ExpressionStatement" }
]
},
{
@@ -432,8 +432,8 @@ ruleTester.run("strict", rule, {
options: ["safe"],
parserOptions: { ecmaFeatures: { impliedStrict: true } },
errors: [
- { message: "'use strict' is unnecessary when implied strict mode is enabled.", type: "ExpressionStatement" },
- { message: "'use strict' is unnecessary when implied strict mode is enabled.", type: "ExpressionStatement" }
+ { messageId: "implied", type: "ExpressionStatement" },
+ { messageId: "implied", type: "ExpressionStatement" }
]
},
{
@@ -442,8 +442,8 @@ ruleTester.run("strict", rule, {
options: ["safe"],
parserOptions: { sourceType: "module", ecmaFeatures: { impliedStrict: true } },
errors: [
- { message: "'use strict' is unnecessary inside of modules.", type: "ExpressionStatement" },
- { message: "'use strict' is unnecessary inside of modules.", type: "ExpressionStatement" }
+ { messageId: "module", type: "ExpressionStatement" },
+ { messageId: "module", type: "ExpressionStatement" }
]
},
@@ -452,22 +452,22 @@ ruleTester.run("strict", rule, {
code: "'use strict'; function foo() { return; }",
output: null,
errors: [
- { message: "Use the function form of 'use strict'.", type: "ExpressionStatement" },
- { message: "Use the function form of 'use strict'.", type: "FunctionDeclaration" }
+ { messageId: "function", type: "ExpressionStatement" },
+ { messageId: "function", type: "FunctionDeclaration" }
]
},
{
code: "function foo() { return; }",
output: null,
- errors: [{ message: "Use the function form of 'use strict'.", type: "FunctionDeclaration" }]
+ errors: [{ messageId: "function", type: "FunctionDeclaration" }]
},
{
code: "function foo() { 'use strict'; return; }",
output: null,
parserOptions: { ecmaFeatures: { globalReturn: true } },
errors: [
- { message: "Use the global form of 'use strict'.", type: "Program" },
- { message: "Use the global form of 'use strict'.", type: "ExpressionStatement" }
+ { messageId: "global", type: "Program" },
+ { messageId: "global", type: "ExpressionStatement" }
]
},
{
@@ -475,8 +475,8 @@ ruleTester.run("strict", rule, {
output: " function foo() { return; }",
parserOptions: { ecmaFeatures: { impliedStrict: true } },
errors: [
- { message: "'use strict' is unnecessary when implied strict mode is enabled.", type: "ExpressionStatement" },
- { message: "'use strict' is unnecessary when implied strict mode is enabled.", type: "ExpressionStatement" }
+ { messageId: "implied", type: "ExpressionStatement" },
+ { messageId: "implied", type: "ExpressionStatement" }
]
},
{
@@ -484,8 +484,8 @@ ruleTester.run("strict", rule, {
output: " function foo() { return; }",
parserOptions: { sourceType: "module", ecmaFeatures: { impliedStrict: true } },
errors: [
- { message: "'use strict' is unnecessary inside of modules.", type: "ExpressionStatement" },
- { message: "'use strict' is unnecessary inside of modules.", type: "ExpressionStatement" }
+ { messageId: "module", type: "ExpressionStatement" },
+ { messageId: "module", type: "ExpressionStatement" }
]
},
@@ -495,14 +495,14 @@ ruleTester.run("strict", rule, {
output: null,
options: [],
parserOptions: { ecmaVersion: 6 },
- errors: ["'use strict' directive inside a function with non-simple parameter list throws a syntax error since ES2016."]
+ errors: [{ messageId: "nonSimpleParameterList" }]
},
{
code: "(function() { 'use strict'; function foo(a = 0) { 'use strict' } }())",
output: null,
options: [],
parserOptions: { ecmaVersion: 6 },
- errors: ["'use strict' directive inside a function with non-simple parameter list throws a syntax error since ES2016."]
+ errors: [{ messageId: "nonSimpleParameterList" }]
},
{
code: "function foo(a = 0) { 'use strict' }",
@@ -511,7 +511,7 @@ ruleTester.run("strict", rule, {
parserOptions: { ecmaVersion: 6, ecmaFeatures: { globalReturn: true } },
errors: [
"Use the global form of 'use strict'.",
- "'use strict' directive inside a function with non-simple parameter list throws a syntax error since ES2016."
+ { messageId: "nonSimpleParameterList" }
]
},
{
@@ -519,14 +519,14 @@ ruleTester.run("strict", rule, {
output: null,
options: [],
parserOptions: { ecmaVersion: 6, ecmaFeatures: { globalReturn: true } },
- errors: ["'use strict' directive inside a function with non-simple parameter list throws a syntax error since ES2016."]
+ errors: [{ messageId: "nonSimpleParameterList" }]
},
{
code: "function foo(a = 0) { 'use strict' }",
output: null,
options: ["never"],
parserOptions: { ecmaVersion: 6 },
- errors: ["'use strict' directive inside a function with non-simple parameter list throws a syntax error since ES2016."]
+ errors: [{ messageId: "nonSimpleParameterList" }]
},
{
code: "function foo(a = 0) { 'use strict' }",
@@ -535,7 +535,7 @@ ruleTester.run("strict", rule, {
parserOptions: { ecmaVersion: 6 },
errors: [
"Use the global form of 'use strict'.",
- "'use strict' directive inside a function with non-simple parameter list throws a syntax error since ES2016."
+ { messageId: "nonSimpleParameterList" }
]
},
{
@@ -543,28 +543,28 @@ ruleTester.run("strict", rule, {
output: null,
options: ["global"],
parserOptions: { ecmaVersion: 6 },
- errors: ["'use strict' directive inside a function with non-simple parameter list throws a syntax error since ES2016."]
+ errors: [{ messageId: "nonSimpleParameterList" }]
},
{
code: "function foo(a = 0) { 'use strict' }",
output: null,
options: ["function"],
parserOptions: { ecmaVersion: 6 },
- errors: ["'use strict' directive inside a function with non-simple parameter list throws a syntax error since ES2016."]
+ errors: [{ messageId: "nonSimpleParameterList" }]
},
{
code: "(function() { 'use strict'; function foo(a = 0) { 'use strict' } }())",
output: null,
options: ["function"],
parserOptions: { ecmaVersion: 6 },
- errors: ["'use strict' directive inside a function with non-simple parameter list throws a syntax error since ES2016."]
+ errors: [{ messageId: "nonSimpleParameterList" }]
},
{
code: "function foo(a = 0) { }",
output: null,
options: ["function"],
parserOptions: { ecmaVersion: 6 },
- errors: ["Wrap function 'foo' in a function with 'use strict' directive."]
+ errors: [{ messageId: "wrap", data: { name: "function 'foo'" } }]
},
{
code: "(function() { function foo(a = 0) { } }())",
diff --git a/tests/lib/rules/switch-colon-spacing.js b/tests/lib/rules/switch-colon-spacing.js
index 009f2163856..f09b2e2060b 100644
--- a/tests/lib/rules/switch-colon-spacing.js
+++ b/tests/lib/rules/switch-colon-spacing.js
@@ -18,6 +18,11 @@ const rule = require("../../../lib/rules/switch-colon-spacing"),
const ruleTester = new RuleTester();
+const expectedBeforeError = { messagesId: "expectedBefore" };
+const expectedAfterError = { messagesId: "expectedAfter" };
+const unexpectedBeforeError = { messagesId: "unexpectedBefore" };
+const unexpectedAfterError = { messagesId: "unexpectedAfter" };
+
ruleTester.run("switch-colon-spacing", rule, {
valid: [
"switch(a){}",
@@ -59,16 +64,16 @@ ruleTester.run("switch-colon-spacing", rule, {
code: "switch(a){case 0 :break;}",
output: "switch(a){case 0: break;}",
errors: [
- "Unexpected space(s) before this colon.",
- "Expected space(s) after this colon."
+ unexpectedBeforeError,
+ expectedAfterError
]
},
{
code: "switch(a){default :break;}",
output: "switch(a){default: break;}",
errors: [
- "Unexpected space(s) before this colon.",
- "Expected space(s) after this colon."
+ unexpectedBeforeError,
+ expectedAfterError
]
},
{
@@ -76,8 +81,8 @@ ruleTester.run("switch-colon-spacing", rule, {
output: "switch(a){case 0:break;}",
options: [{ before: false, after: false }],
errors: [
- "Unexpected space(s) before this colon.",
- "Unexpected space(s) after this colon."
+ unexpectedBeforeError,
+ unexpectedAfterError
]
},
{
@@ -85,8 +90,8 @@ ruleTester.run("switch-colon-spacing", rule, {
output: "switch(a){default:break;}",
options: [{ before: false, after: false }],
errors: [
- "Unexpected space(s) before this colon.",
- "Unexpected space(s) after this colon."
+ unexpectedBeforeError,
+ unexpectedAfterError
]
},
{
@@ -94,8 +99,8 @@ ruleTester.run("switch-colon-spacing", rule, {
output: "switch(a){case 0: break;}",
options: [{ before: false, after: true }],
errors: [
- "Unexpected space(s) before this colon.",
- "Expected space(s) after this colon."
+ unexpectedBeforeError,
+ expectedAfterError
]
},
{
@@ -103,8 +108,8 @@ ruleTester.run("switch-colon-spacing", rule, {
output: "switch(a){default: break;}",
options: [{ before: false, after: true }],
errors: [
- "Unexpected space(s) before this colon.",
- "Expected space(s) after this colon."
+ unexpectedBeforeError,
+ expectedAfterError
]
},
{
@@ -112,8 +117,8 @@ ruleTester.run("switch-colon-spacing", rule, {
output: "switch(a){case 0 :break;}",
options: [{ before: true, after: false }],
errors: [
- "Expected space(s) before this colon.",
- "Unexpected space(s) after this colon."
+ expectedBeforeError,
+ unexpectedAfterError
]
},
{
@@ -121,8 +126,8 @@ ruleTester.run("switch-colon-spacing", rule, {
output: "switch(a){default :break;}",
options: [{ before: true, after: false }],
errors: [
- "Expected space(s) before this colon.",
- "Unexpected space(s) after this colon."
+ expectedBeforeError,
+ unexpectedAfterError
]
},
{
@@ -130,8 +135,8 @@ ruleTester.run("switch-colon-spacing", rule, {
output: "switch(a){case 0 : break;}",
options: [{ before: true, after: true }],
errors: [
- "Expected space(s) before this colon.",
- "Expected space(s) after this colon."
+ expectedBeforeError,
+ expectedAfterError
]
},
{
@@ -139,32 +144,32 @@ ruleTester.run("switch-colon-spacing", rule, {
output: "switch(a){default : break;}",
options: [{ before: true, after: true }],
errors: [
- "Expected space(s) before this colon.",
- "Expected space(s) after this colon."
+ expectedBeforeError,
+ expectedAfterError
]
},
{
code: "switch(a){case 0 /**/ :break;}",
output: "switch(a){case 0 /**/ : break;}",
errors: [
- "Unexpected space(s) before this colon.",
- "Expected space(s) after this colon."
+ unexpectedBeforeError,
+ expectedAfterError
]
},
{
code: "switch(a){case 0 :/**/break;}",
output: "switch(a){case 0:/**/break;}",
errors: [
- "Unexpected space(s) before this colon.",
- "Expected space(s) after this colon."
+ unexpectedBeforeError,
+ expectedAfterError
]
},
{
code: "switch(a){case (0) :break;}",
output: "switch(a){case (0): break;}",
errors: [
- "Unexpected space(s) before this colon.",
- "Expected space(s) after this colon."
+ unexpectedBeforeError,
+ expectedAfterError
]
}
]
diff --git a/tests/lib/rules/symbol-description.js b/tests/lib/rules/symbol-description.js
index 4c0dc076d73..f9d68995ff1 100644
--- a/tests/lib/rules/symbol-description.js
+++ b/tests/lib/rules/symbol-description.js
@@ -33,14 +33,14 @@ ruleTester.run("symbol-description", rule, {
{
code: "Symbol();",
errors: [{
- message: "Expected Symbol to have a description.",
+ messageId: "expected",
type: "CallExpression"
}]
},
{
code: "Symbol(); Symbol = function () {};",
errors: [{
- message: "Expected Symbol to have a description.",
+ messageId: "expected",
type: "CallExpression"
}]
}
diff --git a/tests/lib/rules/template-curly-spacing.js b/tests/lib/rules/template-curly-spacing.js
index 3331b8f934c..bd40184542d 100644
--- a/tests/lib/rules/template-curly-spacing.js
+++ b/tests/lib/rules/template-curly-spacing.js
@@ -33,10 +33,10 @@ ruleTester.run("template-curly-spacing", rule, {
code: "`${ foo } ${ bar }`",
output: "`${foo} ${bar}`",
errors: [
- { message: "Unexpected space(s) after '${'.", column: 2 },
- { message: "Unexpected space(s) before '}'.", column: 9 },
- { message: "Unexpected space(s) after '${'.", column: 11 },
- { message: "Unexpected space(s) before '}'.", column: 18 }
+ { messageId: "unexpectedAfter", column: 2 },
+ { messageId: "unexpectedBefore", column: 9 },
+ { messageId: "unexpectedAfter", column: 11 },
+ { messageId: "unexpectedBefore", column: 18 }
]
},
{
@@ -44,10 +44,10 @@ ruleTester.run("template-curly-spacing", rule, {
output: "`${foo} ${bar}`",
options: ["never"],
errors: [
- { message: "Unexpected space(s) after '${'.", column: 2 },
- { message: "Unexpected space(s) before '}'.", column: 9 },
- { message: "Unexpected space(s) after '${'.", column: 11 },
- { message: "Unexpected space(s) before '}'.", column: 18 }
+ { messageId: "unexpectedAfter", column: 2 },
+ { messageId: "unexpectedBefore", column: 9 },
+ { messageId: "unexpectedAfter", column: 11 },
+ { messageId: "unexpectedBefore", column: 18 }
]
},
{
@@ -55,20 +55,20 @@ ruleTester.run("template-curly-spacing", rule, {
output: "`${ foo } ${ bar }`",
options: ["always"],
errors: [
- { message: "Expected space(s) after '${'.", column: 2 },
- { message: "Expected space(s) before '}'.", column: 7 },
- { message: "Expected space(s) after '${'.", column: 9 },
- { message: "Expected space(s) before '}'.", column: 14 }
+ { messageId: "expectedAfter", column: 2 },
+ { messageId: "expectedBefore", column: 7 },
+ { messageId: "expectedAfter", column: 9 },
+ { messageId: "expectedBefore", column: 14 }
]
},
{
code: "tag`${ foo } ${ bar }`",
output: "tag`${foo} ${bar}`",
errors: [
- { message: "Unexpected space(s) after '${'.", column: 5 },
- { message: "Unexpected space(s) before '}'.", column: 12 },
- { message: "Unexpected space(s) after '${'.", column: 14 },
- { message: "Unexpected space(s) before '}'.", column: 21 }
+ { messageId: "unexpectedAfter", column: 5 },
+ { messageId: "unexpectedBefore", column: 12 },
+ { messageId: "unexpectedAfter", column: 14 },
+ { messageId: "unexpectedBefore", column: 21 }
]
},
{
@@ -76,10 +76,10 @@ ruleTester.run("template-curly-spacing", rule, {
output: "tag`${foo} ${bar}`",
options: ["never"],
errors: [
- { message: "Unexpected space(s) after '${'.", column: 5 },
- { message: "Unexpected space(s) before '}'.", column: 12 },
- { message: "Unexpected space(s) after '${'.", column: 14 },
- { message: "Unexpected space(s) before '}'.", column: 21 }
+ { messageId: "unexpectedAfter", column: 5 },
+ { messageId: "unexpectedBefore", column: 12 },
+ { messageId: "unexpectedAfter", column: 14 },
+ { messageId: "unexpectedBefore", column: 21 }
]
},
{
@@ -87,10 +87,10 @@ ruleTester.run("template-curly-spacing", rule, {
output: "tag`${ foo } ${ bar }`",
options: ["always"],
errors: [
- { message: "Expected space(s) after '${'.", column: 5 },
- { message: "Expected space(s) before '}'.", column: 10 },
- { message: "Expected space(s) after '${'.", column: 12 },
- { message: "Expected space(s) before '}'.", column: 17 }
+ { messageId: "expectedAfter", column: 5 },
+ { messageId: "expectedBefore", column: 10 },
+ { messageId: "expectedAfter", column: 12 },
+ { messageId: "expectedBefore", column: 17 }
]
}
]
diff --git a/tests/lib/rules/template-tag-spacing.js b/tests/lib/rules/template-tag-spacing.js
index 2475d727ba2..4de2d807184 100644
--- a/tests/lib/rules/template-tag-spacing.js
+++ b/tests/lib/rules/template-tag-spacing.js
@@ -17,6 +17,8 @@ const rule = require("../../../lib/rules/template-tag-spacing"),
//------------------------------------------------------------------------------
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
+const unexpectedError = { messageId: "unexpected" };
+const missingError = { messageId: "missing" };
ruleTester.run("template-tag-spacing", rule, {
valid: [
@@ -53,225 +55,167 @@ ruleTester.run("template-tag-spacing", rule, {
{
code: "tag `name`",
output: "tag`name`",
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "tag `name`",
output: "tag`name`",
options: ["never"],
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "tag`name`",
output: "tag `name`",
options: ["always"],
- errors: [
- { message: "Missing space between template tag and template literal." }
- ]
+ errors: [missingError]
},
{
code: "tag /*here's a comment*/`Hello world`",
output: "tag/*here's a comment*/`Hello world`",
options: ["never"],
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "tag/*here's a comment*/ `Hello world`",
output: "tag/*here's a comment*/`Hello world`",
options: ["never"],
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "tag/*here's a comment*/`Hello world`",
output: "tag /*here's a comment*/`Hello world`",
options: ["always"],
- errors: [
- { message: "Missing space between template tag and template literal." }
- ]
+ errors: [missingError]
},
{
code: "tag // here's a comment \n`bar`",
output: null,
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "tag // here's a comment \n`bar`",
output: null,
options: ["never"],
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "tag `hello ${name}`",
output: "tag`hello ${name}`",
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "tag `hello ${name}`",
output: "tag`hello ${name}`",
options: ["never"],
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "tag`hello ${name}`",
output: "tag `hello ${name}`",
options: ["always"],
- errors: [
- { message: "Missing space between template tag and template literal." }
- ]
+ errors: [missingError]
},
{
code: "new tag `name`",
output: "new tag`name`",
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "new tag `name`",
output: "new tag`name`",
options: ["never"],
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "new tag`name`",
output: "new tag `name`",
options: ["always"],
- errors: [
- { message: "Missing space between template tag and template literal." }
- ]
+ errors: [missingError]
},
{
code: "new tag `hello ${name}`",
output: "new tag`hello ${name}`",
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "new tag `hello ${name}`",
output: "new tag`hello ${name}`",
options: ["never"],
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "new tag`hello ${name}`",
output: "new tag `hello ${name}`",
options: ["always"],
- errors: [
- { message: "Missing space between template tag and template literal." }
- ]
+ errors: [missingError]
},
{
code: "(tag) `name`",
output: "(tag)`name`",
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "(tag) `name`",
output: "(tag)`name`",
options: ["never"],
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "(tag)`name`",
output: "(tag) `name`",
options: ["always"],
- errors: [
- { message: "Missing space between template tag and template literal." }
- ]
+ errors: [missingError]
},
{
code: "(tag) `hello ${name}`",
output: "(tag)`hello ${name}`",
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "(tag) `hello ${name}`",
output: "(tag)`hello ${name}`",
options: ["never"],
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "(tag)`hello ${name}`",
output: "(tag) `hello ${name}`",
options: ["always"],
- errors: [
- { message: "Missing space between template tag and template literal." }
- ]
+ errors: [missingError]
},
{
code: "new (tag) `name`",
output: "new (tag)`name`",
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "new (tag) `name`",
output: "new (tag)`name`",
options: ["never"],
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "new (tag)`name`",
output: "new (tag) `name`",
options: ["always"],
- errors: [
- { message: "Missing space between template tag and template literal." }
- ]
+ errors: [missingError]
},
{
code: "new (tag) `hello ${name}`",
output: "new (tag)`hello ${name}`",
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "new (tag) `hello ${name}`",
output: "new (tag)`hello ${name}`",
options: ["never"],
- errors: [
- { message: "Unexpected space between template tag and template literal." }
- ]
+ errors: [unexpectedError]
},
{
code: "new (tag)`hello ${name}`",
output: "new (tag) `hello ${name}`",
options: ["always"],
- errors: [
- { message: "Missing space between template tag and template literal." }
- ]
+ errors: [missingError]
}
]
});
diff --git a/tests/lib/rules/unicode-bom.js b/tests/lib/rules/unicode-bom.js
index f5b9899002f..c15563aad85 100644
--- a/tests/lib/rules/unicode-bom.js
+++ b/tests/lib/rules/unicode-bom.js
@@ -16,6 +16,8 @@ const rule = require("../../../lib/rules/unicode-bom"),
//------------------------------------------------------------------------------
const ruleTester = new RuleTester();
+const expectedError = { messageId: "expected", type: "Program" };
+const unexpectedError = { messageId: "unexpected", type: "Program" };
ruleTester.run("unicode-bom", rule, {
@@ -39,24 +41,24 @@ ruleTester.run("unicode-bom", rule, {
code: "var a = 123;",
output: "\uFEFFvar a = 123;",
options: ["always"],
- errors: [{ message: "Expected Unicode BOM (Byte Order Mark).", type: "Program" }]
+ errors: [expectedError]
},
{
code: " // here's a comment \nvar a = 123;",
output: "\uFEFF // here's a comment \nvar a = 123;",
options: ["always"],
- errors: [{ message: "Expected Unicode BOM (Byte Order Mark).", type: "Program" }]
+ errors: [expectedError]
},
{
code: "\uFEFF var a = 123;",
output: " var a = 123;",
- errors: [{ message: "Unexpected Unicode BOM (Byte Order Mark).", type: "Program" }]
+ errors: [unexpectedError]
},
{
code: "\uFEFF var a = 123;",
output: " var a = 123;",
options: ["never"],
- errors: [{ message: "Unexpected Unicode BOM (Byte Order Mark).", type: "Program" }]
+ errors: [unexpectedError]
}
]
});
diff --git a/tests/lib/rules/use-isnan.js b/tests/lib/rules/use-isnan.js
index 9b42b61668a..865a656c1f5 100644
--- a/tests/lib/rules/use-isnan.js
+++ b/tests/lib/rules/use-isnan.js
@@ -16,9 +16,10 @@ const rule = require("../../../lib/rules/use-isnan"),
// Tests
//------------------------------------------------------------------------------
-
const ruleTester = new RuleTester();
+const error = { messageId: "useIsNaN", type: "BinaryExpression" };
+
ruleTester.run("use-isnan", rule, {
valid: [
"var x = NaN;",
@@ -39,67 +40,67 @@ ruleTester.run("use-isnan", rule, {
invalid: [
{
code: "123 == NaN;",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "123 === NaN;",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "NaN === \"abc\";",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "NaN == \"abc\";",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "123 != NaN;",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "123 !== NaN;",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "NaN !== \"abc\";",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "NaN != \"abc\";",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "NaN < \"abc\";",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "\"abc\" < NaN;",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "NaN > \"abc\";",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "\"abc\" > NaN;",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "NaN <= \"abc\";",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "\"abc\" <= NaN;",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "NaN >= \"abc\";",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
},
{
code: "\"abc\" >= NaN;",
- errors: [{ message: "Use the isNaN function to compare with NaN.", type: "BinaryExpression" }]
+ errors: [error]
}
]
});
diff --git a/tests/lib/rules/valid-jsdoc.js b/tests/lib/rules/valid-jsdoc.js
index c300d08ea94..33e9e53df9b 100644
--- a/tests/lib/rules/valid-jsdoc.js
+++ b/tests/lib/rules/valid-jsdoc.js
@@ -1088,7 +1088,8 @@ ruleTester.run("valid-jsdoc", rule, {
output: null,
options: [{ requireReturn: false }],
errors: [{
- message: "Expected JSDoc for 'argName' but found 'bogusName'.",
+ messageId: "expected",
+ data: { name: "argName", jsdocName: "bogusName" },
type: "Block",
line: 4,
column: 6,
@@ -1100,7 +1101,7 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/** @@foo */\nfunction foo(){}",
output: null,
errors: [{
- message: "JSDoc syntax error.",
+ messageId: "syntaxError",
type: "Block"
}]
},
@@ -1120,7 +1121,8 @@ ruleTester.run("valid-jsdoc", rule, {
output: null,
options: [{ requireReturn: false }],
errors: [{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}]
},
@@ -1128,7 +1130,7 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/** @@returns {void} Foo */\nfunction foo(){}",
output: null,
errors: [{
- message: "JSDoc syntax error.",
+ messageId: "syntaxError",
type: "Block"
}]
},
@@ -1136,7 +1138,7 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/** Foo \n@returns {void Foo\n */\nfunction foo(){}",
output: null,
errors: [{
- message: "JSDoc type missing brace.",
+ messageId: "missingBrace",
type: "Block"
}]
},
@@ -1145,7 +1147,8 @@ ruleTester.run("valid-jsdoc", rule, {
output: "/** Foo \n@returns {void} Foo\n */\nfunction foo(){}",
options: [{ prefer: { return: "returns" } }],
errors: [{
- message: "Use @returns instead.",
+ messageId: "use",
+ data: { name: "returns" },
type: "Block",
line: 2,
column: 1,
@@ -1158,10 +1161,12 @@ ruleTester.run("valid-jsdoc", rule, {
output: "/** Foo \n@arg {int} bar baz\n */\nfunction foo(bar){}",
options: [{ prefer: { argument: "arg" } }],
errors: [{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}, {
- message: "Use @arg instead.",
+ messageId: "use",
+ data: { name: "arg" },
type: "Block",
line: 2,
column: 1,
@@ -1174,7 +1179,8 @@ ruleTester.run("valid-jsdoc", rule, {
output: null,
options: [{ prefer: { returns: "return" } }],
errors: [{
- message: "Missing JSDoc @return for function.",
+ messageId: "missingReturn",
+ data: { returns: "return" },
type: "Block"
}]
},
@@ -1184,7 +1190,8 @@ ruleTester.run("valid-jsdoc", rule, {
options: [{ prefer: { return: "returns" } }],
parserOptions: { ecmaVersion: 6 },
errors: [{
- message: "Use @returns instead.",
+ messageId: "use",
+ data: { name: "returns" },
type: "Block",
line: 2,
column: 1,
@@ -1196,7 +1203,7 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/** Foo \n@param {void Foo\n */\nfunction foo(){}",
output: null,
errors: [{
- message: "JSDoc type missing brace.",
+ messageId: "missingBrace",
type: "Block"
}]
},
@@ -1204,7 +1211,7 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/** Foo \n@param {} p Bar\n */\nfunction foo(){}",
output: null,
errors: [{
- message: "JSDoc syntax error.",
+ messageId: "syntaxError",
type: "Block"
}]
},
@@ -1212,7 +1219,7 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/** Foo \n@param {void Foo */\nfunction foo(){}",
output: null,
errors: [{
- message: "JSDoc type missing brace.",
+ messageId: "missingBrace",
type: "Block"
}]
},
@@ -1220,10 +1227,12 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/** Foo\n* @param p Desc \n*/\nfunction foo(){}",
output: null,
errors: [{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}, {
- message: "Missing JSDoc parameter type for 'p'.",
+ messageId: "missingParamType",
+ data: { name: "p" },
type: "Block",
line: 2,
column: 3,
@@ -1235,10 +1244,12 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/**\n* Foo\n* @param {string} p \n*/\nfunction foo(){}",
output: null,
errors: [{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}, {
- message: "Missing JSDoc parameter description for 'p'.",
+ messageId: "missingParamDesc",
+ data: { name: "p" },
type: "Block",
line: 3,
column: 3,
@@ -1250,10 +1261,12 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/**\n* Foo\n* @param {string} p \n*/\nvar foo = function(){}",
output: null,
errors: [{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}, {
- message: "Missing JSDoc parameter description for 'p'.",
+ messageId: "missingParamDesc",
+ data: { name: "p" },
type: "Block",
line: 3,
column: 3,
@@ -1265,10 +1278,12 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/**\n* Foo\n* @param {string} p \n*/\nvar foo = \nfunction(){}",
output: null,
errors: [{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}, {
- message: "Missing JSDoc parameter description for 'p'.",
+ messageId: "missingParamDesc",
+ data: { name: "p" },
type: "Block",
line: 3,
column: 3,
@@ -1301,11 +1316,12 @@ ruleTester.run("valid-jsdoc", rule, {
},
errors: [
{
- message: "JSDoc description does not satisfy the regex pattern.",
+ messageId: "unsatisfiedDesc",
type: "Block"
},
{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}
]
@@ -1314,7 +1330,7 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/**\n* Foo\n* @returns {string} \n*/\nfunction foo(){}",
output: null,
errors: [{
- message: "Missing JSDoc return description.",
+ messageId: "missingReturnDesc",
type: "Block"
}]
},
@@ -1322,7 +1338,8 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/**\n* Foo\n* @returns {string} something \n*/\nfunction foo(p){}",
output: null,
errors: [{
- message: "Missing JSDoc for parameter 'p'.",
+ messageId: "missingParam",
+ data: { name: "p" },
type: "Block"
}]
},
@@ -1331,7 +1348,8 @@ ruleTester.run("valid-jsdoc", rule, {
output: null,
parserOptions: { ecmaVersion: 6 },
errors: [{
- message: "Missing JSDoc for parameter 'a'.",
+ messageId: "missingParam",
+ data: { name: "a" },
type: "Block"
}]
},
@@ -1340,7 +1358,8 @@ ruleTester.run("valid-jsdoc", rule, {
output: null,
parserOptions: { ecmaVersion: 6 },
errors: [{
- message: "Expected JSDoc for 'b' but found 'a'.",
+ messageId: "expected",
+ data: { name: "b", jsdocName: "a" },
type: "Block",
line: 3,
column: 3,
@@ -1348,7 +1367,8 @@ ruleTester.run("valid-jsdoc", rule, {
endColumn: 32
},
{
- message: "Expected JSDoc for 'a' but found 'b'.",
+ messageId: "expected",
+ data: { name: "a", jsdocName: "b" },
type: "Block",
line: 4,
column: 3,
@@ -1360,10 +1380,12 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/**\n* Foo\n* @param {string} p desc\n* @param {string} p desc \n*/\nfunction foo(){}",
output: null,
errors: [{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}, {
- message: "Duplicate JSDoc parameter 'p'.",
+ messageId: "duplicateParam",
+ data: { name: "p" },
type: "Block",
line: 4,
column: 3,
@@ -1375,7 +1397,8 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/**\n* Foo\n* @param {string} a desc\n@returns {void}*/\nfunction foo(b){}",
output: null,
errors: [{
- message: "Expected JSDoc for 'b' but found 'a'.",
+ messageId: "expected",
+ data: { name: "b", jsdocName: "a" },
type: "Block",
line: 3,
column: 3,
@@ -1387,7 +1410,8 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/**\n* Foo\n* @override\n* @param {string} a desc\n */\nfunction foo(b){}",
output: null,
errors: [{
- message: "Expected JSDoc for 'b' but found 'a'.",
+ messageId: "expected",
+ data: { name: "b", jsdocName: "a" },
type: "Block",
line: 4,
column: 3,
@@ -1399,7 +1423,8 @@ ruleTester.run("valid-jsdoc", rule, {
code: "/**\n* Foo\n* @inheritdoc\n* @param {string} a desc\n */\nfunction foo(b){}",
output: null,
errors: [{
- message: "Expected JSDoc for 'b' but found 'a'.",
+ messageId: "expected",
+ data: { name: "b", jsdocName: "a" },
type: "Block",
line: 4,
column: 3,
@@ -1412,7 +1437,8 @@ ruleTester.run("valid-jsdoc", rule, {
output: null,
options: [{ requireReturn: false }],
errors: [{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}]
},
@@ -1421,7 +1447,8 @@ ruleTester.run("valid-jsdoc", rule, {
output: null,
options: [{ requireReturn: false }],
errors: [{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}]
},
@@ -1430,7 +1457,8 @@ ruleTester.run("valid-jsdoc", rule, {
output: null,
options: [{ requireReturn: false }],
errors: [{
- message: "Unexpected @returns tag; function has no return statement.",
+ messageId: "unexpectedTag",
+ data: { title: "returns" },
type: "Block",
line: 4,
column: 1,
@@ -1444,7 +1472,8 @@ ruleTester.run("valid-jsdoc", rule, {
options: [{ prefer: { return: "returns" } }],
parserOptions: { sourceType: "module" },
errors: [{
- message: "Use @returns instead.",
+ messageId: "use",
+ data: { name: "returns" },
type: "Block",
line: 4,
column: 3,
@@ -1458,7 +1487,8 @@ ruleTester.run("valid-jsdoc", rule, {
options: [{ prefer: { return: "returns" } }],
parserOptions: { sourceType: "module" },
errors: [{
- message: "Use @returns instead.",
+ messageId: "use",
+ data: { name: "returns" },
type: "Block",
line: 4,
column: 3,
@@ -1472,7 +1502,8 @@ ruleTester.run("valid-jsdoc", rule, {
options: [{ requireReturn: false }],
parserOptions: { ecmaVersion: 6 },
errors: [{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}]
},
@@ -1482,7 +1513,8 @@ ruleTester.run("valid-jsdoc", rule, {
options: [{ requireReturn: false }],
parserOptions: { ecmaVersion: 6 },
errors: [{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}]
},
@@ -1492,7 +1524,8 @@ ruleTester.run("valid-jsdoc", rule, {
options: [{ requireReturn: false }],
parserOptions: { ecmaVersion: 6 },
errors: [{
- message: "Unexpected @returns tag; function has no return statement.",
+ messageId: "unexpectedTag",
+ data: { title: "returns" },
type: "Block",
line: 1,
column: 5,
@@ -1505,11 +1538,13 @@ ruleTester.run("valid-jsdoc", rule, {
output: null,
errors: [
{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
},
{
- message: "Missing JSDoc parameter type for 'fields'.",
+ messageId: "missingParamType",
+ data: { name: "fields" },
type: "Block",
line: 2,
column: 3,
@@ -1525,7 +1560,7 @@ ruleTester.run("valid-jsdoc", rule, {
matchDescription: "^[A-Z][A-Za-z0-9\\s]*[.]$"
}],
errors: [{
- message: "JSDoc description does not satisfy the regex pattern.",
+ messageId: "unsatisfiedDesc",
type: "Block"
}]
},
@@ -1534,7 +1569,7 @@ ruleTester.run("valid-jsdoc", rule, {
output: null,
options: [{ prefer: { return: "return" } }],
errors: [{
- message: "Missing JSDoc return type.",
+ messageId: "missingReturnType",
type: "Block"
}]
},
@@ -1546,7 +1581,8 @@ ruleTester.run("valid-jsdoc", rule, {
requireReturn: false
}],
errors: [{
- message: "Unexpected @return tag; function has no return statement.",
+ messageId: "unexpectedTag",
+ data: { title: "return" },
type: "Block",
line: 2,
column: 1,
@@ -1580,11 +1616,11 @@ ruleTester.run("valid-jsdoc", rule, {
},
errors: [
{
- message: "JSDoc description does not satisfy the regex pattern.",
+ messageId: "unsatisfiedDesc",
type: "Block"
},
{
- message: "JSDoc description does not satisfy the regex pattern.",
+ messageId: "unsatisfiedDesc",
type: "Block"
}
]
@@ -1613,11 +1649,12 @@ ruleTester.run("valid-jsdoc", rule, {
},
errors: [
{
- message: "JSDoc description does not satisfy the regex pattern.",
+ messageId: "unsatisfiedDesc",
type: "Block"
},
{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}
]
@@ -1650,11 +1687,13 @@ ruleTester.run("valid-jsdoc", rule, {
},
errors: [
{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
},
{
- message: "Missing JSDoc for parameter 'xs'.",
+ messageId: "missingParam",
+ data: { name: "xs" },
type: "Block"
}
]
@@ -1669,7 +1708,7 @@ ruleTester.run("valid-jsdoc", rule, {
output: null,
options: [{ requireReturn: false }],
errors: [{
- message: "JSDoc type missing brace.",
+ messageId: "missingBrace",
type: "Block"
}]
},
@@ -1683,7 +1722,7 @@ ruleTester.run("valid-jsdoc", rule, {
output: null,
options: [{ requireReturn: false }],
errors: [{
- message: "JSDoc syntax error.",
+ messageId: "syntaxError",
type: "Block"
}]
},
@@ -1701,7 +1740,8 @@ ruleTester.run("valid-jsdoc", rule, {
ecmaVersion: 2017
},
errors: [{
- message: "Missing JSDoc @returns for function.",
+ messageId: "missingReturn",
+ data: { returns: "returns" },
type: "Block"
}]
},
@@ -1730,7 +1770,8 @@ ruleTester.run("valid-jsdoc", rule, {
}],
errors: [
{
- message: "Use 'string' instead of 'String'.",
+ messageId: "useType",
+ data: { expectedTypeName: "string", currentTypeName: "String" },
type: "Block",
line: 3,
column: 11,
@@ -1738,7 +1779,8 @@ ruleTester.run("valid-jsdoc", rule, {
endColumn: 17
},
{
- message: "Use 'ASTNode' instead of 'Astnode'.",
+ messageId: "useType",
+ data: { expectedTypeName: "ASTNode", currentTypeName: "Astnode" },
type: "Block",
line: 4,
column: 13,
@@ -1770,7 +1812,8 @@ ruleTester.run("valid-jsdoc", rule, {
}],
errors: [
{
- message: "Use 'string' instead of 'String'.",
+ messageId: "useType",
+ data: { expectedTypeName: "string", currentTypeName: "String" },
type: "Block",
line: 3,
column: 15,
@@ -1778,7 +1821,8 @@ ruleTester.run("valid-jsdoc", rule, {
endColumn: 21
},
{
- message: "Use 'ASTNode' instead of 'Astnode'.",
+ messageId: "useType",
+ data: { expectedTypeName: "ASTNode", currentTypeName: "Astnode" },
type: "Block",
line: 4,
column: 13,
@@ -1809,7 +1853,8 @@ ruleTester.run("valid-jsdoc", rule, {
}],
errors: [
{
- message: "Use 'Test' instead of 'test'.",
+ messageId: "useType",
+ data: { expectedTypeName: "Test", currentTypeName: "test" },
type: "Block",
line: 3,
column: 25,
@@ -1841,7 +1886,8 @@ ruleTester.run("valid-jsdoc", rule, {
}],
errors: [
{
- message: "Use 'string' instead of 'String'.",
+ messageId: "useType",
+ data: { expectedTypeName: "string", currentTypeName: "String" },
type: "Block",
line: 3,
column: 18,
@@ -1873,7 +1919,8 @@ ruleTester.run("valid-jsdoc", rule, {
}],
errors: [
{
- message: "Use 'number' instead of 'Number'.",
+ messageId: "useType",
+ data: { expectedTypeName: "number", currentTypeName: "Number" },
type: "Block",
line: 3,
column: 23,
@@ -1881,7 +1928,8 @@ ruleTester.run("valid-jsdoc", rule, {
endColumn: 29
},
{
- message: "Use 'number' instead of 'Number'.",
+ messageId: "useType",
+ data: { expectedTypeName: "number", currentTypeName: "Number" },
type: "Block",
line: 3,
column: 38,
@@ -1889,7 +1937,8 @@ ruleTester.run("valid-jsdoc", rule, {
endColumn: 44
},
{
- message: "Use 'string' instead of 'String'.",
+ messageId: "useType",
+ data: { expectedTypeName: "string", currentTypeName: "String" },
type: "Block",
line: 4,
column: 30,
@@ -1921,7 +1970,8 @@ ruleTester.run("valid-jsdoc", rule, {
}],
errors: [
{
- message: "Use 'string' instead of 'String'.",
+ messageId: "useType",
+ data: { expectedTypeName: "string", currentTypeName: "String" },
type: "Block",
line: 3,
column: 19,
@@ -1929,7 +1979,8 @@ ruleTester.run("valid-jsdoc", rule, {
endColumn: 25
},
{
- message: "Use 'number' instead of 'Number'.",
+ messageId: "useType",
+ data: { expectedTypeName: "number", currentTypeName: "Number" },
type: "Block",
line: 3,
column: 27,
@@ -1937,7 +1988,8 @@ ruleTester.run("valid-jsdoc", rule, {
endColumn: 33
},
{
- message: "Use 'string' instead of 'String'.",
+ messageId: "useType",
+ data: { expectedTypeName: "string", currentTypeName: "String" },
type: "Block",
line: 4,
column: 21,
@@ -1945,7 +1997,8 @@ ruleTester.run("valid-jsdoc", rule, {
endColumn: 27
},
{
- message: "Use 'string' instead of 'String'.",
+ messageId: "useType",
+ data: { expectedTypeName: "string", currentTypeName: "String" },
type: "Block",
line: 4,
column: 29,
@@ -1978,7 +2031,8 @@ ruleTester.run("valid-jsdoc", rule, {
}],
errors: [
{
- message: "Use 'Object' instead of 'object'.",
+ messageId: "useType",
+ data: { expectedTypeName: "Object", currentTypeName: "object" },
type: "Block",
line: 3,
column: 11,
@@ -1986,7 +2040,8 @@ ruleTester.run("valid-jsdoc", rule, {
endColumn: 17
},
{
- message: "Use 'string' instead of 'String'.",
+ messageId: "useType",
+ data: { expectedTypeName: "string", currentTypeName: "String" },
type: "Block",
line: 3,
column: 18,
@@ -1994,7 +2049,8 @@ ruleTester.run("valid-jsdoc", rule, {
endColumn: 24
},
{
- message: "Use 'Object' instead of 'object'.",
+ messageId: "useType",
+ data: { expectedTypeName: "Object", currentTypeName: "object" },
type: "Block",
line: 3,
column: 25,
@@ -2002,7 +2058,8 @@ ruleTester.run("valid-jsdoc", rule, {
endColumn: 31
},
{
- message: "Use 'string' instead of 'String'.",
+ messageId: "useType",
+ data: { expectedTypeName: "string", currentTypeName: "String" },
type: "Block",
line: 3,
column: 32,
@@ -2010,7 +2067,8 @@ ruleTester.run("valid-jsdoc", rule, {
endColumn: 38
},
{
- message: "Use 'number' instead of 'Number'.",
+ messageId: "useType",
+ data: { expectedTypeName: "number", currentTypeName: "Number" },
type: "Block",
line: 3,
column: 40,
@@ -2044,7 +2102,8 @@ ruleTester.run("valid-jsdoc", rule, {
}],
errors: [
{
- message: "Use 'string' instead of 'String'.",
+ messageId: "useType",
+ data: { expectedTypeName: "string", currentTypeName: "String" },
type: "Block",
line: 3,
column: 16,
diff --git a/tests/lib/rules/valid-typeof.js b/tests/lib/rules/valid-typeof.js
index 2d3bd7d4bfe..203609cb628 100644
--- a/tests/lib/rules/valid-typeof.js
+++ b/tests/lib/rules/valid-typeof.js
@@ -79,93 +79,93 @@ ruleTester.run("valid-typeof", rule, {
invalid: [
{
code: "typeof foo === 'strnig'",
- errors: [{ message: "Invalid typeof comparison value.", type: "Literal" }]
+ errors: [{ messageId: "invalidValue", type: "Literal" }]
},
{
code: "'strnig' === typeof foo",
- errors: [{ message: "Invalid typeof comparison value.", type: "Literal" }]
+ errors: [{ messageId: "invalidValue", type: "Literal" }]
},
{
code: "if (typeof bar === 'umdefined') {}",
- errors: [{ message: "Invalid typeof comparison value.", type: "Literal" }]
+ errors: [{ messageId: "invalidValue", type: "Literal" }]
},
{
code: "typeof foo !== 'strnig'",
- errors: [{ message: "Invalid typeof comparison value.", type: "Literal" }]
+ errors: [{ messageId: "invalidValue", type: "Literal" }]
},
{
code: "'strnig' !== typeof foo",
- errors: [{ message: "Invalid typeof comparison value.", type: "Literal" }]
+ errors: [{ messageId: "invalidValue", type: "Literal" }]
},
{
code: "if (typeof bar !== 'umdefined') {}",
- errors: [{ message: "Invalid typeof comparison value.", type: "Literal" }]
+ errors: [{ messageId: "invalidValue", type: "Literal" }]
},
{
code: "typeof foo != 'strnig'",
- errors: [{ message: "Invalid typeof comparison value.", type: "Literal" }]
+ errors: [{ messageId: "invalidValue", type: "Literal" }]
},
{
code: "'strnig' != typeof foo",
- errors: [{ message: "Invalid typeof comparison value.", type: "Literal" }]
+ errors: [{ messageId: "invalidValue", type: "Literal" }]
},
{
code: "if (typeof bar != 'umdefined') {}",
- errors: [{ message: "Invalid typeof comparison value.", type: "Literal" }]
+ errors: [{ messageId: "invalidValue", type: "Literal" }]
},
{
code: "typeof foo == 'strnig'",
- errors: [{ message: "Invalid typeof comparison value.", type: "Literal" }]
+ errors: [{ messageId: "invalidValue", type: "Literal" }]
},
{
code: "'strnig' == typeof foo",
- errors: [{ message: "Invalid typeof comparison value.", type: "Literal" }]
+ errors: [{ messageId: "invalidValue", type: "Literal" }]
},
{
code: "if (typeof bar == 'umdefined') {}",
- errors: [{ message: "Invalid typeof comparison value.", type: "Literal" }]
+ errors: [{ messageId: "invalidValue", type: "Literal" }]
},
{
code: "if (typeof bar === `umdefined`) {}",
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: "Invalid typeof comparison value.", type: "TemplateLiteral" }]
+ errors: [{ messageId: "invalidValue", type: "TemplateLiteral" }]
},
{
code: "typeof foo == 'invalid string'",
options: [{ requireStringLiterals: true }],
- errors: [{ message: "Invalid typeof comparison value.", type: "Literal" }]
+ errors: [{ messageId: "invalidValue", type: "Literal" }]
},
{
code: "typeof foo == Object",
options: [{ requireStringLiterals: true }],
- errors: [{ message: "Typeof comparisons should be to string literals.", type: "Identifier" }]
+ errors: [{ messageId: "notString", type: "Identifier" }]
},
{
code: "typeof foo === undefined",
options: [{ requireStringLiterals: true }],
- errors: [{ message: "Typeof comparisons should be to string literals.", type: "Identifier" }]
+ errors: [{ messageId: "notString", type: "Identifier" }]
},
{
code: "undefined === typeof foo",
options: [{ requireStringLiterals: true }],
- errors: [{ message: "Typeof comparisons should be to string literals.", type: "Identifier" }]
+ errors: [{ messageId: "notString", type: "Identifier" }]
},
{
code: "undefined == typeof foo",
options: [{ requireStringLiterals: true }],
- errors: [{ message: "Typeof comparisons should be to string literals.", type: "Identifier" }]
+ errors: [{ messageId: "notString", type: "Identifier" }]
},
{
code: "typeof foo === `undefined${foo}`",
options: [{ requireStringLiterals: true }],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: "Typeof comparisons should be to string literals.", type: "TemplateLiteral" }]
+ errors: [{ messageId: "notString", type: "TemplateLiteral" }]
},
{
code: "typeof foo === `${string}`",
options: [{ requireStringLiterals: true }],
parserOptions: { ecmaVersion: 6 },
- errors: [{ message: "Typeof comparisons should be to string literals.", type: "TemplateLiteral" }]
+ errors: [{ messageId: "notString", type: "TemplateLiteral" }]
}
]
});
diff --git a/tests/lib/rules/vars-on-top.js b/tests/lib/rules/vars-on-top.js
index 3b64c08931d..54b4d412eaa 100644
--- a/tests/lib/rules/vars-on-top.js
+++ b/tests/lib/rules/vars-on-top.js
@@ -17,6 +17,7 @@ const rule = require("../../../lib/rules/vars-on-top"),
//------------------------------------------------------------------------------
const ruleTester = new EslintTester();
+const error = { messageId: "top", type: "VariableDeclaration" };
ruleTester.run("vars-on-top", rule, {
@@ -203,12 +204,7 @@ ruleTester.run("vars-on-top", rule, {
"}",
"var second = 0;"
].join("\n"),
- errors: [
- {
- message: "All 'var' declarations must be at the top of the function scope.",
- type: "VariableDeclaration"
- }
- ]
+ errors: [error]
},
{
code: [
@@ -223,12 +219,7 @@ ruleTester.run("vars-on-top", rule, {
" first = second;",
"}"
].join("\n"),
- errors: [
- {
- message: "All 'var' declarations must be at the top of the function scope.",
- type: "VariableDeclaration"
- }
- ]
+ errors: [error]
},
{
code: [
@@ -240,12 +231,7 @@ ruleTester.run("vars-on-top", rule, {
" first = second;",
"}"
].join("\n"),
- errors: [
- {
- message: "All 'var' declarations must be at the top of the function scope.",
- type: "VariableDeclaration"
- }
- ]
+ errors: [error]
},
{
code: [
@@ -255,12 +241,7 @@ ruleTester.run("vars-on-top", rule, {
" }",
"}"
].join("\n"),
- errors: [
- {
- message: "All 'var' declarations must be at the top of the function scope.",
- type: "VariableDeclaration"
- }
- ]
+ errors: [error]
},
{
code: [
@@ -272,12 +253,7 @@ ruleTester.run("vars-on-top", rule, {
" }",
"}"
].join("\n"),
- errors: [
- {
- message: "All 'var' declarations must be at the top of the function scope.",
- type: "VariableDeclaration"
- }
- ]
+ errors: [error]
},
{
code: [
@@ -291,12 +267,7 @@ ruleTester.run("vars-on-top", rule, {
" }",
"}"
].join("\n"),
- errors: [
- {
- message: "All 'var' declarations must be at the top of the function scope.",
- type: "VariableDeclaration"
- }
- ]
+ errors: [error]
},
{
code: [
@@ -310,12 +281,7 @@ ruleTester.run("vars-on-top", rule, {
" }",
"}"
].join("\n"),
- errors: [
- {
- message: "All 'var' declarations must be at the top of the function scope.",
- type: "VariableDeclaration"
- }
- ]
+ errors: [error]
},
{
code: [
@@ -329,12 +295,7 @@ ruleTester.run("vars-on-top", rule, {
" }",
"}"
].join("\n"),
- errors: [
- {
- message: "All 'var' declarations must be at the top of the function scope.",
- type: "VariableDeclaration"
- }
- ]
+ errors: [error]
},
{
code: [
@@ -345,12 +306,7 @@ ruleTester.run("vars-on-top", rule, {
" }",
"}"
].join("\n"),
- errors: [
- {
- message: "All 'var' declarations must be at the top of the function scope.",
- type: "VariableDeclaration"
- }
- ]
+ errors: [error]
},
{
code: [
@@ -361,12 +317,7 @@ ruleTester.run("vars-on-top", rule, {
" } while (first == 10);",
"}"
].join("\n"),
- errors: [
- {
- message: "All 'var' declarations must be at the top of the function scope.",
- type: "VariableDeclaration"
- }
- ]
+ errors: [error]
},
{
code: [
@@ -377,12 +328,7 @@ ruleTester.run("vars-on-top", rule, {
" }",
"}"
].join("\n"),
- errors: [
- {
- message: "All 'var' declarations must be at the top of the function scope.",
- type: "VariableDeclaration"
- }
- ]
+ errors: [error]
},
{
code: [
@@ -394,12 +340,7 @@ ruleTester.run("vars-on-top", rule, {
" }",
"}"
].join("\n"),
- errors: [
- {
- message: "All 'var' declarations must be at the top of the function scope.",
- type: "VariableDeclaration"
- }
- ]
+ errors: [error]
},
{
code: [
@@ -412,28 +353,23 @@ ruleTester.run("vars-on-top", rule, {
"}"
].join("\n"),
parserOptions: { ecmaVersion: 6 },
- errors: [
- {
- message: "All 'var' declarations must be at the top of the function scope.",
- type: "VariableDeclaration"
- }
- ]
+ errors: [error]
},
{
code: "'use strict'; 0; var x; f();",
- errors: [{ message: "All 'var' declarations must be at the top of the function scope.", type: "VariableDeclaration" }]
+ errors: [error]
},
{
code: "'use strict'; var x; 'directive'; var y; f();",
- errors: [{ message: "All 'var' declarations must be at the top of the function scope.", type: "VariableDeclaration" }]
+ errors: [error]
},
{
code: "function f() { 'use strict'; 0; var x; f(); }",
- errors: [{ message: "All 'var' declarations must be at the top of the function scope.", type: "VariableDeclaration" }]
+ errors: [error]
},
{
code: "function f() { 'use strict'; var x; 'directive'; var y; f(); }",
- errors: [{ message: "All 'var' declarations must be at the top of the function scope.", type: "VariableDeclaration" }]
+ errors: [error]
},
{
code: [
@@ -444,7 +380,7 @@ ruleTester.run("vars-on-top", rule, {
ecmaVersion: 6,
sourceType: "module"
},
- errors: [{ message: "All 'var' declarations must be at the top of the function scope.", type: "VariableDeclaration" }]
+ errors: [error]
},
{
code: [
@@ -456,7 +392,7 @@ ruleTester.run("vars-on-top", rule, {
ecmaVersion: 6,
sourceType: "module"
},
- errors: [{ message: "All 'var' declarations must be at the top of the function scope.", type: "VariableDeclaration" }]
+ errors: [error]
},
{
code: [
@@ -468,7 +404,7 @@ ruleTester.run("vars-on-top", rule, {
ecmaVersion: 6,
sourceType: "module"
},
- errors: [{ message: "All 'var' declarations must be at the top of the function scope.", type: "VariableDeclaration" }]
+ errors: [error]
},
{
code: [
@@ -479,7 +415,7 @@ ruleTester.run("vars-on-top", rule, {
ecmaVersion: 6,
sourceType: "module"
},
- errors: [{ message: "All 'var' declarations must be at the top of the function scope.", type: "VariableDeclaration" }]
+ errors: [error]
},
{
code: [
@@ -490,7 +426,7 @@ ruleTester.run("vars-on-top", rule, {
ecmaVersion: 6,
sourceType: "module"
},
- errors: [{ message: "All 'var' declarations must be at the top of the function scope.", type: "VariableDeclaration" }]
+ errors: [error]
}
]
});
diff --git a/tests/lib/rules/wrap-iife.js b/tests/lib/rules/wrap-iife.js
index 6425ed8714b..0a5cd00a5f4 100644
--- a/tests/lib/rules/wrap-iife.js
+++ b/tests/lib/rules/wrap-iife.js
@@ -16,9 +16,12 @@ const rule = require("../../../lib/rules/wrap-iife"),
// Tests
//------------------------------------------------------------------------------
-
const ruleTester = new RuleTester();
+const wrapInvocationError = { messageId: "wrapInvocation", type: "CallExpression" };
+const wrapExpressionError = { messageId: "wrapExpression", type: "CallExpression" };
+const moveInvocationError = { messageId: "moveInvocation", type: "CallExpression" };
+
ruleTester.run("wrap-iife", rule, {
valid: [
{
@@ -110,34 +113,34 @@ ruleTester.run("wrap-iife", rule, {
{
code: "0, function(){ }();",
output: "0, (function(){ }());",
- errors: [{ message: "Wrap an immediate function invocation in parentheses.", type: "CallExpression" }]
+ errors: [wrapInvocationError]
},
{
code: "[function(){ }()];",
output: "[(function(){ }())];",
- errors: [{ message: "Wrap an immediate function invocation in parentheses.", type: "CallExpression" }]
+ errors: [wrapInvocationError]
},
{
code: "var a = function(){ }();",
output: "var a = (function(){ }());",
- errors: [{ message: "Wrap an immediate function invocation in parentheses.", type: "CallExpression" }]
+ errors: [wrapInvocationError]
},
{
code: "(function(){ }(), 0);",
output: "((function(){ }()), 0);",
- errors: [{ message: "Wrap an immediate function invocation in parentheses.", type: "CallExpression" }]
+ errors: [wrapInvocationError]
},
{
code: "(function a(){ })();",
output: "(function a(){ }());",
options: ["outside"],
- errors: [{ message: "Move the invocation into the parens that contain the function.", type: "CallExpression" }]
+ errors: [moveInvocationError]
},
{
code: "(function a(){ }());",
output: "(function a(){ })();",
options: ["inside"],
- errors: [{ message: "Wrap only the function expression in parens.", type: "CallExpression" }]
+ errors: [wrapExpressionError]
},
{
@@ -145,55 +148,55 @@ ruleTester.run("wrap-iife", rule, {
code: "( /* a */ function /* b */ foo /* c */ ( /* d */ bar /* e */ ) /* f */ { /* g */ return; /* h */ } /* i */ ( /* j */ baz /* k */) /* l */ ) /* m */ ;",
output: "( /* a */ function /* b */ foo /* c */ ( /* d */ bar /* e */ ) /* f */ { /* g */ return; /* h */ }) /* i */ ( /* j */ baz /* k */) /* l */ /* m */ ;",
options: ["inside"],
- errors: [{ message: "Wrap only the function expression in parens.", type: "CallExpression" }]
+ errors: [wrapExpressionError]
},
{
code: "( /* a */ function /* b */ foo /* c */ ( /* d */ bar /* e */ ) /* f */ { /* g */ return; /* h */ } /* i */ ) /* j */ ( /* k */ baz /* l */) /* m */ ;",
output: "( /* a */ function /* b */ foo /* c */ ( /* d */ bar /* e */ ) /* f */ { /* g */ return; /* h */ } /* i */ /* j */ ( /* k */ baz /* l */)) /* m */ ;",
options: ["outside"],
- errors: [{ message: "Move the invocation into the parens that contain the function.", type: "CallExpression" }]
+ errors: [moveInvocationError]
},
{
code: "+function(){return 1;}()",
output: "+(function(){return 1;}())",
options: ["outside"],
- errors: [{ message: "Wrap an immediate function invocation in parentheses.", type: "CallExpression" }]
+ errors: [wrapInvocationError]
},
{
code: "+function(){return 1;}()",
output: "+(function(){return 1;})()",
options: ["inside"],
- errors: [{ message: "Wrap an immediate function invocation in parentheses.", type: "CallExpression" }]
+ errors: [wrapInvocationError]
},
{
code: "window.bar = function() { return 3; }.call(this, arg1);",
output: "window.bar = (function() { return 3; }).call(this, arg1);",
options: ["inside", { functionPrototypeMethods: true }],
- errors: [{ message: "Wrap an immediate function invocation in parentheses.", type: "CallExpression" }]
+ errors: [wrapInvocationError]
},
{
code: "window.bar = function() { return 3; }['call'](this, arg1);",
output: "window.bar = (function() { return 3; })['call'](this, arg1);",
options: ["inside", { functionPrototypeMethods: true }],
- errors: [{ message: "Wrap an immediate function invocation in parentheses.", type: "CallExpression" }]
+ errors: [wrapInvocationError]
},
{
code: "window.bar = function() { return 3; }.call(this, arg1);",
output: "window.bar = (function() { return 3; }.call(this, arg1));",
options: ["outside", { functionPrototypeMethods: true }],
- errors: [{ message: "Wrap an immediate function invocation in parentheses.", type: "CallExpression" }]
+ errors: [wrapInvocationError]
},
{
code: "window.bar = (function() { return 3; }.call(this, arg1));",
output: "window.bar = (function() { return 3; }).call(this, arg1);",
options: ["inside", { functionPrototypeMethods: true }],
- errors: [{ message: "Wrap only the function expression in parens.", type: "CallExpression" }]
+ errors: [wrapExpressionError]
},
{
code: "window.bar = (function() { return 3; }).call(this, arg1);",
output: "window.bar = (function() { return 3; }.call(this, arg1));",
options: ["outside", { functionPrototypeMethods: true }],
- errors: [{ message: "Move the invocation into the parens that contain the function.", type: "CallExpression" }]
+ errors: [moveInvocationError]
}
]
});
diff --git a/tests/lib/rules/yield-star-spacing.js b/tests/lib/rules/yield-star-spacing.js
index 70bff205463..4bc3dc53db3 100644
--- a/tests/lib/rules/yield-star-spacing.js
+++ b/tests/lib/rules/yield-star-spacing.js
@@ -18,6 +18,11 @@ const rule = require("../../../lib/rules/yield-star-spacing"),
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
+const missingBeforeError = { messageId: "missingBefore", type: "Punctuator" };
+const missingAfterError = { messageId: "missingAfter", type: "Punctuator" };
+const unexpectedBeforeError = { messageId: "unexpectedBefore", type: "Punctuator" };
+const unexpectedAfterError = { messageId: "unexpectedAfter", type: "Punctuator" };
+
ruleTester.run("yield-star-spacing", rule, {
valid: [
@@ -141,13 +146,7 @@ ruleTester.run("yield-star-spacing", rule, {
{
code: "function *foo(){ yield *foo1; }",
output: "function *foo(){ yield* foo1; }",
- errors: [{
- message: "Unexpected space before *.",
- type: "Punctuator"
- }, {
- message: "Missing space after *.",
- type: "Punctuator"
- }]
+ errors: [unexpectedBeforeError, missingAfterError]
},
// after
@@ -155,31 +154,19 @@ ruleTester.run("yield-star-spacing", rule, {
code: "function *foo(){ yield *foo1; }",
output: "function *foo(){ yield* foo1; }",
options: ["after"],
- errors: [{
- message: "Unexpected space before *.",
- type: "Punctuator"
- }, {
- message: "Missing space after *.",
- type: "Punctuator"
- }]
+ errors: [unexpectedBeforeError, missingAfterError]
},
{
code: "function *foo(){ yield * foo; }",
output: "function *foo(){ yield* foo; }",
options: ["after"],
- errors: [{
- message: "Unexpected space before *.",
- type: "Punctuator"
- }]
+ errors: [unexpectedBeforeError]
},
{
code: "function *foo(){ yield*foo2; }",
output: "function *foo(){ yield* foo2; }",
options: ["after"],
- errors: [{
- message: "Missing space after *.",
- type: "Punctuator"
- }]
+ errors: [missingAfterError]
},
// before
@@ -187,31 +174,19 @@ ruleTester.run("yield-star-spacing", rule, {
code: "function *foo(){ yield* foo; }",
output: "function *foo(){ yield *foo; }",
options: ["before"],
- errors: [{
- message: "Missing space before *.",
- type: "Punctuator"
- }, {
- message: "Unexpected space after *.",
- type: "Punctuator"
- }]
+ errors: [missingBeforeError, unexpectedAfterError]
},
{
code: "function *foo(){ yield * foo; }",
output: "function *foo(){ yield *foo; }",
options: ["before"],
- errors: [{
- message: "Unexpected space after *.",
- type: "Punctuator"
- }]
+ errors: [unexpectedAfterError]
},
{
code: "function *foo(){ yield*foo; }",
output: "function *foo(){ yield *foo; }",
options: ["before"],
- errors: [{
- message: "Missing space before *.",
- type: "Punctuator"
- }]
+ errors: [missingBeforeError]
},
// both
@@ -219,31 +194,19 @@ ruleTester.run("yield-star-spacing", rule, {
code: "function *foo(){ yield* foo; }",
output: "function *foo(){ yield * foo; }",
options: ["both"],
- errors: [{
- message: "Missing space before *.",
- type: "Punctuator"
- }]
+ errors: [missingBeforeError]
},
{
code: "function *foo(){ yield *foo3; }",
output: "function *foo(){ yield * foo3; }",
options: ["both"],
- errors: [{
- message: "Missing space after *.",
- type: "Punctuator"
- }]
+ errors: [missingAfterError]
},
{
code: "function *foo(){ yield*foo4; }",
output: "function *foo(){ yield * foo4; }",
options: ["both"],
- errors: [{
- message: "Missing space before *.",
- type: "Punctuator"
- }, {
- message: "Missing space after *.",
- type: "Punctuator"
- }]
+ errors: [missingBeforeError, missingAfterError]
},
// neither
@@ -251,31 +214,19 @@ ruleTester.run("yield-star-spacing", rule, {
code: "function *foo(){ yield* foo; }",
output: "function *foo(){ yield*foo; }",
options: ["neither"],
- errors: [{
- message: "Unexpected space after *.",
- type: "Punctuator"
- }]
+ errors: [unexpectedAfterError]
},
{
code: "function *foo(){ yield *foo; }",
output: "function *foo(){ yield*foo; }",
options: ["neither"],
- errors: [{
- message: "Unexpected space before *.",
- type: "Punctuator"
- }]
+ errors: [unexpectedBeforeError]
},
{
code: "function *foo(){ yield * foo; }",
output: "function *foo(){ yield*foo; }",
options: ["neither"],
- errors: [{
- message: "Unexpected space before *.",
- type: "Punctuator"
- }, {
- message: "Unexpected space after *.",
- type: "Punctuator"
- }]
+ errors: [unexpectedBeforeError, unexpectedAfterError]
}
]
diff --git a/tests/lib/rules/yoda.js b/tests/lib/rules/yoda.js
index 5d605923a16..da2bf1200c6 100644
--- a/tests/lib/rules/yoda.js
+++ b/tests/lib/rules/yoda.js
@@ -98,7 +98,8 @@ ruleTester.run("yoda", rule, {
options: ["never"],
errors: [
{
- message: "Expected literal to be on the right side of ==.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "==" },
type: "BinaryExpression"
}
]
@@ -109,7 +110,8 @@ ruleTester.run("yoda", rule, {
options: ["never"],
errors: [
{
- message: "Expected literal to be on the right side of ===.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "===" },
type: "BinaryExpression"
}
]
@@ -120,7 +122,8 @@ ruleTester.run("yoda", rule, {
options: ["never"],
errors: [
{
- message: "Expected literal to be on the right side of !=.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "!=" },
type: "BinaryExpression"
}
]
@@ -131,7 +134,8 @@ ruleTester.run("yoda", rule, {
options: ["never"],
errors: [
{
- message: "Expected literal to be on the right side of !==.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "!==" },
type: "BinaryExpression"
}
]
@@ -142,7 +146,8 @@ ruleTester.run("yoda", rule, {
options: ["never"],
errors: [
{
- message: "Expected literal to be on the right side of <=.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<=" },
type: "BinaryExpression"
}
]
@@ -153,7 +158,8 @@ ruleTester.run("yoda", rule, {
options: ["never"],
errors: [
{
- message: "Expected literal to be on the right side of >=.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: ">=" },
type: "BinaryExpression"
}
]
@@ -164,7 +170,8 @@ ruleTester.run("yoda", rule, {
options: ["never"],
errors: [
{
- message: "Expected literal to be on the right side of <.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<" },
type: "BinaryExpression"
}
]
@@ -175,7 +182,8 @@ ruleTester.run("yoda", rule, {
options: ["never"],
errors: [
{
- message: "Expected literal to be on the right side of >.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: ">" },
type: "BinaryExpression"
}
]
@@ -186,7 +194,8 @@ ruleTester.run("yoda", rule, {
options: ["never"],
errors: [
{
- message: "Expected literal to be on the right side of <.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<" },
type: "BinaryExpression"
}
]
@@ -197,7 +206,8 @@ ruleTester.run("yoda", rule, {
options: ["always"],
errors: [
{
- message: "Expected literal to be on the left side of ==.",
+ messageId: "expected",
+ data: { expectedSide: "left", operator: "==" },
type: "BinaryExpression"
}
]
@@ -208,7 +218,8 @@ ruleTester.run("yoda", rule, {
options: ["always"],
errors: [
{
- message: "Expected literal to be on the left side of ===.",
+ messageId: "expected",
+ data: { expectedSide: "left", operator: "===" },
type: "BinaryExpression"
}
]
@@ -219,7 +230,8 @@ ruleTester.run("yoda", rule, {
options: ["never", { exceptRange: true }],
errors: [
{
- message: "Expected literal to be on the right side of <=.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<=" },
type: "BinaryExpression"
}
]
@@ -230,7 +242,8 @@ ruleTester.run("yoda", rule, {
options: ["never", { exceptRange: true }],
errors: [
{
- message: "Expected literal to be on the right side of <=.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<=" },
type: "BinaryExpression"
}
]
@@ -241,7 +254,8 @@ ruleTester.run("yoda", rule, {
options: ["never", { exceptRange: true }],
errors: [
{
- message: "Expected literal to be on the right side of <.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<" },
type: "BinaryExpression"
}
]
@@ -252,7 +266,8 @@ ruleTester.run("yoda", rule, {
options: ["never", { exceptRange: true }],
errors: [
{
- message: "Expected literal to be on the right side of <.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<" },
type: "BinaryExpression"
}
]
@@ -263,7 +278,8 @@ ruleTester.run("yoda", rule, {
options: ["never", { exceptRange: true }],
errors: [
{
- message: "Expected literal to be on the right side of <=.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<=" },
type: "BinaryExpression"
}
]
@@ -274,7 +290,8 @@ ruleTester.run("yoda", rule, {
options: ["never", { exceptRange: true }],
errors: [
{
- message: "Expected literal to be on the right side of <=.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<=" },
type: "BinaryExpression"
}
]
@@ -285,7 +302,8 @@ ruleTester.run("yoda", rule, {
options: ["always", { exceptRange: true }],
errors: [
{
- message: "Expected literal to be on the left side of <.",
+ messageId: "expected",
+ data: { expectedSide: "left", operator: "<" },
type: "BinaryExpression"
}
]
@@ -296,7 +314,8 @@ ruleTester.run("yoda", rule, {
options: ["never", { exceptRange: true }],
errors: [
{
- message: "Expected literal to be on the right side of <=.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<=" },
type: "BinaryExpression"
}
]
@@ -307,7 +326,8 @@ ruleTester.run("yoda", rule, {
options: ["never", { exceptRange: true }],
errors: [
{
- message: "Expected literal to be on the right side of <=.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<=" },
type: "BinaryExpression"
}
]
@@ -318,7 +338,8 @@ ruleTester.run("yoda", rule, {
options: ["never", { exceptRange: true }],
errors: [
{
- message: "Expected literal to be on the right side of <=.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<=" },
type: "BinaryExpression"
}
]
@@ -329,7 +350,8 @@ ruleTester.run("yoda", rule, {
options: ["never", { onlyEquality: true }],
errors: [
{
- message: "Expected literal to be on the right side of ==.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "==" },
type: "BinaryExpression"
}
]
@@ -340,7 +362,8 @@ ruleTester.run("yoda", rule, {
options: ["never", { onlyEquality: true }],
errors: [
{
- message: "Expected literal to be on the right side of ===.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "===" },
type: "BinaryExpression"
}
]
@@ -351,7 +374,8 @@ ruleTester.run("yoda", rule, {
options: ["always", { onlyEquality: true }],
errors: [
{
- message: "Expected literal to be on the left side of ===.",
+ messageId: "expected",
+ data: { expectedSide: "left", operator: "===" },
type: "BinaryExpression"
}
]
@@ -361,7 +385,8 @@ ruleTester.run("yoda", rule, {
output: "if (x >= 0 && x < 1) {}",
errors: [
{
- message: "Expected literal to be on the right side of <=.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<=" },
type: "BinaryExpression"
}
]
@@ -372,7 +397,8 @@ ruleTester.run("yoda", rule, {
options: ["never"],
errors: [
{
- message: "Expected literal to be on the right side of <.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "<" },
type: "BinaryExpression"
}
]
@@ -383,7 +409,8 @@ ruleTester.run("yoda", rule, {
options: ["always"],
errors: [
{
- message: "Expected literal to be on the left side of >.",
+ messageId: "expected",
+ data: { expectedSide: "left", operator: ">" },
type: "BinaryExpression"
}
]
@@ -394,7 +421,8 @@ ruleTester.run("yoda", rule, {
options: ["always"],
errors: [
{
- message: "Expected literal to be on the left side of ===.",
+ messageId: "expected",
+ data: { expectedSide: "left", operator: "===" },
type: "BinaryExpression"
}
]
@@ -405,7 +433,8 @@ ruleTester.run("yoda", rule, {
options: ["always"],
errors: [
{
- message: "Expected literal to be on the left side of ===.",
+ messageId: "expected",
+ data: { expectedSide: "left", operator: "===" },
type: "BinaryExpression"
}
]
@@ -418,7 +447,8 @@ ruleTester.run("yoda", rule, {
options: ["never"],
errors: [
{
- message: "Expected literal to be on the right side of ===.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "===" },
type: "BinaryExpression"
}
]
@@ -429,7 +459,8 @@ ruleTester.run("yoda", rule, {
options: ["never"],
errors: [
{
- message: "Expected literal to be on the right side of ===.",
+ messageId: "expected",
+ data: { expectedSide: "right", operator: "===" },
type: "BinaryExpression"
}
]
@@ -440,7 +471,8 @@ ruleTester.run("yoda", rule, {
options: ["always"],
errors: [
{
- message: "Expected literal to be on the left side of ===.",
+ messageId: "expected",
+ data: { expectedSide: "left", operator: "===" },
type: "BinaryExpression"
}
]
@@ -451,7 +483,8 @@ ruleTester.run("yoda", rule, {
options: ["always"],
errors: [
{
- message: "Expected literal to be on the left side of ===.",
+ messageId: "expected",
+ data: { expectedSide: "left", operator: "===" },
type: "BinaryExpression"
}
]
@@ -462,7 +495,8 @@ ruleTester.run("yoda", rule, {
options: ["always"],
errors: [
{
- message: "Expected literal to be on the left side of ===.",
+ messageId: "expected",
+ data: { expectedSide: "left", operator: "===" },
type: "BinaryExpression"
}
]
diff --git a/tests/tools/internal-rules/no-invalid-meta.js b/tests/tools/internal-rules/no-invalid-meta.js
index b0168f409b1..3d2b08a7709 100644
--- a/tests/tools/internal-rules/no-invalid-meta.js
+++ b/tests/tools/internal-rules/no-invalid-meta.js
@@ -105,7 +105,7 @@ ruleTester.run("no-invalid-meta", rule, {
"};"
].join("\n"),
errors: [{
- message: "Rule does not export an Object. Make sure the rule follows the new rule format.",
+ messageId: "incorrectExport",
line: 1,
column: 18
}]
@@ -121,7 +121,7 @@ ruleTester.run("no-invalid-meta", rule, {
"};"
].join("\n"),
errors: [{
- message: "Rule is missing a meta property.",
+ messageId: "missingMeta",
line: 1,
column: 18
}]
@@ -139,7 +139,7 @@ ruleTester.run("no-invalid-meta", rule, {
"};"
].join("\n"),
errors: [{
- message: "Rule is missing a meta.docs property.",
+ messageId: "missingMetaDocs",
line: 2,
column: 5
}]
@@ -159,7 +159,7 @@ ruleTester.run("no-invalid-meta", rule, {
"};"
].join("\n"),
errors: [{
- message: "Rule is missing a meta.docs property.",
+ messageId: "missingMetaDocs",
line: 2,
column: 5
}]
@@ -183,7 +183,7 @@ ruleTester.run("no-invalid-meta", rule, {
"};"
].join("\n"),
errors: [{
- message: "Rule is missing a meta.docs.description property.",
+ messageId: "missingMetaDocsDescription",
line: 2,
column: 5
}]
@@ -207,7 +207,7 @@ ruleTester.run("no-invalid-meta", rule, {
"};"
].join("\n"),
errors: [{
- message: "Rule is missing a meta.docs.category property.",
+ messageId: "missingMetaDocsCategory",
line: 2,
column: 5
}]
@@ -231,7 +231,7 @@ ruleTester.run("no-invalid-meta", rule, {
"};"
].join("\n"),
errors: [{
- message: "Rule is missing a meta.docs.recommended property.",
+ messageId: "missingMetaDocsRecommended",
line: 2,
column: 5
}]
@@ -255,7 +255,7 @@ ruleTester.run("no-invalid-meta", rule, {
"};"
].join("\n"),
errors: [{
- message: "Rule is missing a meta.schema property.",
+ messageId: "missingMetaSchema",
line: 2,
column: 5
}]
@@ -263,7 +263,7 @@ ruleTester.run("no-invalid-meta", rule, {
{
code: "",
errors: [{
- message: "Rule does not export anything. Make sure rule exports an object according to new rule format.",
+ messageId: "noExport",
line: 1,
column: 1
}]
@@ -271,7 +271,7 @@ ruleTester.run("no-invalid-meta", rule, {
{
code: "foo();",
errors: [{
- message: "Rule does not export anything. Make sure rule exports an object according to new rule format.",
+ messageId: "noExport",
line: 1,
column: 1
}]
@@ -279,7 +279,7 @@ ruleTester.run("no-invalid-meta", rule, {
{
code: "foo = bar;",
errors: [{
- message: "Rule does not export anything. Make sure rule exports an object according to new rule format.",
+ messageId: "noExport",
line: 1,
column: 1
}]
diff --git a/tools/internal-rules/no-invalid-meta.js b/tools/internal-rules/no-invalid-meta.js
index 973b2a4808b..aeb7862fa2e 100644
--- a/tools/internal-rules/no-invalid-meta.js
+++ b/tools/internal-rules/no-invalid-meta.js
@@ -111,32 +111,32 @@ function checkMetaValidity(context, exportsNode) {
const metaProperty = getMetaPropertyFromExportsNode(exportsNode);
if (!metaProperty) {
- context.report(exportsNode, "Rule is missing a meta property.");
+ context.report({ node: exportsNode, messageId: "missingMeta" });
return;
}
if (!hasMetaDocs(metaProperty)) {
- context.report(metaProperty, "Rule is missing a meta.docs property.");
+ context.report({ node: metaProperty, messageId: "missingMetaDocs" });
return;
}
if (!hasMetaDocsDescription(metaProperty)) {
- context.report(metaProperty, "Rule is missing a meta.docs.description property.");
+ context.report({ node: metaProperty, messageId: "missingMetaDocsDescription" });
return;
}
if (!hasMetaDocsCategory(metaProperty)) {
- context.report(metaProperty, "Rule is missing a meta.docs.category property.");
+ context.report({ node: metaProperty, messageId: "missingMetaDocsCategory" });
return;
}
if (!hasMetaDocsRecommended(metaProperty)) {
- context.report(metaProperty, "Rule is missing a meta.docs.recommended property.");
+ context.report({ node: metaProperty, messageId: "missingMetaDocsRecommended" });
return;
}
if (!hasMetaSchema(metaProperty)) {
- context.report(metaProperty, "Rule is missing a meta.schema property.");
+ context.report({ node: metaProperty, messageId: "missingMetaSchema" });
}
}
@@ -162,7 +162,17 @@ module.exports = {
recommended: false
},
type: "problem",
- schema: []
+ schema: [],
+ messages: {
+ missingMeta: "Rule is missing a meta property.",
+ missingMetaDocs: "Rule is missing a meta.docs property.",
+ missingMetaDocsDescription: "Rule is missing a meta.docs.description property.",
+ missingMetaDocsCategory: "Rule is missing a meta.docs.category property.",
+ missingMetaDocsRecommended: "Rule is missing a meta.docs.recommended property.",
+ missingMetaSchema: "Rule is missing a meta.schema property.",
+ noExport: "Rule does not export anything. Make sure rule exports an object according to new rule format.",
+ incorrectExport: "Rule does not export an Object. Make sure the rule follows the new rule format."
+ }
},
create(context) {
@@ -184,12 +194,12 @@ module.exports = {
if (!exportsNode) {
context.report({
node,
- message: "Rule does not export anything. Make sure rule exports an object according to new rule format."
+ messageId: "noExport"
});
} else if (!isCorrectExportsFormat(exportsNode)) {
context.report({
node: exportsNode,
- message: "Rule does not export an Object. Make sure the rule follows the new rule format."
+ messageId: "incorrectExport"
});
} else {
checkMetaValidity(context, exportsNode);