From 3734a669983de7d5107ba8f39b291c6e3116489f Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Thu, 6 Feb 2020 11:08:15 +1300 Subject: [PATCH] Chore: use ids for messages (#12859) * Chore: refactor `sort-vars` to use messageIds * Chore: refactor `space-infix-ops` to use messageIds * Chore: refactor `space-before-function-paren` to use messageIds * Chore: refactor `space-before-blocks` to use messageIds * Chore: refactor `spaced-comment` to use messageIds * Chore: refactor `sort-keys` to use messageIds * Chore: refactor `sort-imports` to use messageIds * Chore: refactor `semi-style` to use messageIds * Chore: refactor `semi-spacing` to use messageIds * Chore: refactor `rest-spread-spacing` to use messageIds * Chore: refactor `require-yield` to use messageIds * Chore: refactor `require-jsdoc` to use messageIds * Chore: refactor `radix` to use messageIds * Chore: refactor `quote-props` to use messageIds * Chore: refactor `prefer-template` to use messageIds * Chore: refactor `prefer-spread` to use messageIds * Chore: refactor `prefer-rest-params` to use messageIds * Chore: refactor `prefer-reflect` to use messageIds * Chore: refactor `prefer-promise-reject-errors` to use messageIds * Chore: refactor `prefer-destructuring` to use messageIds * Chore: refactor `prefer-arrow-callback` to use messageIds * Chore: refactor `padding-line-between-statements` to use messageIds * Chore: refactor `padded-blocks` to use messageIds * Chore: refactor `operator-linebreak` to use messageIds * Chore: refactor `one-var` to use messageIds * Chore: refactor `one-var-declaration-per-line` to use messageIds * Chore: refactor `object-shorthand` to use messageIds * Chore: refactor `object-property-newline` to use messageIds * Chore: refactor `object-curly-spacing` to use messageIds * Chore: refactor `object-curly-newline` to use messageIds * Chore: refactor `nonblock-statement-body-position` to use messageIds * Chore: refactor `no-with` to use messageIds * Chore: refactor `no-whitespace-before-property` to use messageIds * Chore: refactor `no-warning-comments` to use messageIds * Chore: refactor `no-var` to use messageIds * Chore: refactor `no-useless-return` to use messageIds * Chore: refactor `no-useless-rename` to use messageIds * Chore: refactor `no-useless-concat` to use messageIds * Chore: refactor `no-useless-computed-key` to use messageIds * Chore: refactor `no-useless-catch` to use messageIds * Chore: refactor `no-useless-call` to use messageIds * Chore: refactor `no-unused-vars` to use messageIds * Chore: refactor `no-unused-expressions` to use messageIds * Chore: refactor `no-unsafe-finally` to use messageIds * Chore: refactor `no-unreachable` to use messageIds * Chore: refactor `no-unneeded-ternary` to use messageIds * Chore: refactor `no-unmodified-loop-condition` to use messageIds * Chore: refactor `no-underscore-dangle` to use messageIds * Chore: refactor `no-undefined` to use messageIds * Chore: refactor `no-undef-init` to use messageIds * Chore: refactor `no-trailing-spaces` to use messageIds * Chore: refactor `no-this-before-super` to use messageIds * Chore: refactor `no-sync` to use messageIds * Chore: refactor `no-ternary` to use messageIds * Chore: refactor `no-template-curly-in-string` to use messageIds * Chore: refactor `no-tabs` to use messageIds * Chore: refactor `no-sparse-arrays` to use messageIds * Chore: refactor `no-spaced-func` to use messageIds * Chore: refactor `no-shadow-restricted-names` to use messageIds * Chore: refactor `no-sequences` to use messageIds * Chore: refactor `no-self-compare` to use messageIds * Chore: refactor `no-self-assign` to use messageIds * Chore: refactor `no-script-url` to use messageIds * Chore: refactor `no-return-await` to use messageIds * Chore: refactor `no-return-assign` to use messageIds * Chore: refactor `no-restricted-properties` to use messageIds * Chore: refactor `no-restricted-modules` to use messageIds * Chore: refactor `no-regex-spaces` to use messageIds * Chore: refactor `no-prototype-builtins` to use messageIds * Chore: refactor `no-proto` to use messageIds * Chore: refactor `no-process-exit` to use messageIds * Chore: refactor `no-process-env` to use messageIds * Chore: refactor `no-restricted-syntax` to use messageIds * Chore: refactor `no-native-reassign` to use messageIds * Chore: refactor `no-negated-in-lhs` to use messageIds * Chore: refactor `no-invalid-regexp` to use messageIds * Chore: refactor some tests to use `messageId`s * Chore: update `linter` tests to include `messageId` * Chore: correct message for `space-before-blocks` * Chore: use default values intead of `||` --- lib/rules/no-invalid-regexp.js | 8 +- lib/rules/no-native-reassign.js | 8 +- lib/rules/no-negated-in-lhs.js | 8 +- lib/rules/no-process-env.js | 8 +- lib/rules/no-process-exit.js | 8 +- lib/rules/no-proto.js | 8 +- lib/rules/no-prototype-builtins.js | 8 +- lib/rules/no-regex-spaces.js | 8 +- lib/rules/no-restricted-modules.js | 38 +- lib/rules/no-restricted-properties.js | 13 +- lib/rules/no-restricted-syntax.js | 11 +- lib/rules/no-return-assign.js | 11 +- lib/rules/no-return-await.js | 10 +- lib/rules/no-script-url.js | 8 +- lib/rules/no-self-assign.js | 8 +- lib/rules/no-self-compare.js | 8 +- lib/rules/no-sequences.js | 8 +- lib/rules/no-shadow-restricted-names.js | 10 +- lib/rules/no-spaced-func.js | 8 +- lib/rules/no-sparse-arrays.js | 8 +- lib/rules/no-sync.js | 8 +- lib/rules/no-tabs.js | 8 +- lib/rules/no-template-curly-in-string.js | 8 +- lib/rules/no-ternary.js | 8 +- lib/rules/no-this-before-super.js | 8 +- lib/rules/no-trailing-spaces.js | 8 +- lib/rules/no-undef-init.js | 8 +- lib/rules/no-undefined.js | 8 +- lib/rules/no-underscore-dangle.js | 14 +- lib/rules/no-unmodified-loop-condition.js | 8 +- lib/rules/no-unneeded-ternary.js | 11 +- lib/rules/no-unreachable.js | 8 +- lib/rules/no-unsafe-finally.js | 8 +- lib/rules/no-unused-expressions.js | 8 +- lib/rules/no-unused-vars.js | 61 +- lib/rules/no-useless-call.js | 8 +- lib/rules/no-useless-catch.js | 11 +- lib/rules/no-useless-computed-key.js | 10 +- lib/rules/no-useless-concat.js | 8 +- lib/rules/no-useless-rename.js | 8 +- lib/rules/no-useless-return.js | 8 +- lib/rules/no-var.js | 8 +- lib/rules/no-warning-comments.js | 8 +- lib/rules/no-whitespace-before-property.js | 8 +- lib/rules/no-with.js | 8 +- lib/rules/nonblock-statement-body-position.js | 11 +- lib/rules/object-curly-newline.js | 17 +- lib/rules/object-curly-spacing.js | 17 +- lib/rules/object-property-newline.js | 15 +- lib/rules/object-shorthand.js | 26 +- lib/rules/one-var-declaration-per-line.js | 9 +- lib/rules/one-var.js | 32 +- lib/rules/operator-linebreak.js | 17 +- lib/rules/padded-blocks.js | 18 +- lib/rules/padding-line-between-statements.js | 9 +- lib/rules/prefer-arrow-callback.js | 8 +- lib/rules/prefer-destructuring.js | 8 +- lib/rules/prefer-promise-reject-errors.js | 8 +- lib/rules/prefer-reflect.js | 8 +- lib/rules/prefer-rest-params.js | 8 +- lib/rules/prefer-spread.js | 8 +- lib/rules/prefer-template.js | 8 +- lib/rules/quote-props.js | 29 +- lib/rules/radix.js | 17 +- lib/rules/require-jsdoc.js | 8 +- lib/rules/require-yield.js | 8 +- lib/rules/rest-spread-spacing.js | 11 +- lib/rules/semi-spacing.js | 17 +- lib/rules/semi-style.js | 8 +- lib/rules/sort-imports.js | 14 +- lib/rules/sort-keys.js | 8 +- lib/rules/sort-vars.js | 8 +- lib/rules/space-before-blocks.js | 11 +- lib/rules/space-before-function-paren.js | 11 +- lib/rules/space-infix-ops.js | 8 +- lib/rules/spaced-comment.js | 35 +- tests/lib/linter/linter.js | 6 + tests/lib/rules/camelcase.js | 42 +- tests/lib/rules/class-methods-use-this.js | 18 +- tests/lib/rules/grouped-accessor-pairs.js | 32 +- tests/lib/rules/no-invalid-regexp.js | 33 +- tests/lib/rules/no-magic-numbers.js | 2 +- tests/lib/rules/no-native-reassign.js | 22 +- tests/lib/rules/no-negated-in-lhs.js | 2 +- tests/lib/rules/no-obj-calls.js | 3 +- tests/lib/rules/no-octal-escape.js | 4 +- tests/lib/rules/no-process-env.js | 6 +- tests/lib/rules/no-process-exit.js | 6 +- tests/lib/rules/no-proto.js | 8 +- tests/lib/rules/no-prototype-builtins.js | 15 +- tests/lib/rules/no-regex-spaces.js | 81 +- tests/lib/rules/no-restricted-exports.js | 3 +- tests/lib/rules/no-restricted-modules.js | 23 +- tests/lib/rules/no-restricted-properties.js | 246 +++- tests/lib/rules/no-restricted-syntax.js | 36 +- tests/lib/rules/no-return-assign.js | 23 +- tests/lib/rules/no-return-await.js | 2 +- tests/lib/rules/no-script-url.js | 4 +- tests/lib/rules/no-self-assign.js | 70 +- tests/lib/rules/no-self-compare.js | 28 +- tests/lib/rules/no-sequences.js | 4 +- tests/lib/rules/no-setter-return.js | 2 +- tests/lib/rules/no-shadow-restricted-names.js | 82 +- tests/lib/rules/no-spaced-func.js | 26 +- tests/lib/rules/no-sparse-arrays.js | 4 +- tests/lib/rules/no-sync.js | 26 +- tests/lib/rules/no-tabs.js | 25 +- .../lib/rules/no-template-curly-in-string.js | 16 +- tests/lib/rules/no-ternary.js | 6 +- tests/lib/rules/no-this-before-super.js | 28 +- tests/lib/rules/no-trailing-spaces.js | 82 +- tests/lib/rules/no-undef-init.js | 42 +- tests/lib/rules/no-undefined.js | 6 +- tests/lib/rules/no-underscore-dangle.js | 30 +- .../lib/rules/no-unmodified-loop-condition.js | 34 +- tests/lib/rules/no-unneeded-ternary.js | 56 +- tests/lib/rules/no-unreachable.js | 56 +- tests/lib/rules/no-unsafe-finally.js | 32 +- tests/lib/rules/no-unsafe-negation.js | 3 +- tests/lib/rules/no-unused-expressions.js | 56 +- tests/lib/rules/no-unused-vars.js | 469 +++++-- tests/lib/rules/no-useless-call.js | 135 +- tests/lib/rules/no-useless-catch.js | 10 +- tests/lib/rules/no-useless-computed-key.js | 196 ++- tests/lib/rules/no-useless-concat.js | 18 +- tests/lib/rules/no-useless-rename.js | 191 ++- tests/lib/rules/no-useless-return.js | 8 +- tests/lib/rules/no-var.js | 74 +- tests/lib/rules/no-warning-comments.js | 186 ++- .../rules/no-whitespace-before-property.js | 484 +++++-- tests/lib/rules/no-with.js | 2 +- .../rules/nonblock-statement-body-position.js | 4 +- tests/lib/rules/object-curly-newline.js | 260 ++-- tests/lib/rules/object-curly-spacing.js | 246 ++-- tests/lib/rules/object-property-newline.js | 84 +- tests/lib/rules/object-shorthand.js | 14 +- .../lib/rules/one-var-declaration-per-line.js | 2 +- tests/lib/rules/one-var.js | 371 ++++-- tests/lib/rules/operator-linebreak.js | 162 ++- tests/lib/rules/padded-blocks.js | 128 +- .../rules/padding-line-between-statements.js | 529 ++++---- tests/lib/rules/prefer-arrow-callback.js | 2 +- tests/lib/rules/prefer-destructuring.js | 54 +- .../rules/prefer-exponentiation-operator.js | 5 +- .../lib/rules/prefer-promise-reject-errors.js | 2 +- tests/lib/rules/prefer-reflect.js | 60 +- tests/lib/rules/prefer-rest-params.js | 8 +- tests/lib/rules/prefer-spread.js | 2 +- tests/lib/rules/prefer-template.js | 2 +- tests/lib/rules/quote-props.js | 132 +- tests/lib/rules/radix.js | 36 +- tests/lib/rules/require-jsdoc.js | 22 +- tests/lib/rules/require-yield.js | 14 +- tests/lib/rules/rest-spread-spacing.js | 141 +- tests/lib/rules/semi-spacing.js | 54 +- tests/lib/rules/semi-style.js | 168 ++- tests/lib/rules/sort-imports.js | 50 +- tests/lib/rules/sort-keys.js | 1175 +++++++++++++++-- tests/lib/rules/sort-vars.js | 2 +- tests/lib/rules/space-before-blocks.js | 20 +- .../lib/rules/space-before-function-paren.js | 82 +- tests/lib/rules/space-infix-ops.js | 99 +- tests/lib/rules/spaced-comment.js | 100 +- tests/lib/rules/wrap-regex.js | 6 +- 164 files changed, 5603 insertions(+), 2429 deletions(-) diff --git a/lib/rules/no-invalid-regexp.js b/lib/rules/no-invalid-regexp.js index 4ede995891b..c09e36fd017 100644 --- a/lib/rules/no-invalid-regexp.js +++ b/lib/rules/no-invalid-regexp.js @@ -39,9 +39,11 @@ module.exports = { } }, additionalProperties: false - }] + }], - // no messages, because the error text comes directly from the regexpp module + messages: { + regexMessage: "{{message}}." + } }, create(context) { @@ -118,7 +120,7 @@ module.exports = { if (message) { context.report({ node, - message: "{{message}}.", + messageId: "regexMessage", data: { message } }); } diff --git a/lib/rules/no-native-reassign.js b/lib/rules/no-native-reassign.js index eb233c80b1c..833e3b7ce40 100644 --- a/lib/rules/no-native-reassign.js +++ b/lib/rules/no-native-reassign.js @@ -37,7 +37,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + nativeReassign: "Read-only global '{{name}}' should not be modified." + } }, create(context) { @@ -65,7 +69,7 @@ module.exports = { ) { context.report({ node: identifier, - message: "Read-only global '{{name}}' should not be modified.", + messageId: "nativeReassign", data: identifier }); } diff --git a/lib/rules/no-negated-in-lhs.js b/lib/rules/no-negated-in-lhs.js index 0084ad1570b..1229cedd119 100644 --- a/lib/rules/no-negated-in-lhs.js +++ b/lib/rules/no-negated-in-lhs.js @@ -24,7 +24,11 @@ module.exports = { replacedBy: ["no-unsafe-negation"], deprecated: true, - schema: [] + schema: [], + + messages: { + negatedLHS: "The 'in' expression's left operand is negated." + } }, create(context) { @@ -33,7 +37,7 @@ module.exports = { BinaryExpression(node) { if (node.operator === "in" && node.left.type === "UnaryExpression" && node.left.operator === "!") { - context.report({ node, message: "The 'in' expression's left operand is negated." }); + context.report({ node, messageId: "negatedLHS" }); } } }; diff --git a/lib/rules/no-process-env.js b/lib/rules/no-process-env.js index a66d9709b09..0f8d7f8a339 100644 --- a/lib/rules/no-process-env.js +++ b/lib/rules/no-process-env.js @@ -19,7 +19,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-process-env" }, - schema: [] + schema: [], + + messages: { + unexpectedProcessEnv: "Unexpected use of process.env." + } }, create(context) { @@ -31,7 +35,7 @@ module.exports = { propertyName = node.property.name; if (objectName === "process" && !node.computed && propertyName && propertyName === "env") { - context.report({ node, message: "Unexpected use of process.env." }); + context.report({ node, messageId: "unexpectedProcessEnv" }); } } diff --git a/lib/rules/no-process-exit.js b/lib/rules/no-process-exit.js index fcfc6b2af59..29871660cc6 100644 --- a/lib/rules/no-process-exit.js +++ b/lib/rules/no-process-exit.js @@ -19,7 +19,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-process-exit" }, - schema: [] + schema: [], + + messages: { + noProcessExit: "Don't use process.exit(); throw an error instead." + } }, create(context) { @@ -30,7 +34,7 @@ module.exports = { return { "CallExpression > MemberExpression.callee[object.name = 'process'][property.name = 'exit']"(node) { - context.report({ node: node.parent, message: "Don't use process.exit(); throw an error instead." }); + context.report({ node: node.parent, messageId: "noProcessExit" }); } }; diff --git a/lib/rules/no-proto.js b/lib/rules/no-proto.js index aae481a7412..82ce02fa4e3 100644 --- a/lib/rules/no-proto.js +++ b/lib/rules/no-proto.js @@ -26,7 +26,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-proto" }, - schema: [] + schema: [], + + messages: { + unexpectedProto: "The '__proto__' property is deprecated." + } }, create(context) { @@ -35,7 +39,7 @@ module.exports = { MemberExpression(node) { if (getStaticPropertyName(node) === "__proto__") { - context.report({ node, message: "The '__proto__' property is deprecated." }); + context.report({ node, messageId: "unexpectedProto" }); } } }; diff --git a/lib/rules/no-prototype-builtins.js b/lib/rules/no-prototype-builtins.js index 87a760156e3..5bed2539a64 100644 --- a/lib/rules/no-prototype-builtins.js +++ b/lib/rules/no-prototype-builtins.js @@ -19,7 +19,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-prototype-builtins" }, - schema: [] + schema: [], + + messages: { + prototypeBuildIn: "Do not access Object.prototype method '{{prop}}' from target object." + } }, create(context) { @@ -42,7 +46,7 @@ module.exports = { if (DISALLOWED_PROPS.indexOf(propName) > -1) { context.report({ - message: "Do not access Object.prototype method '{{prop}}' from target object.", + messageId: "prototypeBuildIn", loc: node.callee.property.loc.start, data: { prop: propName }, node diff --git a/lib/rules/no-regex-spaces.js b/lib/rules/no-regex-spaces.js index 1b937ae0de8..afb26d70259 100644 --- a/lib/rules/no-regex-spaces.js +++ b/lib/rules/no-regex-spaces.js @@ -45,7 +45,11 @@ module.exports = { }, schema: [], - fixable: "code" + fixable: "code", + + messages: { + multipleSpaces: "Spaces are hard to count. Use {{{length}}}." + } }, create(context) { @@ -96,7 +100,7 @@ module.exports = { ) { context.report({ node: nodeToReport, - message: "Spaces are hard to count. Use {{{length}}}.", + messageId: "multipleSpaces", data: { length }, fix(fixer) { if (pattern !== rawPattern) { diff --git a/lib/rules/no-restricted-modules.js b/lib/rules/no-restricted-modules.js index ef8748a7d04..abbc30a05fb 100644 --- a/lib/rules/no-restricted-modules.js +++ b/lib/rules/no-restricted-modules.js @@ -4,13 +4,6 @@ */ "use strict"; -//------------------------------------------------------------------------------ -// Helpers -//------------------------------------------------------------------------------ - -const DEFAULT_MESSAGE_TEMPLATE = "'{{moduleName}}' module is restricted from being used."; -const CUSTOM_MESSAGE_TEMPLATE = "'{{moduleName}}' module is restricted from being used. {{customMessage}}"; - //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ @@ -72,6 +65,13 @@ module.exports = { additionalItems: false } ] + }, + + messages: { + defaultMessage: "'{{name}}' module is restricted from being used.", + // eslint-disable-next-line eslint-plugin/report-message-format + customMessage: "'{{name}}' module is restricted from being used. {{customMessage}}", + patternMessage: "'{{name}}' module is restricted from being used by a pattern." } }, @@ -126,17 +126,17 @@ module.exports = { * @private */ function reportPath(node) { - const moduleName = node.arguments[0].value.trim(); - const customMessage = restrictedPathMessages[moduleName]; - const message = customMessage - ? CUSTOM_MESSAGE_TEMPLATE - : DEFAULT_MESSAGE_TEMPLATE; + const name = node.arguments[0].value.trim(); + const customMessage = restrictedPathMessages[name]; + const messageId = customMessage + ? "customMessage" + : "defaultMessage"; context.report({ node, - message, + messageId, data: { - moduleName, + name, customMessage } }); @@ -158,18 +158,18 @@ module.exports = { // node has arguments and first argument is string if (node.arguments.length && isString(node.arguments[0])) { - const moduleName = node.arguments[0].value.trim(); + const name = node.arguments[0].value.trim(); // check if argument value is in restricted modules array - if (isRestrictedPath(moduleName)) { + if (isRestrictedPath(name)) { reportPath(node); } - if (restrictedPatterns.length > 0 && ig.ignores(moduleName)) { + if (restrictedPatterns.length > 0 && ig.ignores(name)) { context.report({ node, - message: "'{{moduleName}}' module is restricted from being used by a pattern.", - data: { moduleName } + messageId: "patternMessage", + data: { name } }); } } diff --git a/lib/rules/no-restricted-properties.js b/lib/rules/no-restricted-properties.js index bdab22b19c4..7ab83995a3e 100644 --- a/lib/rules/no-restricted-properties.js +++ b/lib/rules/no-restricted-properties.js @@ -61,6 +61,13 @@ module.exports = { ] }, uniqueItems: true + }, + + messages: { + // eslint-disable-next-line eslint-plugin/report-message-format + restrictedObjectProperty: "'{{objectName}}.{{propertyName}}' is restricted from being used.{{message}}", + // eslint-disable-next-line eslint-plugin/report-message-format + restrictedProperty: "'{{propertyName}}' is restricted from being used.{{message}}" } }, @@ -114,8 +121,7 @@ module.exports = { context.report({ node, - // eslint-disable-next-line eslint-plugin/report-message-format - message: "'{{objectName}}.{{propertyName}}' is restricted from being used.{{message}}", + messageId: "restrictedObjectProperty", data: { objectName, propertyName, @@ -127,8 +133,7 @@ module.exports = { context.report({ node, - // eslint-disable-next-line eslint-plugin/report-message-format - message: "'{{propertyName}}' is restricted from being used.{{message}}", + messageId: "restrictedProperty", data: { propertyName, message diff --git a/lib/rules/no-restricted-syntax.js b/lib/rules/no-restricted-syntax.js index 41aa9fa390a..9572603a824 100644 --- a/lib/rules/no-restricted-syntax.js +++ b/lib/rules/no-restricted-syntax.js @@ -39,6 +39,11 @@ module.exports = { }, uniqueItems: true, minItems: 0 + }, + + messages: { + // eslint-disable-next-line eslint-plugin/report-message-format + restrictedSyntax: "{{message}}" } }, @@ -48,14 +53,14 @@ module.exports = { const hasCustomMessage = !isStringFormat && Boolean(selectorOrObject.message); const selector = isStringFormat ? selectorOrObject : selectorOrObject.selector; - const message = hasCustomMessage ? selectorOrObject.message : "Using '{{selector}}' is not allowed."; + const message = hasCustomMessage ? selectorOrObject.message : `Using '${selector}' is not allowed.`; return Object.assign(result, { [selector](node) { context.report({ node, - message, - data: hasCustomMessage ? {} : { selector } + messageId: "restrictedSyntax", + data: { message } }); } }); diff --git a/lib/rules/no-return-assign.js b/lib/rules/no-return-assign.js index ea6a6bb49fc..4b57d42eb99 100644 --- a/lib/rules/no-return-assign.js +++ b/lib/rules/no-return-assign.js @@ -35,7 +35,12 @@ module.exports = { { enum: ["except-parens", "always"] } - ] + ], + + messages: { + returnAssignment: "Return statement should not contain assignment.", + arrowAssignment: "Arrow function should not return assignment." + } }, create(context) { @@ -61,12 +66,12 @@ module.exports = { if (parent && parent.type === "ReturnStatement") { context.report({ node: parent, - message: "Return statement should not contain assignment." + messageId: "returnAssignment" }); } else if (parent && parent.type === "ArrowFunctionExpression" && parent.body === currentChild) { context.report({ node: parent, - message: "Arrow function should not return assignment." + messageId: "arrowAssignment" }); } } diff --git a/lib/rules/no-return-await.js b/lib/rules/no-return-await.js index 6652b5932dc..d1d89826856 100644 --- a/lib/rules/no-return-await.js +++ b/lib/rules/no-return-await.js @@ -10,8 +10,6 @@ const astUtils = require("./utils/ast-utils"); // Rule Definition //------------------------------------------------------------------------------ -const message = "Redundant use of `await` on a return value."; - module.exports = { meta: { type: "suggestion", @@ -28,7 +26,11 @@ module.exports = { fixable: null, schema: [ - ] + ], + + messages: { + redundantUseOfAwait: "Redundant use of `await` on a return value." + } }, create(context) { @@ -42,7 +44,7 @@ module.exports = { context.report({ node: context.getSourceCode().getFirstToken(node), loc: node.loc, - message + messageId: "redundantUseOfAwait" }); } diff --git a/lib/rules/no-script-url.js b/lib/rules/no-script-url.js index 40e9bfe8b27..2078fc1dcea 100644 --- a/lib/rules/no-script-url.js +++ b/lib/rules/no-script-url.js @@ -22,7 +22,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-script-url" }, - schema: [] + schema: [], + + messages: { + unexpectedScriptURL: "Script URL is a form of eval." + } }, create(context) { @@ -34,7 +38,7 @@ module.exports = { const value = node.value.toLowerCase(); if (value.indexOf("javascript:") === 0) { - context.report({ node, message: "Script URL is a form of eval." }); + context.report({ node, messageId: "unexpectedScriptURL" }); } } } diff --git a/lib/rules/no-self-assign.js b/lib/rules/no-self-assign.js index 705d0f409c4..170e46b0593 100644 --- a/lib/rules/no-self-assign.js +++ b/lib/rules/no-self-assign.js @@ -196,7 +196,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + selfAssignment: "'{{name}}' is assigned to itself." + } }, create(context) { @@ -211,7 +215,7 @@ module.exports = { function report(node) { context.report({ node, - message: "'{{name}}' is assigned to itself.", + messageId: "selfAssignment", data: { name: sourceCode.getText(node).replace(SPACES, "") } diff --git a/lib/rules/no-self-compare.js b/lib/rules/no-self-compare.js index 8986240ec5c..79b6ac7ea0f 100644 --- a/lib/rules/no-self-compare.js +++ b/lib/rules/no-self-compare.js @@ -21,7 +21,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-self-compare" }, - schema: [] + schema: [], + + messages: { + comparingToSelf: "Comparing to itself is potentially pointless." + } }, create(context) { @@ -47,7 +51,7 @@ module.exports = { const operators = new Set(["===", "==", "!==", "!=", ">", "<", ">=", "<="]); if (operators.has(node.operator) && hasSameTokens(node.left, node.right)) { - context.report({ node, message: "Comparing to itself is potentially pointless." }); + context.report({ node, messageId: "comparingToSelf" }); } } }; diff --git a/lib/rules/no-sequences.js b/lib/rules/no-sequences.js index 8046a8711a3..d67635d1175 100644 --- a/lib/rules/no-sequences.js +++ b/lib/rules/no-sequences.js @@ -26,7 +26,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-sequences" }, - schema: [] + schema: [], + + messages: { + unexpectedCommaExpression: "Unexpected use of comma operator." + } }, create(context) { @@ -107,7 +111,7 @@ module.exports = { const firstCommaToken = sourceCode.getTokenAfter(node.expressions[0], astUtils.isCommaToken); - context.report({ node, loc: firstCommaToken.loc, message: "Unexpected use of comma operator." }); + context.report({ node, loc: firstCommaToken.loc, messageId: "unexpectedCommaExpression" }); } }; diff --git a/lib/rules/no-shadow-restricted-names.js b/lib/rules/no-shadow-restricted-names.js index 9030d523b70..9647e9a1bcd 100644 --- a/lib/rules/no-shadow-restricted-names.js +++ b/lib/rules/no-shadow-restricted-names.js @@ -32,7 +32,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-shadow-restricted-names" }, - schema: [] + schema: [], + + messages: { + shadowingRestrictedName: "Shadowing of global property '{{name}}'." + } }, create(context) { @@ -46,9 +50,9 @@ module.exports = { if (variable.defs.length > 0 && RESTRICTED.has(variable.name) && !safelyShadowsUndefined(variable)) { context.report({ node: variable.defs[0].name, - message: "Shadowing of global property '{{idName}}'.", + messageId: "shadowingRestrictedName", data: { - idName: variable.name + name: variable.name } }); } diff --git a/lib/rules/no-spaced-func.js b/lib/rules/no-spaced-func.js index 8535881f435..961bc681f7e 100644 --- a/lib/rules/no-spaced-func.js +++ b/lib/rules/no-spaced-func.js @@ -26,7 +26,11 @@ module.exports = { replacedBy: ["func-call-spacing"], fixable: "whitespace", - schema: [] + schema: [], + + messages: { + noSpacedFunction: "Unexpected space between function name and paren." + } }, create(context) { @@ -62,7 +66,7 @@ module.exports = { context.report({ node, loc: lastCalleeToken.loc.start, - message: "Unexpected space between function name and paren.", + messageId: "noSpacedFunction", fix(fixer) { return fixer.removeRange([prevToken.range[1], parenToken.range[0]]); } diff --git a/lib/rules/no-sparse-arrays.js b/lib/rules/no-sparse-arrays.js index 985109c36b2..e8407c3faed 100644 --- a/lib/rules/no-sparse-arrays.js +++ b/lib/rules/no-sparse-arrays.js @@ -19,7 +19,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-sparse-arrays" }, - schema: [] + schema: [], + + messages: { + unexpectedSparseArray: "Unexpected comma in middle of array." + } }, create(context) { @@ -36,7 +40,7 @@ module.exports = { const emptySpot = node.elements.indexOf(null) > -1; if (emptySpot) { - context.report({ node, message: "Unexpected comma in middle of array." }); + context.report({ node, messageId: "unexpectedSparseArray" }); } } diff --git a/lib/rules/no-sync.js b/lib/rules/no-sync.js index 578bac96d3d..d8111059631 100644 --- a/lib/rules/no-sync.js +++ b/lib/rules/no-sync.js @@ -33,7 +33,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + noSync: "Unexpected sync method: '{{propertyName}}'." + } }, create(context) { @@ -45,7 +49,7 @@ module.exports = { [selector](node) { context.report({ node, - message: "Unexpected sync method: '{{propertyName}}'.", + messageId: "noSync", data: { propertyName: node.property.name } diff --git a/lib/rules/no-tabs.js b/lib/rules/no-tabs.js index 3fc0b78b6e7..ca7be261653 100644 --- a/lib/rules/no-tabs.js +++ b/lib/rules/no-tabs.js @@ -35,7 +35,11 @@ module.exports = { } }, additionalProperties: false - }] + }], + + messages: { + unexpectedTab: "Unexpected tab character." + } }, create(context) { @@ -64,7 +68,7 @@ module.exports = { column: match.index + match[0].length } }, - message: "Unexpected tab character." + messageId: "unexpectedTab" }); } }); diff --git a/lib/rules/no-template-curly-in-string.js b/lib/rules/no-template-curly-in-string.js index f7822e961cc..539cd5be5ff 100644 --- a/lib/rules/no-template-curly-in-string.js +++ b/lib/rules/no-template-curly-in-string.js @@ -19,7 +19,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-template-curly-in-string" }, - schema: [] + schema: [], + + messages: { + unexpectedTemplateExpression: "Unexpected template string expression." + } }, create(context) { @@ -30,7 +34,7 @@ module.exports = { if (typeof node.value === "string" && regex.test(node.value)) { context.report({ node, - message: "Unexpected template string expression." + messageId: "unexpectedTemplateExpression" }); } } diff --git a/lib/rules/no-ternary.js b/lib/rules/no-ternary.js index 890f2abfa0c..b3ced860566 100644 --- a/lib/rules/no-ternary.js +++ b/lib/rules/no-ternary.js @@ -20,7 +20,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-ternary" }, - schema: [] + schema: [], + + messages: { + noTernaryOperator: "Ternary operator used." + } }, create(context) { @@ -28,7 +32,7 @@ module.exports = { return { ConditionalExpression(node) { - context.report({ node, message: "Ternary operator used." }); + context.report({ node, messageId: "noTernaryOperator" }); } }; diff --git a/lib/rules/no-this-before-super.js b/lib/rules/no-this-before-super.js index 6975ea060bf..44288c0c971 100644 --- a/lib/rules/no-this-before-super.js +++ b/lib/rules/no-this-before-super.js @@ -45,7 +45,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-this-before-super" }, - schema: [] + schema: [], + + messages: { + noBeforeSuper: "'{{kind}}' is not allowed before 'super()'." + } }, create(context) { @@ -187,7 +191,7 @@ module.exports = { const invalidNode = info.invalidNodes[i]; context.report({ - message: "'{{kind}}' is not allowed before 'super()'.", + messageId: "noBeforeSuper", node: invalidNode, data: { kind: invalidNode.type === "Super" ? "super" : "this" diff --git a/lib/rules/no-trailing-spaces.js b/lib/rules/no-trailing-spaces.js index 3a4124f4c0f..98ae62c8963 100644 --- a/lib/rules/no-trailing-spaces.js +++ b/lib/rules/no-trailing-spaces.js @@ -42,7 +42,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + trailingSpace: "Trailing spaces not allowed." + } }, create(context) { @@ -74,7 +78,7 @@ module.exports = { context.report({ node, loc: location, - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", fix(fixer) { return fixer.removeRange(fixRange); } diff --git a/lib/rules/no-undef-init.js b/lib/rules/no-undef-init.js index 1fdccb867b3..5c240fef742 100644 --- a/lib/rules/no-undef-init.js +++ b/lib/rules/no-undef-init.js @@ -23,7 +23,11 @@ module.exports = { }, schema: [], - fixable: "code" + fixable: "code", + + messages: { + unnecessaryUndefinedInit: "It's not necessary to initialize '{{name}}' to undefined." + } }, create(context) { @@ -43,7 +47,7 @@ module.exports = { if (init === "undefined" && node.parent.kind !== "const" && !shadowed) { context.report({ node, - message: "It's not necessary to initialize '{{name}}' to undefined.", + messageId: "unnecessaryUndefinedInit", data: { name }, fix(fixer) { if (node.parent.kind === "var") { diff --git a/lib/rules/no-undefined.js b/lib/rules/no-undefined.js index b92f6700637..a075d903e21 100644 --- a/lib/rules/no-undefined.js +++ b/lib/rules/no-undefined.js @@ -19,7 +19,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-undefined" }, - schema: [] + schema: [], + + messages: { + unexpectedUndefined: "Unexpected use of undefined." + } }, create(context) { @@ -32,7 +36,7 @@ module.exports = { function report(node) { context.report({ node, - message: "Unexpected use of undefined." + messageId: "unexpectedUndefined" }); } diff --git a/lib/rules/no-underscore-dangle.js b/lib/rules/no-underscore-dangle.js index e910e2739a7..1468198ac4e 100644 --- a/lib/rules/no-underscore-dangle.js +++ b/lib/rules/no-underscore-dangle.js @@ -49,7 +49,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unexpectedUnderscore: "Unexpected dangling '_' in '{{identifier}}'." + } }, create(context) { @@ -134,7 +138,7 @@ module.exports = { if (typeof identifier !== "undefined" && hasTrailingUnderscore(identifier) && !isAllowed(identifier)) { context.report({ node, - message: "Unexpected dangling '_' in '{{identifier}}'.", + messageId: "unexpectedUnderscore", data: { identifier } @@ -156,7 +160,7 @@ module.exports = { !isSpecialCaseIdentifierInVariableExpression(identifier) && !isAllowed(identifier)) { context.report({ node, - message: "Unexpected dangling '_' in '{{identifier}}'.", + messageId: "unexpectedUnderscore", data: { identifier } @@ -183,7 +187,7 @@ module.exports = { !isSpecialCaseIdentifierForMemberExpression(identifier) && !isAllowed(identifier)) { context.report({ node, - message: "Unexpected dangling '_' in '{{identifier}}'.", + messageId: "unexpectedUnderscore", data: { identifier } @@ -204,7 +208,7 @@ module.exports = { if (typeof identifier !== "undefined" && enforceInMethodNames && isMethod && hasTrailingUnderscore(identifier)) { context.report({ node, - message: "Unexpected dangling '_' in '{{identifier}}'.", + messageId: "unexpectedUnderscore", data: { identifier } diff --git a/lib/rules/no-unmodified-loop-condition.js b/lib/rules/no-unmodified-loop-condition.js index 3b8e7417d5b..7031a4dd8b8 100644 --- a/lib/rules/no-unmodified-loop-condition.js +++ b/lib/rules/no-unmodified-loop-condition.js @@ -167,7 +167,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-unmodified-loop-condition" }, - schema: [] + schema: [], + + messages: { + loopConditionNotModified: "'{{name}}' is not modified in this loop." + } }, create(context) { @@ -184,7 +188,7 @@ module.exports = { context.report({ node, - message: "'{{name}}' is not modified in this loop.", + messageId: "loopConditionNotModified", data: node }); } diff --git a/lib/rules/no-unneeded-ternary.js b/lib/rules/no-unneeded-ternary.js index 893baa34f74..d4438e2fe08 100644 --- a/lib/rules/no-unneeded-ternary.js +++ b/lib/rules/no-unneeded-ternary.js @@ -47,7 +47,12 @@ module.exports = { } ], - fixable: "code" + fixable: "code", + + messages: { + unnecessaryConditionalExpression: "Unnecessary use of boolean literals in conditional expression.", + unnecessaryConditionalAssignment: "Unnecessary use of conditional expression for default assignment." + } }, create(context) { @@ -118,7 +123,7 @@ module.exports = { context.report({ node, loc: node.consequent.loc.start, - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", fix(fixer) { if (node.consequent.value === node.alternate.value) { @@ -140,7 +145,7 @@ module.exports = { context.report({ node, loc: node.consequent.loc.start, - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", fix: fixer => { const shouldParenthesizeAlternate = ( astUtils.getPrecedence(node.alternate) < OR_PRECEDENCE && diff --git a/lib/rules/no-unreachable.js b/lib/rules/no-unreachable.js index 91c4ca71509..415631a6f7d 100644 --- a/lib/rules/no-unreachable.js +++ b/lib/rules/no-unreachable.js @@ -110,7 +110,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-unreachable" }, - schema: [] + schema: [], + + messages: { + unreachableCode: "Unreachable code." + } }, create(context) { @@ -154,7 +158,7 @@ module.exports = { */ if (!range.isEmpty) { context.report({ - message: "Unreachable code.", + messageId: "unreachableCode", loc: range.location, node: range.startNode }); diff --git a/lib/rules/no-unsafe-finally.js b/lib/rules/no-unsafe-finally.js index a41dff9c803..11bf06e872a 100644 --- a/lib/rules/no-unsafe-finally.js +++ b/lib/rules/no-unsafe-finally.js @@ -29,7 +29,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-unsafe-finally" }, - schema: [] + schema: [], + + messages: { + unsafeUsage: "Unsafe usage of {{nodeType}}." + } }, create(context) { @@ -86,7 +90,7 @@ module.exports = { function check(node) { if (isInFinallyBlock(node, node.label)) { context.report({ - message: "Unsafe usage of {{nodeType}}.", + messageId: "unsafeUsage", data: { nodeType: node.type }, diff --git a/lib/rules/no-unused-expressions.js b/lib/rules/no-unused-expressions.js index fd0440256be..26a25b7584b 100644 --- a/lib/rules/no-unused-expressions.js +++ b/lib/rules/no-unused-expressions.js @@ -38,7 +38,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unusedExpression: "Expected an assignment or function call and instead saw an expression." + } }, create(context) { @@ -127,7 +131,7 @@ module.exports = { return { ExpressionStatement(node) { if (!isValidExpression(node.expression) && !isDirective(node, context.getAncestors())) { - context.report({ node, message: "Expected an assignment or function call and instead saw an expression." }); + context.report({ node, messageId: "unusedExpression" }); } } }; diff --git a/lib/rules/no-unused-vars.js b/lib/rules/no-unused-vars.js index ee26d95ef87..18c48bf0d78 100644 --- a/lib/rules/no-unused-vars.js +++ b/lib/rules/no-unused-vars.js @@ -11,6 +11,18 @@ const astUtils = require("./utils/ast-utils"); +//------------------------------------------------------------------------------ +// Typedefs +//------------------------------------------------------------------------------ + +/** + * Bag of data used for formatting the `unusedVar` lint message. + * @typedef {Object} UnusedVarMessageData + * @property {string} varName The name of the unused var. + * @property {'defined'|'assigned a value'} action Description of the vars state. + * @property {string} additional Any additional info to be appended at the end. + */ + //------------------------------------------------------------------------------ // Rule Definition //------------------------------------------------------------------------------ @@ -60,7 +72,11 @@ module.exports = { } ] } - ] + ], + + messages: { + unusedVar: "'{{varName}}' is {{action}} but never used{{additional}}." + } }, create(context) { @@ -101,12 +117,12 @@ module.exports = { } /** - * Generate the warning message about the variable being - * defined and unused, including the ignore pattern if configured. + * Generates the message data about the variable being defined and unused, + * including the ignore pattern if configured. * @param {Variable} unusedVar eslint-scope variable object. - * @returns {string} The warning message to be used with this unused variable. + * @returns {UnusedVarMessageData} The message data to be used with this unused variable. */ - function getDefinedMessage(unusedVar) { + function getDefinedMessageData(unusedVar) { const defType = unusedVar.defs && unusedVar.defs[0] && unusedVar.defs[0].type; let type; let pattern; @@ -122,20 +138,29 @@ module.exports = { pattern = config.varsIgnorePattern.toString(); } - const additional = type ? ` Allowed unused ${type} must match ${pattern}.` : ""; + const additional = type ? `. Allowed unused ${type} must match ${pattern}` : ""; - return `'{{name}}' is defined but never used.${additional}`; + return { + varName: unusedVar.name, + action: "defined", + additional + }; } /** * Generate the warning message about the variable being * assigned and unused, including the ignore pattern if configured. - * @returns {string} The warning message to be used with this unused variable. + * @param {Variable} unusedVar eslint-scope variable object. + * @returns {UnusedVarMessageData} The message data to be used with this unused variable. */ - function getAssignedMessage() { - const additional = config.varsIgnorePattern ? ` Allowed unused vars must match ${config.varsIgnorePattern.toString()}.` : ""; - - return `'{{name}}' is assigned a value but never used.${additional}`; + function getAssignedMessageData(unusedVar) { + const additional = config.varsIgnorePattern ? `. Allowed unused vars must match ${config.varsIgnorePattern.toString()}` : ""; + + return { + varName: unusedVar.name, + action: "assigned a value", + additional + }; } //-------------------------------------------------------------------------- @@ -595,10 +620,10 @@ module.exports = { if (unusedVar.defs.length > 0) { context.report({ node: unusedVar.identifiers[0], - message: unusedVar.references.some(ref => ref.isWrite()) - ? getAssignedMessage() - : getDefinedMessage(unusedVar), - data: unusedVar + messageId: "unusedVar", + data: unusedVar.references.some(ref => ref.isWrite()) + ? getAssignedMessageData(unusedVar) + : getDefinedMessageData(unusedVar) }); // If there are no regular declaration, report the first `/*globals*/` comment directive. @@ -608,8 +633,8 @@ module.exports = { context.report({ node: programNode, loc: astUtils.getNameLocationInGlobalDirectiveComment(sourceCode, directiveComment, unusedVar.name), - message: getDefinedMessage(unusedVar), - data: unusedVar + messageId: "unusedVar", + data: getDefinedMessageData(unusedVar) }); } } diff --git a/lib/rules/no-useless-call.js b/lib/rules/no-useless-call.js index 11cf524d124..afc729d5de0 100644 --- a/lib/rules/no-useless-call.js +++ b/lib/rules/no-useless-call.js @@ -58,7 +58,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-useless-call" }, - schema: [] + schema: [], + + messages: { + unnecessaryCall: "Unnecessary '.{{name}}()'." + } }, create(context) { @@ -75,7 +79,7 @@ module.exports = { const thisArg = node.arguments[0]; if (isValidThisArg(expectedThis, thisArg, sourceCode)) { - context.report({ node, message: "unnecessary '.{{name}}()'.", data: { name: node.callee.property.name } }); + context.report({ node, messageId: "unnecessaryCall", data: { name: node.callee.property.name } }); } } }; diff --git a/lib/rules/no-useless-catch.js b/lib/rules/no-useless-catch.js index 37bf453aecd..f303c272948 100644 --- a/lib/rules/no-useless-catch.js +++ b/lib/rules/no-useless-catch.js @@ -20,7 +20,12 @@ module.exports = { url: "https://eslint.org/docs/rules/no-useless-catch" }, - schema: [] + schema: [], + + messages: { + unnecessaryCatchClause: "Unnecessary catch clause.", + unnecessaryCatch: "Unnecessary try/catch wrapper." + } }, create(context) { @@ -37,12 +42,12 @@ module.exports = { if (node.parent.finalizer) { context.report({ node, - message: "Unnecessary catch clause." + messageId: "unnecessaryCatchClause" }); } else { context.report({ node: node.parent, - message: "Unnecessary try/catch wrapper." + messageId: "unnecessaryCatch" }); } } diff --git a/lib/rules/no-useless-computed-key.js b/lib/rules/no-useless-computed-key.js index 0e0acbea7c3..e0505a318ef 100644 --- a/lib/rules/no-useless-computed-key.js +++ b/lib/rules/no-useless-computed-key.js @@ -15,8 +15,6 @@ const astUtils = require("./utils/ast-utils"); // Rule Definition //------------------------------------------------------------------------------ -const MESSAGE_UNNECESSARY_COMPUTED = "Unnecessarily computed property [{{property}}] found."; - module.exports = { meta: { type: "suggestion", @@ -38,7 +36,11 @@ module.exports = { }, additionalProperties: false }], - fixable: "code" + fixable: "code", + + messages: { + unnecessarilyComputedProperty: "Unnecessarily computed property [{{property}}] found." + } }, create(context) { const sourceCode = context.getSourceCode(); @@ -68,7 +70,7 @@ module.exports = { if (key.type === "Literal" && (nodeType === "string" || nodeType === "number") && key.value !== allowedKey) { context.report({ node, - message: MESSAGE_UNNECESSARY_COMPUTED, + messageId: "unnecessarilyComputedProperty", data: { property: sourceCode.getText(key) }, fix(fixer) { const leftSquareBracket = sourceCode.getTokenBefore(key, astUtils.isOpeningBracketToken); diff --git a/lib/rules/no-useless-concat.js b/lib/rules/no-useless-concat.js index 50e039c2ce9..aa46742abdd 100644 --- a/lib/rules/no-useless-concat.js +++ b/lib/rules/no-useless-concat.js @@ -75,7 +75,11 @@ module.exports = { url: "https://eslint.org/docs/rules/no-useless-concat" }, - schema: [] + schema: [], + + messages: { + unexpectedConcat: "Unexpected string concatenation of literals." + } }, create(context) { @@ -102,7 +106,7 @@ module.exports = { context.report({ node, loc: operatorToken.loc.start, - message: "Unexpected string concatenation of literals." + messageId: "unexpectedConcat" }); } } diff --git a/lib/rules/no-useless-rename.js b/lib/rules/no-useless-rename.js index eb570a3ef5c..fa88f37f50b 100644 --- a/lib/rules/no-useless-rename.js +++ b/lib/rules/no-useless-rename.js @@ -32,7 +32,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unnecessarilyRenamed: "{{type}} {{name}} unnecessarily renamed." + } }, create(context) { @@ -59,7 +63,7 @@ module.exports = { return context.report({ node, - message: "{{type}} {{name}} unnecessarily renamed.", + messageId: "unnecessarilyRenamed", data: { name, type diff --git a/lib/rules/no-useless-return.js b/lib/rules/no-useless-return.js index ecdd44240c9..111cb21015f 100644 --- a/lib/rules/no-useless-return.js +++ b/lib/rules/no-useless-return.js @@ -73,7 +73,11 @@ module.exports = { }, fixable: "code", - schema: [] + schema: [], + + messages: { + unnecessaryReturn: "Unnecessary return statement." + } }, create(context) { @@ -208,7 +212,7 @@ module.exports = { context.report({ node, loc: node.loc, - message: "Unnecessary return statement.", + messageId: "unnecessaryReturn", fix(fixer) { if (isRemovable(node) && !sourceCode.getCommentsInside(node).length) { diff --git a/lib/rules/no-var.js b/lib/rules/no-var.js index 74203f8bf3b..f2cb96b1f70 100644 --- a/lib/rules/no-var.js +++ b/lib/rules/no-var.js @@ -191,7 +191,11 @@ module.exports = { }, schema: [], - fixable: "code" + fixable: "code", + + messages: { + unexpectedVar: "Unexpected var, use let or const instead." + } }, create(context) { @@ -307,7 +311,7 @@ module.exports = { function report(node) { context.report({ node, - message: "Unexpected var, use let or const instead.", + messageId: "unexpectedVar", fix(fixer) { const varToken = sourceCode.getFirstToken(node, { filter: t => t.value === "var" }); diff --git a/lib/rules/no-warning-comments.js b/lib/rules/no-warning-comments.js index a400c446767..d70bd5dd5c4 100644 --- a/lib/rules/no-warning-comments.js +++ b/lib/rules/no-warning-comments.js @@ -39,7 +39,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unexpectedComment: "Unexpected '{{matchedTerm}}' comment." + } }, create(context) { @@ -140,7 +144,7 @@ module.exports = { matches.forEach(matchedTerm => { context.report({ node, - message: "Unexpected '{{matchedTerm}}' comment.", + messageId: "unexpectedComment", data: { matchedTerm } diff --git a/lib/rules/no-whitespace-before-property.js b/lib/rules/no-whitespace-before-property.js index 9541401a317..ccd0b091b74 100644 --- a/lib/rules/no-whitespace-before-property.js +++ b/lib/rules/no-whitespace-before-property.js @@ -26,7 +26,11 @@ module.exports = { }, fixable: "whitespace", - schema: [] + schema: [], + + messages: { + unexpectedWhitespace: "Unexpected whitespace before property {{propName}}." + } }, create(context) { @@ -49,7 +53,7 @@ module.exports = { context.report({ node, - message: "Unexpected whitespace before property {{propName}}.", + messageId: "unexpectedWhitespace", data: { propName: sourceCode.getText(node.property) }, diff --git a/lib/rules/no-with.js b/lib/rules/no-with.js index 5763661584c..d3e52e02f3d 100644 --- a/lib/rules/no-with.js +++ b/lib/rules/no-with.js @@ -20,14 +20,18 @@ module.exports = { url: "https://eslint.org/docs/rules/no-with" }, - schema: [] + schema: [], + + messages: { + unexpectedWith: "Unexpected use of 'with' statement." + } }, create(context) { return { WithStatement(node) { - context.report({ node, message: "Unexpected use of 'with' statement." }); + context.report({ node, messageId: "unexpectedWith" }); } }; diff --git a/lib/rules/nonblock-statement-body-position.js b/lib/rules/nonblock-statement-body-position.js index 01763cea92f..34e6eeac39d 100644 --- a/lib/rules/nonblock-statement-body-position.js +++ b/lib/rules/nonblock-statement-body-position.js @@ -40,7 +40,12 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + expectNoLinebreak: "Expected no linebreak before this statement.", + expectLinebreak: "Expected a linebreak before this statement." + } }, create(context) { @@ -79,13 +84,13 @@ module.exports = { if (tokenBefore.loc.end.line === node.loc.start.line && option === "below") { context.report({ node, - message: "Expected a linebreak before this statement.", + messageId: "expectLinebreak", fix: fixer => fixer.insertTextBefore(node, "\n") }); } else if (tokenBefore.loc.end.line !== node.loc.start.line && option === "beside") { context.report({ node, - message: "Expected no linebreak before this statement.", + messageId: "expectNoLinebreak", fix(fixer) { if (sourceCode.getText().slice(tokenBefore.range[1], node.range[0]).trim()) { return null; diff --git a/lib/rules/object-curly-newline.js b/lib/rules/object-curly-newline.js index e870a69a954..b48b2526a0b 100644 --- a/lib/rules/object-curly-newline.js +++ b/lib/rules/object-curly-newline.js @@ -159,7 +159,14 @@ module.exports = { } ] } - ] + ], + + messages: { + unexpectedLinebreakBeforeClosingBrace: "Unexpected line break before this closing brace.", + unexpectedLinebreakAfterOpeningBrace: "Unexpected line break after this opening brace.", + expectedLinebreakBeforeClosingBrace: "Expected a line break before this closing brace.", + expectedLinebreakAfterOpeningBrace: "Expected a line break after this opening brace." + } }, create(context) { @@ -215,7 +222,7 @@ module.exports = { if (needsLineBreaks) { if (astUtils.isTokenOnSameLine(openBrace, first)) { context.report({ - message: "Expected a line break after this opening brace.", + messageId: "expectedLinebreakAfterOpeningBrace", node, loc: openBrace.loc.start, fix(fixer) { @@ -229,7 +236,7 @@ module.exports = { } if (astUtils.isTokenOnSameLine(last, closeBrace)) { context.report({ - message: "Expected a line break before this closing brace.", + messageId: "expectedLinebreakBeforeClosingBrace", node, loc: closeBrace.loc.start, fix(fixer) { @@ -251,7 +258,7 @@ module.exports = { (consistent && hasLineBreakBetweenOpenBraceAndFirst && !hasLineBreakBetweenCloseBraceAndLast) ) { context.report({ - message: "Unexpected line break after this opening brace.", + messageId: "unexpectedLinebreakAfterOpeningBrace", node, loc: openBrace.loc.start, fix(fixer) { @@ -271,7 +278,7 @@ module.exports = { (consistent && !hasLineBreakBetweenOpenBraceAndFirst && hasLineBreakBetweenCloseBraceAndLast) ) { context.report({ - message: "Unexpected line break before this closing brace.", + messageId: "unexpectedLinebreakBeforeClosingBrace", node, loc: closeBrace.loc.start, fix(fixer) { diff --git a/lib/rules/object-curly-spacing.js b/lib/rules/object-curly-spacing.js index 117a7a35426..c0044f5033c 100644 --- a/lib/rules/object-curly-spacing.js +++ b/lib/rules/object-curly-spacing.js @@ -39,7 +39,14 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + requireSpaceBefore: "A space is required before '{{token}}'.", + requireSpaceAfter: "A space is required after '{{token}}'.", + unexpectedSpaceBefore: "There should be no space before '{{token}}'.", + unexpectedSpaceAfter: "There should be no space after '{{token}}'." + } }, create(context) { @@ -79,7 +86,7 @@ module.exports = { context.report({ node, loc: { start: token.loc.end, end: nextToken.loc.start }, - message: "There should be no space after '{{token}}'.", + messageId: "unexpectedSpaceAfter", data: { token: token.value }, @@ -101,7 +108,7 @@ module.exports = { context.report({ node, loc: { start: previousToken.loc.end, end: token.loc.start }, - message: "There should be no space before '{{token}}'.", + messageId: "unexpectedSpaceBefore", data: { token: token.value }, @@ -121,7 +128,7 @@ module.exports = { context.report({ node, loc: token.loc, - message: "A space is required after '{{token}}'.", + messageId: "requireSpaceAfter", data: { token: token.value }, @@ -141,7 +148,7 @@ module.exports = { context.report({ node, loc: token.loc, - message: "A space is required before '{{token}}'.", + messageId: "requireSpaceBefore", data: { token: token.value }, diff --git a/lib/rules/object-property-newline.js b/lib/rules/object-property-newline.js index bf777b5ff65..074bc775ae3 100644 --- a/lib/rules/object-property-newline.js +++ b/lib/rules/object-property-newline.js @@ -37,16 +37,21 @@ module.exports = { } ], - fixable: "whitespace" + fixable: "whitespace", + + messages: { + propertiesOnNewlineAll: "Object properties must go on a new line if they aren't all on the same line.", + propertiesOnNewline: "Object properties must go on a new line." + } }, create(context) { const allowSameLine = context.options[0] && ( (context.options[0].allowAllPropertiesOnSameLine || context.options[0].allowMultiplePropertiesPerLine /* Deprecated */) ); - const errorMessage = allowSameLine - ? "Object properties must go on a new line if they aren't all on the same line." - : "Object properties must go on a new line."; + const messageId = allowSameLine + ? "propertiesOnNewlineAll" + : "propertiesOnNewline"; const sourceCode = context.getSourceCode(); @@ -73,7 +78,7 @@ module.exports = { context.report({ node, loc: firstTokenOfCurrentProperty.loc.start, - message: errorMessage, + messageId, fix(fixer) { const comma = sourceCode.getTokenBefore(firstTokenOfCurrentProperty); const rangeAfterComma = [comma.range[1], firstTokenOfCurrentProperty.range[0]]; diff --git a/lib/rules/object-shorthand.js b/lib/rules/object-shorthand.js index d4afd09c5a5..3999ff8b99f 100644 --- a/lib/rules/object-shorthand.js +++ b/lib/rules/object-shorthand.js @@ -92,6 +92,16 @@ module.exports = { maxItems: 2 } ] + }, + + messages: { + expectedAllPropertiesShorthanded: "Expected shorthand for all properties.", + expectedLiteralMethodLongform: "Expected longform method syntax for string literal keys.", + expectedPropertyShorthand: "Expected property shorthand.", + expectedPropertyLongform: "Expected longform property syntax.", + expectedMethodShorthand: "Expected method shorthand.", + expectedMethodLongform: "Expected longform method syntax.", + unexpectedMix: "Unexpected mix of shorthand and non-shorthand properties." } }, @@ -211,7 +221,7 @@ module.exports = { // We have at least 1 shorthand property if (shorthandProperties.length > 0) { - context.report({ node, message: "Unexpected mix of shorthand and non-shorthand properties." }); + context.report({ node, messageId: "unexpectedMix" }); } else if (checkRedundancy) { /* @@ -221,7 +231,7 @@ module.exports = { const canAlwaysUseShorthand = properties.every(isRedundant); if (canAlwaysUseShorthand) { - context.report({ node, message: "Expected shorthand for all properties." }); + context.report({ node, messageId: "expectedAllPropertiesShorthanded" }); } } } @@ -430,12 +440,12 @@ module.exports = { // Checks for property/method shorthand. if (isConciseProperty) { if (node.method && (APPLY_NEVER || AVOID_QUOTES && isStringLiteral(node.key))) { - const message = APPLY_NEVER ? "Expected longform method syntax." : "Expected longform method syntax for string literal keys."; + const messageId = APPLY_NEVER ? "expectedMethodLongform" : "expectedLiteralMethodLongform"; // { x() {} } should be written as { x: function() {} } context.report({ node, - message, + messageId, fix: fixer => makeFunctionLongform(fixer, node) }); } else if (APPLY_NEVER) { @@ -443,7 +453,7 @@ module.exports = { // { x } should be written as { x: x } context.report({ node, - message: "Expected longform property syntax.", + messageId: "expectedPropertyLongform", fix: fixer => fixer.insertTextAfter(node.key, `: ${node.key.name}`) }); } @@ -464,7 +474,7 @@ module.exports = { ) { context.report({ node, - message: "Expected method shorthand.", + messageId: "expectedMethodShorthand", fix: fixer => makeFunctionShorthand(fixer, node) }); } @@ -473,7 +483,7 @@ module.exports = { // {x: x} should be written as {x} context.report({ node, - message: "Expected property shorthand.", + messageId: "expectedPropertyShorthand", fix(fixer) { return fixer.replaceText(node, node.value.name); } @@ -486,7 +496,7 @@ module.exports = { // {"x": x} should be written as {x} context.report({ node, - message: "Expected property shorthand.", + messageId: "expectedPropertyShorthand", fix(fixer) { return fixer.replaceText(node, node.value.name); } diff --git a/lib/rules/one-var-declaration-per-line.js b/lib/rules/one-var-declaration-per-line.js index b64656eefed..30ca2cf4983 100644 --- a/lib/rules/one-var-declaration-per-line.js +++ b/lib/rules/one-var-declaration-per-line.js @@ -25,12 +25,15 @@ module.exports = { } ], - fixable: "whitespace" + fixable: "whitespace", + + messages: { + expectVarOnNewline: "Expected variable declaration to be on a new line." + } }, create(context) { - const ERROR_MESSAGE = "Expected variable declaration to be on a new line."; const always = context.options[0] === "always"; //-------------------------------------------------------------------------- @@ -67,7 +70,7 @@ module.exports = { if (always || prev.init || current.init) { context.report({ node, - message: ERROR_MESSAGE, + messageId: "expectVarOnNewline", loc: current.loc.start, fix: fixer => fixer.insertTextBefore(current, "\n") }); diff --git a/lib/rules/one-var.js b/lib/rules/one-var.js index e79461ce46c..c31a0d2b13c 100644 --- a/lib/rules/one-var.js +++ b/lib/rules/one-var.js @@ -60,7 +60,17 @@ module.exports = { } ] } - ] + ], + + messages: { + combineUninitialized: "Combine this with the previous '{{type}}' statement with uninitialized variables.", + combineInitialized: "Combine this with the previous '{{type}}' statement with initialized variables.", + splitUninitialized: "Split uninitialized '{{type}}' declarations into multiple statements.", + splitInitialized: "Split initialized '{{type}}' declarations into multiple statements.", + splitRequires: "Split requires to be separated into a single block.", + combine: "Combine this with the previous '{{type}}' statement.", + split: "Split '{{type}}' declarations into multiple statements." + } }, create(context) { @@ -361,7 +371,7 @@ module.exports = { if (options.separateRequires && mixedRequires) { context.report({ node, - message: "Split requires to be separated into a single block." + messageId: "splitRequires" }); } } @@ -384,7 +394,7 @@ module.exports = { if (options[type].initialized === MODE_CONSECUTIVE && options[type].uninitialized === MODE_CONSECUTIVE) { context.report({ node, - message: "Combine this with the previous '{{type}}' statement.", + messageId: "combine", data: { type }, @@ -393,7 +403,7 @@ module.exports = { } else if (options[type].initialized === MODE_CONSECUTIVE && declarationCounts.initialized > 0 && previousDeclCounts.initialized > 0) { context.report({ node, - message: "Combine this with the previous '{{type}}' statement with initialized variables.", + messageId: "combineInitialized", data: { type }, @@ -404,7 +414,7 @@ module.exports = { previousDeclCounts.uninitialized > 0) { context.report({ node, - message: "Combine this with the previous '{{type}}' statement with uninitialized variables.", + messageId: "combineUninitialized", data: { type }, @@ -419,7 +429,7 @@ module.exports = { if (options[type].initialized === MODE_ALWAYS && options[type].uninitialized === MODE_ALWAYS) { context.report({ node, - message: "Combine this with the previous '{{type}}' statement.", + messageId: "combine", data: { type }, @@ -429,7 +439,7 @@ module.exports = { if (options[type].initialized === MODE_ALWAYS && declarationCounts.initialized > 0) { context.report({ node, - message: "Combine this with the previous '{{type}}' statement with initialized variables.", + messageId: "combineInitialized", data: { type }, @@ -442,7 +452,7 @@ module.exports = { } context.report({ node, - message: "Combine this with the previous '{{type}}' statement with uninitialized variables.", + messageId: "combineUninitialized", data: { type }, @@ -462,7 +472,7 @@ module.exports = { // both initialized and uninitialized context.report({ node, - message: "Split '{{type}}' declarations into multiple statements.", + messageId: "split", data: { type }, @@ -473,7 +483,7 @@ module.exports = { // initialized context.report({ node, - message: "Split initialized '{{type}}' declarations into multiple statements.", + messageId: "splitInitialized", data: { type }, @@ -484,7 +494,7 @@ module.exports = { // uninitialized context.report({ node, - message: "Split uninitialized '{{type}}' declarations into multiple statements.", + messageId: "splitUninitialized", data: { type }, diff --git a/lib/rules/operator-linebreak.js b/lib/rules/operator-linebreak.js index bce0ef56a0c..c2fddcffd25 100644 --- a/lib/rules/operator-linebreak.js +++ b/lib/rules/operator-linebreak.js @@ -47,7 +47,14 @@ module.exports = { } ], - fixable: "code" + fixable: "code", + + messages: { + operatorAtBeginning: "'{{operator}}' should be placed at the beginning of the line.", + operatorAtEnd: "'{{operator}}' should be placed at the end of the line.", + badLinebreak: "Bad line breaking before and after '{{operator}}'.", + noLinebreak: "There should be no line break before or after '{{operator}}'." + } }, create(context) { @@ -169,7 +176,7 @@ module.exports = { line: operatorToken.loc.end.line, column: operatorToken.loc.end.column }, - message: "Bad line breaking before and after '{{operator}}'.", + messageId: "badLinebreak", data: { operator }, @@ -184,7 +191,7 @@ module.exports = { line: operatorToken.loc.end.line, column: operatorToken.loc.end.column }, - message: "'{{operator}}' should be placed at the beginning of the line.", + messageId: "operatorAtBeginning", data: { operator }, @@ -199,7 +206,7 @@ module.exports = { line: operatorToken.loc.end.line, column: operatorToken.loc.end.column }, - message: "'{{operator}}' should be placed at the end of the line.", + messageId: "operatorAtEnd", data: { operator }, @@ -214,7 +221,7 @@ module.exports = { line: operatorToken.loc.end.line, column: operatorToken.loc.end.column }, - message: "There should be no line break before or after '{{operator}}'.", + messageId: "noLinebreak", data: { operator }, diff --git a/lib/rules/padded-blocks.js b/lib/rules/padded-blocks.js index bfdcf76f24f..f58a7535ba8 100644 --- a/lib/rules/padded-blocks.js +++ b/lib/rules/padded-blocks.js @@ -60,7 +60,12 @@ module.exports = { } } } - ] + ], + + messages: { + alwaysPadBlock: "Block must be padded by blank lines.", + neverPadBlock: "Block must not be padded by blank lines." + } }, create(context) { @@ -90,9 +95,6 @@ module.exports = { options.allowSingleLineBlocks = exceptOptions.allowSingleLineBlocks === true; } - const ALWAYS_MESSAGE = "Block must be padded by blank lines.", - NEVER_MESSAGE = "Block must not be padded by blank lines."; - const sourceCode = context.getSourceCode(); /** @@ -208,7 +210,7 @@ module.exports = { fix(fixer) { return fixer.insertTextAfter(tokenBeforeFirst, "\n"); }, - message: ALWAYS_MESSAGE + messageId: "alwaysPadBlock" }); } if (!blockHasBottomPadding) { @@ -218,7 +220,7 @@ module.exports = { fix(fixer) { return fixer.insertTextBefore(tokenAfterLast, "\n"); }, - message: ALWAYS_MESSAGE + messageId: "alwaysPadBlock" }); } } else { @@ -230,7 +232,7 @@ module.exports = { fix(fixer) { return fixer.replaceTextRange([tokenBeforeFirst.range[1], firstBlockToken.range[0] - firstBlockToken.loc.start.column], "\n"); }, - message: NEVER_MESSAGE + messageId: "neverPadBlock" }); } @@ -239,7 +241,7 @@ module.exports = { context.report({ node, loc: { line: tokenAfterLast.loc.end.line, column: tokenAfterLast.loc.end.column - 1 }, - message: NEVER_MESSAGE, + messageId: "neverPadBlock", fix(fixer) { return fixer.replaceTextRange([lastBlockToken.range[1], tokenAfterLast.range[0] - tokenAfterLast.loc.start.column], "\n"); } diff --git a/lib/rules/padding-line-between-statements.js b/lib/rules/padding-line-between-statements.js index 350a9dbf2ab..eea19f5ce58 100644 --- a/lib/rules/padding-line-between-statements.js +++ b/lib/rules/padding-line-between-statements.js @@ -243,7 +243,7 @@ function verifyForNever(context, _, nextNode, paddingLines) { context.report({ node: nextNode, - message: "Unexpected blank line before this statement.", + messageId: "unexpectedBlankLine", fix(fixer) { if (paddingLines.length >= 2) { return null; @@ -282,7 +282,7 @@ function verifyForAlways(context, prevNode, nextNode, paddingLines) { context.report({ node: nextNode, - message: "Expected blank line before this statement.", + messageId: "expectedBlankLine", fix(fixer) { const sourceCode = context.getSourceCode(); let prevToken = getActualLastToken(sourceCode, prevNode); @@ -468,6 +468,11 @@ module.exports = { required: ["blankLine", "prev", "next"] }, additionalItems: false + }, + + messages: { + unexpectedBlankLine: "Unexpected blank line before this statement.", + expectedBlankLine: "Expected blank line before this statement." } }, diff --git a/lib/rules/prefer-arrow-callback.js b/lib/rules/prefer-arrow-callback.js index 1fdd7f2c877..d4e0251940c 100644 --- a/lib/rules/prefer-arrow-callback.js +++ b/lib/rules/prefer-arrow-callback.js @@ -158,7 +158,11 @@ module.exports = { } ], - fixable: "code" + fixable: "code", + + messages: { + preferArrowCallback: "Unexpected function expression." + } }, create(context) { @@ -267,7 +271,7 @@ module.exports = { ) { context.report({ node, - message: "Unexpected function expression.", + messageId: "preferArrowCallback", fix(fixer) { if ((!callbackInfo.isLexicalThis && scopeInfo.this) || hasDuplicateParams(node.params)) { diff --git a/lib/rules/prefer-destructuring.js b/lib/rules/prefer-destructuring.js index eff37294a9b..1a51956dde5 100644 --- a/lib/rules/prefer-destructuring.js +++ b/lib/rules/prefer-destructuring.js @@ -82,7 +82,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + preferDestructuring: "Use {{type}} destructuring." + } }, create(context) { @@ -137,7 +141,7 @@ module.exports = { function report(reportNode, type, fix) { context.report({ node: reportNode, - message: "Use {{type}} destructuring.", + messageId: "preferDestructuring", data: { type }, fix }); diff --git a/lib/rules/prefer-promise-reject-errors.js b/lib/rules/prefer-promise-reject-errors.js index e142a96b55c..56911b67adc 100644 --- a/lib/rules/prefer-promise-reject-errors.js +++ b/lib/rules/prefer-promise-reject-errors.js @@ -31,7 +31,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + rejectAnError: "Expected the Promise rejection reason to be an Error." + } }, create(context) { @@ -58,7 +62,7 @@ module.exports = { ) { context.report({ node: callExpression, - message: "Expected the Promise rejection reason to be an Error." + messageId: "rejectAnError" }); } } diff --git a/lib/rules/prefer-reflect.js b/lib/rules/prefer-reflect.js index 261abce0ded..fb2de923bea 100644 --- a/lib/rules/prefer-reflect.js +++ b/lib/rules/prefer-reflect.js @@ -49,7 +49,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + preferReflect: "Avoid using {{existing}}, instead use {{substitute}}." + } }, create(context) { @@ -89,7 +93,7 @@ module.exports = { function report(node, existing, substitute) { context.report({ node, - message: "Avoid using {{existing}}, instead use {{substitute}}.", + messageId: "preferReflect", data: { existing, substitute diff --git a/lib/rules/prefer-rest-params.js b/lib/rules/prefer-rest-params.js index 3a28584f6bc..3ecea732af8 100644 --- a/lib/rules/prefer-rest-params.js +++ b/lib/rules/prefer-rest-params.js @@ -70,7 +70,11 @@ module.exports = { url: "https://eslint.org/docs/rules/prefer-rest-params" }, - schema: [] + schema: [], + + messages: { + preferRestParams: "Use the rest parameters instead of 'arguments'." + } }, create(context) { @@ -84,7 +88,7 @@ module.exports = { context.report({ node: reference.identifier, loc: reference.identifier.loc, - message: "Use the rest parameters instead of 'arguments'." + messageId: "preferRestParams" }); } diff --git a/lib/rules/prefer-spread.js b/lib/rules/prefer-spread.js index 14c05bd9710..bcb0dc0dd4c 100644 --- a/lib/rules/prefer-spread.js +++ b/lib/rules/prefer-spread.js @@ -59,7 +59,11 @@ module.exports = { }, schema: [], - fixable: null + fixable: null, + + messages: { + preferSpread: "Use the spread operator instead of '.apply()'." + } }, create(context) { @@ -78,7 +82,7 @@ module.exports = { if (isValidThisArg(expectedThis, thisArg, sourceCode)) { context.report({ node, - message: "Use the spread operator instead of '.apply()'." + messageId: "preferSpread" }); } } diff --git a/lib/rules/prefer-template.js b/lib/rules/prefer-template.js index fa6e58d9721..e8f980ebd38 100644 --- a/lib/rules/prefer-template.js +++ b/lib/rules/prefer-template.js @@ -142,7 +142,11 @@ module.exports = { }, schema: [], - fixable: "code" + fixable: "code", + + messages: { + unexpectedStringConcatenation: "Unexpected string concatenation." + } }, create(context) { @@ -261,7 +265,7 @@ module.exports = { if (hasNonStringLiteral(topBinaryExpr)) { context.report({ node: topBinaryExpr, - message: "Unexpected string concatenation.", + messageId: "unexpectedStringConcatenation", fix: fixer => fixNonStringBinaryExpression(fixer, node) }); } diff --git a/lib/rules/quote-props.js b/lib/rules/quote-props.js index 4cc53b988f6..a2a4e1d4792 100644 --- a/lib/rules/quote-props.js +++ b/lib/rules/quote-props.js @@ -67,7 +67,16 @@ module.exports = { ] }, - fixable: "code" + fixable: "code", + messages: { + requireQuotesDueToReservedWord: "Properties should be quoted as '{{property}}' is a reserved word.", + inconsistentlyQuotedProperty: "Inconsistently quoted property '{{key}}' found.", + unnecessarilyQuotedProperty: "Unnecessarily quoted property '{{property}}' found.", + unquotedReservedProperty: "Unquoted reserved word '{{property}}' used as key.", + unquotedNumericProperty: "Unquoted number literal '{{property}}' used as key.", + unquotedPropertyFound: "Unquoted property '{{property}}' found.", + redundantQuoting: "Properties shouldn't be quoted as all quotes are redundant." + } }, create(context) { @@ -77,10 +86,6 @@ module.exports = { CHECK_UNNECESSARY = !context.options[1] || context.options[1].unnecessary !== false, NUMBERS = context.options[1] && context.options[1].numbers, - MESSAGE_UNNECESSARY = "Unnecessarily quoted property '{{property}}' found.", - MESSAGE_UNQUOTED = "Unquoted property '{{property}}' found.", - MESSAGE_NUMERIC = "Unquoted number literal '{{property}}' used as key.", - MESSAGE_RESERVED = "Unquoted reserved word '{{property}}' used as key.", sourceCode = context.getSourceCode(); @@ -166,7 +171,7 @@ module.exports = { if (CHECK_UNNECESSARY && areQuotesRedundant(key.value, tokens, NUMBERS)) { context.report({ node, - message: MESSAGE_UNNECESSARY, + messageId: "unnecessarilyQuotedProperty", data: { property: key.value }, fix: fixer => fixer.replaceText(key, getUnquotedKey(key)) }); @@ -174,14 +179,14 @@ module.exports = { } else if (KEYWORDS && key.type === "Identifier" && isKeyword(key.name)) { context.report({ node, - message: MESSAGE_RESERVED, + messageId: "unquotedReservedProperty", data: { property: key.name }, fix: fixer => fixer.replaceText(key, getQuotedKey(key)) }); } else if (NUMBERS && key.type === "Literal" && astUtils.isNumericLiteral(key)) { context.report({ node, - message: MESSAGE_NUMERIC, + messageId: "unquotedNumericProperty", data: { property: key.value }, fix: fixer => fixer.replaceText(key, getQuotedKey(key)) }); @@ -199,7 +204,7 @@ module.exports = { if (!node.method && !node.computed && !node.shorthand && !(key.type === "Literal" && typeof key.value === "string")) { context.report({ node, - message: MESSAGE_UNQUOTED, + messageId: "unquotedPropertyFound", data: { property: key.name || key.value }, fix: fixer => fixer.replaceText(key, getQuotedKey(key)) }); @@ -254,7 +259,7 @@ module.exports = { quotedProps.forEach(property => { context.report({ node: property, - message: "Properties shouldn't be quoted as all quotes are redundant.", + messageId: "redundantQuoting", fix: fixer => fixer.replaceText(property.key, getUnquotedKey(property.key)) }); }); @@ -262,7 +267,7 @@ module.exports = { unquotedProps.forEach(property => { context.report({ node: property, - message: "Properties should be quoted as '{{property}}' is a reserved word.", + messageId: "requireQuotesDueToReservedWord", data: { property: keywordKeyName }, fix: fixer => fixer.replaceText(property.key, getQuotedKey(property.key)) }); @@ -271,7 +276,7 @@ module.exports = { unquotedProps.forEach(property => { context.report({ node: property, - message: "Inconsistently quoted property '{{key}}' found.", + messageId: "inconsistentlyQuotedProperty", data: { key: property.key.name || property.key.value }, fix: fixer => fixer.replaceText(property.key, getQuotedKey(property.key)) }); diff --git a/lib/rules/radix.js b/lib/rules/radix.js index d1503dba1a4..3903cb2a6a2 100644 --- a/lib/rules/radix.js +++ b/lib/rules/radix.js @@ -89,7 +89,14 @@ module.exports = { { enum: ["always", "as-needed"] } - ] + ], + + messages: { + missingParameters: "Missing parameters.", + redundantRadix: "Redundant radix parameter.", + missingRadix: "Missing radix parameter.", + invalidRadix: "Invalid radix parameter, must be an integer between 2 and 36." + } }, create(context) { @@ -108,7 +115,7 @@ module.exports = { case 0: context.report({ node, - message: "Missing parameters." + messageId: "missingParameters" }); break; @@ -116,7 +123,7 @@ module.exports = { if (mode === MODE_ALWAYS) { context.report({ node, - message: "Missing radix parameter." + messageId: "missingRadix" }); } break; @@ -125,12 +132,12 @@ module.exports = { if (mode === MODE_AS_NEEDED && isDefaultRadix(args[1])) { context.report({ node, - message: "Redundant radix parameter." + messageId: "redundantRadix" }); } else if (!isValidRadix(args[1])) { context.report({ node, - message: "Invalid radix parameter, must be an integer between 2 and 36." + messageId: "invalidRadix" }); } break; diff --git a/lib/rules/require-jsdoc.js b/lib/rules/require-jsdoc.js index 416a22ce6c4..e581b2bee46 100644 --- a/lib/rules/require-jsdoc.js +++ b/lib/rules/require-jsdoc.js @@ -52,7 +52,11 @@ module.exports = { ], deprecated: true, - replacedBy: [] + replacedBy: [], + + messages: { + missingJSDocComment: "Missing JSDoc comment." + } }, create(context) { @@ -72,7 +76,7 @@ module.exports = { * @returns {void} */ function report(node) { - context.report({ node, message: "Missing JSDoc comment." }); + context.report({ node, messageId: "missingJSDocComment" }); } /** diff --git a/lib/rules/require-yield.js b/lib/rules/require-yield.js index dbfd759948a..af2344dfa6b 100644 --- a/lib/rules/require-yield.js +++ b/lib/rules/require-yield.js @@ -20,7 +20,11 @@ module.exports = { url: "https://eslint.org/docs/rules/require-yield" }, - schema: [] + schema: [], + + messages: { + missingYield: "This generator function does not have 'yield'." + } }, create(context) { @@ -51,7 +55,7 @@ module.exports = { const countYield = stack.pop(); if (countYield === 0 && node.body.body.length > 0) { - context.report({ node, message: "This generator function does not have 'yield'." }); + context.report({ node, messageId: "missingYield" }); } } diff --git a/lib/rules/rest-spread-spacing.js b/lib/rules/rest-spread-spacing.js index cd740fd3a99..4bb5f787c6c 100644 --- a/lib/rules/rest-spread-spacing.js +++ b/lib/rules/rest-spread-spacing.js @@ -26,7 +26,12 @@ module.exports = { { enum: ["always", "never"] } - ] + ], + + messages: { + unexpectedWhitespace: "Unexpected whitespace after {{type}} operator.", + expectedWhitespace: "Expected whitespace after {{type}} operator." + } }, create(context) { @@ -78,7 +83,7 @@ module.exports = { line: operator.loc.end.line, column: operator.loc.end.column }, - message: "Expected whitespace after {{type}} operator.", + messageId: "expectedWhitespace", data: { type }, @@ -93,7 +98,7 @@ module.exports = { line: operator.loc.end.line, column: operator.loc.end.column }, - message: "Unexpected whitespace after {{type}} operator.", + messageId: "unexpectedWhitespace", data: { type }, diff --git a/lib/rules/semi-spacing.js b/lib/rules/semi-spacing.js index 083dc26199f..92948533d27 100644 --- a/lib/rules/semi-spacing.js +++ b/lib/rules/semi-spacing.js @@ -39,7 +39,14 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unexpectedWhitespaceBefore: "Unexpected whitespace before semicolon.", + unexpectedWhitespaceAfter: "Unexpected whitespace after semicolon.", + missingWhitespaceBefore: "Missing whitespace before semicolon.", + missingWhitespaceAfter: "Missing whitespace after semicolon." + } }, create(context) { @@ -124,7 +131,7 @@ module.exports = { context.report({ node, loc: location, - message: "Unexpected whitespace before semicolon.", + messageId: "unexpectedWhitespaceBefore", fix(fixer) { const tokenBefore = sourceCode.getTokenBefore(token); @@ -137,7 +144,7 @@ module.exports = { context.report({ node, loc: location, - message: "Missing whitespace before semicolon.", + messageId: "missingWhitespaceBefore", fix(fixer) { return fixer.insertTextBefore(token, " "); } @@ -151,7 +158,7 @@ module.exports = { context.report({ node, loc: location, - message: "Unexpected whitespace after semicolon.", + messageId: "unexpectedWhitespaceAfter", fix(fixer) { const tokenAfter = sourceCode.getTokenAfter(token); @@ -164,7 +171,7 @@ module.exports = { context.report({ node, loc: location, - message: "Missing whitespace after semicolon.", + messageId: "missingWhitespaceAfter", fix(fixer) { return fixer.insertTextAfter(token, " "); } diff --git a/lib/rules/semi-style.js b/lib/rules/semi-style.js index da3c4a38742..0c9bec4c85e 100644 --- a/lib/rules/semi-style.js +++ b/lib/rules/semi-style.js @@ -75,7 +75,11 @@ module.exports = { }, schema: [{ enum: ["last", "first"] }], - fixable: "whitespace" + fixable: "whitespace", + + messages: { + expectedSemiColon: "Expected this semicolon to be at {{pos}}." + } }, create(context) { @@ -97,7 +101,7 @@ module.exports = { if ((expected === "last" && !prevIsSameLine) || (expected === "first" && !nextIsSameLine)) { context.report({ loc: semiToken.loc, - message: "Expected this semicolon to be at {{pos}}.", + messageId: "expectedSemiColon", data: { pos: (expected === "last") ? "the end of the previous line" diff --git a/lib/rules/sort-imports.js b/lib/rules/sort-imports.js index 3b7f1d01034..65ad9a18a93 100644 --- a/lib/rules/sort-imports.js +++ b/lib/rules/sort-imports.js @@ -50,7 +50,13 @@ module.exports = { } ], - fixable: "code" + fixable: "code", + + messages: { + sortImportsAlphabetically: "Imports should be sorted alphabetically.", + sortMembersAlphabetically: "Member '{{memberName}}' of the import declaration should be sorted alphabetically.", + unexpectedSyntaxOrder: "Expected '{{syntaxA}}' syntax before '{{syntaxB}}' syntax." + } }, create(context) { @@ -132,7 +138,7 @@ module.exports = { if (currentMemberSyntaxGroupIndex < previousMemberSyntaxGroupIndex) { context.report({ node, - message: "Expected '{{syntaxA}}' syntax before '{{syntaxB}}' syntax.", + messageId: "unexpectedSyntaxOrder", data: { syntaxA: memberSyntaxSortOrder[currentMemberSyntaxGroupIndex], syntaxB: memberSyntaxSortOrder[previousMemberSyntaxGroupIndex] @@ -146,7 +152,7 @@ module.exports = { ) { context.report({ node, - message: "Imports should be sorted alphabetically." + messageId: "sortImportsAlphabetically" }); } } @@ -163,7 +169,7 @@ module.exports = { if (firstUnsortedIndex !== -1) { context.report({ node: importSpecifiers[firstUnsortedIndex], - message: "Member '{{memberName}}' of the import declaration should be sorted alphabetically.", + messageId: "sortMembersAlphabetically", data: { memberName: importSpecifiers[firstUnsortedIndex].local.name }, fix(fixer) { if (importSpecifiers.some(specifier => diff --git a/lib/rules/sort-keys.js b/lib/rules/sort-keys.js index f03325609ea..8a95ee25d61 100644 --- a/lib/rules/sort-keys.js +++ b/lib/rules/sort-keys.js @@ -109,7 +109,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + sortKeys: "Expected object keys to be in {{natural}}{{insensitive}}{{order}}ending order. '{{thisName}}' should be before '{{prevName}}'." + } }, create(context) { @@ -167,7 +171,7 @@ module.exports = { context.report({ node, loc: node.key.loc, - message: "Expected object keys to be in {{natural}}{{insensitive}}{{order}}ending order. '{{thisName}}' should be before '{{prevName}}'.", + messageId: "sortKeys", data: { thisName, prevName, diff --git a/lib/rules/sort-vars.js b/lib/rules/sort-vars.js index e85c6534e3a..7add2cf74b2 100644 --- a/lib/rules/sort-vars.js +++ b/lib/rules/sort-vars.js @@ -33,7 +33,11 @@ module.exports = { } ], - fixable: "code" + fixable: "code", + + messages: { + sortVars: "Variables within the same declaration block should be sorted alphabetically." + } }, create(context) { @@ -56,7 +60,7 @@ module.exports = { if (currentVariableName < lastVariableName) { context.report({ node: decl, - message: "Variables within the same declaration block should be sorted alphabetically.", + messageId: "sortVars", fix(fixer) { if (unfixable || fixed) { return null; diff --git a/lib/rules/space-before-blocks.js b/lib/rules/space-before-blocks.js index 038e88db521..9b56481bf35 100644 --- a/lib/rules/space-before-blocks.js +++ b/lib/rules/space-before-blocks.js @@ -47,7 +47,12 @@ module.exports = { } ] } - ] + ], + + messages: { + unexpectedSpace: "Unexpected space before opening brace.", + missingSpace: "Missing space before opening brace." + } }, create(context) { @@ -114,7 +119,7 @@ module.exports = { if (requireSpace && !hasSpace) { context.report({ node, - message: "Missing space before opening brace.", + messageId: "missingSpace", fix(fixer) { return fixer.insertTextBefore(node, " "); } @@ -122,7 +127,7 @@ module.exports = { } else if (requireNoSpace && hasSpace) { context.report({ node, - message: "Unexpected space before opening brace.", + messageId: "unexpectedSpace", fix(fixer) { return fixer.removeRange([precedingToken.range[1], node.range[0]]); } diff --git a/lib/rules/space-before-function-paren.js b/lib/rules/space-before-function-paren.js index 3a6d430f362..af609c2e7c7 100644 --- a/lib/rules/space-before-function-paren.js +++ b/lib/rules/space-before-function-paren.js @@ -50,7 +50,12 @@ module.exports = { } ] } - ] + ], + + messages: { + unexpectedSpace: "Unexpected space before function parentheses.", + missingSpace: "Missing space before function parentheses." + } }, create(context) { @@ -123,7 +128,7 @@ module.exports = { context.report({ node, loc: leftToken.loc.end, - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", fix(fixer) { const comments = sourceCode.getCommentsBefore(rightToken); @@ -141,7 +146,7 @@ module.exports = { context.report({ node, loc: leftToken.loc.end, - message: "Missing space before function parentheses.", + messageId: "missingSpace", fix: fixer => fixer.insertTextAfter(leftToken, " ") }); } diff --git a/lib/rules/space-infix-ops.js b/lib/rules/space-infix-ops.js index 5a380ad1db2..471c22210eb 100644 --- a/lib/rules/space-infix-ops.js +++ b/lib/rules/space-infix-ops.js @@ -32,7 +32,11 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + missingSpace: "Operator '{{operator}}' must be spaced." + } }, create(context) { @@ -70,7 +74,7 @@ module.exports = { context.report({ node: mainNode, loc: culpritToken.loc, - message: "Operator '{{operator}}' must be spaced.", + messageId: "missingSpace", data: { operator: culpritToken.value }, diff --git a/lib/rules/spaced-comment.js b/lib/rules/spaced-comment.js index daf56cd6bb4..d3221f0ea79 100644 --- a/lib/rules/spaced-comment.js +++ b/lib/rules/spaced-comment.js @@ -221,7 +221,16 @@ module.exports = { }, additionalProperties: false } - ] + ], + + messages: { + unexpectedSpaceAfterMarker: "Unexpected space or tab after marker ({{refChar}}) in comment.", + expectedExceptionAfter: "Expected exception block, space or tab after '{{refChar}}' in comment.", + unexpectedSpaceBefore: "Unexpected space or tab before '*/' in comment.", + unexpectedSpaceAfter: "Unexpected space or tab after '{{refChar}}' in comment.", + expectedSpaceBefore: "Expected space or tab before '*/' in comment.", + expectedSpaceAfter: "Expected space or tab after '{{refChar}}' in comment." + } }, create(context) { @@ -259,12 +268,12 @@ module.exports = { /** * Reports a beginning spacing error with an appropriate message. * @param {ASTNode} node A comment node to check. - * @param {string} message An error message to report. + * @param {string} messageId An error message to report. * @param {Array} match An array of match results for markers. * @param {string} refChar Character used for reference in the error message. * @returns {void} */ - function reportBegin(node, message, match, refChar) { + function reportBegin(node, messageId, match, refChar) { const type = node.type.toLowerCase(), commentIdentifier = type === "block" ? "/*" : "//"; @@ -284,7 +293,7 @@ module.exports = { return fixer.replaceTextRange([start, end], commentIdentifier + (match[1] ? match[1] : "")); }, - message, + messageId, data: { refChar } }); } @@ -292,11 +301,11 @@ module.exports = { /** * Reports an ending spacing error with an appropriate message. * @param {ASTNode} node A comment node to check. - * @param {string} message An error message to report. + * @param {string} messageId An error message to report. * @param {string} match An array of the matched whitespace characters. * @returns {void} */ - function reportEnd(node, message, match) { + function reportEnd(node, messageId, match) { context.report({ node, fix(fixer) { @@ -309,7 +318,7 @@ module.exports = { return fixer.replaceTextRange([start, end], ""); }, - message + messageId }); } @@ -338,26 +347,26 @@ module.exports = { const marker = hasMarker ? commentIdentifier + hasMarker[0] : commentIdentifier; if (rule.hasExceptions) { - reportBegin(node, "Expected exception block, space or tab after '{{refChar}}' in comment.", hasMarker, marker); + reportBegin(node, "expectedExceptionAfter", hasMarker, marker); } else { - reportBegin(node, "Expected space or tab after '{{refChar}}' in comment.", hasMarker, marker); + reportBegin(node, "expectedSpaceAfter", hasMarker, marker); } } if (balanced && type === "block" && !endMatch) { - reportEnd(node, "Expected space or tab before '*/' in comment."); + reportEnd(node, "expectedSpaceBefore"); } } else { if (beginMatch) { if (!beginMatch[1]) { - reportBegin(node, "Unexpected space or tab after '{{refChar}}' in comment.", beginMatch, commentIdentifier); + reportBegin(node, "unexpectedSpaceAfter", beginMatch, commentIdentifier); } else { - reportBegin(node, "Unexpected space or tab after marker ({{refChar}}) in comment.", beginMatch, beginMatch[1]); + reportBegin(node, "unexpectedSpaceAfterMarker", beginMatch, beginMatch[1]); } } if (balanced && type === "block" && endMatch) { - reportEnd(node, "Unexpected space or tab before '*/' in comment.", endMatch); + reportEnd(node, "unexpectedSpaceBefore", endMatch); } } } diff --git a/tests/lib/linter/linter.js b/tests/lib/linter/linter.js index 9906193ebda..94a81c18403 100644 --- a/tests/lib/linter/linter.js +++ b/tests/lib/linter/linter.js @@ -3864,6 +3864,7 @@ describe("Linter", () => { endLine: 4, line: 4, message: "'bbb' is assigned a value but never used.", + messageId: "unusedVar", nodeType: "Identifier", ruleId: "no-unused-vars", severity: 2 @@ -3887,6 +3888,7 @@ describe("Linter", () => { endColumn: 28, line: 3, message: "'aaa' is assigned a value but never used.", + messageId: "unusedVar", nodeType: "Identifier", ruleId: "no-unused-vars", severity: 2 @@ -3934,6 +3936,7 @@ describe("Linter", () => { endColumn: 28, line: 2, message: "'aaa' is assigned a value but never used.", + messageId: "unusedVar", nodeType: "Identifier", ruleId: "no-unused-vars", severity: 2 @@ -3956,6 +3959,7 @@ describe("Linter", () => { endColumn: 28, line: 2, message: "'aaa' is assigned a value but never used.", + messageId: "unusedVar", nodeType: "Identifier", ruleId: "no-unused-vars", severity: 2 @@ -3980,6 +3984,7 @@ describe("Linter", () => { endColumn: 28, line: 3, message: "'aaa' is assigned a value but never used.", + messageId: "unusedVar", nodeType: "Identifier", ruleId: "no-unused-vars", severity: 2 @@ -4004,6 +4009,7 @@ describe("Linter", () => { endColumn: 28, line: 3, message: "'aaa' is assigned a value but never used.", + messageId: "unusedVar", nodeType: "Identifier", ruleId: "no-unused-vars", severity: 2 diff --git a/tests/lib/rules/camelcase.js b/tests/lib/rules/camelcase.js index b3d95f93ea6..dffdf11da00 100644 --- a/tests/lib/rules/camelcase.js +++ b/tests/lib/rules/camelcase.js @@ -438,7 +438,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Identifier 'category_id' is not in camel case.", + messageId: "notCamelCase", + data: { name: "category_id" }, type: "Identifier" } ] @@ -595,7 +596,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Identifier 'no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camelcased" }, type: "Identifier" } ] @@ -605,7 +607,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Identifier 'no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camelcased" }, type: "Identifier" } ] @@ -615,11 +618,13 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Identifier 'no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camelcased" }, type: "Identifier" }, { - message: "Identifier 'camelcased_value' is not in camel case.", + messageId: "notCamelCase", + data: { name: "camelcased_value" }, type: "Identifier" } ] @@ -629,7 +634,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Identifier 'no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camelcased" }, type: "Identifier" } ] @@ -639,7 +645,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Identifier 'my_default' is not in camel case.", + messageId: "notCamelCase", + data: { name: "my_default" }, type: "Identifier" } ] @@ -649,7 +656,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Identifier 'no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camelcased" }, type: "Identifier" } ] @@ -659,7 +667,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Identifier 'bar_baz' is not in camel case.", + messageId: "notCamelCase", + data: { name: "bar_baz" }, type: "Identifier" } ] @@ -669,7 +678,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Identifier 'no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camelcased" }, type: "Identifier" } ] @@ -679,7 +689,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Identifier 'no_camelcased' is not in camel case.", + messageId: "notCamelCase", + data: { name: "no_camelcased" }, type: "Identifier" } ] @@ -689,7 +700,8 @@ ruleTester.run("camelcase", rule, { options: [{ allow: ["ignored_bar"] }], errors: [ { - message: "Identifier 'not_ignored_foo' is not in camel case.", + messageId: "notCamelCase", + data: { name: "not_ignored_foo" }, type: "Identifier" } ] @@ -699,7 +711,8 @@ ruleTester.run("camelcase", rule, { options: [{ allow: ["_id$"] }], errors: [ { - message: "Identifier 'not_ignored_foo' is not in camel case.", + messageId: "notCamelCase", + data: { name: "not_ignored_foo" }, type: "Identifier" } ] @@ -710,7 +723,8 @@ ruleTester.run("camelcase", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Identifier 'computed_bar' is not in camel case.", + messageId: "notCamelCase", + data: { name: "computed_bar" }, type: "Identifier" } ] diff --git a/tests/lib/rules/class-methods-use-this.js b/tests/lib/rules/class-methods-use-this.js index 5238b9d68b7..e307d6a0c29 100644 --- a/tests/lib/rules/class-methods-use-this.js +++ b/tests/lib/rules/class-methods-use-this.js @@ -110,15 +110,15 @@ ruleTester.run("class-methods-use-this", rule, { code: "class A { foo(){} 'bar'(){} 123(){} [`baz`](){} [a](){} [f(a)](){} get quux(){} set[a](b){} *quuux(){} }", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Expected 'this' to be used by class method 'foo'.", type: "FunctionExpression", column: 14 }, - { message: "Expected 'this' to be used by class method 'bar'.", type: "FunctionExpression", column: 24 }, - { message: "Expected 'this' to be used by class method '123'.", type: "FunctionExpression", column: 32 }, - { message: "Expected 'this' to be used by class method 'baz'.", type: "FunctionExpression", column: 44 }, - { message: "Expected 'this' to be used by class method.", type: "FunctionExpression", column: 52 }, - { message: "Expected 'this' to be used by class method.", type: "FunctionExpression", column: 63 }, - { message: "Expected 'this' to be used by class getter 'quux'.", type: "FunctionExpression", column: 76 }, - { message: "Expected 'this' to be used by class setter.", type: "FunctionExpression", column: 87 }, - { message: "Expected 'this' to be used by class generator method 'quuux'.", type: "FunctionExpression", column: 99 } + { messageId: "missingThis", data: { name: "method 'foo'" }, type: "FunctionExpression", column: 14 }, + { messageId: "missingThis", data: { name: "method 'bar'" }, type: "FunctionExpression", column: 24 }, + { messageId: "missingThis", data: { name: "method '123'" }, type: "FunctionExpression", column: 32 }, + { messageId: "missingThis", data: { name: "method 'baz'" }, type: "FunctionExpression", column: 44 }, + { messageId: "missingThis", data: { name: "method" }, type: "FunctionExpression", column: 52 }, + { messageId: "missingThis", data: { name: "method" }, type: "FunctionExpression", column: 63 }, + { messageId: "missingThis", data: { name: "getter 'quux'" }, type: "FunctionExpression", column: 76 }, + { messageId: "missingThis", data: { name: "setter" }, type: "FunctionExpression", column: 87 }, + { messageId: "missingThis", data: { name: "generator method 'quuux'" }, type: "FunctionExpression", column: 99 } ] } ] diff --git a/tests/lib/rules/grouped-accessor-pairs.js b/tests/lib/rules/grouped-accessor-pairs.js index c395e6ec9b4..e94c3a46be2 100644 --- a/tests/lib/rules/grouped-accessor-pairs.js +++ b/tests/lib/rules/grouped-accessor-pairs.js @@ -142,77 +142,77 @@ ruleTester.run("grouped-accessor-pairs", rule, { // basic grouping tests with full messages { code: "({ get a(){}, b:1, set a(foo){} })", - errors: [{ message: "Accessor pair getter 'a' and setter 'a' should be grouped.", type: "Property", column: 20 }] + errors: [{ messageId: "notGrouped", data: { formerName: "getter 'a'", latterName: "setter 'a'" }, type: "Property", column: 20 }] }, { code: "({ set 'abc'(foo){}, b:1, get 'abc'(){} })", - errors: [{ message: "Accessor pair setter 'abc' and getter 'abc' should be grouped.", type: "Property", column: 27 }] + errors: [{ messageId: "notGrouped", data: { formerName: "setter 'abc'", latterName: "getter 'abc'" }, type: "Property", column: 27 }] }, { code: "({ get [a](){}, b:1, set [a](foo){} })", - errors: [{ message: "Accessor pair getter and setter should be grouped.", type: "Property", column: 22 }] + errors: [{ messageId: "notGrouped", data: { formerName: "getter", latterName: "setter" }, type: "Property", column: 22 }] }, { code: "class A { get abc(){} b(){} set abc(foo){} }", - errors: [{ message: "Accessor pair getter 'abc' and setter 'abc' should be grouped.", type: "MethodDefinition", column: 29 }] + errors: [{ messageId: "notGrouped", data: { formerName: "getter 'abc'", latterName: "setter 'abc'" }, type: "MethodDefinition", column: 29 }] }, { code: "(class { set abc(foo){} b(){} get abc(){} })", - errors: [{ message: "Accessor pair setter 'abc' and getter 'abc' should be grouped.", type: "MethodDefinition", column: 31 }] + errors: [{ messageId: "notGrouped", data: { formerName: "setter 'abc'", latterName: "getter 'abc'" }, type: "MethodDefinition", column: 31 }] }, { code: "class A { static set a(foo){} b(){} static get a(){} }", - errors: [{ message: "Accessor pair static setter 'a' and static getter 'a' should be grouped.", type: "MethodDefinition", column: 37 }] + errors: [{ messageId: "notGrouped", data: { formerName: "static setter 'a'", latterName: "static getter 'a'" }, type: "MethodDefinition", column: 37 }] }, { code: "(class { static get 123(){} b(){} static set 123(foo){} })", - errors: [{ message: "Accessor pair static getter '123' and static setter '123' should be grouped.", type: "MethodDefinition", column: 35 }] + errors: [{ messageId: "notGrouped", data: { formerName: "static getter '123'", latterName: "static setter '123'" }, type: "MethodDefinition", column: 35 }] }, { code: "class A { static get [a](){} b(){} static set [a](foo){} }", - errors: [{ message: "Accessor pair static getter and static setter should be grouped.", type: "MethodDefinition", column: 36 }] + errors: [{ messageId: "notGrouped", data: { formerName: "static getter", latterName: "static setter" }, type: "MethodDefinition", column: 36 }] }, // basic ordering tests with full messages { code: "({ set a(foo){}, get a(){} })", options: ["getBeforeSet"], - errors: [{ message: "Expected getter 'a' to be before setter 'a'.", type: "Property", column: 18 }] + errors: [{ messageId: "invalidOrder", data: { latterName: "getter 'a'", formerName: "setter 'a'" }, type: "Property", column: 18 }] }, { code: "({ get 123(){}, set 123(foo){} })", options: ["setBeforeGet"], - errors: [{ message: "Expected setter '123' to be before getter '123'.", type: "Property", column: 17 }] + errors: [{ messageId: "invalidOrder", data: { latterName: "setter '123'", formerName: "getter '123'" }, type: "Property", column: 17 }] }, { code: "({ get [a](){}, set [a](foo){} })", options: ["setBeforeGet"], - errors: [{ message: "Expected setter to be before getter.", type: "Property", column: 17 }] + errors: [{ messageId: "invalidOrder", data: { latterName: "setter", formerName: "getter" }, type: "Property", column: 17 }] }, { code: "class A { set abc(foo){} get abc(){} }", options: ["getBeforeSet"], - errors: [{ message: "Expected getter 'abc' to be before setter 'abc'.", type: "MethodDefinition", column: 26 }] + errors: [{ messageId: "invalidOrder", data: { latterName: "getter 'abc'", formerName: "setter 'abc'" }, type: "MethodDefinition", column: 26 }] }, { code: "(class { get [`abc`](){} set [`abc`](foo){} })", options: ["setBeforeGet"], - errors: [{ message: "Expected setter 'abc' to be before getter 'abc'.", type: "MethodDefinition", column: 26 }] + errors: [{ messageId: "invalidOrder", data: { latterName: "setter 'abc'", formerName: "getter 'abc'" }, type: "MethodDefinition", column: 26 }] }, { code: "class A { static get a(){} static set a(foo){} }", options: ["setBeforeGet"], - errors: [{ message: "Expected static setter 'a' to be before static getter 'a'.", type: "MethodDefinition", column: 28 }] + errors: [{ messageId: "invalidOrder", data: { latterName: "static setter 'a'", formerName: "static getter 'a'" }, type: "MethodDefinition", column: 28 }] }, { code: "(class { static set 'abc'(foo){} static get 'abc'(){} })", options: ["getBeforeSet"], - errors: [{ message: "Expected static getter 'abc' to be before static setter 'abc'.", type: "MethodDefinition", column: 34 }] + errors: [{ messageId: "invalidOrder", data: { latterName: "static getter 'abc'", formerName: "static setter 'abc'" }, type: "MethodDefinition", column: 34 }] }, { code: "class A { static set [abc](foo){} static get [abc](){} }", options: ["getBeforeSet"], - errors: [{ message: "Expected static getter to be before static setter.", type: "MethodDefinition", column: 35 }] + errors: [{ messageId: "invalidOrder", data: { formerName: "static setter", latterName: "static getter" }, type: "MethodDefinition", column: 35 }] }, // ordering option does not affect the grouping check diff --git a/tests/lib/rules/no-invalid-regexp.js b/tests/lib/rules/no-invalid-regexp.js index fb30b186ffc..ba1827a4fab 100644 --- a/tests/lib/rules/no-invalid-regexp.js +++ b/tests/lib/rules/no-invalid-regexp.js @@ -44,14 +44,39 @@ ruleTester.run("no-invalid-regexp", rule, { { code: "new RegExp('\\\\p{Letter}', 'u')", parserOptions: { ecmaVersion: 2018 } } ], invalid: [ - { code: "RegExp('[');", errors: [{ message: "Invalid regular expression: /[/: Unterminated character class.", type: "CallExpression" }] }, - { code: "RegExp('.', 'z');", errors: [{ message: "Invalid flags supplied to RegExp constructor 'z'.", type: "CallExpression" }] }, - { code: "new RegExp(')');", errors: [{ message: "Invalid regular expression: /)/: Unmatched ')'.", type: "NewExpression" }] }, + { + code: "RegExp('[');", + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid regular expression: /[/: Unterminated character class" }, + type: "CallExpression" + }] + }, + { + code: "RegExp('.', 'z');", + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid flags supplied to RegExp constructor 'z'" }, + type: "CallExpression" + }] + }, + { + code: "new RegExp(')');", + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid regular expression: /)/: Unmatched ')'" }, + type: "NewExpression" + }] + }, // https://github.com/eslint/eslint/issues/10861 { code: String.raw`new RegExp('\\');`, - errors: [{ message: "Invalid regular expression: /\\/: \\ at end of pattern.", type: "NewExpression" }] + errors: [{ + messageId: "regexMessage", + data: { message: "Invalid regular expression: /\\/: \\ at end of pattern" }, + type: "NewExpression" + }] } ] }); diff --git a/tests/lib/rules/no-magic-numbers.js b/tests/lib/rules/no-magic-numbers.js index 5935ac79b2e..36c0302d137 100644 --- a/tests/lib/rules/no-magic-numbers.js +++ b/tests/lib/rules/no-magic-numbers.js @@ -207,7 +207,7 @@ ruleTester.run("no-magic-numbers", rule, { { code: "function getSecondsInMinute() {return 60;}", errors: [ - { message: "No magic number: 60." } + { messageId: "noMagic", data: { raw: "60" } } ] }, { diff --git a/tests/lib/rules/no-native-reassign.js b/tests/lib/rules/no-native-reassign.js index 034d11c7188..8bb14d70c5d 100644 --- a/tests/lib/rules/no-native-reassign.js +++ b/tests/lib/rules/no-native-reassign.js @@ -31,32 +31,32 @@ ruleTester.run("no-native-reassign", rule, { "/*global a:true*/ a = 1" ], invalid: [ - { code: "String = 'hello world';", errors: [{ message: "Read-only global 'String' should not be modified.", type: "Identifier" }] }, - { code: "String++;", errors: [{ message: "Read-only global 'String' should not be modified.", type: "Identifier" }] }, + { code: "String = 'hello world';", errors: [{ messageId: "nativeReassign", data: { name: "String" }, type: "Identifier" }] }, + { code: "String++;", errors: [{ messageId: "nativeReassign", data: { name: "String" }, type: "Identifier" }] }, { code: "({Object = 0, String = 0} = {});", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Read-only global 'Object' should not be modified.", type: "Identifier" }, - { message: "Read-only global 'String' should not be modified.", type: "Identifier" } + { messageId: "nativeReassign", data: { name: "Object" }, type: "Identifier" }, + { messageId: "nativeReassign", data: { name: "String" }, type: "Identifier" } ] }, { code: "top = 0;", env: { browser: true }, - errors: [{ message: "Read-only global 'top' should not be modified.", type: "Identifier" }] + errors: [{ messageId: "nativeReassign", data: { name: "top" }, type: "Identifier" }] }, { code: "require = 0;", env: { node: true }, - errors: [{ message: "Read-only global 'require' should not be modified.", type: "Identifier" }] + errors: [{ messageId: "nativeReassign", data: { name: "require" }, type: "Identifier" }] }, // Notifications of readonly are moved from no-undef: https://github.com/eslint/eslint/issues/4504 - { code: "/*global b:false*/ function f() { b = 1; }", errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }] }, - { code: "function f() { b = 1; }", globals: { b: false }, errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }] }, - { code: "/*global b:false*/ function f() { b++; }", errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }] }, - { code: "/*global b*/ b = 1;", errors: [{ message: "Read-only global 'b' should not be modified.", type: "Identifier" }] }, - { code: "Array = 1;", errors: [{ message: "Read-only global 'Array' should not be modified.", type: "Identifier" }] } + { code: "/*global b:false*/ function f() { b = 1; }", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, + { code: "function f() { b = 1; }", globals: { b: false }, errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, + { code: "/*global b:false*/ function f() { b++; }", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, + { code: "/*global b*/ b = 1;", errors: [{ messageId: "nativeReassign", data: { name: "b" }, type: "Identifier" }] }, + { code: "Array = 1;", errors: [{ messageId: "nativeReassign", data: { name: "Array" }, type: "Identifier" }] } ] }); diff --git a/tests/lib/rules/no-negated-in-lhs.js b/tests/lib/rules/no-negated-in-lhs.js index 80f96d0bb4e..7cb9429f670 100644 --- a/tests/lib/rules/no-negated-in-lhs.js +++ b/tests/lib/rules/no-negated-in-lhs.js @@ -25,6 +25,6 @@ ruleTester.run("no-negated-in-lhs", rule, { "!(a in b)" ], invalid: [ - { code: "!a in b", errors: [{ message: "The 'in' expression's left operand is negated.", type: "BinaryExpression" }] } + { code: "!a in b", errors: [{ messageId: "negatedLHS", type: "BinaryExpression" }] } ] }); diff --git a/tests/lib/rules/no-obj-calls.js b/tests/lib/rules/no-obj-calls.js index db7261568ea..df0c39afb5a 100644 --- a/tests/lib/rules/no-obj-calls.js +++ b/tests/lib/rules/no-obj-calls.js @@ -69,10 +69,9 @@ ruleTester.run("no-obj-calls", rule, { ], invalid: [ - // test full message { code: "Math();", - errors: [{ message: "'Math' is not a function.", type: "CallExpression" }] + errors: [{ messageId: "unexpectedCall", data: { name: "Math" }, type: "CallExpression" }] }, { diff --git a/tests/lib/rules/no-octal-escape.js b/tests/lib/rules/no-octal-escape.js index d89910f8663..d36f3fc6228 100644 --- a/tests/lib/rules/no-octal-escape.js +++ b/tests/lib/rules/no-octal-escape.js @@ -58,9 +58,7 @@ ruleTester.run("no-octal-escape", rule, { ], invalid: [ - // Test full message - { code: "var foo = \"foo \\01 bar\";", errors: [{ message: "Don't use octal: '\\01'. Use '\\u....' instead.", type: "Literal" }] }, - + { code: "var foo = \"foo \\01 bar\";", errors: [{ messageId: "octalEscapeSequence", data: { sequence: "01" }, type: "Literal" }] }, { code: "var foo = \"foo \\000 bar\";", errors: [{ messageId: "octalEscapeSequence", data: { sequence: "000" }, type: "Literal" }] }, { code: "var foo = \"foo \\377 bar\";", errors: [{ messageId: "octalEscapeSequence", data: { sequence: "377" }, type: "Literal" }] }, { code: "var foo = \"foo \\378 bar\";", errors: [{ messageId: "octalEscapeSequence", data: { sequence: "37" }, type: "Literal" }] }, diff --git a/tests/lib/rules/no-process-env.js b/tests/lib/rules/no-process-env.js index 6a720385972..9c6724b5164 100644 --- a/tests/lib/rules/no-process-env.js +++ b/tests/lib/rules/no-process-env.js @@ -30,21 +30,21 @@ ruleTester.run("no-process-env", rule, { { code: "process.env", errors: [{ - message: "Unexpected use of process.env.", + messageId: "unexpectedProcessEnv", type: "MemberExpression" }] }, { code: "process.env.ENV", errors: [{ - message: "Unexpected use of process.env.", + messageId: "unexpectedProcessEnv", type: "MemberExpression" }] }, { code: "f(process.env)", errors: [{ - message: "Unexpected use of process.env.", + messageId: "unexpectedProcessEnv", type: "MemberExpression" }] } diff --git a/tests/lib/rules/no-process-exit.js b/tests/lib/rules/no-process-exit.js index 0aeac053eb0..6637ae32aae 100644 --- a/tests/lib/rules/no-process-exit.js +++ b/tests/lib/rules/no-process-exit.js @@ -29,21 +29,21 @@ ruleTester.run("no-process-exit", rule, { { code: "process.exit(0);", errors: [{ - message: "Don't use process.exit(); throw an error instead.", + messageId: "noProcessExit", type: "CallExpression" }] }, { code: "process.exit(1);", errors: [{ - message: "Don't use process.exit(); throw an error instead.", + messageId: "noProcessExit", type: "CallExpression" }] }, { code: "f(process.exit(1));", errors: [{ - message: "Don't use process.exit(); throw an error instead.", + messageId: "noProcessExit", type: "CallExpression" }] } diff --git a/tests/lib/rules/no-proto.js b/tests/lib/rules/no-proto.js index f6bea000a90..3e0e7e06155 100644 --- a/tests/lib/rules/no-proto.js +++ b/tests/lib/rules/no-proto.js @@ -26,9 +26,9 @@ ruleTester.run("no-proto", rule, { { code: "foo[`__proto__\n`] = null;", parserOptions: { ecmaVersion: 6 } } ], invalid: [ - { code: "var a = test.__proto__;", errors: [{ message: "The '__proto__' property is deprecated.", type: "MemberExpression" }] }, - { code: "var a = test['__proto__'];", errors: [{ message: "The '__proto__' property is deprecated.", type: "MemberExpression" }] }, - { code: "var a = test[`__proto__`];", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "The '__proto__' property is deprecated.", type: "MemberExpression" }] }, - { code: "test[`__proto__`] = function () {};", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "The '__proto__' property is deprecated.", type: "MemberExpression" }] } + { code: "var a = test.__proto__;", errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] }, + { code: "var a = test['__proto__'];", errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] }, + { code: "var a = test[`__proto__`];", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] }, + { code: "test[`__proto__`] = function () {};", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedProto", type: "MemberExpression" }] } ] }); diff --git a/tests/lib/rules/no-prototype-builtins.js b/tests/lib/rules/no-prototype-builtins.js index 3a25f0b61c1..b1493e45561 100644 --- a/tests/lib/rules/no-prototype-builtins.js +++ b/tests/lib/rules/no-prototype-builtins.js @@ -41,7 +41,8 @@ const invalid = [ errors: [{ line: 1, column: 5, - message: "Do not access Object.prototype method 'hasOwnProperty' from target object.", + messageId: "prototypeBuildIn", + data: { prop: "hasOwnProperty" }, type: "CallExpression" }] }, @@ -50,7 +51,8 @@ const invalid = [ errors: [{ line: 1, column: 5, - message: "Do not access Object.prototype method 'isPrototypeOf' from target object.", + messageId: "prototypeBuildIn", + data: { prop: "isPrototypeOf" }, type: "CallExpression" }] }, @@ -59,7 +61,8 @@ const invalid = [ errors: [{ line: 1, column: 5, - message: "Do not access Object.prototype method 'propertyIsEnumerable' from target object." + messageId: "prototypeBuildIn", + data: { prop: "propertyIsEnumerable" } }] }, { @@ -67,7 +70,8 @@ const invalid = [ errors: [{ line: 1, column: 9, - message: "Do not access Object.prototype method 'hasOwnProperty' from target object.", + messageId: "prototypeBuildIn", + data: { prop: "hasOwnProperty" }, type: "CallExpression" }] }, @@ -76,7 +80,8 @@ const invalid = [ errors: [{ line: 1, column: 13, - message: "Do not access Object.prototype method 'isPrototypeOf' from target object.", + messageId: "prototypeBuildIn", + data: { prop: "isPrototypeOf" }, type: "CallExpression" }] } diff --git a/tests/lib/rules/no-regex-spaces.js b/tests/lib/rules/no-regex-spaces.js index 0fc7e751a65..fdcd1cec27a 100644 --- a/tests/lib/rules/no-regex-spaces.js +++ b/tests/lib/rules/no-regex-spaces.js @@ -69,7 +69,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = /bar {2}baz/;", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "Literal" } ] @@ -79,7 +80,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = /bar {4}baz/;", errors: [ { - message: "Spaces are hard to count. Use {4}.", + messageId: "multipleSpaces", + data: { length: "4" }, type: "Literal" } ] @@ -89,7 +91,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = / a b {2}c d /;", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "Literal" } ] @@ -99,7 +102,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = RegExp(' a b c d {2}');", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "CallExpression" } ] @@ -109,7 +113,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = RegExp('bar {4}baz');", errors: [ { - message: "Spaces are hard to count. Use {4}.", + messageId: "multipleSpaces", + data: { length: "4" }, type: "CallExpression" } ] @@ -119,7 +124,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = new RegExp('bar {4}baz');", errors: [ { - message: "Spaces are hard to count. Use {4}.", + messageId: "multipleSpaces", + data: { length: "4" }, type: "NewExpression" } ] @@ -132,7 +138,8 @@ ruleTester.run("no-regex-spaces", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Spaces are hard to count. Use {4}.", + messageId: "multipleSpaces", + data: { length: "4" }, type: "CallExpression" } ] @@ -142,7 +149,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = /bar {2} {3}baz/;", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "Literal" } ] @@ -152,7 +160,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = /bar {3} ?baz/;", errors: [ { - message: "Spaces are hard to count. Use {3}.", + messageId: "multipleSpaces", + data: { length: "3" }, type: "Literal" } ] @@ -162,7 +171,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = new RegExp('bar {2} *baz')", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "NewExpression" } ] @@ -172,7 +182,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = RegExp('bar {2} +baz')", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "CallExpression" } ] @@ -182,7 +193,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = new RegExp('bar {4}');", errors: [ { - message: "Spaces are hard to count. Use {4}.", + messageId: "multipleSpaces", + data: { length: "4" }, type: "NewExpression" } ] @@ -192,7 +204,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = /bar\\ {2}baz/;", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "Literal" } ] @@ -202,7 +215,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = /[ ] {2}/;", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "Literal" } ] @@ -212,7 +226,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = / {2}[ ] /;", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "Literal" } ] @@ -222,7 +237,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = new RegExp('[ ] {2}');", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "NewExpression" } ] @@ -232,7 +248,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = RegExp(' {2}[ ]');", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "CallExpression" } ] @@ -242,7 +259,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = /\\[ {2}/;", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "Literal" } ] @@ -252,7 +270,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = /\\[ {2}\\]/;", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "Literal" } ] @@ -262,7 +281,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = /(?: {2})/;", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "Literal" } ] @@ -272,7 +292,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = RegExp('^foo(?= {3})');", errors: [ { - message: "Spaces are hard to count. Use {3}.", + messageId: "multipleSpaces", + data: { length: "3" }, type: "CallExpression" } ] @@ -282,7 +303,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = /\\ {2}/", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "Literal" } ] @@ -292,7 +314,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = / \\ {2}/", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "Literal" } ] @@ -304,7 +327,8 @@ ruleTester.run("no-regex-spaces", rule, { output: "var foo = / {2}foo /;", errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "Literal" } ] @@ -316,7 +340,8 @@ ruleTester.run("no-regex-spaces", rule, { output: null, errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "NewExpression" } ] @@ -326,7 +351,8 @@ ruleTester.run("no-regex-spaces", rule, { output: null, errors: [ { - message: "Spaces are hard to count. Use {3}.", + messageId: "multipleSpaces", + data: { length: "3" }, type: "CallExpression" } ] @@ -336,7 +362,8 @@ ruleTester.run("no-regex-spaces", rule, { output: null, errors: [ { - message: "Spaces are hard to count. Use {2}.", + messageId: "multipleSpaces", + data: { length: "2" }, type: "NewExpression" } ] diff --git a/tests/lib/rules/no-restricted-exports.js b/tests/lib/rules/no-restricted-exports.js index d8ae6e9c718..6d0e693b57d 100644 --- a/tests/lib/rules/no-restricted-exports.js +++ b/tests/lib/rules/no-restricted-exports.js @@ -104,11 +104,10 @@ ruleTester.run("no-restricted-exports", rule, { invalid: [ - // full message test { code: "export function someFunction() {}", options: [{ restrictedNamedExports: ["someFunction"] }], - errors: [{ message: "'someFunction' is restricted from being used as an exported name.", type: "Identifier" }] + errors: [{ messageId: "restrictedNamed", data: { name: "someFunction" }, type: "Identifier" }] }, // basic tests diff --git a/tests/lib/rules/no-restricted-modules.js b/tests/lib/rules/no-restricted-modules.js index 97158d33332..f8b0a026bb3 100644 --- a/tests/lib/rules/no-restricted-modules.js +++ b/tests/lib/rules/no-restricted-modules.js @@ -35,31 +35,31 @@ ruleTester.run("no-restricted-modules", rule, { invalid: [{ code: "require(\"fs\")", options: ["fs"], - errors: [{ message: "'fs' module is restricted from being used.", type: "CallExpression" }] + errors: [{ messageId: "defaultMessage", data: { name: "fs" }, type: "CallExpression" }] }, { code: "require(\"os \")", options: ["fs", "crypto ", "stream", "os"], - errors: [{ message: "'os' module is restricted from being used.", type: "CallExpression" }] + errors: [{ messageId: "defaultMessage", data: { name: "os" }, type: "CallExpression" }] }, { code: "require(\"foo/bar\");", options: ["foo/bar"], - errors: [{ message: "'foo/bar' module is restricted from being used.", type: "CallExpression" }] + errors: [{ messageId: "defaultMessage", data: { name: "foo/bar" }, type: "CallExpression" }] }, { code: "var withPaths = require(\"foo/bar\");", options: [{ paths: ["foo/bar"] }], - errors: [{ message: "'foo/bar' module is restricted from being used.", type: "CallExpression" }] + errors: [{ messageId: "defaultMessage", data: { name: "foo/bar" }, type: "CallExpression" }] }, { code: "var withPatterns = require(\"foo/bar\");", options: [{ patterns: ["foo/*"] }], - errors: [{ message: "'foo/bar' module is restricted from being used by a pattern.", type: "CallExpression" }] + errors: [{ messageId: "patternMessage", data: { name: "foo/bar" }, type: "CallExpression" }] }, { code: "var withPatternsAndPaths = require(\"foo/bar\");", options: [{ patterns: ["foo/*"], paths: ["foo"] }], - errors: [{ message: "'foo/bar' module is restricted from being used by a pattern.", type: "CallExpression" }] + errors: [{ messageId: "patternMessage", data: { name: "foo/bar" }, type: "CallExpression" }] }, { code: "var withGitignores = require(\"foo/bar\");", options: [{ patterns: ["foo/*", "!foo/baz"], paths: ["foo"] }], - errors: [{ message: "'foo/bar' module is restricted from being used by a pattern.", type: "CallExpression" }] + errors: [{ messageId: "patternMessage", data: { name: "foo/bar" }, type: "CallExpression" }] }, { code: "var withGitignores = require(\"foo\");", options: [{ @@ -67,7 +67,8 @@ ruleTester.run("no-restricted-modules", rule, { message: "Please use 'bar' module instead." }], errors: [{ - message: "'foo' module is restricted from being used. Please use 'bar' module instead.", + messageId: "customMessage", + data: { name: "foo", customMessage: "Please use 'bar' module instead." }, type: "CallExpression" }] }, { @@ -81,7 +82,8 @@ ruleTester.run("no-restricted-modules", rule, { "baz" ], errors: [{ - message: "'bar' module is restricted from being used. Please use 'baz' module instead.", + messageId: "customMessage", + data: { name: "bar", customMessage: "Please use 'baz' module instead." }, type: "CallExpression" }] }, { @@ -93,7 +95,8 @@ ruleTester.run("no-restricted-modules", rule, { }] }], errors: [{ - message: "'foo' module is restricted from being used. Please use 'bar' module instead.", + messageId: "customMessage", + data: { name: "foo", customMessage: "Please use 'bar' module instead." }, type: "CallExpression" }] }] diff --git a/tests/lib/rules/no-restricted-properties.js b/tests/lib/rules/no-restricted-properties.js index 9c5c57950f3..c9fb2b72afc 100644 --- a/tests/lib/rules/no-restricted-properties.js +++ b/tests/lib/rules/no-restricted-properties.js @@ -180,7 +180,12 @@ ruleTester.run("no-restricted-properties", rule, { property: "disallowedProperty" }], errors: [{ - message: "'someObject.disallowedProperty' is restricted from being used.", + messageId: "restrictedObjectProperty", + data: { + objectName: "someObject", + propertyName: "disallowedProperty", + message: "" + }, type: "MemberExpression" }] }, { @@ -191,7 +196,12 @@ ruleTester.run("no-restricted-properties", rule, { message: "Please use someObject.allowedProperty instead." }], errors: [{ - message: "'someObject.disallowedProperty' is restricted from being used. Please use someObject.allowedProperty instead.", + messageId: "restrictedObjectProperty", + data: { + objectName: "someObject", + propertyName: "disallowedProperty", + message: " Please use someObject.allowedProperty instead." + }, type: "MemberExpression" }] }, { @@ -204,10 +214,20 @@ ruleTester.run("no-restricted-properties", rule, { property: "anotherDisallowedProperty" }], errors: [{ - message: "'someObject.disallowedProperty' is restricted from being used.", + messageId: "restrictedObjectProperty", + data: { + objectName: "someObject", + propertyName: "disallowedProperty", + message: "" + }, type: "MemberExpression" }, { - message: "'anotherObject.anotherDisallowedProperty' is restricted from being used.", + messageId: "restrictedObjectProperty", + data: { + objectName: "anotherObject", + propertyName: "anotherDisallowedProperty", + message: "" + }, type: "MemberExpression" }] }, { @@ -217,7 +237,12 @@ ruleTester.run("no-restricted-properties", rule, { message: "Please use Object.getPrototypeOf instead." }], errors: [{ - message: "'__proto__' is restricted from being used. Please use Object.getPrototypeOf instead.", + messageId: "restrictedProperty", + data: { + objectName: "", + propertyName: "__proto__", + message: " Please use Object.getPrototypeOf instead." + }, type: "MemberExpression" }] }, { @@ -227,38 +252,99 @@ ruleTester.run("no-restricted-properties", rule, { message: "Please use Object.getPrototypeOf instead." }], errors: [{ - message: "'__proto__' is restricted from being used. Please use Object.getPrototypeOf instead.", + messageId: "restrictedProperty", + data: { + objectName: "", + propertyName: "__proto__", + message: " Please use Object.getPrototypeOf instead." + }, type: "MemberExpression" }] }, { code: "foo.bar.baz;", options: [{ object: "foo" }], - errors: [{ message: "'foo.bar' is restricted from being used.", type: "MemberExpression" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "foo", + propertyName: "bar", + message: "" + }, + type: "MemberExpression" + }] }, { code: "foo.bar();", options: [{ object: "foo" }], - errors: [{ message: "'foo.bar' is restricted from being used.", type: "MemberExpression" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "foo", + propertyName: "bar", + message: "" + }, + type: "MemberExpression" + }] }, { code: "foo.bar.baz();", options: [{ object: "foo" }], - errors: [{ message: "'foo.bar' is restricted from being used.", type: "MemberExpression" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "foo", + propertyName: "bar", + message: "" + }, + type: "MemberExpression" + }] }, { code: "foo.bar.baz;", options: [{ property: "bar" }], - errors: [{ message: "'bar' is restricted from being used.", type: "MemberExpression" }] + errors: [{ + messageId: "restrictedProperty", + data: { + objectName: "", + propertyName: "bar", + message: "" + }, + type: "MemberExpression" + }] }, { code: "foo.bar();", options: [{ property: "bar" }], - errors: [{ message: "'bar' is restricted from being used.", type: "MemberExpression" }] + errors: [{ + messageId: "restrictedProperty", + data: { + objectName: "", + propertyName: "bar", + message: "" + }, + type: "MemberExpression" + }] }, { code: "foo.bar.baz();", options: [{ property: "bar" }], - errors: [{ message: "'bar' is restricted from being used.", type: "MemberExpression" }] + errors: [{ + messageId: "restrictedProperty", + data: { + objectName: "", + propertyName: "bar", + message: "" + }, + type: "MemberExpression" + }] }, { code: "foo[/(?0)/]", options: [{ property: "/(?0)/" }], parserOptions: { ecmaVersion: 2018 }, - errors: [{ message: "'/(?0)/' is restricted from being used.", type: "MemberExpression" }] + errors: [{ + messageId: "restrictedProperty", + data: { + objectName: "", + propertyName: "/(?0)/", + message: "" + }, + type: "MemberExpression" + }] }, { code: "require.call({}, 'foo')", options: [{ @@ -266,7 +352,12 @@ ruleTester.run("no-restricted-properties", rule, { message: "Please call require() directly." }], errors: [{ - message: "'require.call' is restricted from being used. Please call require() directly.", + messageId: "restrictedObjectProperty", + data: { + objectName: "require", + propertyName: "call", + message: " Please call require() directly." + }, type: "MemberExpression" }] }, { @@ -275,69 +366,170 @@ ruleTester.run("no-restricted-properties", rule, { object: "require" }], errors: [{ - message: "'require.resolve' is restricted from being used.", + messageId: "restrictedObjectProperty", + data: { + objectName: "require", + propertyName: "resolve", + message: "" + }, type: "MemberExpression" }] }, { code: "let {bar} = foo;", options: [{ object: "foo", property: "bar" }], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'foo.bar' is restricted from being used.", type: "ObjectPattern" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "foo", + propertyName: "bar", + message: "" + }, + type: "ObjectPattern" + }] }, { code: "let {bar: baz} = foo;", options: [{ object: "foo", property: "bar" }], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'foo.bar' is restricted from being used.", type: "ObjectPattern" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "foo", + propertyName: "bar", + message: "" + }, + type: "ObjectPattern" + }] }, { code: "let {'bar': baz} = foo;", options: [{ object: "foo", property: "bar" }], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'foo.bar' is restricted from being used.", type: "ObjectPattern" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "foo", + propertyName: "bar", + message: "" + }, + type: "ObjectPattern" + }] }, { code: "let {bar: {baz: qux}} = foo;", options: [{ object: "foo", property: "bar" }], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'foo.bar' is restricted from being used.", type: "ObjectPattern" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "foo", + propertyName: "bar", + message: "" + }, + type: "ObjectPattern" + }] }, { code: "let {bar} = foo;", options: [{ object: "foo" }], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'foo.bar' is restricted from being used.", type: "ObjectPattern" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "foo", + propertyName: "bar", + message: "" + }, + type: "ObjectPattern" + }] }, { code: "let {bar: baz} = foo;", options: [{ object: "foo" }], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'foo.bar' is restricted from being used.", type: "ObjectPattern" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "foo", + propertyName: "bar", + message: "" + }, + type: "ObjectPattern" + }] }, { code: "let {bar} = foo;", options: [{ property: "bar" }], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'bar' is restricted from being used.", type: "ObjectPattern" }] + errors: [{ + messageId: "restrictedProperty", + data: { + objectName: "", + propertyName: "bar", + message: "" + }, + type: "ObjectPattern" + }] }, { code: "let bar; ({bar} = foo);", options: [{ object: "foo", property: "bar" }], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'foo.bar' is restricted from being used.", type: "ObjectPattern" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "foo", + propertyName: "bar", + message: "" + }, + type: "ObjectPattern" + }] }, { code: "let bar; ({bar: baz = 1} = foo);", options: [{ object: "foo", property: "bar" }], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'foo.bar' is restricted from being used.", type: "ObjectPattern" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "foo", + propertyName: "bar", + message: "" + }, + type: "ObjectPattern" + }] }, { code: "function qux({bar} = foo) {}", options: [{ object: "foo", property: "bar" }], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'foo.bar' is restricted from being used.", type: "ObjectPattern" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "foo", + propertyName: "bar", + message: "" + }, + type: "ObjectPattern" + }] }, { code: "function qux({bar: baz} = foo) {}", options: [{ object: "foo", property: "bar" }], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'foo.bar' is restricted from being used.", type: "ObjectPattern" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "foo", + propertyName: "bar", + message: "" + }, + type: "ObjectPattern" + }] }, { code: "var {['foo']: qux, bar} = baz", options: [{ object: "baz", property: "foo" }], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'baz.foo' is restricted from being used.", type: "ObjectPattern" }] + errors: [{ + messageId: "restrictedObjectProperty", + data: { + objectName: "baz", + propertyName: "foo", + message: "" + }, + type: "ObjectPattern" + }] } ] }); diff --git a/tests/lib/rules/no-restricted-syntax.js b/tests/lib/rules/no-restricted-syntax.js index ed45540aafb..c8ba48fb8ec 100644 --- a/tests/lib/rules/no-restricted-syntax.js +++ b/tests/lib/rules/no-restricted-syntax.js @@ -47,87 +47,87 @@ ruleTester.run("no-restricted-syntax", rule, { { code: "var foo = 41;", options: ["VariableDeclaration"], - errors: [{ message: "Using 'VariableDeclaration' is not allowed.", type: "VariableDeclaration" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'VariableDeclaration' is not allowed." }, type: "VariableDeclaration" }] }, { code: ";function lol(a) { return 42; }", options: ["EmptyStatement"], - errors: [{ message: "Using 'EmptyStatement' is not allowed.", type: "EmptyStatement" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'EmptyStatement' is not allowed." }, type: "EmptyStatement" }] }, { code: "try { voila(); } catch (e) { oops(); }", options: ["TryStatement", "CallExpression", "CatchClause"], errors: [ - { message: "Using 'TryStatement' is not allowed.", type: "TryStatement" }, - { message: "Using 'CallExpression' is not allowed.", type: "CallExpression" }, - { message: "Using 'CatchClause' is not allowed.", type: "CatchClause" }, - { message: "Using 'CallExpression' is not allowed.", type: "CallExpression" } + { messageId: "restrictedSyntax", data: { message: "Using 'TryStatement' is not allowed." }, type: "TryStatement" }, + { messageId: "restrictedSyntax", data: { message: "Using 'CallExpression' is not allowed." }, type: "CallExpression" }, + { messageId: "restrictedSyntax", data: { message: "Using 'CatchClause' is not allowed." }, type: "CatchClause" }, + { messageId: "restrictedSyntax", data: { message: "Using 'CallExpression' is not allowed." }, type: "CallExpression" } ] }, { code: "bar;", options: ["Identifier[name=\"bar\"]"], - errors: [{ message: "Using 'Identifier[name=\"bar\"]' is not allowed.", type: "Identifier" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'Identifier[name=\"bar\"]' is not allowed." }, type: "Identifier" }] }, { code: "bar;", options: ["Identifier", "Identifier[name=\"bar\"]"], errors: [ - { message: "Using 'Identifier' is not allowed.", type: "Identifier" }, - { message: "Using 'Identifier[name=\"bar\"]' is not allowed.", type: "Identifier" } + { messageId: "restrictedSyntax", data: { message: "Using 'Identifier' is not allowed." }, type: "Identifier" }, + { messageId: "restrictedSyntax", data: { message: "Using 'Identifier[name=\"bar\"]' is not allowed." }, type: "Identifier" } ] }, { code: "() => {}", options: ["ArrowFunctionExpression > BlockStatement"], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "Using 'ArrowFunctionExpression > BlockStatement' is not allowed.", type: "BlockStatement" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'ArrowFunctionExpression > BlockStatement' is not allowed." }, type: "BlockStatement" }] }, { code: "({ foo: 1, 'bar': 2 })", options: ["Property > Literal.key"], - errors: [{ message: "Using 'Property > Literal.key' is not allowed.", type: "Literal" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'Property > Literal.key' is not allowed." }, type: "Literal" }] }, { code: "A: for (;;) break A;", options: ["BreakStatement[label]"], - errors: [{ message: "Using 'BreakStatement[label]' is not allowed.", type: "BreakStatement" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'BreakStatement[label]' is not allowed." }, type: "BreakStatement" }] }, { code: "function foo(bar, baz, qux) {}", options: ["FunctionDeclaration[params.length>2]"], - errors: [{ message: "Using 'FunctionDeclaration[params.length>2]' is not allowed.", type: "FunctionDeclaration" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'FunctionDeclaration[params.length>2]' is not allowed." }, type: "FunctionDeclaration" }] }, // object format { code: "var foo = 41;", options: [{ selector: "VariableDeclaration" }], - errors: [{ message: "Using 'VariableDeclaration' is not allowed.", type: "VariableDeclaration" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'VariableDeclaration' is not allowed." }, type: "VariableDeclaration" }] }, { code: "function foo(bar, baz, qux) {}", options: [{ selector: "FunctionDeclaration[params.length>2]" }], - errors: [{ message: "Using 'FunctionDeclaration[params.length>2]' is not allowed.", type: "FunctionDeclaration" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'FunctionDeclaration[params.length>2]' is not allowed." }, type: "FunctionDeclaration" }] }, { code: "function foo(bar, baz, qux) {}", options: [{ selector: "FunctionDeclaration[params.length>2]", message: "custom error message." }], - errors: [{ message: "custom error message.", type: "FunctionDeclaration" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "custom error message." }, type: "FunctionDeclaration" }] }, // with object format, the custom message may contain the string '{{selector}}' { code: "function foo(bar, baz, qux) {}", options: [{ selector: "FunctionDeclaration[params.length>2]", message: "custom message with {{selector}}" }], - errors: [{ message: "custom message with {{selector}}", type: "FunctionDeclaration" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "custom message with {{selector}}" }, type: "FunctionDeclaration" }] }, // https://github.com/eslint/eslint/issues/8733 { code: "console.log(/a/i);", options: ["Literal[regex.flags=/./]"], - errors: [{ message: "Using 'Literal[regex.flags=/./]' is not allowed.", type: "Literal" }] + errors: [{ messageId: "restrictedSyntax", data: { message: "Using 'Literal[regex.flags=/./]' is not allowed." }, type: "Literal" }] } ] }); diff --git a/tests/lib/rules/no-return-assign.js b/tests/lib/rules/no-return-assign.js index e63b1d29244..e9d0c585edc 100644 --- a/tests/lib/rules/no-return-assign.js +++ b/tests/lib/rules/no-return-assign.js @@ -16,11 +16,6 @@ const rule = require("../../../lib/rules/no-return-assign"), // Tests //------------------------------------------------------------------------------ -const error = { - message: "Return statement should not contain assignment.", - type: "ReturnStatement" -}; - const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); ruleTester.run("no-return-assign", rule, { @@ -62,44 +57,44 @@ ruleTester.run("no-return-assign", rule, { invalid: [ { code: "function x() { return result = a * b; };", - errors: [error] + errors: [{ messageId: "returnAssignment", type: "ReturnStatement" }] }, { code: "function x() { return (result) = (a * b); };", - errors: [error] + errors: [{ messageId: "returnAssignment", type: "ReturnStatement" }] }, { code: "function x() { return result = a * b; };", options: ["except-parens"], - errors: [error] + errors: [{ messageId: "returnAssignment", type: "ReturnStatement" }] }, { code: "function x() { return (result) = (a * b); };", options: ["except-parens"], - errors: [error] + errors: [{ messageId: "returnAssignment", type: "ReturnStatement" }] }, { code: "() => { return result = a * b; }", - errors: [error] + errors: [{ messageId: "returnAssignment", type: "ReturnStatement" }] }, { code: "() => result = a * b", - errors: ["Arrow function should not return assignment."] + errors: [{ messageId: "arrowAssignment", type: "ArrowFunctionExpression" }] }, { code: "function x() { return result = a * b; };", options: ["always"], - errors: [error] + errors: [{ messageId: "returnAssignment", type: "ReturnStatement" }] }, { code: "function x() { return (result = a * b); };", options: ["always"], - errors: [error] + errors: [{ messageId: "returnAssignment", type: "ReturnStatement" }] }, { code: "function x() { return result || (result = a * b); };", options: ["always"], - errors: [error] + errors: [{ messageId: "returnAssignment", type: "ReturnStatement" }] } ] }); diff --git a/tests/lib/rules/no-return-await.js b/tests/lib/rules/no-return-await.js index f38f678f0ea..508d7cb8528 100644 --- a/tests/lib/rules/no-return-await.js +++ b/tests/lib/rules/no-return-await.js @@ -17,7 +17,7 @@ const { RuleTester } = require("../../../lib/rule-tester"); //------------------------------------------------------------------------------ // pending https://github.com/eslint/espree/issues/304, the type should be "Keyword" -const errors = [{ message: "Redundant use of `await` on a return value.", type: "Identifier" }]; +const errors = [{ messageId: "redundantUseOfAwait", type: "Identifier" }]; const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2017 } }); diff --git a/tests/lib/rules/no-script-url.js b/tests/lib/rules/no-script-url.js index a66136e2218..6eca268ce8d 100644 --- a/tests/lib/rules/no-script-url.js +++ b/tests/lib/rules/no-script-url.js @@ -28,13 +28,13 @@ ruleTester.run("no-script-url", rule, { { code: "var a = 'javascript:void(0);';", errors: [ - { message: "Script URL is a form of eval.", type: "Literal" } + { messageId: "unexpectedScriptURL", type: "Literal" } ] }, { code: "var a = 'javascript:';", errors: [ - { message: "Script URL is a form of eval.", type: "Literal" } + { messageId: "unexpectedScriptURL", type: "Literal" } ] } ] diff --git a/tests/lib/rules/no-self-assign.js b/tests/lib/rules/no-self-assign.js index c20c01fcb5a..5149dac65b2 100644 --- a/tests/lib/rules/no-self-assign.js +++ b/tests/lib/rules/no-self-assign.js @@ -82,59 +82,59 @@ ruleTester.run("no-self-assign", rule, { } ], invalid: [ - { code: "a = a", errors: ["'a' is assigned to itself."] }, - { code: "[a] = [a]", parserOptions: { ecmaVersion: 6 }, errors: ["'a' is assigned to itself."] }, - { code: "[a, b] = [a, b]", parserOptions: { ecmaVersion: 6 }, errors: ["'a' is assigned to itself.", "'b' is assigned to itself."] }, - { code: "[a, b] = [a, c]", parserOptions: { ecmaVersion: 6 }, errors: ["'a' is assigned to itself."] }, - { code: "[a, b] = [, b]", parserOptions: { ecmaVersion: 6 }, errors: ["'b' is assigned to itself."] }, - { code: "[a, ...b] = [a, ...b]", parserOptions: { ecmaVersion: 6 }, errors: ["'a' is assigned to itself.", "'b' is assigned to itself."] }, - { code: "[[a], {b}] = [[a], {b}]", parserOptions: { ecmaVersion: 6 }, errors: ["'a' is assigned to itself.", "'b' is assigned to itself."] }, - { code: "({a} = {a})", parserOptions: { ecmaVersion: 6 }, errors: ["'a' is assigned to itself."] }, - { code: "({a: b} = {a: b})", parserOptions: { ecmaVersion: 6 }, errors: ["'b' is assigned to itself."] }, - { code: "({'a': b} = {'a': b})", parserOptions: { ecmaVersion: 6 }, errors: ["'b' is assigned to itself."] }, - { code: "({a: b} = {'a': b})", parserOptions: { ecmaVersion: 6 }, errors: ["'b' is assigned to itself."] }, - { code: "({'a': b} = {a: b})", parserOptions: { ecmaVersion: 6 }, errors: ["'b' is assigned to itself."] }, - { code: "({1: b} = {1: b})", parserOptions: { ecmaVersion: 6 }, errors: ["'b' is assigned to itself."] }, - { code: "({1: b} = {'1': b})", parserOptions: { ecmaVersion: 6 }, errors: ["'b' is assigned to itself."] }, - { code: "({'1': b} = {1: b})", parserOptions: { ecmaVersion: 6 }, errors: ["'b' is assigned to itself."] }, - { code: "({['a']: b} = {a: b})", parserOptions: { ecmaVersion: 6 }, errors: ["'b' is assigned to itself."] }, - { code: "({'a': b} = {[`a`]: b})", parserOptions: { ecmaVersion: 6 }, errors: ["'b' is assigned to itself."] }, - { code: "({1: b} = {[1]: b})", parserOptions: { ecmaVersion: 6 }, errors: ["'b' is assigned to itself."] }, - { code: "({a, b} = {a, b})", parserOptions: { ecmaVersion: 6 }, errors: ["'a' is assigned to itself.", "'b' is assigned to itself."] }, - { code: "({a, b} = {b, a})", parserOptions: { ecmaVersion: 6 }, errors: ["'b' is assigned to itself.", "'a' is assigned to itself."] }, - { code: "({a, b} = {c, a})", parserOptions: { ecmaVersion: 6 }, errors: ["'a' is assigned to itself."] }, - { code: "({a: {b}, c: [d]} = {a: {b}, c: [d]})", parserOptions: { ecmaVersion: 6 }, errors: ["'b' is assigned to itself.", "'d' is assigned to itself."] }, - { code: "({a, b} = {a, ...x, b})", parserOptions: { ecmaVersion: 2018 }, errors: ["'b' is assigned to itself."] }, + { code: "a = a", errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, + { code: "[a] = [a]", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, + { code: "[a, b] = [a, b]", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "[a, b] = [a, c]", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, + { code: "[a, b] = [, b]", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "[a, ...b] = [a, ...b]", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "[[a], {b}] = [[a], {b}]", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({a} = {a})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, + { code: "({a: b} = {a: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({'a': b} = {'a': b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({a: b} = {'a': b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({'a': b} = {a: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({1: b} = {1: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({1: b} = {'1': b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({'1': b} = {1: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({['a']: b} = {a: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({'a': b} = {[`a`]: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({1: b} = {[1]: b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({a, b} = {a, b})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }, { messageId: "selfAssignment", data: { name: "b" } }] }, + { code: "({a, b} = {b, a})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }, { messageId: "selfAssignment", data: { name: "a" } }] }, + { code: "({a, b} = {c, a})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "a" } }] }, + { code: "({a: {b}, c: [d]} = {a: {b}, c: [d]})", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }, { messageId: "selfAssignment", data: { name: "d" } }] }, + { code: "({a, b} = {a, ...x, b})", parserOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "selfAssignment", data: { name: "b" } }] }, { code: "a.b = a.b", - errors: ["'a.b' is assigned to itself."] + errors: [{ messageId: "selfAssignment", data: { name: "a.b" } }] }, { code: "a.b.c = a.b.c", - errors: ["'a.b.c' is assigned to itself."] + errors: [{ messageId: "selfAssignment", data: { name: "a.b.c" } }] }, { code: "a[b] = a[b]", - errors: ["'a[b]' is assigned to itself."] + errors: [{ messageId: "selfAssignment", data: { name: "a[b]" } }] }, { code: "a['b'] = a['b']", - errors: ["'a['b']' is assigned to itself."] + errors: [{ messageId: "selfAssignment", data: { name: "a['b']" } }] }, { code: "a[\n 'b'\n] = a[\n 'b'\n]", - errors: ["'a['b']' is assigned to itself."] + errors: [{ messageId: "selfAssignment", data: { name: "a['b']" } }] }, - { code: "a.b = a.b", options: [{ props: true }], errors: ["'a.b' is assigned to itself."] }, - { code: "a.b.c = a.b.c", options: [{ props: true }], errors: ["'a.b.c' is assigned to itself."] }, - { code: "a[b] = a[b]", options: [{ props: true }], errors: ["'a[b]' is assigned to itself."] }, - { code: "a['b'] = a['b']", options: [{ props: true }], errors: ["'a['b']' is assigned to itself."] }, - { code: "a[\n 'b'\n] = a[\n 'b'\n]", options: [{ props: true }], errors: ["'a['b']' is assigned to itself."] }, + { code: "a.b = a.b", options: [{ props: true }], errors: [{ messageId: "selfAssignment", data: { name: "a.b" } }] }, + { code: "a.b.c = a.b.c", options: [{ props: true }], errors: [{ messageId: "selfAssignment", data: { name: "a.b.c" } }] }, + { code: "a[b] = a[b]", options: [{ props: true }], errors: [{ messageId: "selfAssignment", data: { name: "a[b]" } }] }, + { code: "a['b'] = a['b']", options: [{ props: true }], errors: [{ messageId: "selfAssignment", data: { name: "a['b']" } }] }, + { code: "a[\n 'b'\n] = a[\n 'b'\n]", options: [{ props: true }], errors: [{ messageId: "selfAssignment", data: { name: "a['b']" } }] }, { code: "this.x = this.x", options: [{ props: true }], - errors: ["'this.x' is assigned to itself."] + errors: [{ messageId: "selfAssignment", data: { name: "this.x" } }] }, - { code: "a['/(?0)/'] = a[/(?0)/]", options: [{ props: true }], parserOptions: { ecmaVersion: 2018 }, errors: ["'a[/(?0)/]' is assigned to itself."] } + { code: "a['/(?0)/'] = a[/(?0)/]", options: [{ props: true }], parserOptions: { ecmaVersion: 2018 }, errors: [{ messageId: "selfAssignment", data: { name: "a[/(?0)/]" } }] } ] }); diff --git a/tests/lib/rules/no-self-compare.js b/tests/lib/rules/no-self-compare.js index 3c09a182755..85bc1e21c07 100644 --- a/tests/lib/rules/no-self-compare.js +++ b/tests/lib/rules/no-self-compare.js @@ -26,19 +26,19 @@ ruleTester.run("no-self-compare", rule, { "foo.bar.baz === foo.bar.qux" ], invalid: [ - { code: "if (x === x) { }", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] }, - { code: "if (x !== x) { }", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] }, - { code: "if (x > x) { }", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] }, - { code: "if ('x' > 'x') { }", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] }, - { code: "do {} while (x === x)", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] }, - { code: "x === x", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] }, - { code: "x !== x", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] }, - { code: "x == x", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] }, - { code: "x != x", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] }, - { code: "x > x", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] }, - { code: "x < x", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] }, - { code: "x >= x", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] }, - { code: "x <= x", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] }, - { code: "foo.bar().baz.qux >= foo.bar ().baz .qux", errors: [{ message: "Comparing to itself is potentially pointless.", type: "BinaryExpression" }] } + { code: "if (x === x) { }", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, + { code: "if (x !== x) { }", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, + { code: "if (x > x) { }", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, + { code: "if ('x' > 'x') { }", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, + { code: "do {} while (x === x)", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, + { code: "x === x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, + { code: "x !== x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, + { code: "x == x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, + { code: "x != x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, + { code: "x > x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, + { code: "x < x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, + { code: "x >= x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, + { code: "x <= x", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] }, + { code: "foo.bar().baz.qux >= foo.bar ().baz .qux", errors: [{ messageId: "comparingToSelf", type: "BinaryExpression" }] } ] }); diff --git a/tests/lib/rules/no-sequences.js b/tests/lib/rules/no-sequences.js index 7fcba267b7e..ae988ee3dae 100644 --- a/tests/lib/rules/no-sequences.js +++ b/tests/lib/rules/no-sequences.js @@ -23,7 +23,7 @@ const rule = require("../../../lib/rules/no-sequences"), */ function errors(column) { return [{ - message: "Unexpected use of comma operator.", + messageId: "unexpectedCommaExpression", type: "SequenceExpression", line: 1, column @@ -57,7 +57,7 @@ ruleTester.run("no-sequences", rule, { { code: "1, 2;", errors: [{ - message: "Unexpected use of comma operator.", + messageId: "unexpectedCommaExpression", type: "SequenceExpression", line: 1, column: 2, diff --git a/tests/lib/rules/no-setter-return.js b/tests/lib/rules/no-setter-return.js index 8ba7daa777a..b70b4e3f1c0 100644 --- a/tests/lib/rules/no-setter-return.js +++ b/tests/lib/rules/no-setter-return.js @@ -252,7 +252,7 @@ ruleTester.run("no-setter-return", rule, { // full error test { code: "({ set a(val){ return val + 1; } })", - errors: [{ message: "Setter cannot return a value.", type: "ReturnStatement", column: 16, endColumn: 31 }] + errors: [{ messageId: "returnsValue", type: "ReturnStatement", column: 16, endColumn: 31 }] }, // basic tests diff --git a/tests/lib/rules/no-shadow-restricted-names.js b/tests/lib/rules/no-shadow-restricted-names.js index 00bf01161bc..da2df0fb9d8 100644 --- a/tests/lib/rules/no-shadow-restricted-names.js +++ b/tests/lib/rules/no-shadow-restricted-names.js @@ -37,90 +37,90 @@ ruleTester.run("no-shadow-restricted-names", rule, { { code: "function NaN(NaN) { var NaN; !function NaN(NaN) { try {} catch(NaN) {} }; }", errors: [ - { message: "Shadowing of global property 'NaN'.", type: "Identifier" }, - { message: "Shadowing of global property 'NaN'.", type: "Identifier" }, - { message: "Shadowing of global property 'NaN'.", type: "Identifier" }, - { message: "Shadowing of global property 'NaN'.", type: "Identifier" }, - { message: "Shadowing of global property 'NaN'.", type: "Identifier" }, - { message: "Shadowing of global property 'NaN'.", type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "NaN" }, type: "Identifier" } ] }, { code: "function undefined(undefined) { !function undefined(undefined) { try {} catch(undefined) {} }; }", errors: [ - { message: "Shadowing of global property 'undefined'.", type: "Identifier" }, - { message: "Shadowing of global property 'undefined'.", type: "Identifier" }, - { message: "Shadowing of global property 'undefined'.", type: "Identifier" }, - { message: "Shadowing of global property 'undefined'.", type: "Identifier" }, - { message: "Shadowing of global property 'undefined'.", type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" } ] }, { code: "function Infinity(Infinity) { var Infinity; !function Infinity(Infinity) { try {} catch(Infinity) {} }; }", errors: [ - { message: "Shadowing of global property 'Infinity'.", type: "Identifier" }, - { message: "Shadowing of global property 'Infinity'.", type: "Identifier" }, - { message: "Shadowing of global property 'Infinity'.", type: "Identifier" }, - { message: "Shadowing of global property 'Infinity'.", type: "Identifier" }, - { message: "Shadowing of global property 'Infinity'.", type: "Identifier" }, - { message: "Shadowing of global property 'Infinity'.", type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "Infinity" }, type: "Identifier" } ] }, { code: "function arguments(arguments) { var arguments; !function arguments(arguments) { try {} catch(arguments) {} }; }", errors: [ - { message: "Shadowing of global property 'arguments'.", type: "Identifier" }, - { message: "Shadowing of global property 'arguments'.", type: "Identifier" }, - { message: "Shadowing of global property 'arguments'.", type: "Identifier" }, - { message: "Shadowing of global property 'arguments'.", type: "Identifier" }, - { message: "Shadowing of global property 'arguments'.", type: "Identifier" }, - { message: "Shadowing of global property 'arguments'.", type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "arguments" }, type: "Identifier" } ] }, { code: "function eval(eval) { var eval; !function eval(eval) { try {} catch(eval) {} }; }", errors: [ - { message: "Shadowing of global property 'eval'.", type: "Identifier" }, - { message: "Shadowing of global property 'eval'.", type: "Identifier" }, - { message: "Shadowing of global property 'eval'.", type: "Identifier" }, - { message: "Shadowing of global property 'eval'.", type: "Identifier" }, - { message: "Shadowing of global property 'eval'.", type: "Identifier" }, - { message: "Shadowing of global property 'eval'.", type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" } ] }, { code: "var eval = (eval) => { var eval; !function eval(eval) { try {} catch(eval) {} }; }", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Shadowing of global property 'eval'.", type: "Identifier" }, - { message: "Shadowing of global property 'eval'.", type: "Identifier" }, - { message: "Shadowing of global property 'eval'.", type: "Identifier" }, - { message: "Shadowing of global property 'eval'.", type: "Identifier" }, - { message: "Shadowing of global property 'eval'.", type: "Identifier" }, - { message: "Shadowing of global property 'eval'.", type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "eval" }, type: "Identifier" } ] }, { code: "var [undefined] = [1]", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Shadowing of global property 'undefined'.", type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" } ] }, { code: "var {undefined} = obj; var {a: undefined} = obj; var {a: {b: {undefined}}} = obj; var {a, ...undefined} = obj;", parserOptions: { ecmaVersion: 9 }, errors: [ - { message: "Shadowing of global property 'undefined'.", type: "Identifier" }, - { message: "Shadowing of global property 'undefined'.", type: "Identifier" }, - { message: "Shadowing of global property 'undefined'.", type: "Identifier" }, - { message: "Shadowing of global property 'undefined'.", type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" }, + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" } ] }, { code: "var undefined; undefined = 5;", errors: [ - { message: "Shadowing of global property 'undefined'.", type: "Identifier" } + { messageId: "shadowingRestrictedName", data: { name: "undefined" }, type: "Identifier" } ] } ] diff --git a/tests/lib/rules/no-spaced-func.js b/tests/lib/rules/no-spaced-func.js index b3404eb88ba..6afcbe6dcf4 100644 --- a/tests/lib/rules/no-spaced-func.js +++ b/tests/lib/rules/no-spaced-func.js @@ -43,64 +43,64 @@ ruleTester.run("no-spaced-func", rule, { code: "f ();", output: "f();", errors: [ - { message: "Unexpected space between function name and paren.", type: "CallExpression" }] + { messageId: "noSpacedFunction", type: "CallExpression" }] }, { code: "f (a, b);", output: "f(a, b);", - errors: [{ message: "Unexpected space between function name and paren.", type: "CallExpression" }] + errors: [{ messageId: "noSpacedFunction", type: "CallExpression" }] }, { code: "f\n();", output: "f();", - errors: [{ message: "Unexpected space between function name and paren.", type: "CallExpression" }] + errors: [{ messageId: "noSpacedFunction", type: "CallExpression" }] }, { code: "f.b ();", output: "f.b();", - errors: [{ message: "Unexpected space between function name and paren.", type: "CallExpression", column: 3 }] + errors: [{ messageId: "noSpacedFunction", type: "CallExpression", column: 3 }] }, { code: "f.b().c ();", output: "f.b().c();", - errors: [{ message: "Unexpected space between function name and paren.", type: "CallExpression", column: 7 }] + errors: [{ messageId: "noSpacedFunction", type: "CallExpression", column: 7 }] }, { code: "f() ()", output: "f()()", - errors: [{ message: "Unexpected space between function name and paren.", type: "CallExpression" }] + errors: [{ messageId: "noSpacedFunction", type: "CallExpression" }] }, { code: "(function() {} ())", output: "(function() {}())", - errors: [{ message: "Unexpected space between function name and paren.", type: "CallExpression" }] + errors: [{ messageId: "noSpacedFunction", type: "CallExpression" }] }, { code: "var f = new Foo ()", output: "var f = new Foo()", - errors: [{ message: "Unexpected space between function name and paren.", type: "NewExpression" }] + errors: [{ messageId: "noSpacedFunction", type: "NewExpression" }] }, { code: "f ( (0) )", output: "f( (0) )", - errors: [{ message: "Unexpected space between function name and paren.", type: "CallExpression" }] + errors: [{ messageId: "noSpacedFunction", type: "CallExpression" }] }, { code: "f(0) (1)", output: "f(0)(1)", - errors: [{ message: "Unexpected space between function name and paren.", type: "CallExpression" }] + errors: [{ messageId: "noSpacedFunction", type: "CallExpression" }] }, { code: "(f) (0)", output: "(f)(0)", - errors: [{ message: "Unexpected space between function name and paren.", type: "CallExpression" }] + errors: [{ messageId: "noSpacedFunction", type: "CallExpression" }] }, { code: "f ();\n t ();", output: "f();\n t();", errors: [ - { message: "Unexpected space between function name and paren.", type: "CallExpression" }, - { message: "Unexpected space between function name and paren.", type: "CallExpression" } + { messageId: "noSpacedFunction", type: "CallExpression" }, + { messageId: "noSpacedFunction", type: "CallExpression" } ] } ] diff --git a/tests/lib/rules/no-sparse-arrays.js b/tests/lib/rules/no-sparse-arrays.js index b858de0e7f9..11536a3fa3c 100644 --- a/tests/lib/rules/no-sparse-arrays.js +++ b/tests/lib/rules/no-sparse-arrays.js @@ -27,14 +27,14 @@ ruleTester.run("no-sparse-arrays", rule, { { code: "var a = [,];", errors: [{ - message: "Unexpected comma in middle of array.", + messageId: "unexpectedSparseArray", type: "ArrayExpression" }] }, { code: "var a = [ 1,, 2];", errors: [{ - message: "Unexpected comma in middle of array.", + messageId: "unexpectedSparseArray", type: "ArrayExpression" }] } diff --git a/tests/lib/rules/no-sync.js b/tests/lib/rules/no-sync.js index c8cf36e178c..b69605da6b3 100644 --- a/tests/lib/rules/no-sync.js +++ b/tests/lib/rules/no-sync.js @@ -25,13 +25,25 @@ ruleTester.run("no-sync", rule, { { code: "if (true) {fs.fooSync();}", options: [{ allowAtRootLevel: true }] } ], invalid: [ - { code: "var foo = fs.fooSync();", errors: [{ message: "Unexpected sync method: 'fooSync'.", type: "MemberExpression" }] }, - { code: "var foo = fs.fooSync();", options: [{ allowAtRootLevel: false }], errors: [{ message: "Unexpected sync method: 'fooSync'.", type: "MemberExpression" }] }, - { code: "if (true) {fs.fooSync();}", errors: [{ message: "Unexpected sync method: 'fooSync'.", type: "MemberExpression" }] }, - { code: "var foo = fs.fooSync;", errors: [{ message: "Unexpected sync method: 'fooSync'.", type: "MemberExpression" }] }, - { code: "function someFunction() {fs.fooSync();}", errors: [{ message: "Unexpected sync method: 'fooSync'.", type: "MemberExpression" }] }, - { code: "function someFunction() {fs.fooSync();}", options: [{ allowAtRootLevel: true }], errors: [{ message: "Unexpected sync method: 'fooSync'.", type: "MemberExpression" }] }, - { code: "var a = function someFunction() {fs.fooSync();}", options: [{ allowAtRootLevel: true }], errors: [{ message: "Unexpected sync method: 'fooSync'.", type: "MemberExpression" }] } + { code: "var foo = fs.fooSync();", errors: [{ messageId: "noSync", data: { propertyName: "fooSync" }, type: "MemberExpression" }] }, + { + code: "var foo = fs.fooSync();", + options: [{ allowAtRootLevel: false }], + errors: [{ messageId: "noSync", data: { propertyName: "fooSync" }, type: "MemberExpression" }] + }, + { code: "if (true) {fs.fooSync();}", errors: [{ messageId: "noSync", data: { propertyName: "fooSync" }, type: "MemberExpression" }] }, + { code: "var foo = fs.fooSync;", errors: [{ messageId: "noSync", data: { propertyName: "fooSync" }, type: "MemberExpression" }] }, + { code: "function someFunction() {fs.fooSync();}", errors: [{ messageId: "noSync", data: { propertyName: "fooSync" }, type: "MemberExpression" }] }, + { + code: "function someFunction() {fs.fooSync();}", + options: [{ allowAtRootLevel: true }], + errors: [{ messageId: "noSync", data: { propertyName: "fooSync" }, type: "MemberExpression" }] + }, + { + code: "var a = function someFunction() {fs.fooSync();}", + options: [{ allowAtRootLevel: true }], + errors: [{ messageId: "noSync", data: { propertyName: "fooSync" }, type: "MemberExpression" }] + } ] }); diff --git a/tests/lib/rules/no-tabs.js b/tests/lib/rules/no-tabs.js index 637f4905162..95319d89889 100644 --- a/tests/lib/rules/no-tabs.js +++ b/tests/lib/rules/no-tabs.js @@ -16,7 +16,6 @@ const { RuleTester } = require("../../../lib/rule-tester"); //------------------------------------------------------------------------------ const ruleTester = new RuleTester(); -const ERROR_MESSAGE = "Unexpected tab character."; ruleTester.run("no-tabs", rule, { valid: [ @@ -38,7 +37,7 @@ ruleTester.run("no-tabs", rule, { { code: "function test(){\t}", errors: [{ - message: ERROR_MESSAGE, + messageId: "unexpectedTab", line: 1, column: 17, endLine: 1, @@ -48,7 +47,7 @@ ruleTester.run("no-tabs", rule, { { code: "/** \t comment test */", errors: [{ - message: ERROR_MESSAGE, + messageId: "unexpectedTab", line: 1, column: 5, endLine: 1, @@ -61,7 +60,7 @@ ruleTester.run("no-tabs", rule, { " //\tsdfdsf \n" + "}", errors: [{ - message: ERROR_MESSAGE, + messageId: "unexpectedTab", line: 2, column: 5, endLine: 2, @@ -74,7 +73,7 @@ ruleTester.run("no-tabs", rule, { " //sdfdsf \n" + "}", errors: [{ - message: ERROR_MESSAGE, + messageId: "unexpectedTab", line: 1, column: 9, endLine: 1, @@ -88,14 +87,14 @@ ruleTester.run("no-tabs", rule, { "\t}", errors: [ { - message: ERROR_MESSAGE, + messageId: "unexpectedTab", line: 2, column: 5, endLine: 2, endColumn: 6 }, { - message: ERROR_MESSAGE, + messageId: "unexpectedTab", line: 3, column: 1, endLine: 3, @@ -107,7 +106,7 @@ ruleTester.run("no-tabs", rule, { code: "\t// Comment with leading tab \t and inline tab", options: [{ allowIndentationTabs: true }], errors: [{ - message: ERROR_MESSAGE, + messageId: "unexpectedTab", line: 1, column: 30, endLine: 1, @@ -118,35 +117,35 @@ ruleTester.run("no-tabs", rule, { code: "\t\ta =\t\t\tb +\tc\t\t;\t\t", errors: [ { - message: ERROR_MESSAGE, + messageId: "unexpectedTab", line: 1, column: 1, endLine: 1, endColumn: 3 }, { - message: ERROR_MESSAGE, + messageId: "unexpectedTab", line: 1, column: 6, endLine: 1, endColumn: 9 }, { - message: ERROR_MESSAGE, + messageId: "unexpectedTab", line: 1, column: 12, endLine: 1, endColumn: 13 }, { - message: ERROR_MESSAGE, + messageId: "unexpectedTab", line: 1, column: 14, endLine: 1, endColumn: 16 }, { - message: ERROR_MESSAGE, + messageId: "unexpectedTab", line: 1, column: 17, endLine: 1, diff --git a/tests/lib/rules/no-template-curly-in-string.js b/tests/lib/rules/no-template-curly-in-string.js index 1ea31c16dcd..04dfd49e885 100644 --- a/tests/lib/rules/no-template-curly-in-string.js +++ b/tests/lib/rules/no-template-curly-in-string.js @@ -18,7 +18,7 @@ const rule = require("../../../lib/rules/no-template-curly-in-string"), const ruleTester = new RuleTester(); -const message = "Unexpected template string expression."; +const messageId = "unexpectedTemplateExpression"; const parserOptions = { ecmaVersion: 6 }; ruleTester.run("no-template-curly-in-string", rule, { @@ -43,37 +43,37 @@ ruleTester.run("no-template-curly-in-string", rule, { { code: "'Hello, ${name}'", parserOptions, - errors: [{ message }] + errors: [{ messageId }] }, { code: "\"Hello, ${name}\"", parserOptions, - errors: [{ message }] + errors: [{ messageId }] }, { code: "'${greeting}, ${name}'", parserOptions, - errors: [{ message }] + errors: [{ messageId }] }, { code: "'Hello, ${index + 1}'", parserOptions, - errors: [{ message }] + errors: [{ messageId }] }, { code: "'Hello, ${name + \" foo\"}'", parserOptions, - errors: [{ message }] + errors: [{ messageId }] }, { code: "'Hello, ${name || \"foo\"}'", parserOptions, - errors: [{ message }] + errors: [{ messageId }] }, { code: "'Hello, ${{foo: \"bar\"}.foo}'", parserOptions, - errors: [{ message }] + errors: [{ messageId }] } ] }); diff --git a/tests/lib/rules/no-ternary.js b/tests/lib/rules/no-ternary.js index 68fa21b8875..35d025034e7 100644 --- a/tests/lib/rules/no-ternary.js +++ b/tests/lib/rules/no-ternary.js @@ -23,8 +23,8 @@ ruleTester.run("no-ternary", rule, { "\"x ? y\";" ], invalid: [ - { code: "var foo = true ? thing : stuff;", errors: [{ message: "Ternary operator used.", type: "ConditionalExpression" }] }, - { code: "true ? thing() : stuff();", errors: [{ message: "Ternary operator used.", type: "ConditionalExpression" }] }, - { code: "function foo(bar) { return bar ? baz : qux; }", errors: [{ message: "Ternary operator used.", type: "ConditionalExpression" }] } + { code: "var foo = true ? thing : stuff;", errors: [{ messageId: "noTernaryOperator", type: "ConditionalExpression" }] }, + { code: "true ? thing() : stuff();", errors: [{ messageId: "noTernaryOperator", type: "ConditionalExpression" }] }, + { code: "function foo(bar) { return bar ? baz : qux; }", errors: [{ messageId: "noTernaryOperator", type: "ConditionalExpression" }] } ] }); diff --git a/tests/lib/rules/no-this-before-super.js b/tests/lib/rules/no-this-before-super.js index 958fb3d54a4..c41b8c9c179 100644 --- a/tests/lib/rules/no-this-before-super.js +++ b/tests/lib/rules/no-this-before-super.js @@ -100,67 +100,67 @@ ruleTester.run("no-this-before-super", rule, { // disallows all `this`/`super` if `super()` is missing. { code: "class A extends B { constructor() { this.c = 0; } }", - errors: [{ message: "'this' is not allowed before 'super()'.", type: "ThisExpression" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] }, { code: "class A extends B { constructor() { this.c(); } }", - errors: [{ message: "'this' is not allowed before 'super()'.", type: "ThisExpression" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] }, { code: "class A extends B { constructor() { super.c(); } }", - errors: [{ message: "'super' is not allowed before 'super()'.", type: "Super" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "super" }, type: "Super" }] }, // disallows `this`/`super` before `super()`. { code: "class A extends B { constructor() { this.c = 0; super(); } }", - errors: [{ message: "'this' is not allowed before 'super()'.", type: "ThisExpression" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] }, { code: "class A extends B { constructor() { this.c(); super(); } }", - errors: [{ message: "'this' is not allowed before 'super()'.", type: "ThisExpression" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] }, { code: "class A extends B { constructor() { super.c(); super(); } }", - errors: [{ message: "'super' is not allowed before 'super()'.", type: "Super" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "super" }, type: "Super" }] }, // disallows `this`/`super` in arguments of `super()`. { code: "class A extends B { constructor() { super(this.c); } }", - errors: [{ message: "'this' is not allowed before 'super()'.", type: "ThisExpression" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] }, { code: "class A extends B { constructor() { super(this.c()); } }", - errors: [{ message: "'this' is not allowed before 'super()'.", type: "ThisExpression" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] }, { code: "class A extends B { constructor() { super(super.c()); } }", - errors: [{ message: "'super' is not allowed before 'super()'.", type: "Super" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "super" }, type: "Super" }] }, // even if is nested, reports correctly. { code: "class A extends B { constructor() { class C extends D { constructor() { super(); this.e(); } } this.f(); super(); } }", - errors: [{ message: "'this' is not allowed before 'super()'.", type: "ThisExpression", column: 96 }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression", column: 96 }] }, { code: "class A extends B { constructor() { class C extends D { constructor() { this.e(); super(); } } super(); this.f(); } }", - errors: [{ message: "'this' is not allowed before 'super()'.", type: "ThisExpression", column: 73 }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression", column: 73 }] }, // multi code path. { code: "class A extends B { constructor() { if (a) super(); this.a(); } }", - errors: [{ message: "'this' is not allowed before 'super()'.", type: "ThisExpression" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] }, { code: "class A extends B { constructor() { try { super(); } finally { this.a; } } }", - errors: [{ message: "'this' is not allowed before 'super()'.", type: "ThisExpression" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] }, { code: "class A extends B { constructor() { try { super(); } catch (err) { } this.a; } }", - errors: [{ message: "'this' is not allowed before 'super()'.", type: "ThisExpression" }] + errors: [{ messageId: "noBeforeSuper", data: { kind: "this" }, type: "ThisExpression" }] } ] }); diff --git a/tests/lib/rules/no-trailing-spaces.js b/tests/lib/rules/no-trailing-spaces.js index b1ff90ea28f..1275e0708ca 100644 --- a/tests/lib/rules/no-trailing-spaces.js +++ b/tests/lib/rules/no-trailing-spaces.js @@ -114,7 +114,7 @@ ruleTester.run("no-trailing-spaces", rule, { " short2: short\r\n" + "}", errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -134,7 +134,7 @@ ruleTester.run("no-trailing-spaces", rule, { " short2: short\n" + "}", errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -154,7 +154,7 @@ ruleTester.run("no-trailing-spaces", rule, { " short2: short\n" + "}\n", errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -175,7 +175,7 @@ ruleTester.run("no-trailing-spaces", rule, { "}\n", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -189,7 +189,7 @@ ruleTester.run("no-trailing-spaces", rule, { "measAr.push(\"
\",\n" + " \"
\");", errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -201,7 +201,7 @@ ruleTester.run("no-trailing-spaces", rule, { "measAr.push(\"
\",\n" + " \"
\");", errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -209,7 +209,7 @@ ruleTester.run("no-trailing-spaces", rule, { code: "var a = 5; \n", output: "var a = 5;\n", errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -217,10 +217,10 @@ ruleTester.run("no-trailing-spaces", rule, { code: "var a = 5; \n b = 3; ", output: "var a = 5;\n b = 3;", errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }, { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -228,10 +228,10 @@ ruleTester.run("no-trailing-spaces", rule, { code: "var a = 5; \n\n b = 3; ", output: "var a = 5;\n\n b = 3;", errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }, { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -239,7 +239,7 @@ ruleTester.run("no-trailing-spaces", rule, { code: "var a = 5;\t\n b = 3;", output: "var a = 5;\n b = 3;", errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -247,7 +247,7 @@ ruleTester.run("no-trailing-spaces", rule, { code: " \n var c = 1;", output: "\n var c = 1;", errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -255,7 +255,7 @@ ruleTester.run("no-trailing-spaces", rule, { code: "\t\n\tvar c = 2;", output: "\n\tvar c = 2;", errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -264,7 +264,7 @@ ruleTester.run("no-trailing-spaces", rule, { output: "var a = 5;\n", options: [{}], errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -273,14 +273,14 @@ ruleTester.run("no-trailing-spaces", rule, { output: "var a = 5;\n b = 3;", options: [{}], errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 1, column: 11, endLine: 1, endColumn: 12 }, { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 2, column: 8, @@ -293,7 +293,7 @@ ruleTester.run("no-trailing-spaces", rule, { output: "var a = 5;\n b = 3;", options: [{}], errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 1, column: 11, @@ -306,7 +306,7 @@ ruleTester.run("no-trailing-spaces", rule, { output: "\n var c = 1;", options: [{}], errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 1, column: 1, @@ -319,7 +319,7 @@ ruleTester.run("no-trailing-spaces", rule, { output: "\n\tvar c = 2;", options: [{}], errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program" }] }, @@ -330,7 +330,7 @@ ruleTester.run("no-trailing-spaces", rule, { skipBlankLines: true }], errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 1, column: 15, // there are invalid spaces in columns 15 and 16 @@ -346,7 +346,7 @@ ruleTester.run("no-trailing-spaces", rule, { }], errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 1, column: 15, @@ -354,7 +354,7 @@ ruleTester.run("no-trailing-spaces", rule, { endColumn: 18 }, { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 2, column: 15, @@ -368,7 +368,7 @@ ruleTester.run("no-trailing-spaces", rule, { output: "let str = `${a}\n \n${b}`;\n", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 3, column: 7, @@ -382,7 +382,7 @@ ruleTester.run("no-trailing-spaces", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 4, column: 7, @@ -390,7 +390,7 @@ ruleTester.run("no-trailing-spaces", rule, { endColumn: 9 }, { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 5, column: 1, @@ -405,7 +405,7 @@ ruleTester.run("no-trailing-spaces", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 4, column: 7, @@ -423,7 +423,7 @@ ruleTester.run("no-trailing-spaces", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 3, column: 7, @@ -440,7 +440,7 @@ ruleTester.run("no-trailing-spaces", rule, { options: [{ skipBlankLines: true }], errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 2, column: 8, @@ -454,7 +454,7 @@ ruleTester.run("no-trailing-spaces", rule, { output: "\nabcdefg", errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 1, column: 1, @@ -462,7 +462,7 @@ ruleTester.run("no-trailing-spaces", rule, { endColumn: 5 }, { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 2, column: 8, @@ -479,7 +479,7 @@ ruleTester.run("no-trailing-spaces", rule, { options: [{ ignoreComments: true }], errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 1, column: 17, @@ -494,7 +494,7 @@ ruleTester.run("no-trailing-spaces", rule, { options: [{ ignoreComments: true }], errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 1, column: 6 @@ -507,7 +507,7 @@ ruleTester.run("no-trailing-spaces", rule, { options: [{ ignoreComments: true }], errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 1, column: 9 @@ -520,7 +520,7 @@ ruleTester.run("no-trailing-spaces", rule, { options: [{ ignoreComments: true }], errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 2, column: 4 @@ -533,7 +533,7 @@ ruleTester.run("no-trailing-spaces", rule, { options: [{ ignoreComments: true }], errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 2, column: 8 @@ -546,7 +546,7 @@ ruleTester.run("no-trailing-spaces", rule, { options: [{ ignoreComments: false }], errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 1, column: 26, @@ -561,7 +561,7 @@ ruleTester.run("no-trailing-spaces", rule, { options: [{ ignoreComments: false }], errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 1, column: 3, @@ -569,7 +569,7 @@ ruleTester.run("no-trailing-spaces", rule, { endColumn: 4 }, { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 2, column: 24, @@ -584,7 +584,7 @@ ruleTester.run("no-trailing-spaces", rule, { options: [{ ignoreComments: false }], errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 1, column: 20, @@ -599,7 +599,7 @@ ruleTester.run("no-trailing-spaces", rule, { options: [], errors: [ { - message: "Trailing spaces not allowed.", + messageId: "trailingSpace", type: "Program", line: 1, column: 34, diff --git a/tests/lib/rules/no-undef-init.js b/tests/lib/rules/no-undef-init.js index 509de01100e..b57b9cdc0bb 100644 --- a/tests/lib/rules/no-undef-init.js +++ b/tests/lib/rules/no-undef-init.js @@ -28,70 +28,70 @@ ruleTester.run("no-undef-init", rule, { { code: "var a = undefined;", output: null, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "var a = undefined, b = 1;", output: null, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "var a = 1, b = undefined, c = 5;", output: null, - errors: [{ message: "It's not necessary to initialize 'b' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "b" }, type: "VariableDeclarator" }] }, { code: "var [a] = undefined;", output: null, parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize '[a]' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "[a]" }, type: "VariableDeclarator" }] }, { code: "var {a} = undefined;", output: null, parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize '{a}' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "{a}" }, type: "VariableDeclarator" }] }, { code: "for(var i in [1,2,3]){var a = undefined; for(var j in [1,2,3]){}}", output: null, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = undefined;", output: "let a;", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = undefined, b = 1;", output: "let a, b = 1;", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = 1, b = undefined, c = 5;", output: "let a = 1, b, c = 5;", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize 'b' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "b" }, type: "VariableDeclarator" }] }, { code: "let [a] = undefined;", output: null, parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize '[a]' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "[a]" }, type: "VariableDeclarator" }] }, { code: "let {a} = undefined;", output: null, parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize '{a}' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "{a}" }, type: "VariableDeclarator" }] }, { code: "for(var i in [1,2,3]){let a = undefined; for(var j in [1,2,3]){}}", output: "for(var i in [1,2,3]){let a; for(var j in [1,2,3]){}}", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, // Should not autofix if it would remove comments @@ -99,55 +99,55 @@ ruleTester.run("no-undef-init", rule, { code: "let /* comment */a = undefined;", output: "let /* comment */a;", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a/**/ = undefined;", output: null, parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a /**/ = undefined;", output: null, parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a//\n= undefined;", output: null, parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = /**/undefined;", output: null, parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = //\nundefined;", output: null, parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = undefined/* comment */;", output: "let a/* comment */;", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = undefined/* comment */, b;", output: "let a/* comment */, b;", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] }, { code: "let a = undefined//comment\n, b;", output: "let a//comment\n, b;", parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "It's not necessary to initialize 'a' to undefined.", type: "VariableDeclarator" }] + errors: [{ messageId: "unnecessaryUndefinedInit", data: { name: "a" }, type: "VariableDeclarator" }] } ] }); diff --git a/tests/lib/rules/no-undefined.js b/tests/lib/rules/no-undefined.js index 3223fcbe678..8afccc52bc4 100644 --- a/tests/lib/rules/no-undefined.js +++ b/tests/lib/rules/no-undefined.js @@ -23,7 +23,7 @@ const ES6_MODULE = { ecmaVersion: 6, sourceType: "module" }; // Tests //------------------------------------------------------------------------------ -const errors = [{ message: "Unexpected use of undefined.", type: "Identifier" }]; +const errors = [{ messageId: "unexpectedUndefined", type: "Identifier" }]; const ruleTester = new RuleTester({ parserOptions: ES6_SCRIPT }); @@ -84,10 +84,10 @@ ruleTester.run("no-undefined", rule, { { code: "var undefined = true; undefined = false;", errors: [{ - message: "Unexpected use of undefined.", + messageId: "unexpectedUndefined", column: 5 }, { - message: "Unexpected use of undefined.", + messageId: "unexpectedUndefined", column: 23 }] }, diff --git a/tests/lib/rules/no-underscore-dangle.js b/tests/lib/rules/no-underscore-dangle.js index b3774dc18a6..afc9813673d 100644 --- a/tests/lib/rules/no-underscore-dangle.js +++ b/tests/lib/rules/no-underscore-dangle.js @@ -42,20 +42,20 @@ ruleTester.run("no-underscore-dangle", rule, { { code: "this.constructor._bar", options: [{ allowAfterThisConstructor: true }] } ], invalid: [ - { code: "var _foo = 1", errors: [{ message: "Unexpected dangling '_' in '_foo'.", type: "VariableDeclarator" }] }, - { code: "var foo_ = 1", errors: [{ message: "Unexpected dangling '_' in 'foo_'.", type: "VariableDeclarator" }] }, - { code: "function _foo() {}", errors: [{ message: "Unexpected dangling '_' in '_foo'.", type: "FunctionDeclaration" }] }, - { code: "function foo_() {}", errors: [{ message: "Unexpected dangling '_' in 'foo_'.", type: "FunctionDeclaration" }] }, - { code: "var __proto__ = 1;", errors: [{ message: "Unexpected dangling '_' in '__proto__'.", type: "VariableDeclarator" }] }, - { code: "foo._bar;", errors: [{ message: "Unexpected dangling '_' in '_bar'.", type: "MemberExpression" }] }, - { code: "this._prop;", errors: [{ message: "Unexpected dangling '_' in '_prop'.", type: "MemberExpression" }] }, - { code: "class foo { constructor() { super._prop; } }", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Unexpected dangling '_' in '_prop'.", type: "MemberExpression" }] }, - { code: "class foo { constructor() { this._prop; } }", options: [{ allowAfterSuper: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Unexpected dangling '_' in '_prop'.", type: "MemberExpression" }] }, - { code: "class foo { _onClick() { } }", options: [{ enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Unexpected dangling '_' in '_onClick'.", type: "MethodDefinition" }] }, - { code: "class foo { onClick_() { } }", options: [{ enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Unexpected dangling '_' in 'onClick_'.", type: "MethodDefinition" }] }, - { code: "const o = { _onClick() { } }", options: [{ enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Unexpected dangling '_' in '_onClick'.", type: "Property" }] }, - { code: "const o = { onClick_() { } }", options: [{ enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Unexpected dangling '_' in 'onClick_'.", type: "Property" }] }, - { code: "this.constructor._bar", errors: [{ message: "Unexpected dangling '_' in '_bar'.", type: "MemberExpression" }] }, - { code: "foo.constructor._bar", options: [{ allowAfterThisConstructor: true }], errors: [{ message: "Unexpected dangling '_' in '_bar'.", type: "MemberExpression" }] } + { code: "var _foo = 1", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" }, type: "VariableDeclarator" }] }, + { code: "var foo_ = 1", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "foo_" }, type: "VariableDeclarator" }] }, + { code: "function _foo() {}", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_foo" }, type: "FunctionDeclaration" }] }, + { code: "function foo_() {}", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "foo_" }, type: "FunctionDeclaration" }] }, + { code: "var __proto__ = 1;", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "__proto__" }, type: "VariableDeclarator" }] }, + { code: "foo._bar;", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "MemberExpression" }] }, + { code: "this._prop;", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_prop" }, type: "MemberExpression" }] }, + { code: "class foo { constructor() { super._prop; } }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_prop" }, type: "MemberExpression" }] }, + { code: "class foo { constructor() { this._prop; } }", options: [{ allowAfterSuper: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_prop" }, type: "MemberExpression" }] }, + { code: "class foo { _onClick() { } }", options: [{ enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_onClick" }, type: "MethodDefinition" }] }, + { code: "class foo { onClick_() { } }", options: [{ enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "onClick_" }, type: "MethodDefinition" }] }, + { code: "const o = { _onClick() { } }", options: [{ enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_onClick" }, type: "Property" }] }, + { code: "const o = { onClick_() { } }", options: [{ enforceInMethodNames: true }], parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "onClick_" }, type: "Property" }] }, + { code: "this.constructor._bar", errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "MemberExpression" }] }, + { code: "foo.constructor._bar", options: [{ allowAfterThisConstructor: true }], errors: [{ messageId: "unexpectedUnderscore", data: { identifier: "_bar" }, type: "MemberExpression" }] } ] }); diff --git a/tests/lib/rules/no-unmodified-loop-condition.js b/tests/lib/rules/no-unmodified-loop-condition.js index 269ee30dd93..70c04d039d0 100644 --- a/tests/lib/rules/no-unmodified-loop-condition.js +++ b/tests/lib/rules/no-unmodified-loop-condition.js @@ -44,16 +44,28 @@ ruleTester.run("no-unmodified-loop-condition", rule, { "var a = [1, 2, 3]; var len = a.length; for (var i = 0; i < len - 1; i++) {}" ], invalid: [ - { code: "var foo = 0; while (foo) { } foo = 1;", errors: ["'foo' is not modified in this loop."] }, - { code: "var foo = 0; while (!foo) { } foo = 1;", errors: ["'foo' is not modified in this loop."] }, - { code: "var foo = 0; while (foo != null) { } foo = 1;", errors: ["'foo' is not modified in this loop."] }, - { code: "var foo = 0, bar = 9; while (foo < bar) { } foo = 1;", errors: ["'foo' is not modified in this loop.", "'bar' is not modified in this loop."] }, - { code: "var foo = 0, bar = 0; while (foo && bar) { ++bar; } foo = 1;", errors: ["'foo' is not modified in this loop."] }, - { code: "var foo = 0, bar = 0; while (foo && bar) { ++foo; } foo = 1;", errors: ["'bar' is not modified in this loop."] }, - { code: "var a, b, c; while (a < c && b < c) { ++a; } foo = 1;", errors: ["'b' is not modified in this loop.", "'c' is not modified in this loop."] }, - { code: "var foo = 0; while (foo ? 1 : 0) { } foo = 1;", errors: ["'foo' is not modified in this loop."] }, - { code: "var foo = 0; while (foo) { update(); } function update(foo) { ++foo; }", errors: ["'foo' is not modified in this loop."] }, - { code: "var foo; do { } while (foo);", errors: ["'foo' is not modified in this loop."] }, - { code: "for (var foo = 0; foo < 10; ) { } foo = 1;", errors: ["'foo' is not modified in this loop."] } + { code: "var foo = 0; while (foo) { } foo = 1;", errors: [{ messageId: "loopConditionNotModified", data: { name: "foo" } }] }, + { code: "var foo = 0; while (!foo) { } foo = 1;", errors: [{ messageId: "loopConditionNotModified", data: { name: "foo" } }] }, + { code: "var foo = 0; while (foo != null) { } foo = 1;", errors: [{ messageId: "loopConditionNotModified", data: { name: "foo" } }] }, + { + code: "var foo = 0, bar = 9; while (foo < bar) { } foo = 1;", + errors: [ + { messageId: "loopConditionNotModified", data: { name: "foo" } }, + { messageId: "loopConditionNotModified", data: { name: "bar" } } + ] + }, + { code: "var foo = 0, bar = 0; while (foo && bar) { ++bar; } foo = 1;", errors: [{ messageId: "loopConditionNotModified", data: { name: "foo" } }] }, + { code: "var foo = 0, bar = 0; while (foo && bar) { ++foo; } foo = 1;", errors: [{ messageId: "loopConditionNotModified", data: { name: "bar" } }] }, + { + code: "var a, b, c; while (a < c && b < c) { ++a; } foo = 1;", + errors: [ + { messageId: "loopConditionNotModified", data: { name: "b" } }, + { messageId: "loopConditionNotModified", data: { name: "c" } } + ] + }, + { code: "var foo = 0; while (foo ? 1 : 0) { } foo = 1;", errors: [{ messageId: "loopConditionNotModified", data: { name: "foo" } }] }, + { code: "var foo = 0; while (foo) { update(); } function update(foo) { ++foo; }", errors: [{ messageId: "loopConditionNotModified", data: { name: "foo" } }] }, + { code: "var foo; do { } while (foo);", errors: [{ messageId: "loopConditionNotModified", data: { name: "foo" } }] }, + { code: "for (var foo = 0; foo < 10; ) { } foo = 1;", errors: [{ messageId: "loopConditionNotModified", data: { name: "foo" } }] } ] }); diff --git a/tests/lib/rules/no-unneeded-ternary.js b/tests/lib/rules/no-unneeded-ternary.js index a297b211ba7..25aab8a0cd1 100644 --- a/tests/lib/rules/no-unneeded-ternary.js +++ b/tests/lib/rules/no-unneeded-ternary.js @@ -51,7 +51,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = x === 2 ? true : false;", output: "var a = x === 2;", errors: [{ - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression", line: 1, column: 19 @@ -61,7 +61,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = x >= 2 ? true : false;", output: "var a = x >= 2;", errors: [{ - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression", line: 1, column: 18 @@ -71,7 +71,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = x ? true : false;", output: "var a = !!x;", errors: [{ - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression", line: 1, column: 13 @@ -81,7 +81,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = x === 1 ? false : true;", output: "var a = x !== 1;", errors: [{ - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression", line: 1, column: 19 @@ -91,7 +91,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = x != 1 ? false : true;", output: "var a = x == 1;", errors: [{ - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression", line: 1, column: 18 @@ -101,7 +101,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = foo() ? false : true;", output: "var a = !foo();", errors: [{ - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression", line: 1, column: 17 @@ -111,7 +111,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = !foo() ? false : true;", output: "var a = !!foo();", errors: [{ - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression", line: 1, column: 18 @@ -121,7 +121,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = foo + bar ? false : true;", output: "var a = !(foo + bar);", errors: [{ - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression", line: 1, column: 21 @@ -131,7 +131,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = x instanceof foo ? false : true;", output: "var a = !(x instanceof foo);", errors: [{ - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression", line: 1, column: 28 @@ -141,7 +141,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = foo ? false : false;", output: "var a = false;", errors: [{ - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression", line: 1, column: 15 @@ -151,7 +151,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = foo() ? false : false;", output: null, errors: [{ - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression", line: 1, column: 17 @@ -161,7 +161,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = x instanceof foo ? true : false;", output: "var a = x instanceof foo;", errors: [{ - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression", line: 1, column: 28 @@ -171,7 +171,7 @@ ruleTester.run("no-unneeded-ternary", rule, { code: "var a = !foo ? true : false;", output: "var a = !foo;", errors: [{ - message: "Unnecessary use of boolean literals in conditional expression.", + messageId: "unnecessaryConditionalExpression", type: "ConditionalExpression", line: 1, column: 16 @@ -190,7 +190,7 @@ ruleTester.run("no-unneeded-ternary", rule, { `, options: [{ defaultAssignment: false }], errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 4, column: 38 @@ -201,7 +201,7 @@ ruleTester.run("no-unneeded-ternary", rule, { output: "foo || (bar ? baz : qux)", options: [{ defaultAssignment: false }], errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 7 @@ -213,7 +213,7 @@ ruleTester.run("no-unneeded-ternary", rule, { options: [{ defaultAssignment: false }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 24 @@ -224,7 +224,7 @@ ruleTester.run("no-unneeded-ternary", rule, { output: "var a = foo || 'No';", options: [{ defaultAssignment: false }], errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 15 @@ -235,7 +235,7 @@ ruleTester.run("no-unneeded-ternary", rule, { output: "var a = ((foo)) || ((((((((((((((bar))))))))))))));", options: [{ defaultAssignment: false }], errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 24 @@ -247,7 +247,7 @@ ruleTester.run("no-unneeded-ternary", rule, { options: [{ defaultAssignment: false }], parserOptions: { ecmaVersion: 2015 }, errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 13 @@ -259,7 +259,7 @@ ruleTester.run("no-unneeded-ternary", rule, { options: [{ defaultAssignment: false }], parserOptions: { ecmaVersion: 2015 }, errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 13 @@ -271,7 +271,7 @@ ruleTester.run("no-unneeded-ternary", rule, { options: [{ defaultAssignment: false }], parserOptions: { ecmaVersion: 2015 }, errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 13 @@ -283,7 +283,7 @@ ruleTester.run("no-unneeded-ternary", rule, { options: [{ defaultAssignment: false }], parserOptions: { ecmaVersion: 2015 }, errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 13 @@ -295,7 +295,7 @@ ruleTester.run("no-unneeded-ternary", rule, { options: [{ defaultAssignment: false }], parserOptions: { ecmaVersion: 2015 }, errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 13 @@ -307,7 +307,7 @@ ruleTester.run("no-unneeded-ternary", rule, { options: [{ defaultAssignment: false }], parserOptions: { ecmaVersion: 2015 }, errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 13 @@ -319,7 +319,7 @@ ruleTester.run("no-unneeded-ternary", rule, { options: [{ defaultAssignment: false }], parserOptions: { ecmaVersion: 2015 }, errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 13 @@ -330,7 +330,7 @@ ruleTester.run("no-unneeded-ternary", rule, { output: "f(x || 1);", options: [{ defaultAssignment: false }], errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 7 @@ -341,7 +341,7 @@ ruleTester.run("no-unneeded-ternary", rule, { output: "x || 1;", options: [{ defaultAssignment: false }], errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 5 @@ -352,7 +352,7 @@ ruleTester.run("no-unneeded-ternary", rule, { output: "var a = foo || bar;", options: [{ defaultAssignment: false }], errors: [{ - message: "Unnecessary use of conditional expression for default assignment.", + messageId: "unnecessaryConditionalAssignment", type: "ConditionalExpression", line: 1, column: 15 diff --git a/tests/lib/rules/no-unreachable.js b/tests/lib/rules/no-unreachable.js index 2c9b60fb882..1e3f7116126 100644 --- a/tests/lib/rules/no-unreachable.js +++ b/tests/lib/rules/no-unreachable.js @@ -50,32 +50,32 @@ ruleTester.run("no-unreachable", rule, { "A: { break A; } foo()" ], invalid: [ - { code: "function foo() { return x; var x = 1; }", errors: [{ message: "Unreachable code.", type: "VariableDeclaration" }] }, - { code: "function foo() { return x; var x, y = 1; }", errors: [{ message: "Unreachable code.", type: "VariableDeclaration" }] }, - { code: "while (true) { continue; var x = 1; }", errors: [{ message: "Unreachable code.", type: "VariableDeclaration" }] }, - { code: "function foo() { return; x = 1; }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "function foo() { throw error; x = 1; }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "while (true) { break; x = 1; }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "while (true) { continue; x = 1; }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "function foo() { switch (foo) { case 1: return; x = 1; } }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "function foo() { switch (foo) { case 1: throw e; x = 1; } }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "while (true) { switch (foo) { case 1: break; x = 1; } }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "while (true) { switch (foo) { case 1: continue; x = 1; } }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "var x = 1; throw 'uh oh'; var y = 2;", errors: [{ message: "Unreachable code.", type: "VariableDeclaration" }] }, - { code: "function foo() { var x = 1; if (x) { return; } else { throw e; } x = 2; }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "function foo() { var x = 1; if (x) return; else throw -1; x = 2; }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "function foo() { var x = 1; try { return; } finally {} x = 2; }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "function foo() { var x = 1; try { } finally { return; } x = 2; }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "function foo() { var x = 1; do { return; } while (x); x = 2; }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "function foo() { var x = 1; while (x) { if (x) break; else continue; x = 2; } }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "function foo() { var x = 1; for (;;) { if (x) continue; } x = 2; }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, - { code: "function foo() { var x = 1; while (true) { } x = 2; }", errors: [{ message: "Unreachable code.", type: "ExpressionStatement" }] }, + { code: "function foo() { return x; var x = 1; }", errors: [{ messageId: "unreachableCode", type: "VariableDeclaration" }] }, + { code: "function foo() { return x; var x, y = 1; }", errors: [{ messageId: "unreachableCode", type: "VariableDeclaration" }] }, + { code: "while (true) { continue; var x = 1; }", errors: [{ messageId: "unreachableCode", type: "VariableDeclaration" }] }, + { code: "function foo() { return; x = 1; }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "function foo() { throw error; x = 1; }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "while (true) { break; x = 1; }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "while (true) { continue; x = 1; }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "function foo() { switch (foo) { case 1: return; x = 1; } }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "function foo() { switch (foo) { case 1: throw e; x = 1; } }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "while (true) { switch (foo) { case 1: break; x = 1; } }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "while (true) { switch (foo) { case 1: continue; x = 1; } }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "var x = 1; throw 'uh oh'; var y = 2;", errors: [{ messageId: "unreachableCode", type: "VariableDeclaration" }] }, + { code: "function foo() { var x = 1; if (x) { return; } else { throw e; } x = 2; }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "function foo() { var x = 1; if (x) return; else throw -1; x = 2; }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "function foo() { var x = 1; try { return; } finally {} x = 2; }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "function foo() { var x = 1; try { } finally { return; } x = 2; }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "function foo() { var x = 1; do { return; } while (x); x = 2; }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "function foo() { var x = 1; while (x) { if (x) break; else continue; x = 2; } }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "function foo() { var x = 1; for (;;) { if (x) continue; } x = 2; }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, + { code: "function foo() { var x = 1; while (true) { } x = 2; }", errors: [{ messageId: "unreachableCode", type: "ExpressionStatement" }] }, { code: "const arrow_direction = arrow => { switch (arrow) { default: throw new Error(); }; g() }", parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Unreachable code.", + messageId: "unreachableCode", type: "ExpressionStatement", line: 1, column: 86, @@ -100,7 +100,7 @@ ruleTester.run("no-unreachable", rule, { `, errors: [ { - message: "Unreachable code.", + messageId: "unreachableCode", type: "ExpressionStatement", line: 5, column: 21, @@ -125,7 +125,7 @@ ruleTester.run("no-unreachable", rule, { `, errors: [ { - message: "Unreachable code.", + messageId: "unreachableCode", type: "ExpressionStatement", line: 5, column: 21, @@ -149,7 +149,7 @@ ruleTester.run("no-unreachable", rule, { `, errors: [ { - message: "Unreachable code.", + messageId: "unreachableCode", type: "ExpressionStatement", line: 5, column: 25, @@ -157,7 +157,7 @@ ruleTester.run("no-unreachable", rule, { endColumn: 29 }, { - message: "Unreachable code.", + messageId: "unreachableCode", type: "ExpressionStatement", line: 9, column: 25, @@ -182,7 +182,7 @@ ruleTester.run("no-unreachable", rule, { `, errors: [ { - message: "Unreachable code.", + messageId: "unreachableCode", type: "ExpressionStatement", line: 5, column: 25, @@ -190,7 +190,7 @@ ruleTester.run("no-unreachable", rule, { endColumn: 29 }, { - message: "Unreachable code.", + messageId: "unreachableCode", type: "ExpressionStatement", line: 9, column: 25, @@ -198,7 +198,7 @@ ruleTester.run("no-unreachable", rule, { endColumn: 29 }, { - message: "Unreachable code.", + messageId: "unreachableCode", type: "ExpressionStatement", line: 11, column: 21, diff --git a/tests/lib/rules/no-unsafe-finally.js b/tests/lib/rules/no-unsafe-finally.js index 2151f9848c6..814211882b9 100644 --- a/tests/lib/rules/no-unsafe-finally.js +++ b/tests/lib/rules/no-unsafe-finally.js @@ -46,66 +46,66 @@ ruleTester.run("no-unsafe-finally", rule, { invalid: [ { code: "var foo = function() { \n try { \n return 1; \n } catch(err) { \n return 2; \n } finally { \n return 3; \n } \n }", - errors: [{ message: "Unsafe usage of ReturnStatement.", type: "ReturnStatement", line: 7, column: 2 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "ReturnStatement" }, type: "ReturnStatement", line: 7, column: 2 }] }, { code: "var foo = function() { try { return 1 } catch(err) { return 2 } finally { if(true) { return 3 } else { return 2 } } }", errors: [ - { message: "Unsafe usage of ReturnStatement.", type: "ReturnStatement", line: 1, column: 86 }, - { message: "Unsafe usage of ReturnStatement.", type: "ReturnStatement", line: 1, column: 104 } + { messageId: "unsafeUsage", data: { nodeType: "ReturnStatement" }, type: "ReturnStatement", line: 1, column: 86 }, + { messageId: "unsafeUsage", data: { nodeType: "ReturnStatement" }, type: "ReturnStatement", line: 1, column: 104 } ] }, { code: "var foo = function() { try { return 1 } catch(err) { return 2 } finally { return 3 } }", - errors: [{ message: "Unsafe usage of ReturnStatement.", type: "ReturnStatement", line: 1, column: 75 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "ReturnStatement" }, type: "ReturnStatement", line: 1, column: 75 }] }, { code: "var foo = function() { try { return 1 } catch(err) { return 2 } finally { return function(x) { return y } } }", - errors: [{ message: "Unsafe usage of ReturnStatement.", type: "ReturnStatement", line: 1, column: 75 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "ReturnStatement" }, type: "ReturnStatement", line: 1, column: 75 }] }, { code: "var foo = function() { try { return 1 } catch(err) { return 2 } finally { return { x: function(c) { return c } } } }", - errors: [{ message: "Unsafe usage of ReturnStatement.", type: "ReturnStatement", line: 1, column: 75 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "ReturnStatement" }, type: "ReturnStatement", line: 1, column: 75 }] }, { code: "var foo = function() { try { return 1 } catch(err) { return 2 } finally { throw new Error() } }", - errors: [{ message: "Unsafe usage of ThrowStatement.", type: "ThrowStatement", line: 1, column: 75 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "ThrowStatement" }, type: "ThrowStatement", line: 1, column: 75 }] }, { code: "var foo = function() { try { foo(); } finally { try { bar(); } finally { return; } } };", - errors: [{ message: "Unsafe usage of ReturnStatement.", type: "ReturnStatement", line: 1, column: 74 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "ReturnStatement" }, type: "ReturnStatement", line: 1, column: 74 }] }, { code: "var foo = function() { label: try { return 0; } finally { break label; } return 1; }", - errors: [{ message: "Unsafe usage of BreakStatement.", type: "BreakStatement", line: 1, column: 59 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "BreakStatement" }, type: "BreakStatement", line: 1, column: 59 }] }, { code: "var foo = function() { \n a: try { \n return 1; \n } catch(err) { \n return 2; \n } finally { \n break a; \n } \n }", - errors: [{ message: "Unsafe usage of BreakStatement.", type: "BreakStatement", line: 7, column: 2 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "BreakStatement" }, type: "BreakStatement", line: 7, column: 2 }] }, { code: "var foo = function() { while (true) try {} finally { break; } }", - errors: [{ message: "Unsafe usage of BreakStatement.", type: "BreakStatement", line: 1, column: 54 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "BreakStatement" }, type: "BreakStatement", line: 1, column: 54 }] }, { code: "var foo = function() { while (true) try {} finally { continue; } }", - errors: [{ message: "Unsafe usage of ContinueStatement.", type: "ContinueStatement", line: 1, column: 54 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "ContinueStatement" }, type: "ContinueStatement", line: 1, column: 54 }] }, { code: "var foo = function() { switch (true) { case true: try {} finally { break; } } }", - errors: [{ message: "Unsafe usage of BreakStatement.", type: "BreakStatement", line: 1, column: 68 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "BreakStatement" }, type: "BreakStatement", line: 1, column: 68 }] }, { code: "var foo = function() { a: while (true) try {} finally { switch (true) { case true: break a; } } }", - errors: [{ message: "Unsafe usage of BreakStatement.", type: "BreakStatement", line: 1, column: 84 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "BreakStatement" }, type: "BreakStatement", line: 1, column: 84 }] }, { code: "var foo = function() { a: while (true) try {} finally { switch (true) { case true: continue; } } }", - errors: [{ message: "Unsafe usage of ContinueStatement.", type: "ContinueStatement", line: 1, column: 84 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "ContinueStatement" }, type: "ContinueStatement", line: 1, column: 84 }] }, { code: "var foo = function() { a: switch (true) { case true: try {} finally { switch (true) { case true: break a; } } } }", - errors: [{ message: "Unsafe usage of BreakStatement.", type: "BreakStatement", line: 1, column: 98 }] + errors: [{ messageId: "unsafeUsage", data: { nodeType: "BreakStatement" }, type: "BreakStatement", line: 1, column: 98 }] } ] }); diff --git a/tests/lib/rules/no-unsafe-negation.js b/tests/lib/rules/no-unsafe-negation.js index 23e6cd5ceb5..bc7a23e2388 100644 --- a/tests/lib/rules/no-unsafe-negation.js +++ b/tests/lib/rules/no-unsafe-negation.js @@ -63,7 +63,8 @@ ruleTester.run("no-unsafe-negation", rule, { { code: "!a in b", errors: [{ - message: "Unexpected negating the left operand of 'in' operator.", + messageId: "unexpected", + data: { operator: "in" }, suggestions: [ { desc: "Negate 'in' expression instead of its left operand. This changes the current behavior.", diff --git a/tests/lib/rules/no-unused-expressions.js b/tests/lib/rules/no-unused-expressions.js index 51de4916791..34051daa7b5 100644 --- a/tests/lib/rules/no-unused-expressions.js +++ b/tests/lib/rules/no-unused-expressions.js @@ -73,56 +73,56 @@ ruleTester.run("no-unused-expressions", rule, { } ], invalid: [ - { code: "0", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "f(), 0", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "{0}", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "[]", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a && b();", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a() || false", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a || (b = c)", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a ? b() || (c = d) : e", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, + { code: "0", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "a", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "f(), 0", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "{0}", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "[]", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "a && b();", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "a() || false", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "a || (b = c)", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "a ? b() || (c = d) : e", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "`untagged template literal`", parserOptions: { ecmaVersion: 6 }, - errors: ["Expected an assignment or function call and instead saw an expression."] + errors: [{ messageId: "unusedExpression" }] }, { code: "tag`tagged template literal`", parserOptions: { ecmaVersion: 6 }, - errors: ["Expected an assignment or function call and instead saw an expression."] + errors: [{ messageId: "unusedExpression" }] }, - { code: "a && b()", options: [{ allowTernary: true }], errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a ? b() : c()", options: [{ allowShortCircuit: true }], errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a || b", options: [{ allowShortCircuit: true }], errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a() && b", options: [{ allowShortCircuit: true }], errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a ? b : 0", options: [{ allowTernary: true }], errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "a ? b : c()", options: [{ allowTernary: true }], errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "foo.bar;", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "!a", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "+a", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "\"directive one\"; f(); \"directive two\";", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "function foo() {\"directive one\"; f(); \"directive two\"; }", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "if (0) { \"not a directive\"; f(); }", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "function foo() { var foo = true; \"use strict\"; }", errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, - { code: "var foo = () => { var foo = true; \"use strict\"; }", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "Expected an assignment or function call and instead saw an expression.", type: "ExpressionStatement" }] }, + { code: "a && b()", options: [{ allowTernary: true }], errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "a ? b() : c()", options: [{ allowShortCircuit: true }], errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "a || b", options: [{ allowShortCircuit: true }], errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "a() && b", options: [{ allowShortCircuit: true }], errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "a ? b : 0", options: [{ allowTernary: true }], errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "a ? b : c()", options: [{ allowTernary: true }], errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "foo.bar;", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "!a", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "+a", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "\"directive one\"; f(); \"directive two\";", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "function foo() {\"directive one\"; f(); \"directive two\"; }", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "if (0) { \"not a directive\"; f(); }", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "function foo() { var foo = true; \"use strict\"; }", errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, + { code: "var foo = () => { var foo = true; \"use strict\"; }", parserOptions: { ecmaVersion: 6 }, errors: [{ messageId: "unusedExpression", type: "ExpressionStatement" }] }, { code: "`untagged template literal`", options: [{ allowTaggedTemplates: true }], parserOptions: { ecmaVersion: 6 }, - errors: ["Expected an assignment or function call and instead saw an expression."] + errors: [{ messageId: "unusedExpression" }] }, { code: "`untagged template literal`", options: [{ allowTaggedTemplates: false }], parserOptions: { ecmaVersion: 6 }, - errors: ["Expected an assignment or function call and instead saw an expression."] + errors: [{ messageId: "unusedExpression" }] }, { code: "tag`tagged template literal`", options: [{ allowTaggedTemplates: false }], parserOptions: { ecmaVersion: 6 }, - errors: ["Expected an assignment or function call and instead saw an expression."] + errors: [{ messageId: "unusedExpression" }] } ] }); diff --git a/tests/lib/rules/no-unused-vars.js b/tests/lib/rules/no-unused-vars.js index dc69a1bee0b..b25a3a5960c 100644 --- a/tests/lib/rules/no-unused-vars.js +++ b/tests/lib/rules/no-unused-vars.js @@ -37,21 +37,39 @@ ruleTester.defineRule("use-every-a", context => { /** * Returns an expected error for defined-but-not-used variables. * @param {string} varName The name of the variable + * @param {string} [additional] The additional text for the message data * @param {string} [type] The node type (defaults to "Identifier") * @returns {Object} An expected error object */ -function definedError(varName, type) { - return { message: `'${varName}' is defined but never used.`, type: type || "Identifier" }; +function definedError(varName, additional = "", type = "Identifier") { + return { + messageId: "unusedVar", + data: { + varName, + action: "defined", + additional + }, + type + }; } /** * Returns an expected error for assigned-but-not-used variables. * @param {string} varName The name of the variable + * @param {string} [additional] The additional text for the message data * @param {string} [type] The node type (defaults to "Identifier") * @returns {Object} An expected error object */ -function assignedError(varName, type) { - return { message: `'${varName}' is assigned a value but never used.`, type: type || "Identifier" }; +function assignedError(varName, additional = "", type = "Identifier") { + return { + messageId: "unusedVar", + data: { + varName, + action: "assigned a value", + additional + }, + type + }; } ruleTester.run("no-unused-vars", rule, { @@ -294,7 +312,7 @@ ruleTester.run("no-unused-vars", rule, { { code: "var a=10", errors: [assignedError("a")] }, { code: "function f() { var a = 1; return function(){ f(a *= 2); }; }", errors: [definedError("f")] }, { code: "function f() { var a = 1; return function(){ f(++a); }; }", errors: [definedError("f")] }, - { code: "/*global a */", errors: [definedError("a", "Program")] }, + { code: "/*global a */", errors: [definedError("a", "", "Program")] }, { code: "function foo(first, second) {\ndoStuff(function() {\nconsole.log(second);});};", errors: [definedError("foo")] }, { code: "var a=10;", options: ["all"], errors: [assignedError("a")] }, { code: "var a=10; a=20;", options: ["all"], errors: [assignedError("a")] }, @@ -304,7 +322,15 @@ ruleTester.run("no-unused-vars", rule, { { code: "var a=10, b=0, c=null; setTimeout(function() { var b=2; var c=2; alert(a+b+c); }, 0);", options: ["all"], errors: [assignedError("b"), assignedError("c")] }, { code: "function f(){var a=[];return a.map(function(){});}", options: ["all"], errors: [definedError("f")] }, { code: "function f(){var a=[];return a.map(function g(){});}", options: ["all"], errors: [definedError("f")] }, - { code: "function foo() {function foo(x) {\nreturn x; }; return function() {return foo; }; }", errors: [{ message: "'foo' is defined but never used.", line: 1, type: "Identifier" }] }, + { + code: "function foo() {function foo(x) {\nreturn x; }; return function() {return foo; }; }", + errors: [{ + messageId: "unusedVar", + data: { varName: "foo", action: "defined", additional: "" }, + line: 1, + type: "Identifier" + }] + }, { code: "function f(){var x;function a(){x=42;}function b(){alert(x);}}", options: ["all"], errors: 3 }, { code: "function f(a) {}; f();", options: ["all"], errors: [definedError("a")] }, { code: "function a(x, y, z){ return y; }; a();", options: ["all"], errors: [definedError("z")] }, @@ -317,7 +343,7 @@ ruleTester.run("no-unused-vars", rule, { { code: "(function(foo, baz, bar) { return baz; })();", options: [{ vars: "all", args: "all" }], errors: [definedError("foo"), definedError("bar")] }, { code: "(function z(foo) { var bar = 33; })();", options: [{ vars: "all", args: "all" }], errors: [definedError("foo"), assignedError("bar")] }, { code: "(function z(foo) { z(); })();", options: [{}], errors: [definedError("foo")] }, - { code: "function f() { var a = 1; return function(){ f(a = 2); }; }", options: [{}], errors: [definedError("f"), { message: "'a' is assigned a value but never used." }] }, + { code: "function f() { var a = 1; return function(){ f(a = 2); }; }", options: [{}], errors: [definedError("f"), assignedError("a")] }, { code: "import x from \"y\";", parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("x")] }, { code: "export function fn2({ x, y }) {\n console.log(x); \n};", parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("y")] }, { code: "export function fn2( x, y ) {\n console.log(x); \n};", parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [definedError("y")] }, @@ -330,53 +356,179 @@ ruleTester.run("no-unused-vars", rule, { { code: "var _a; var b;", options: [{ vars: "all", varsIgnorePattern: "^_" }], - errors: [{ message: "'b' is defined but never used. Allowed unused vars must match /^_/u.", line: 1, column: 13 }] + errors: [{ + line: 1, + column: 13, + messageId: "unusedVar", + data: { + varName: "b", + action: "defined", + additional: ". Allowed unused vars must match /^_/u" + } + }] }, { code: "var a; function foo() { var _b; var c_; } foo();", options: [{ vars: "local", varsIgnorePattern: "^_" }], - errors: [{ message: "'c_' is defined but never used. Allowed unused vars must match /^_/u.", line: 1, column: 37 }] + errors: [{ + line: 1, + column: 37, + messageId: "unusedVar", + data: { + varName: "c_", + action: "defined", + additional: ". Allowed unused vars must match /^_/u" + } + }] }, { code: "function foo(a, _b) { } foo();", options: [{ args: "all", argsIgnorePattern: "^_" }], - errors: [{ message: "'a' is defined but never used. Allowed unused args must match /^_/u.", line: 1, column: 14 }] + errors: [{ + line: 1, + column: 14, + messageId: "unusedVar", + data: { + varName: "a", + action: "defined", + additional: ". Allowed unused args must match /^_/u" + } + }] }, { code: "function foo(a, _b, c) { return a; } foo();", options: [{ args: "after-used", argsIgnorePattern: "^_" }], - errors: [{ message: "'c' is defined but never used. Allowed unused args must match /^_/u.", line: 1, column: 21 }] + errors: [{ + line: 1, + column: 21, + messageId: "unusedVar", + data: { + varName: "c", + action: "defined", + additional: ". Allowed unused args must match /^_/u" + } + }] }, { code: "function foo(_a) { } foo();", options: [{ args: "all", argsIgnorePattern: "[iI]gnored" }], - errors: [{ message: "'_a' is defined but never used. Allowed unused args must match /[iI]gnored/u.", line: 1, column: 14 }] + errors: [{ + line: 1, + column: 14, + messageId: "unusedVar", + data: { + varName: "_a", + action: "defined", + additional: ". Allowed unused args must match /[iI]gnored/u" + } + }] }, { code: "var [ firstItemIgnored, secondItem ] = items;", options: [{ vars: "all", varsIgnorePattern: "[iI]gnored" }], parserOptions: { ecmaVersion: 6 }, - errors: [{ message: "'secondItem' is assigned a value but never used. Allowed unused vars must match /[iI]gnored/u.", line: 1, column: 25 }] + errors: [{ + line: 1, + column: 25, + messageId: "unusedVar", + data: { + varName: "secondItem", + action: "assigned a value", + additional: ". Allowed unused vars must match /[iI]gnored/u" + } + }] }, // for-in loops (see #2342) - { code: "(function(obj) { var name; for ( name in obj ) { i(); return; } })({});", errors: [{ message: "'name' is assigned a value but never used.", line: 1, column: 22 }] }, - { code: "(function(obj) { var name; for ( name in obj ) { } })({});", errors: [{ message: "'name' is assigned a value but never used.", line: 1, column: 22 }] }, - { code: "(function(obj) { for ( var name in obj ) { } })({});", errors: [{ message: "'name' is assigned a value but never used.", line: 1, column: 28 }] }, + { + code: "(function(obj) { var name; for ( name in obj ) { i(); return; } })({});", + errors: [{ + line: 1, + column: 22, + messageId: "unusedVar", + data: { + varName: "name", + action: "assigned a value", + additional: "" + } + }] + }, + { + code: "(function(obj) { var name; for ( name in obj ) { } })({});", + errors: [{ + line: 1, + column: 22, + messageId: "unusedVar", + data: { + varName: "name", + action: "assigned a value", + additional: "" + } + }] + }, + { + code: "(function(obj) { for ( var name in obj ) { } })({});", + errors: [{ + line: 1, + column: 28, + messageId: "unusedVar", + data: { + varName: "name", + action: "assigned a value", + additional: "" + } + }] + }, // https://github.com/eslint/eslint/issues/3617 { code: "\n/* global foobar, foo, bar */\nfoobar;", errors: [ - { line: 2, column: 19, message: "'foo' is defined but never used." }, - { line: 2, column: 24, message: "'bar' is defined but never used." } + { + line: 2, + column: 19, + messageId: "unusedVar", + data: { + varName: "foo", + action: "defined", + additional: "" + } + }, + { + line: 2, + column: 24, + messageId: "unusedVar", + data: { + varName: "bar", + action: "defined", + additional: "" + } + } ] }, { code: "\n/* global foobar,\n foo,\n bar\n */\nfoobar;", errors: [ - { line: 3, column: 4, message: "'foo' is defined but never used." }, - { line: 4, column: 4, message: "'bar' is defined but never used." } + { + line: 3, + column: 4, + messageId: "unusedVar", + data: { + varName: "foo", + action: "defined", + additional: "" + } + }, + { + line: 4, + column: 4, + messageId: "unusedVar", + data: { + varName: "bar", + action: "defined", + additional: "" + } + } ] }, @@ -385,26 +537,53 @@ ruleTester.run("no-unused-vars", rule, { code: "const data = { type: 'coords', x: 1, y: 2 };\nconst { type, ...coords } = data;\n console.log(coords);", parserOptions: { ecmaVersion: 2018 }, errors: [ - { line: 2, column: 9, message: "'type' is assigned a value but never used." } + { + line: 2, + column: 9, + messageId: "unusedVar", + data: { + varName: "type", + action: "assigned a value", + additional: "" + } + } ] }, // Unused rest property with ignoreRestSiblings { - code: "const data = { type: 'coords', x: 1, y: 2 };\nconst { type, ...coords } = data;\n console.log(type)", + code: "const data = { type: 'coords', x: 2, y: 2 };\nconst { type, ...coords } = data;\n console.log(type)", options: [{ ignoreRestSiblings: true }], parserOptions: { ecmaVersion: 2018 }, errors: [ - { line: 2, column: 18, message: "'coords' is assigned a value but never used." } + { + line: 2, + column: 18, + messageId: "unusedVar", + data: { + varName: "coords", + action: "assigned a value", + additional: "" + } + } ] }, // Unused rest property without ignoreRestSiblings { - code: "const data = { type: 'coords', x: 1, y: 2 };\nconst { type, ...coords } = data;\n console.log(type)", + code: "const data = { type: 'coords', x: 3, y: 2 };\nconst { type, ...coords } = data;\n console.log(type)", parserOptions: { ecmaVersion: 2018 }, errors: [ - { line: 2, column: 18, message: "'coords' is assigned a value but never used." } + { + line: 2, + column: 18, + messageId: "unusedVar", + data: { + varName: "coords", + action: "assigned a value", + additional: "" + } + } ] }, @@ -413,7 +592,16 @@ ruleTester.run("no-unused-vars", rule, { code: "const data = { vars: ['x','y'], x: 1, y: 2 };\nconst { vars: [x], ...coords } = data;\n console.log(coords)", parserOptions: { ecmaVersion: 2018 }, errors: [ - { line: 2, column: 16, message: "'x' is assigned a value but never used." } + { + line: 2, + column: 16, + messageId: "unusedVar", + data: { + varName: "x", + action: "assigned a value", + additional: "" + } + } ] }, @@ -422,7 +610,16 @@ ruleTester.run("no-unused-vars", rule, { code: "const data = { defaults: { x: 0 }, x: 1, y: 2 };\nconst { defaults: { x }, ...coords } = data;\n console.log(coords)", parserOptions: { ecmaVersion: 2018 }, errors: [ - { line: 2, column: 21, message: "'x' is assigned a value but never used." } + { + line: 2, + column: 21, + messageId: "unusedVar", + data: { + varName: "x", + action: "assigned a value", + additional: "" + } + } ] }, @@ -431,38 +628,83 @@ ruleTester.run("no-unused-vars", rule, { code: "(({a, ...rest}) => {})", options: [{ args: "all", ignoreRestSiblings: true }], parserOptions: { ecmaVersion: 2018 }, - errors: ["'rest' is defined but never used."] + errors: [definedError("rest")] }, // https://github.com/eslint/eslint/issues/3714 { code: "/* global a$fooz,$foo */\na$fooz;", errors: [ - { line: 1, column: 18, message: "'$foo' is defined but never used." } + { + line: 1, + column: 18, + messageId: "unusedVar", + data: { + varName: "$foo", + action: "defined", + additional: "" + } + } ] }, { code: "/* globals a$fooz, $ */\na$fooz;", errors: [ - { line: 1, column: 20, message: "'$' is defined but never used." } + { + line: 1, + column: 20, + messageId: "unusedVar", + data: { + varName: "$", + action: "defined", + additional: "" + } + } ] }, { code: "/*globals $foo*/", errors: [ - { line: 1, column: 11, message: "'$foo' is defined but never used." } + { + line: 1, + column: 11, + messageId: "unusedVar", + data: { + varName: "$foo", + action: "defined", + additional: "" + } + } ] }, { code: "/* global global*/", errors: [ - { line: 1, column: 11, message: "'global' is defined but never used." } + { + line: 1, + column: 11, + messageId: "unusedVar", + data: { + varName: "global", + action: "defined", + additional: "" + } + } ] }, { code: "/*global foo:true*/", errors: [ - { line: 1, column: 10, message: "'foo' is defined but never used." } + { + line: 1, + column: 10, + messageId: "unusedVar", + data: { + varName: "foo", + action: "defined", + additional: "" + } + } ] }, @@ -470,7 +712,16 @@ ruleTester.run("no-unused-vars", rule, { { code: "/*global 変数, 数*/\n変数;", errors: [ - { line: 1, column: 14, message: "'数' is defined but never used." } + { + line: 1, + column: 14, + messageId: "unusedVar", + data: { + varName: "数", + action: "defined", + additional: "" + } + } ] }, @@ -479,7 +730,16 @@ ruleTester.run("no-unused-vars", rule, { code: "/*global 𠮷𩸽, 𠮷*/\n\\u{20BB7}\\u{29E3D};", env: { es6: true }, errors: [ - { line: 1, column: 16, message: "'𠮷' is defined but never used." } + { + line: 1, + column: 16, + messageId: "unusedVar", + data: { + varName: "𠮷", + action: "defined", + additional: "" + } + } ] }, @@ -487,51 +747,51 @@ ruleTester.run("no-unused-vars", rule, { { code: "export default function(a) {}", parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ message: "'a' is defined but never used." }] + errors: [definedError("a")] }, { code: "export default function(a, b) { console.log(a); }", parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ message: "'b' is defined but never used." }] + errors: [definedError("b")] }, { code: "export default (function(a) {});", parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ message: "'a' is defined but never used." }] + errors: [definedError("a")] }, { code: "export default (function(a, b) { console.log(a); });", parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ message: "'b' is defined but never used." }] + errors: [definedError("b")] }, { code: "export default (a) => {};", parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ message: "'a' is defined but never used." }] + errors: [definedError("a")] }, { code: "export default (a, b) => { console.log(a); };", parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [{ message: "'b' is defined but never used." }] + errors: [definedError("b")] }, // caughtErrors { code: "try{}catch(err){};", options: [{ caughtErrors: "all" }], - errors: [{ message: "'err' is defined but never used." }] + errors: [definedError("err")] }, { code: "try{}catch(err){};", options: [{ caughtErrors: "all", caughtErrorsIgnorePattern: "^ignore" }], - errors: [{ message: "'err' is defined but never used. Allowed unused args must match /^ignore/u." }] + errors: [definedError("err", ". Allowed unused args must match /^ignore/u")] }, // multiple try catch with one success { code: "try{}catch(ignoreErr){}try{}catch(err){};", options: [{ caughtErrors: "all", caughtErrorsIgnorePattern: "^ignore" }], - errors: [{ message: "'err' is defined but never used. Allowed unused args must match /^ignore/u." }] + errors: [definedError("err", ". Allowed unused args must match /^ignore/u")] }, // multiple try catch both fail @@ -539,8 +799,8 @@ ruleTester.run("no-unused-vars", rule, { code: "try{}catch(error){}try{}catch(err){};", options: [{ caughtErrors: "all", caughtErrorsIgnorePattern: "^ignore" }], errors: [ - { message: "'error' is defined but never used. Allowed unused args must match /^ignore/u." }, - { message: "'err' is defined but never used. Allowed unused args must match /^ignore/u." } + definedError("error", ". Allowed unused args must match /^ignore/u"), + definedError("err", ". Allowed unused args must match /^ignore/u") ] }, @@ -548,7 +808,7 @@ ruleTester.run("no-unused-vars", rule, { { code: "try{}catch(err){};", options: [{ vars: "all", args: "all", caughtErrors: "all" }], - errors: [{ message: "'err' is defined but never used." }] + errors: [definedError("err")] }, // no conflict in ignore patterns @@ -562,36 +822,36 @@ ruleTester.run("no-unused-vars", rule, { argsIgnorePattern: "^er" } ], - errors: [{ message: "'err' is defined but never used." }] + errors: [definedError("err")] }, // Ignore reads for modifications to itself: https://github.com/eslint/eslint/issues/6348 - { code: "var a = 0; a = a + 1;", errors: [{ message: "'a' is assigned a value but never used." }] }, - { code: "var a = 0; a = a + a;", errors: [{ message: "'a' is assigned a value but never used." }] }, - { code: "var a = 0; a += a + 1;", errors: [{ message: "'a' is assigned a value but never used." }] }, - { code: "var a = 0; a++;", errors: [{ message: "'a' is assigned a value but never used." }] }, - { code: "function foo(a) { a = a + 1 } foo();", errors: [{ message: "'a' is assigned a value but never used." }] }, - { code: "function foo(a) { a += a + 1 } foo();", errors: [{ message: "'a' is assigned a value but never used." }] }, - { code: "function foo(a) { a++ } foo();", errors: [{ message: "'a' is assigned a value but never used." }] }, - { code: "var a = 3; a = a * 5 + 6;", errors: [{ message: "'a' is assigned a value but never used." }] }, - { code: "var a = 2, b = 4; a = a * 2 + b;", errors: [{ message: "'a' is assigned a value but never used." }] }, + { code: "var a = 0; a = a + 1;", errors: [assignedError("a")] }, + { code: "var a = 0; a = a + a;", errors: [assignedError("a")] }, + { code: "var a = 0; a += a + 1;", errors: [assignedError("a")] }, + { code: "var a = 0; a++;", errors: [assignedError("a")] }, + { code: "function foo(a) { a = a + 1 } foo();", errors: [assignedError("a")] }, + { code: "function foo(a) { a += a + 1 } foo();", errors: [assignedError("a")] }, + { code: "function foo(a) { a++ } foo();", errors: [assignedError("a")] }, + { code: "var a = 3; a = a * 5 + 6;", errors: [assignedError("a")] }, + { code: "var a = 2, b = 4; a = a * 2 + b;", errors: [assignedError("a")] }, // https://github.com/eslint/eslint/issues/6576 (For coverage) { code: "function foo(cb) { cb = function(a) { cb(1 + a); }; bar(not_cb); } foo();", - errors: [{ message: "'cb' is assigned a value but never used." }] + errors: [assignedError("cb")] }, { code: "function foo(cb) { cb = function(a) { return cb(1 + a); }(); } foo();", - errors: [{ message: "'cb' is assigned a value but never used." }] + errors: [assignedError("cb")] }, { code: "function foo(cb) { cb = (function(a) { cb(1 + a); }, cb); } foo();", - errors: [{ message: "'cb' is assigned a value but never used." }] + errors: [assignedError("cb")] }, { code: "function foo(cb) { cb = (0, function(a) { cb(1 + a); }); } foo();", - errors: [{ message: "'cb' is assigned a value but never used." }] + errors: [assignedError("cb")] }, // https://github.com/eslint/eslint/issues/6646 @@ -604,7 +864,7 @@ ruleTester.run("no-unused-vars", rule, { " foo()", "}" ].join("\n"), - errors: [{ message: "'b' is assigned a value but never used." }] + errors: [assignedError("b")] }, // https://github.com/eslint/eslint/issues/7124 @@ -612,12 +872,8 @@ ruleTester.run("no-unused-vars", rule, { code: "(function(a, b, c) {})", options: [{ argsIgnorePattern: "c" }], errors: [ - { - message: "'a' is defined but never used. Allowed unused args must match /c/u." - }, - { - message: "'b' is defined but never used. Allowed unused args must match /c/u." - } + definedError("a", ". Allowed unused args must match /c/u"), + definedError("b", ". Allowed unused args must match /c/u") ] }, { @@ -625,12 +881,8 @@ ruleTester.run("no-unused-vars", rule, { options: [{ argsIgnorePattern: "[cd]" }], parserOptions: { ecmaVersion: 6 }, errors: [ - { - message: "'a' is defined but never used. Allowed unused args must match /[cd]/u." - }, - { - message: "'b' is defined but never used. Allowed unused args must match /[cd]/u." - } + definedError("a", ". Allowed unused args must match /[cd]/u"), + definedError("b", ". Allowed unused args must match /[cd]/u") ] }, { @@ -638,15 +890,9 @@ ruleTester.run("no-unused-vars", rule, { options: [{ argsIgnorePattern: "c" }], parserOptions: { ecmaVersion: 6 }, errors: [ - { - message: "'a' is defined but never used. Allowed unused args must match /c/u." - }, - { - message: "'b' is defined but never used. Allowed unused args must match /c/u." - }, - { - message: "'d' is defined but never used. Allowed unused args must match /c/u." - } + definedError("a", ". Allowed unused args must match /c/u"), + definedError("b", ". Allowed unused args must match /c/u"), + definedError("d", ". Allowed unused args must match /c/u") ] }, { @@ -654,20 +900,23 @@ ruleTester.run("no-unused-vars", rule, { options: [{ argsIgnorePattern: "d" }], parserOptions: { ecmaVersion: 6 }, errors: [ - { - message: "'a' is defined but never used. Allowed unused args must match /d/u." - }, - { - message: "'b' is defined but never used. Allowed unused args must match /d/u." - }, - { - message: "'c' is defined but never used. Allowed unused args must match /d/u." - } + definedError("a", ". Allowed unused args must match /d/u"), + definedError("b", ". Allowed unused args must match /d/u"), + definedError("c", ". Allowed unused args must match /d/u") ] }, { code: "/*global\rfoo*/", - errors: [{ message: "'foo' is defined but never used.", line: 2, column: 1 }] + errors: [{ + line: 2, + column: 1, + messageId: "unusedVar", + data: { + varName: "foo", + action: "defined", + additional: "" + } + }] }, // https://github.com/eslint/eslint/issues/8442 @@ -675,46 +924,46 @@ ruleTester.run("no-unused-vars", rule, { code: "(function ({ a }, b ) { return b; })();", parserOptions: { ecmaVersion: 2015 }, errors: [ - "'a' is defined but never used." + definedError("a") ] }, { code: "(function ({ a }, { b, c } ) { return b; })();", parserOptions: { ecmaVersion: 2015 }, errors: [ - "'a' is defined but never used.", - "'c' is defined but never used." + definedError("a"), + definedError("c") ] }, { code: "(function ({ a, b }, { c } ) { return b; })();", parserOptions: { ecmaVersion: 2015 }, errors: [ - "'a' is defined but never used.", - "'c' is defined but never used." + definedError("a"), + definedError("c") ] }, { code: "(function ([ a ], b ) { return b; })();", parserOptions: { ecmaVersion: 2015 }, errors: [ - "'a' is defined but never used." + definedError("a") ] }, { code: "(function ([ a ], [ b, c ] ) { return b; })();", parserOptions: { ecmaVersion: 2015 }, errors: [ - "'a' is defined but never used.", - "'c' is defined but never used." + definedError("a"), + definedError("c") ] }, { code: "(function ([ a, b ], [ c ] ) { return b; })();", parserOptions: { ecmaVersion: 2015 }, errors: [ - "'a' is defined but never used.", - "'c' is defined but never used." + definedError("a"), + definedError("c") ] }, @@ -722,34 +971,32 @@ ruleTester.run("no-unused-vars", rule, { { code: "(function(_a) {})();", options: [{ args: "all", varsIgnorePattern: "^_" }], - errors: [{ message: "'_a' is defined but never used." }] + errors: [definedError("_a")] }, { code: "(function(_a) {})();", options: [{ args: "all", caughtErrorsIgnorePattern: "^_" }], - errors: [{ message: "'_a' is defined but never used." }] + errors: [definedError("_a")] }, // https://github.com/eslint/eslint/issues/10982 { code: "var a = function() { a(); };", - errors: [{ message: "'a' is assigned a value but never used." }] + errors: [assignedError("a")] }, { code: "var a = function(){ return function() { a(); } };", - errors: [ - { message: "'a' is assigned a value but never used." } - ] + errors: [assignedError("a")] }, { code: "const a = () => { a(); };", parserOptions: { ecmaVersion: 2015 }, - errors: [{ message: "'a' is assigned a value but never used." }] + errors: [assignedError("a")] }, { code: "const a = () => () => { a(); };", parserOptions: { ecmaVersion: 2015 }, - errors: [{ message: "'a' is assigned a value but never used." }] + errors: [assignedError("a")] } ] }); diff --git a/tests/lib/rules/no-useless-call.js b/tests/lib/rules/no-useless-call.js index 14367902185..8713ee92c4d 100644 --- a/tests/lib/rules/no-useless-call.js +++ b/tests/lib/rules/no-useless-call.js @@ -49,22 +49,127 @@ ruleTester.run("no-useless-call", rule, { invalid: [ // call. - { code: "foo.call(undefined, 1, 2);", errors: [{ message: "unnecessary '.call()'.", type: "CallExpression" }] }, - { code: "foo.call(void 0, 1, 2);", errors: [{ message: "unnecessary '.call()'.", type: "CallExpression" }] }, - { code: "foo.call(null, 1, 2);", errors: [{ message: "unnecessary '.call()'.", type: "CallExpression" }] }, - { code: "obj.foo.call(obj, 1, 2);", errors: [{ message: "unnecessary '.call()'.", type: "CallExpression" }] }, - { code: "a.b.c.foo.call(a.b.c, 1, 2);", errors: [{ message: "unnecessary '.call()'.", type: "CallExpression" }] }, - { code: "a.b(x, y).c.foo.call(a.b(x, y).c, 1, 2);", errors: [{ message: "unnecessary '.call()'.", type: "CallExpression" }] }, + { + code: "foo.call(undefined, 1, 2);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "call" }, + type: "CallExpression" + }] + }, + { + code: "foo.call(void 0, 1, 2);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "call" }, + type: "CallExpression" + }] + }, + { + code: "foo.call(null, 1, 2);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "call" }, + type: "CallExpression" + }] + }, + { + code: "obj.foo.call(obj, 1, 2);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "call" }, + type: "CallExpression" + }] + }, + { + code: "a.b.c.foo.call(a.b.c, 1, 2);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "call" }, + type: "CallExpression" + }] + }, + { + code: "a.b(x, y).c.foo.call(a.b(x, y).c, 1, 2);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "call" }, + type: "CallExpression" + }] + }, // apply. - { code: "foo.apply(undefined, [1, 2]);", errors: [{ message: "unnecessary '.apply()'.", type: "CallExpression" }] }, - { code: "foo.apply(void 0, [1, 2]);", errors: [{ message: "unnecessary '.apply()'.", type: "CallExpression" }] }, - { code: "foo.apply(null, [1, 2]);", errors: [{ message: "unnecessary '.apply()'.", type: "CallExpression" }] }, - { code: "obj.foo.apply(obj, [1, 2]);", errors: [{ message: "unnecessary '.apply()'.", type: "CallExpression" }] }, - { code: "a.b.c.foo.apply(a.b.c, [1, 2]);", errors: [{ message: "unnecessary '.apply()'.", type: "CallExpression" }] }, - { code: "a.b(x, y).c.foo.apply(a.b(x, y).c, [1, 2]);", errors: [{ message: "unnecessary '.apply()'.", type: "CallExpression" }] }, - { code: "[].concat.apply([ ], [1, 2]);", errors: [{ message: "unnecessary '.apply()'.", type: "CallExpression" }] }, - { code: "[].concat.apply([\n/*empty*/\n], [1, 2]);", errors: [{ message: "unnecessary '.apply()'.", type: "CallExpression" }] }, - { code: "abc.get(\"foo\", 0).concat.apply(abc . get(\"foo\", 0 ), [1, 2]);", errors: [{ message: "unnecessary '.apply()'.", type: "CallExpression" }] } + { + code: "foo.apply(undefined, [1, 2]);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "apply" }, + type: "CallExpression" + }] + }, + { + code: "foo.apply(void 0, [1, 2]);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "apply" }, + type: "CallExpression" + }] + }, + { + code: "foo.apply(null, [1, 2]);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "apply" }, + type: "CallExpression" + }] + }, + { + code: "obj.foo.apply(obj, [1, 2]);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "apply" }, + type: "CallExpression" + }] + }, + { + code: "a.b.c.foo.apply(a.b.c, [1, 2]);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "apply" }, + type: "CallExpression" + }] + }, + { + code: "a.b(x, y).c.foo.apply(a.b(x, y).c, [1, 2]);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "apply" }, + type: "CallExpression" + }] + }, + { + code: "[].concat.apply([ ], [1, 2]);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "apply" }, + type: "CallExpression" + }] + }, + { + code: "[].concat.apply([\n/*empty*/\n], [1, 2]);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "apply" }, + type: "CallExpression" + }] + }, + { + code: "abc.get(\"foo\", 0).concat.apply(abc . get(\"foo\", 0 ), [1, 2]);", + errors: [{ + messageId: "unnecessaryCall", + data: { name: "apply" }, + type: "CallExpression" + }] + } ] }); diff --git a/tests/lib/rules/no-useless-catch.js b/tests/lib/rules/no-useless-catch.js index 040e61ea609..a8b7e342279 100644 --- a/tests/lib/rules/no-useless-catch.js +++ b/tests/lib/rules/no-useless-catch.js @@ -126,7 +126,7 @@ ruleTester.run("no-useless-catch", rule, { } `, errors: [{ - message: "Unnecessary try/catch wrapper.", + messageId: "unnecessaryCatch", type: "TryStatement" }] }, @@ -141,7 +141,7 @@ ruleTester.run("no-useless-catch", rule, { } `, errors: [{ - message: "Unnecessary catch clause.", + messageId: "unnecessaryCatchClause", type: "CatchClause" }] }, @@ -155,7 +155,7 @@ ruleTester.run("no-useless-catch", rule, { } `, errors: [{ - message: "Unnecessary try/catch wrapper.", + messageId: "unnecessaryCatch", type: "TryStatement" }] }, @@ -171,7 +171,7 @@ ruleTester.run("no-useless-catch", rule, { } `, errors: [{ - message: "Unnecessary catch clause.", + messageId: "unnecessaryCatchClause", type: "CatchClause" }] }, @@ -187,7 +187,7 @@ ruleTester.run("no-useless-catch", rule, { `, parserOptions: { ecmaVersion: 8 }, errors: [{ - message: "Unnecessary try/catch wrapper.", + messageId: "unnecessaryCatch", type: "TryStatement" }] } diff --git a/tests/lib/rules/no-useless-computed-key.js b/tests/lib/rules/no-useless-computed-key.js index a5907aede0d..100899c880e 100644 --- a/tests/lib/rules/no-useless-computed-key.js +++ b/tests/lib/rules/no-useless-computed-key.js @@ -56,192 +56,252 @@ ruleTester.run("no-useless-computed-key", rule, { code: "({ ['0']: 0 })", output: "({ '0': 0 })", errors: [{ - message: "Unnecessarily computed property ['0'] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "'0'" }, + type: "Property" }] }, { code: "({ ['0+1,234']: 0 })", output: "({ '0+1,234': 0 })", errors: [{ - message: "Unnecessarily computed property ['0+1,234'] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "'0+1,234'" }, + type: "Property" }] }, { code: "({ [0]: 0 })", output: "({ 0: 0 })", errors: [{ - message: "Unnecessarily computed property [0] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "0" }, + type: "Property" }] }, { code: "({ ['x']: 0 })", output: "({ 'x': 0 })", errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "Property" }] }, { code: "({ ['x']() {} })", output: "({ 'x'() {} })", errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "Property" }] }, { code: "({ [/* this comment prevents a fix */ 'x']: 0 })", output: null, errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "Property" }] }, { code: "({ ['x' /* this comment also prevents a fix */]: 0 })", output: null, errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "Property" }] }, { code: "({ [('x')]: 0 })", output: "({ 'x': 0 })", errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "Property" }] }, { code: "({ *['x']() {} })", output: "({ *'x'() {} })", errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "Property" }] }, { code: "({ async ['x']() {} })", output: "({ async 'x'() {} })", parserOptions: { ecmaVersion: 8 }, errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "Property" }] }, { code: "({ get[.2]() {} })", output: "({ get.2() {} })", errors: [{ - message: "Unnecessarily computed property [.2] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: ".2" }, + type: "Property" }] }, { code: "({ set[.2](value) {} })", output: "({ set.2(value) {} })", errors: [{ - message: "Unnecessarily computed property [.2] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: ".2" }, + type: "Property" }] }, { code: "({ async[.2]() {} })", output: "({ async.2() {} })", parserOptions: { ecmaVersion: 8 }, errors: [{ - message: "Unnecessarily computed property [.2] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: ".2" }, + type: "Property" }] }, { code: "({ [2]() {} })", output: "({ 2() {} })", errors: [{ - message: "Unnecessarily computed property [2] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "Property" }] }, { code: "({ get [2]() {} })", output: "({ get 2() {} })", errors: [{ - message: "Unnecessarily computed property [2] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "Property" }] }, { code: "({ set [2](value) {} })", output: "({ set 2(value) {} })", errors: [{ - message: "Unnecessarily computed property [2] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "Property" }] }, { code: "({ async [2]() {} })", output: "({ async 2() {} })", parserOptions: { ecmaVersion: 8 }, errors: [{ - message: "Unnecessarily computed property [2] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "Property" }] }, { code: "({ get[2]() {} })", output: "({ get 2() {} })", errors: [{ - message: "Unnecessarily computed property [2] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "Property" }] }, { code: "({ set[2](value) {} })", output: "({ set 2(value) {} })", errors: [{ - message: "Unnecessarily computed property [2] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "Property" }] }, { code: "({ async[2]() {} })", output: "({ async 2() {} })", parserOptions: { ecmaVersion: 8 }, errors: [{ - message: "Unnecessarily computed property [2] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "Property" }] }, { code: "({ get['foo']() {} })", output: "({ get'foo'() {} })", errors: [{ - message: "Unnecessarily computed property ['foo'] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "'foo'" }, + type: "Property" }] }, { code: "({ *[2]() {} })", output: "({ *2() {} })", errors: [{ - message: "Unnecessarily computed property [2] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "Property" }] }, { code: "({ async*[2]() {} })", output: "({ async*2() {} })", errors: [{ - message: "Unnecessarily computed property [2] found.", type: "Property" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "Property" }] }, { code: "class Foo { ['0']() {} }", output: "class Foo { '0'() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property ['0'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'0'" }, + type: "MethodDefinition" }] }, { code: "class Foo { ['0+1,234']() {} }", output: "class Foo { '0+1,234'() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property ['0+1,234'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'0+1,234'" }, + type: "MethodDefinition" }] }, { code: "class Foo { ['x']() {} }", output: "class Foo { 'x'() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "MethodDefinition" }] }, { code: "class Foo { [/* this comment prevents a fix */ 'x']() {} }", output: null, options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "MethodDefinition" }] }, { code: "class Foo { ['x' /* this comment also prevents a fix */]() {} }", output: null, options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "MethodDefinition" }] }, { code: "class Foo { [('x')]() {} }", output: "class Foo { 'x'() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "MethodDefinition" }] }, { code: "class Foo { *['x']() {} }", output: "class Foo { *'x'() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "MethodDefinition" }] }, { code: "class Foo { async ['x']() {} }", @@ -249,21 +309,27 @@ ruleTester.run("no-useless-computed-key", rule, { options: [{ enforceForClassMembers: true }], parserOptions: { ecmaVersion: 8 }, errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "MethodDefinition" }] }, { code: "class Foo { get[.2]() {} }", output: "class Foo { get.2() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property [.2] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: ".2" }, + type: "MethodDefinition" }] }, { code: "class Foo { set[.2](value) {} }", output: "class Foo { set.2(value) {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property [.2] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: ".2" }, + type: "MethodDefinition" }] }, { code: "class Foo { async[.2]() {} }", @@ -271,28 +337,36 @@ ruleTester.run("no-useless-computed-key", rule, { options: [{ enforceForClassMembers: true }], parserOptions: { ecmaVersion: 8 }, errors: [{ - message: "Unnecessarily computed property [.2] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: ".2" }, + type: "MethodDefinition" }] }, { code: "class Foo { [2]() {} }", output: "class Foo { 2() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property [2] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "MethodDefinition" }] }, { code: "class Foo { get [2]() {} }", output: "class Foo { get 2() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property [2] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "MethodDefinition" }] }, { code: "class Foo { set [2](value) {} }", output: "class Foo { set 2(value) {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property [2] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "MethodDefinition" }] }, { code: "class Foo { async [2]() {} }", @@ -300,21 +374,27 @@ ruleTester.run("no-useless-computed-key", rule, { options: [{ enforceForClassMembers: true }], parserOptions: { ecmaVersion: 8 }, errors: [{ - message: "Unnecessarily computed property [2] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "MethodDefinition" }] }, { code: "class Foo { get[2]() {} }", output: "class Foo { get 2() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property [2] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "MethodDefinition" }] }, { code: "class Foo { set[2](value) {} }", output: "class Foo { set 2(value) {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property [2] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "MethodDefinition" }] }, { code: "class Foo { async[2]() {} }", @@ -322,63 +402,81 @@ ruleTester.run("no-useless-computed-key", rule, { options: [{ enforceForClassMembers: true }], parserOptions: { ecmaVersion: 8 }, errors: [{ - message: "Unnecessarily computed property [2] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "MethodDefinition" }] }, { code: "class Foo { get['foo']() {} }", output: "class Foo { get'foo'() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property ['foo'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'foo'" }, + type: "MethodDefinition" }] }, { code: "class Foo { *[2]() {} }", output: "class Foo { *2() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property [2] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "MethodDefinition" }] }, { code: "class Foo { async*[2]() {} }", output: "class Foo { async*2() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property [2] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "2" }, + type: "MethodDefinition" }] }, { code: "class Foo { static ['constructor']() {} }", output: "class Foo { static 'constructor'() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property ['constructor'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'constructor'" }, + type: "MethodDefinition" }] }, { code: "class Foo { ['prototype']() {} }", output: "class Foo { 'prototype'() {} }", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property ['prototype'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'prototype'" }, + type: "MethodDefinition" }] }, { code: "(class { ['x']() {} })", output: "(class { 'x'() {} })", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property ['x'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'x'" }, + type: "MethodDefinition" }] }, { code: "(class { static ['constructor']() {} })", output: "(class { static 'constructor'() {} })", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property ['constructor'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'constructor'" }, + type: "MethodDefinition" }] }, { code: "(class { ['prototype']() {} })", output: "(class { 'prototype'() {} })", options: [{ enforceForClassMembers: true }], errors: [{ - message: "Unnecessarily computed property ['prototype'] found.", type: "MethodDefinition" + messageId: "unnecessarilyComputedProperty", + data: { property: "'prototype'" }, + type: "MethodDefinition" }] } ] diff --git a/tests/lib/rules/no-useless-concat.js b/tests/lib/rules/no-useless-concat.js index d5974027d64..9376266623b 100644 --- a/tests/lib/rules/no-useless-concat.js +++ b/tests/lib/rules/no-useless-concat.js @@ -42,25 +42,25 @@ ruleTester.run("no-useless-concat", rule, { { code: "'a' + 'b'", errors: [ - { message: "Unexpected string concatenation of literals." } + { messageId: "unexpectedConcat" } ] }, { code: "foo + 'a' + 'b'", errors: [ - { message: "Unexpected string concatenation of literals." } + { messageId: "unexpectedConcat" } ] }, { code: "'a' + 'b' + 'c'", errors: [ { - message: "Unexpected string concatenation of literals.", + messageId: "unexpectedConcat", line: 1, column: 5 }, { - message: "Unexpected string concatenation of literals.", + messageId: "unexpectedConcat", line: 1, column: 11 } @@ -69,29 +69,29 @@ ruleTester.run("no-useless-concat", rule, { { code: "(foo + 'a') + ('b' + 'c')", errors: [ - { column: 13, message: "Unexpected string concatenation of literals." }, - { column: 20, message: "Unexpected string concatenation of literals." } + { column: 13, messageId: "unexpectedConcat" }, + { column: 20, messageId: "unexpectedConcat" } ] }, { code: "`a` + 'b'", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Unexpected string concatenation of literals." } + { messageId: "unexpectedConcat" } ] }, { code: "`a` + `b`", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Unexpected string concatenation of literals." } + { messageId: "unexpectedConcat" } ] }, { code: "foo + `a` + `b`", parserOptions: { ecmaVersion: 6 }, errors: [ - { message: "Unexpected string concatenation of literals." } + { messageId: "unexpectedConcat" } ] } ] diff --git a/tests/lib/rules/no-useless-rename.js b/tests/lib/rules/no-useless-rename.js index 0dccda27800..af8f6b8a520 100644 --- a/tests/lib/rules/no-useless-rename.js +++ b/tests/lib/rules/no-useless-rename.js @@ -129,357 +129,408 @@ ruleTester.run("no-useless-rename", rule, { { code: "let {foo: foo} = obj;", output: "let {foo} = obj;", - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "let {a, foo: foo} = obj;", output: "let {a, foo} = obj;", - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "let {foo: foo, bar: baz} = obj;", output: "let {foo, bar: baz} = obj;", - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "let {foo: bar, baz: baz} = obj;", output: "let {foo: bar, baz} = obj;", - errors: ["Destructuring assignment baz unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "baz" } }] }, { code: "let {foo: foo, bar: bar} = obj;", output: "let {foo, bar} = obj;", - errors: ["Destructuring assignment foo unnecessarily renamed.", "Destructuring assignment bar unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } } + ] }, { code: "let {foo: {bar: bar}} = obj;", output: "let {foo: {bar}} = obj;", - errors: ["Destructuring assignment bar unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }] }, { code: "let {foo: {bar: bar}, baz: baz} = obj;", output: "let {foo: {bar}, baz} = obj;", - errors: ["Destructuring assignment bar unnecessarily renamed.", "Destructuring assignment baz unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "baz" } } + ] }, { code: "let {'foo': foo} = obj;", output: "let {foo} = obj;", - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "let {'foo': foo, 'bar': baz} = obj;", output: "let {foo, 'bar': baz} = obj;", - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "let {'foo': bar, 'baz': baz} = obj;", output: "let {'foo': bar, baz} = obj;", - errors: ["Destructuring assignment baz unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "baz" } }] }, { code: "let {'foo': foo, 'bar': bar} = obj;", output: "let {foo, bar} = obj;", - errors: ["Destructuring assignment foo unnecessarily renamed.", "Destructuring assignment bar unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } } + ] }, { code: "let {'foo': {'bar': bar}} = obj;", output: "let {'foo': {bar}} = obj;", - errors: ["Destructuring assignment bar unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }] }, { code: "let {'foo': {'bar': bar}, 'baz': baz} = obj;", output: "let {'foo': {bar}, baz} = obj;", - errors: ["Destructuring assignment bar unnecessarily renamed.", "Destructuring assignment baz unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "baz" } } + ] }, { code: "let {foo: foo = 1, 'bar': bar = 1, baz: baz} = obj;", output: "let {foo = 1, bar = 1, baz} = obj;", - errors: ["Destructuring assignment foo unnecessarily renamed.", "Destructuring assignment bar unnecessarily renamed.", "Destructuring assignment baz unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "baz" } } + ] }, { code: "let {foo: {bar: bar = 1, 'baz': baz = 1}} = obj;", output: "let {foo: {bar = 1, baz = 1}} = obj;", - errors: ["Destructuring assignment bar unnecessarily renamed.", "Destructuring assignment baz unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "baz" } } + ] }, { code: "let {foo: {bar: bar = {}} = {}} = obj;", output: "let {foo: {bar = {}} = {}} = obj;", - errors: ["Destructuring assignment bar unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }] }, { code: "function func({foo: foo}) {}", output: "function func({foo}) {}", - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "function func({foo: foo, bar: baz}) {}", output: "function func({foo, bar: baz}) {}", - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "function func({foo: bar, baz: baz}) {}", output: "function func({foo: bar, baz}) {}", - errors: ["Destructuring assignment baz unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "baz" } }] }, { code: "function func({foo: foo, bar: bar}) {}", output: "function func({foo, bar}) {}", - errors: ["Destructuring assignment foo unnecessarily renamed.", "Destructuring assignment bar unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } } + ] }, { code: "function func({foo: foo = 1, 'bar': bar = 1, baz: baz}) {}", output: "function func({foo = 1, bar = 1, baz}) {}", - errors: ["Destructuring assignment foo unnecessarily renamed.", "Destructuring assignment bar unnecessarily renamed.", "Destructuring assignment baz unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "baz" } } + ] }, { code: "function func({foo: {bar: bar = 1, 'baz': baz = 1}}) {}", output: "function func({foo: {bar = 1, baz = 1}}) {}", - errors: ["Destructuring assignment bar unnecessarily renamed.", "Destructuring assignment baz unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "baz" } } + ] }, { code: "function func({foo: {bar: bar = {}} = {}}) {}", output: "function func({foo: {bar = {}} = {}}) {}", - errors: ["Destructuring assignment bar unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }] }, { code: "({foo: foo}) => {}", output: "({foo}) => {}", - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "({foo: foo, bar: baz}) => {}", output: "({foo, bar: baz}) => {}", - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "({foo: bar, baz: baz}) => {}", output: "({foo: bar, baz}) => {}", - errors: ["Destructuring assignment baz unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "baz" } }] }, { code: "({foo: foo, bar: bar}) => {}", output: "({foo, bar}) => {}", - errors: ["Destructuring assignment foo unnecessarily renamed.", "Destructuring assignment bar unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } } + ] }, { code: "({foo: foo = 1, 'bar': bar = 1, baz: baz}) => {}", output: "({foo = 1, bar = 1, baz}) => {}", - errors: ["Destructuring assignment foo unnecessarily renamed.", "Destructuring assignment bar unnecessarily renamed.", "Destructuring assignment baz unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "baz" } } + ] }, { code: "({foo: {bar: bar = 1, 'baz': baz = 1}}) => {}", output: "({foo: {bar = 1, baz = 1}}) => {}", - errors: ["Destructuring assignment bar unnecessarily renamed.", "Destructuring assignment baz unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "baz" } } + ] }, { code: "({foo: {bar: bar = {}} = {}}) => {}", output: "({foo: {bar = {}} = {}}) => {}", - errors: ["Destructuring assignment bar unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }] }, { code: "const {foo: foo, ...stuff} = myObject;", output: "const {foo, ...stuff} = myObject;", parserOptions: { ecmaVersion: 2018 }, - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "const {foo: foo, bar: baz, ...stuff} = myObject;", output: "const {foo, bar: baz, ...stuff} = myObject;", parserOptions: { ecmaVersion: 2018 }, - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "const {foo: foo, bar: bar, ...stuff} = myObject;", output: "const {foo, bar, ...stuff} = myObject;", parserOptions: { ecmaVersion: 2018 }, - errors: ["Destructuring assignment foo unnecessarily renamed.", "Destructuring assignment bar unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } } + ] }, { code: "import {foo as foo} from 'foo';", output: "import {foo} from 'foo';", - errors: ["Import foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }] }, { code: "import {foo as foo, bar as baz} from 'foo';", output: "import {foo, bar as baz} from 'foo';", - errors: ["Import foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }] }, { code: "import {foo as bar, baz as baz} from 'foo';", output: "import {foo as bar, baz} from 'foo';", - errors: ["Import baz unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "baz" } }] }, { code: "import {foo as foo, bar as bar} from 'foo';", output: "import {foo, bar} from 'foo';", - errors: ["Import foo unnecessarily renamed.", "Import bar unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Import", name: "bar" } } + ] }, { code: "var foo = 0; export {foo as foo};", output: "var foo = 0; export {foo};", - errors: ["Export foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "var foo = 0; var bar = 0; export {foo as foo, bar as baz};", output: "var foo = 0; var bar = 0; export {foo, bar as baz};", - errors: ["Export foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "var foo = 0; var baz = 0; export {foo as bar, baz as baz};", output: "var foo = 0; var baz = 0; export {foo as bar, baz};", - errors: ["Export baz unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "baz" } }] }, { code: "var foo = 0; var bar = 0;export {foo as foo, bar as bar};", output: "var foo = 0; var bar = 0;export {foo, bar};", - errors: ["Export foo unnecessarily renamed.", "Export bar unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Export", name: "bar" } } + ] }, { code: "export {foo as foo} from 'foo';", output: "export {foo} from 'foo';", - errors: ["Export foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "export {foo as foo, bar as baz} from 'foo';", output: "export {foo, bar as baz} from 'foo';", - errors: ["Export foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "var foo = 0; var bar = 0; export {foo as bar, baz as baz} from 'foo';", output: "var foo = 0; var bar = 0; export {foo as bar, baz} from 'foo';", - errors: ["Export baz unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "baz" } }] }, { code: "export {foo as foo, bar as bar} from 'foo';", output: "export {foo, bar} from 'foo';", - errors: ["Export foo unnecessarily renamed.", "Export bar unnecessarily renamed."] + errors: [ + { messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }, + { messageId: "unnecessarilyRenamed", data: { type: "Export", name: "bar" } } + ] }, // Should not autofix if it would remove comments { code: "({/* comment */foo: foo} = {});", output: "({/* comment */foo} = {});", - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "({foo, /* comment */bar: bar} = {});", output: "({foo, /* comment */bar} = {});", - errors: ["Destructuring assignment bar unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "bar" } }] }, { code: "({foo/**/ : foo} = {});", output: null, - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "({foo /**/: foo} = {});", output: null, - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "({foo://\nfoo} = {});", output: null, - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "({foo: /**/foo} = {});", output: null, - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "({foo: foo/* comment */} = {});", output: "({foo/* comment */} = {});", - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "({foo: foo//comment\n,bar} = {});", output: "({foo//comment\n,bar} = {});", - errors: ["Destructuring assignment foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Destructuring assignment", name: "foo" } }] }, { code: "import {/* comment */foo as foo} from 'foo';", output: "import {/* comment */foo} from 'foo';", - errors: ["Import foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }] }, { code: "import {foo,/* comment */bar as bar} from 'foo';", output: "import {foo,/* comment */bar} from 'foo';", - errors: ["Import bar unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "bar" } }] }, { code: "import {foo/**/ as foo} from 'foo';", output: null, - errors: ["Import foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }] }, { code: "import {foo /**/as foo} from 'foo';", output: null, - errors: ["Import foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }] }, { code: "import {foo //\nas foo} from 'foo';", output: null, - errors: ["Import foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }] }, { code: "import {foo as/**/foo} from 'foo';", output: null, - errors: ["Import foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }] }, { code: "import {foo as foo/* comment */} from 'foo';", output: "import {foo/* comment */} from 'foo';", - errors: ["Import foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }] }, { code: "import {foo as foo/* comment */,bar} from 'foo';", output: "import {foo/* comment */,bar} from 'foo';", - errors: ["Import foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Import", name: "foo" } }] }, { code: "let foo; export {/* comment */foo as foo};", output: "let foo; export {/* comment */foo};", - errors: ["Export foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "let foo, bar; export {foo,/* comment */bar as bar};", output: "let foo, bar; export {foo,/* comment */bar};", - errors: ["Export bar unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "bar" } }] }, { code: "let foo; export {foo/**/as foo};", output: null, - errors: ["Export foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "let foo; export {foo as/**/ foo};", output: null, - errors: ["Export foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "let foo; export {foo as /**/foo};", output: null, - errors: ["Export foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "let foo; export {foo as//comment\n foo};", output: null, - errors: ["Export foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "let foo; export {foo as foo/* comment*/};", output: "let foo; export {foo/* comment*/};", - errors: ["Export foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "let foo, bar; export {foo as foo/* comment*/,bar};", output: "let foo, bar; export {foo/* comment*/,bar};", - errors: ["Export foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] }, { code: "let foo, bar; export {foo as foo//comment\n,bar};", output: "let foo, bar; export {foo//comment\n,bar};", - errors: ["Export foo unnecessarily renamed."] + errors: [{ messageId: "unnecessarilyRenamed", data: { type: "Export", name: "foo" } }] } ] }); diff --git a/tests/lib/rules/no-useless-return.js b/tests/lib/rules/no-useless-return.js index 1f41f96bb51..434700cc2d8 100644 --- a/tests/lib/rules/no-useless-return.js +++ b/tests/lib/rules/no-useless-return.js @@ -232,8 +232,8 @@ ruleTester.run("no-useless-return", rule, { } `, // Other case is fixed in the second pass. errors: [ - { message: "Unnecessary return statement.", type: "ReturnStatement" }, - { message: "Unnecessary return statement.", type: "ReturnStatement" } + { messageId: "unnecessaryReturn", type: "ReturnStatement" }, + { messageId: "unnecessaryReturn", type: "ReturnStatement" } ] }, { @@ -439,10 +439,10 @@ ruleTester.run("no-useless-return", rule, { code: "function foo() { return; return; }", output: "function foo() { return; }", errors: [{ - message: "Unnecessary return statement.", + messageId: "unnecessaryReturn", type: "ReturnStatement", column: 18 }] } - ].map(invalidCase => Object.assign({ errors: [{ message: "Unnecessary return statement.", type: "ReturnStatement" }] }, invalidCase)) + ].map(invalidCase => Object.assign({ errors: [{ messageId: "unnecessaryReturn", type: "ReturnStatement" }] }, invalidCase)) }); diff --git a/tests/lib/rules/no-var.js b/tests/lib/rules/no-var.js index d7576bfe3ce..84e14ae19c9 100644 --- a/tests/lib/rules/no-var.js +++ b/tests/lib/rules/no-var.js @@ -39,7 +39,7 @@ ruleTester.run("no-var", rule, { parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { - message: "Unexpected var, use let or const instead.", + messageId: "unexpectedVar", type: "VariableDeclaration" } ] @@ -50,7 +50,7 @@ ruleTester.run("no-var", rule, { parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { - message: "Unexpected var, use let or const instead.", + messageId: "unexpectedVar", type: "VariableDeclaration" } ] @@ -61,7 +61,7 @@ ruleTester.run("no-var", rule, { parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { - message: "Unexpected var, use let or const instead.", + messageId: "unexpectedVar", type: "VariableDeclaration" } ] @@ -72,7 +72,7 @@ ruleTester.run("no-var", rule, { parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { - message: "Unexpected var, use let or const instead.", + messageId: "unexpectedVar", type: "VariableDeclaration" } ] @@ -83,7 +83,7 @@ ruleTester.run("no-var", rule, { parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { - message: "Unexpected var, use let or const instead.", + messageId: "unexpectedVar", type: "VariableDeclaration" } ] @@ -94,7 +94,7 @@ ruleTester.run("no-var", rule, { parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ { - message: "Unexpected var, use let or const instead.", + messageId: "unexpectedVar", type: "VariableDeclaration" } ] @@ -104,7 +104,7 @@ ruleTester.run("no-var", rule, { output: "for (let i = 0; i < list.length; ++i) { foo(i) }", parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - { message: "Unexpected var, use let or const instead.", type: "VariableDeclaration" } + { messageId: "unexpectedVar", type: "VariableDeclaration" } ] }, { @@ -112,7 +112,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - { message: "Unexpected var, use let or const instead.", type: "VariableDeclaration" } + { messageId: "unexpectedVar", type: "VariableDeclaration" } ] }, { @@ -120,8 +120,8 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - { message: "Unexpected var, use let or const instead.", type: "VariableDeclaration" }, - { message: "Unexpected var, use let or const instead.", type: "VariableDeclaration" } + { messageId: "unexpectedVar", type: "VariableDeclaration" }, + { messageId: "unexpectedVar", type: "VariableDeclaration" } ] }, @@ -131,8 +131,8 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead.", - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" }, + { messageId: "unexpectedVar" } ] }, { @@ -140,8 +140,8 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead.", - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" }, + { messageId: "unexpectedVar" } ] }, { @@ -149,7 +149,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" } ] }, { @@ -157,7 +157,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" } ] }, { @@ -165,7 +165,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" } ] }, { @@ -173,7 +173,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" } ] }, { @@ -181,7 +181,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" } ] }, @@ -191,7 +191,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" } ] }, { @@ -199,7 +199,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" } ] }, @@ -209,7 +209,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" } ] }, { @@ -217,7 +217,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" } ] }, { @@ -225,7 +225,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" } ] }, { @@ -233,7 +233,7 @@ ruleTester.run("no-var", rule, { output: "let {a, b = a} = {}", parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" } ] }, { @@ -241,7 +241,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" } ] }, { @@ -249,8 +249,8 @@ ruleTester.run("no-var", rule, { output: "let a = b; var b = 1", parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead.", - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" }, + { messageId: "unexpectedVar" } ] }, @@ -263,7 +263,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaVersion: 2015, ecmaFeatures: { globalReturn: true } }, errors: [ - "Unexpected var, use let or const instead." + { messageId: "unexpectedVar" } ] }, @@ -273,7 +273,7 @@ ruleTester.run("no-var", rule, { output: null, parserOptions: { ecmaFeatures: { globalReturn: true } }, errors: [ - { message: "Unexpected var, use let or const instead.", type: "VariableDeclaration" } + { messageId: "unexpectedVar", type: "VariableDeclaration" } ] }, @@ -281,23 +281,23 @@ ruleTester.run("no-var", rule, { { code: "var foo = 1", output: null, - errors: ["Unexpected var, use let or const instead."] + errors: [{ messageId: "unexpectedVar" }] }, { code: "{ var foo = 1 }", output: null, - errors: ["Unexpected var, use let or const instead."] + errors: [{ messageId: "unexpectedVar" }] }, { code: "if (true) { var foo = 1 }", output: null, - errors: ["Unexpected var, use let or const instead."] + errors: [{ messageId: "unexpectedVar" }] }, { code: "var foo = 1", output: "let foo = 1", parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: ["Unexpected var, use let or const instead."] + errors: [{ messageId: "unexpectedVar" }] }, // https://github.com/eslint/eslint/issues/11594 @@ -306,19 +306,19 @@ ruleTester.run("no-var", rule, { output: "declare let foo = 2;", parser: require.resolve("../../fixtures/parsers/typescript-parsers/declare-var"), parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: ["Unexpected var, use let or const instead."] + errors: [{ messageId: "unexpectedVar" }] }, // https://github.com/eslint/eslint/issues/11830 { code: "function foo() { var let; }", output: null, - errors: ["Unexpected var, use let or const instead."] + errors: [{ messageId: "unexpectedVar" }] }, { code: "function foo() { var { let } = {}; }", output: null, - errors: ["Unexpected var, use let or const instead."] + errors: [{ messageId: "unexpectedVar" }] } ] }); diff --git a/tests/lib/rules/no-warning-comments.js b/tests/lib/rules/no-warning-comments.js index 431511dc034..0359b870673 100644 --- a/tests/lib/rules/no-warning-comments.js +++ b/tests/lib/rules/no-warning-comments.js @@ -40,27 +40,169 @@ ruleTester.run("no-warning-comments", rule, { { code: "foo", options: [{ terms: ["foo-bar"] }] } ], invalid: [ - { code: "// fixme", errors: [{ message: "Unexpected 'fixme' comment." }] }, - { code: "// any fixme", options: [{ location: "anywhere" }], errors: [{ message: "Unexpected 'fixme' comment." }] }, - { code: "// any fixme", options: [{ terms: ["fixme"], location: "anywhere" }], errors: [{ message: "Unexpected 'fixme' comment." }] }, - { code: "// any FIXME", options: [{ terms: ["fixme"], location: "anywhere" }], errors: [{ message: "Unexpected 'fixme' comment." }] }, - { code: "// any fIxMe", options: [{ terms: ["fixme"], location: "anywhere" }], errors: [{ message: "Unexpected 'fixme' comment." }] }, - { code: "/* any fixme */", options: [{ terms: ["FIXME"], location: "anywhere" }], errors: [{ message: "Unexpected 'FIXME' comment." }] }, - { code: "/* any FIXME */", options: [{ terms: ["FIXME"], location: "anywhere" }], errors: [{ message: "Unexpected 'FIXME' comment." }] }, - { code: "/* any fIxMe */", options: [{ terms: ["FIXME"], location: "anywhere" }], errors: [{ message: "Unexpected 'FIXME' comment." }] }, - { code: "// any fixme or todo", options: [{ terms: ["fixme", "todo"], location: "anywhere" }], errors: [{ message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'todo' comment." }] }, - { code: "/* any fixme or todo */", options: [{ terms: ["fixme", "todo"], location: "anywhere" }], errors: [{ message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'todo' comment." }] }, - { code: "/* any fixme or todo */", options: [{ location: "anywhere" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }] }, - { code: "/* fixme and todo */", errors: [{ message: "Unexpected 'fixme' comment." }] }, - { code: "/* fixme and todo */", options: [{ location: "anywhere" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }] }, - { code: "/* any fixme */", options: [{ location: "anywhere" }], errors: [{ message: "Unexpected 'fixme' comment." }] }, - { code: "/* fixme! */", options: [{ terms: ["fixme"] }], errors: [{ message: "Unexpected 'fixme' comment." }] }, - { code: "// regex [litera|$]", options: [{ terms: ["[litera|$]"], location: "anywhere" }], errors: [{ message: "Unexpected '[litera|$]' comment." }] }, - { code: "/* eslint one-var: 2 */", options: [{ terms: ["eslint"] }], errors: [{ message: "Unexpected 'eslint' comment." }] }, - { code: "/* eslint one-var: 2 */", options: [{ terms: ["one"], location: "anywhere" }], errors: [{ message: "Unexpected 'one' comment." }] }, - { code: "/* any block comment with TODO, FIXME or XXX */", options: [{ location: "anywhere" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] }, - { code: "/* any block comment with (TODO, FIXME's or XXX!) */", options: [{ location: "anywhere" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] }, - { code: "/** \n *any block comment \n*with (TODO, FIXME's or XXX!) **/", options: [{ location: "anywhere" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] }, - { code: "// any comment with TODO, FIXME or XXX", options: [{ location: "anywhere" }], errors: [{ message: "Unexpected 'todo' comment." }, { message: "Unexpected 'fixme' comment." }, { message: "Unexpected 'xxx' comment." }] } + { + code: "// fixme", + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } } + ] + }, + { + code: "// any fixme", + options: [{ location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } } + ] + }, + { + code: "// any fixme", + options: [{ terms: ["fixme"], location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } } + ] + }, + { + code: "// any FIXME", + options: [{ terms: ["fixme"], location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } } + ] + }, + { + code: "// any fIxMe", + options: [{ terms: ["fixme"], location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } } + ] + }, + { + code: "/* any fixme */", + options: [{ terms: ["FIXME"], location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "FIXME" } } + ] + }, + { + code: "/* any FIXME */", + options: [{ terms: ["FIXME"], location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "FIXME" } } + ] + }, + { + code: "/* any fIxMe */", + options: [{ terms: ["FIXME"], location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "FIXME" } } + ] + }, + { + code: "// any fixme or todo", + options: [{ terms: ["fixme", "todo"], location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } }, + { messageId: "unexpectedComment", data: { matchedTerm: "todo" } } + ] + }, + { + code: "/* any fixme or todo */", + options: [{ terms: ["fixme", "todo"], location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } }, + { messageId: "unexpectedComment", data: { matchedTerm: "todo" } } + ] + }, + { + code: "/* any fixme or todo */", + options: [{ location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "todo" } }, + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } } + ] + }, + { + code: "/* fixme and todo */", + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } } + ] + }, + { + code: "/* fixme and todo */", + options: [{ location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "todo" } }, + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } } + ] + }, + { + code: "/* any fixme */", + options: [{ location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } } + ] + }, + { + code: "/* fixme! */", + options: [{ terms: ["fixme"] }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } } + ] + }, + { + code: "// regex [litera|$]", + options: [{ terms: ["[litera|$]"], location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "[litera|$]" } } + ] + }, + { + code: "/* eslint one-var: 2 */", + options: [{ terms: ["eslint"] }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "eslint" } } + ] + }, + { + code: "/* eslint one-var: 2 */", + options: [{ terms: ["one"], location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "one" } } + ] + }, + { + code: "/* any block comment with TODO, FIXME or XXX */", + options: [{ location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "todo" } }, + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } }, + { messageId: "unexpectedComment", data: { matchedTerm: "xxx" } } + ] + }, + { + code: "/* any block comment with (TODO, FIXME's or XXX!) */", + options: [{ location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "todo" } }, + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } }, + { messageId: "unexpectedComment", data: { matchedTerm: "xxx" } } + ] + }, + { + code: "/** \n *any block comment \n*with (TODO, FIXME's or XXX!) **/", + options: [{ location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "todo" } }, + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } }, + { messageId: "unexpectedComment", data: { matchedTerm: "xxx" } } + ] + }, + { + code: "// any comment with TODO, FIXME or XXX", + options: [{ location: "anywhere" }], + errors: [ + { messageId: "unexpectedComment", data: { matchedTerm: "todo" } }, + { messageId: "unexpectedComment", data: { matchedTerm: "fixme" } }, + { messageId: "unexpectedComment", data: { matchedTerm: "xxx" } } + ] + } ] }); diff --git a/tests/lib/rules/no-whitespace-before-property.js b/tests/lib/rules/no-whitespace-before-property.js index 88eea148a69..d10b30e20e8 100644 --- a/tests/lib/rules/no-whitespace-before-property.js +++ b/tests/lib/rules/no-whitespace-before-property.js @@ -106,453 +106,759 @@ ruleTester.run("no-whitespace-before-property", rule, { { code: "foo. bar", output: "foo.bar", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo .bar", output: "foo.bar", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo [bar]", output: "foo[bar]", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo [0]", output: "foo[0]", - errors: ["Unexpected whitespace before property 0."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "0" } + }] }, { code: "foo ['bar']", output: "foo['bar']", - errors: ["Unexpected whitespace before property 'bar'."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "'bar'" } + }] }, { code: "foo. bar. baz", output: "foo.bar.baz", - errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }, { + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo .bar. baz", output: "foo.bar.baz", - errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }, { + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo [bar] [baz]", output: "foo[bar][baz]", - errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }, { + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo [bar][baz]", output: "foo[bar][baz]", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo[bar] [baz]", output: "foo[bar][baz]", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo.bar [baz]", output: "foo.bar[baz]", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo. bar[baz]", output: "foo.bar[baz]", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo[bar]. baz", output: "foo[bar].baz", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo[ bar ] [ baz ]", output: "foo[ bar ][ baz ]", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo [ 0 ][ baz ]", output: "foo[ 0 ][ baz ]", - errors: ["Unexpected whitespace before property 0."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "0" } + }] }, { code: "foo[ 0 ] [ 'baz' ]", output: "foo[ 0 ][ 'baz' ]", - errors: ["Unexpected whitespace before property 'baz'."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "'baz'" } + }] }, // tabs { code: "foo\t.bar", output: "foo.bar", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo.\tbar", output: "foo.bar", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo\t.bar()", output: "foo.bar()", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo.\tbar()", output: "foo.bar()", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo\t[bar]", output: "foo[bar]", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo\t[0]", output: "foo[0]", - errors: ["Unexpected whitespace before property 0."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "0" } + }] }, { code: "foo\t['bar']", output: "foo['bar']", - errors: ["Unexpected whitespace before property 'bar'."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "'bar'" } + }] }, { code: "foo.\tbar.\tbaz", output: "foo.bar.baz", - errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }, { + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo\t.bar.\tbaz", output: "foo.bar.baz", - errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }, { + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo.\tbar().\tbaz()", output: "foo.bar().baz()", - errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }, { + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo\t.bar().\tbaz()", output: "foo.bar().baz()", - errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }, { + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo\t[bar]\t[baz]", output: "foo[bar][baz]", - errors: ["Unexpected whitespace before property baz.", "Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }, { + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo\t[bar][baz]", output: "foo[bar][baz]", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo[bar]\t[baz]", output: "foo[bar][baz]", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo.bar\t[baz]", output: "foo.bar[baz]", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo.\tbar[baz]", output: "foo.bar[baz]", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo[bar].\tbaz", output: "foo[bar].baz", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, // newlines { code: "foo [bar]\n .baz", output: "foo[bar]\n .baz", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo. bar\n .baz", output: "foo.bar\n .baz", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo .bar\n.baz", output: "foo.bar\n.baz", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo.\n bar. baz", output: "foo.\n bar.baz", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo.\nbar . baz", output: "foo.\nbar.baz", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo. bar()\n .baz()", output: "foo.bar()\n .baz()", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo .bar()\n.baz()", output: "foo.bar()\n.baz()", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo.\n bar(). baz()", output: "foo.\n bar().baz()", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo.\nbar() . baz()", output: "foo.\nbar().baz()", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo\t[bar]\n\t.baz", output: "foo[bar]\n\t.baz", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo.\tbar\n\t.baz", output: "foo.bar\n\t.baz", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo\t.bar\n.baz", output: "foo.bar\n.baz", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo.\n\tbar.\tbaz", output: "foo.\n\tbar.baz", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo.\nbar\t.\tbaz", output: "foo.\nbar.baz", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo.\tbar()\n\t.baz()", output: "foo.bar()\n\t.baz()", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo\t.bar()\n.baz()", output: "foo.bar()\n.baz()", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo.\n\tbar().\tbaz()", output: "foo.\n\tbar().baz()", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo.\nbar()\t.\tbaz()", output: "foo.\nbar().baz()", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, // parens/computed properties { code: "foo ['bar' + baz]", output: "foo['bar' + baz]", - errors: ["Unexpected whitespace before property 'bar' + baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "'bar' + baz" } + }] }, { code: "(foo + bar) .baz", output: "(foo + bar).baz", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "(foo + bar). baz", output: "(foo + bar).baz", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "(foo + bar) [baz]", output: "(foo + bar)[baz]", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "(foo ? bar : baz) .qux", output: "(foo ? bar : baz).qux", - errors: ["Unexpected whitespace before property qux."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "qux" } + }] }, { code: "(foo ? bar : baz). qux", output: "(foo ? bar : baz).qux", - errors: ["Unexpected whitespace before property qux."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "qux" } + }] }, { code: "(foo ? bar : baz) [qux]", output: "(foo ? bar : baz)[qux]", - errors: ["Unexpected whitespace before property qux."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "qux" } + }] }, { code: "( foo ? bar : baz ) [0].qux", output: "( foo ? bar : baz )[0].qux", - errors: ["Unexpected whitespace before property 0."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "0" } + }] }, { code: "( foo ? bar : baz )[0] .qux", output: "( foo ? bar : baz )[0].qux", - errors: ["Unexpected whitespace before property qux."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "qux" } + }] }, { code: "( foo ? bar : baz )[0]. qux", output: "( foo ? bar : baz )[0].qux", - errors: ["Unexpected whitespace before property qux."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "qux" } + }] }, { code: "( foo ? bar : baz ) [0]. qux", output: "( foo ? bar : baz )[0].qux", - errors: ["Unexpected whitespace before property qux.", "Unexpected whitespace before property 0."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "qux" } + }, { + messageId: "unexpectedWhitespace", + data: { propName: "0" } + }] }, { code: "foo.bar [('baz')]", output: "foo.bar[('baz')]", - errors: ["Unexpected whitespace before property 'baz'."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "'baz'" } + }] }, { code: "foo .bar[('baz')]", output: "foo.bar[('baz')]", - errors: ["Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo .bar [('baz')]", output: "foo.bar[('baz')]", - errors: ["Unexpected whitespace before property 'baz'.", "Unexpected whitespace before property bar."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "'baz'" } + }, { + messageId: "unexpectedWhitespace", + data: { propName: "bar" } + }] }, { code: "foo [(('baz'))]", output: "foo[(('baz'))]", - errors: ["Unexpected whitespace before property 'baz'."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "'baz'" } + }] }, { code: "foo [[baz]]", output: "foo[[baz]]", - errors: ["Unexpected whitespace before property [baz]."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "[baz]" } + }] }, { code: "foo [ [ baz ] ]", output: "foo[ [ baz ] ]", - errors: ["Unexpected whitespace before property [ baz ]."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "[ baz ]" } + }] }, { code: "foo [['baz']]", output: "foo[['baz']]", - errors: ["Unexpected whitespace before property ['baz']."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "['baz']" } + }] }, { code: "foo [ [ 'baz' ] ]", output: "foo[ [ 'baz' ] ]", - errors: ["Unexpected whitespace before property [ 'baz' ]."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "[ 'baz' ]" } + }] }, { code: "foo[0] [[('baz')]]", output: "foo[0][[('baz')]]", - errors: ["Unexpected whitespace before property [('baz')]."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "[('baz')]" } + }] }, { code: "foo [0][[('baz')]]", output: "foo[0][[('baz')]]", - errors: ["Unexpected whitespace before property 0."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "0" } + }] }, { code: "foo [0] [[('baz')]]", output: "foo[0][[('baz')]]", - errors: ["Unexpected whitespace before property [('baz')].", "Unexpected whitespace before property 0."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "[('baz')]" } + }, { + messageId: "unexpectedWhitespace", + data: { propName: "0" } + }] }, { code: "foo [bar.baz('qux')]", output: "foo[bar.baz('qux')]", - errors: ["Unexpected whitespace before property bar.baz('qux')."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar.baz('qux')" } + }] }, { code: "foo[bar .baz('qux')]", output: "foo[bar.baz('qux')]", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo [bar . baz('qux')]", output: "foo[bar.baz('qux')]", - errors: ["Unexpected whitespace before property bar . baz('qux').", "Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "bar . baz('qux')" } + }, { + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo [(bar.baz() + 0) + qux]", output: "foo[(bar.baz() + 0) + qux]", - errors: ["Unexpected whitespace before property (bar.baz() + 0) + qux."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "(bar.baz() + 0) + qux" } + }] }, { code: "foo[(bar. baz() + 0) + qux]", output: "foo[(bar.baz() + 0) + qux]", - errors: ["Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo [(bar. baz() + 0) + qux]", output: "foo[(bar.baz() + 0) + qux]", - errors: ["Unexpected whitespace before property (bar. baz() + 0) + qux.", "Unexpected whitespace before property baz."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "(bar. baz() + 0) + qux" } + }, { + messageId: "unexpectedWhitespace", + data: { propName: "baz" } + }] }, { code: "foo ['bar ' + 1 + ' baz']", output: "foo['bar ' + 1 + ' baz']", - errors: ["Unexpected whitespace before property 'bar ' + 1 + ' baz'."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "'bar ' + 1 + ' baz'" } + }] }, { code: "5 .toExponential()", output: null, // This case is not fixed; can't be sure whether 5..toExponential or (5).toExponential is preferred - errors: ["Unexpected whitespace before property toExponential."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "toExponential" } + }] }, { code: "5 .toExponential()", output: null, // Not fixed - errors: ["Unexpected whitespace before property toExponential."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "toExponential" } + }] }, { code: "5. .toExponential()", output: "5..toExponential()", - errors: ["Unexpected whitespace before property toExponential."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "toExponential" } + }] }, { code: "5.0 .toExponential()", output: "5.0.toExponential()", - errors: ["Unexpected whitespace before property toExponential."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "toExponential" } + }] }, { code: "0x5 .toExponential()", output: "0x5.toExponential()", - errors: ["Unexpected whitespace before property toExponential."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "toExponential" } + }] }, { code: "5e0 .toExponential()", output: "5e0.toExponential()", - errors: ["Unexpected whitespace before property toExponential."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "toExponential" } + }] }, { code: "5e-0 .toExponential()", output: "5e-0.toExponential()", - errors: ["Unexpected whitespace before property toExponential."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "toExponential" } + }] }, { code: "5 ['toExponential']()", output: "5['toExponential']()", - errors: ["Unexpected whitespace before property 'toExponential'."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "'toExponential'" } + }] }, { code: "05 .toExponential()", output: "05.toExponential()", - errors: ["Unexpected whitespace before property toExponential."] + errors: [{ + messageId: "unexpectedWhitespace", + data: { propName: "toExponential" } + }] } ] }); diff --git a/tests/lib/rules/no-with.js b/tests/lib/rules/no-with.js index 448a531c0d3..947686727ab 100644 --- a/tests/lib/rules/no-with.js +++ b/tests/lib/rules/no-with.js @@ -23,6 +23,6 @@ ruleTester.run("no-with", rule, { "foo.bar()" ], invalid: [ - { code: "with(foo) { bar() }", errors: [{ message: "Unexpected use of 'with' statement.", type: "WithStatement" }] } + { code: "with(foo) { bar() }", errors: [{ messageId: "unexpectedWith", type: "WithStatement" }] } ] }); diff --git a/tests/lib/rules/nonblock-statement-body-position.js b/tests/lib/rules/nonblock-statement-body-position.js index bd65ecc5732..b029d9316f8 100644 --- a/tests/lib/rules/nonblock-statement-body-position.js +++ b/tests/lib/rules/nonblock-statement-body-position.js @@ -11,8 +11,8 @@ const rule = require("../../../lib/rules/nonblock-statement-body-position"); const { RuleTester } = require("../../../lib/rule-tester"); -const EXPECTED_LINEBREAK = { message: "Expected a linebreak before this statement." }; -const UNEXPECTED_LINEBREAK = { message: "Expected no linebreak before this statement." }; +const EXPECTED_LINEBREAK = { messageId: "expectLinebreak" }; +const UNEXPECTED_LINEBREAK = { messageId: "expectNoLinebreak" }; //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/rules/object-curly-newline.js b/tests/lib/rules/object-curly-newline.js index 191136617b4..ad3b45218b3 100644 --- a/tests/lib/rules/object-curly-newline.js +++ b/tests/lib/rules/object-curly-newline.js @@ -577,7 +577,7 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), output: "var a = { a};", errors: [ - { line: 2, column: 1, message: "Unexpected line break before this closing brace." } + { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, @@ -592,8 +592,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: ["always"], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 1, column: 10, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 10, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -607,8 +607,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: ["always"], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 1, column: 14, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 14, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -622,8 +622,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: ["always"], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 1, column: 20, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 20, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -639,8 +639,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: ["always"], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 2, column: 9, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 9, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -658,8 +658,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: ["always"], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 3, column: 2, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -672,8 +672,8 @@ ruleTester.run("object-curly-newline", rule, { options: ["always"], parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline"), errors: [ - { line: 1, column: 14, message: "Expected a line break after this opening brace." }, - { line: 1, column: 21, message: "Expected a line break before this closing brace." } + { line: 1, column: 14, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 21, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -686,8 +686,8 @@ ruleTester.run("object-curly-newline", rule, { options: ["always"], parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-singleline-type-literal"), errors: [ - { line: 1, column: 14, message: "Expected a line break after this opening brace." }, - { line: 1, column: 21, message: "Expected a line break before this closing brace." } + { line: 1, column: 14, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 21, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, @@ -702,8 +702,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: ["never"], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 2, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -717,8 +717,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: ["never"], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -732,8 +732,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: ["never"], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -749,8 +749,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: ["never"], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 4, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 4, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -768,8 +768,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: ["never"], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 5, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 5, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -786,8 +786,8 @@ ruleTester.run("object-curly-newline", rule, { options: ["never"], parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline"), errors: [ - { line: 1, column: 14, message: "Unexpected line break after this opening brace." }, - { line: 4, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 14, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 4, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -804,8 +804,8 @@ ruleTester.run("object-curly-newline", rule, { options: ["never"], parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-newline/flow-stub-parser-multiline-type-literal"), errors: [ - { line: 1, column: 14, message: "Unexpected line break after this opening brace." }, - { line: 4, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 14, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 4, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, @@ -820,8 +820,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 2, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -833,8 +833,8 @@ ruleTester.run("object-curly-newline", rule, { output: null, options: [{ multiline: true }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -845,8 +845,8 @@ ruleTester.run("object-curly-newline", rule, { output: null, options: [{ multiline: true }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 2, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -860,8 +860,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -876,8 +876,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -891,8 +891,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -907,8 +907,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -924,8 +924,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 2, column: 9, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 9, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -941,8 +941,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 2, column: 9, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 9, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -960,8 +960,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 3, column: 2, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -979,8 +979,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 3, column: 2, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -997,7 +997,7 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" } ] }, { @@ -1009,7 +1009,7 @@ ruleTester.run("object-curly-newline", rule, { output: null, options: [{ multiline: true }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" } ] }, { @@ -1026,7 +1026,7 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true }], errors: [ - { line: 3, column: 5, message: "Expected a line break before this closing brace." } + { line: 3, column: 5, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, @@ -1041,8 +1041,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ minProperties: 2 }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 2, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1056,8 +1056,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ minProperties: 2 }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1071,8 +1071,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ minProperties: 2 }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 1, column: 20, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 20, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1088,8 +1088,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ minProperties: 2 }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 2, column: 9, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 9, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1107,8 +1107,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ minProperties: 2 }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 5, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 5, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, @@ -1123,8 +1123,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true, minProperties: 2 }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 2, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1138,8 +1138,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true, minProperties: 2 }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." }, - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1153,8 +1153,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true, minProperties: 2 }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 1, column: 20, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 20, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1170,8 +1170,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true, minProperties: 2 }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 2, column: 9, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 9, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1189,8 +1189,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true, minProperties: 2 }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 3, column: 2, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, @@ -1205,7 +1205,7 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true, consistent: true }], errors: [ - { line: 2, column: 1, message: "Unexpected line break before this closing brace." } + { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1218,7 +1218,7 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true, consistent: true }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" } ] }, { @@ -1231,7 +1231,7 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true, consistent: true }], errors: [ - { line: 2, column: 1, message: "Unexpected line break before this closing brace." } + { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1244,7 +1244,7 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true, consistent: true }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" } ] }, { @@ -1260,8 +1260,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true, consistent: true }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 2, column: 5, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 5, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1279,8 +1279,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true, consistent: true }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 3, column: 2, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1294,7 +1294,7 @@ ruleTester.run("object-curly-newline", rule, { options: [{ multiline: true, consistent: true }], parserOptions: { ecmaVersion: 6 }, errors: [ - { line: 2, column: 1, message: "Unexpected line break before this closing brace." } + { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1308,7 +1308,7 @@ ruleTester.run("object-curly-newline", rule, { options: [{ multiline: true, consistent: true }], parserOptions: { ecmaVersion: 6 }, errors: [ - { line: 1, column: 5, message: "Unexpected line break after this opening brace." } + { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" } ] }, { @@ -1322,7 +1322,7 @@ ruleTester.run("object-curly-newline", rule, { options: [{ multiline: true, consistent: true }], parserOptions: { ecmaVersion: 6 }, errors: [ - { line: 2, column: 1, message: "Unexpected line break before this closing brace." } + { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1336,7 +1336,7 @@ ruleTester.run("object-curly-newline", rule, { options: [{ multiline: true, consistent: true }], parserOptions: { ecmaVersion: 6 }, errors: [ - { line: 1, column: 5, message: "Unexpected line break after this opening brace." } + { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" } ] }, { @@ -1353,8 +1353,8 @@ ruleTester.run("object-curly-newline", rule, { options: [{ multiline: true, consistent: true }], parserOptions: { ecmaVersion: 6 }, errors: [ - { line: 1, column: 5, message: "Expected a line break after this opening brace." }, - { line: 2, column: 2, message: "Expected a line break before this closing brace." } + { line: 1, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1373,8 +1373,8 @@ ruleTester.run("object-curly-newline", rule, { options: [{ multiline: true, consistent: true }], parserOptions: { ecmaVersion: 6 }, errors: [ - { line: 1, column: 5, message: "Expected a line break after this opening brace." }, - { line: 3, column: 2, message: "Expected a line break before this closing brace." } + { line: 1, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1389,7 +1389,7 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: false, consistent: true }], errors: [ - { line: 1, column: 9, message: "Unexpected line break after this opening brace." } + { line: 1, column: 9, messageId: "unexpectedLinebreakAfterOpeningBrace" } ] }, { @@ -1404,7 +1404,7 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: false, consistent: true }], errors: [ - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1420,7 +1420,7 @@ ruleTester.run("object-curly-newline", rule, { options: [{ multiline: false, consistent: true }], parserOptions: { ecmaVersion: 6 }, errors: [ - { line: 1, column: 5, message: "Unexpected line break after this opening brace." } + { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" } ] }, { @@ -1436,7 +1436,7 @@ ruleTester.run("object-curly-newline", rule, { options: [{ multiline: false, consistent: true }], parserOptions: { ecmaVersion: 6 }, errors: [ - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, @@ -1452,8 +1452,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ multiline: true, consistent: true, minProperties: 2 }], errors: [ - { line: 1, column: 9, message: "Expected a line break after this opening brace." }, - { line: 1, column: 20, message: "Expected a line break before this closing brace." } + { line: 1, column: 9, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 20, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1472,8 +1472,8 @@ ruleTester.run("object-curly-newline", rule, { options: [{ multiline: true, consistent: true, minProperties: 2 }], parserOptions: { ecmaVersion: 6 }, errors: [ - { line: 1, column: 5, message: "Expected a line break after this opening brace." }, - { line: 1, column: 10, message: "Expected a line break before this closing brace." } + { line: 1, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 10, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, @@ -1492,10 +1492,10 @@ ruleTester.run("object-curly-newline", rule, { options: [{ ObjectExpression: "always", ObjectPattern: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [ - { line: 1, column: 5, message: "Unexpected line break after this opening brace." }, - { line: 3, column: 1, message: "Unexpected line break before this closing brace." }, - { line: 3, column: 5, message: "Expected a line break after this opening brace." }, - { line: 3, column: 16, message: "Expected a line break before this closing brace." } + { line: 1, column: 5, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" }, + { line: 3, column: 5, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 16, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, @@ -1513,8 +1513,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ImportDeclaration: "never" }], errors: [ - { line: 1, column: 8, message: "Unexpected line break after this opening brace." }, - { line: 4, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 8, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 4, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1528,8 +1528,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ImportDeclaration: "always" }], errors: [ - { line: 1, column: 8, message: "Expected a line break after this opening brace." }, - { line: 1, column: 13, message: "Expected a line break before this closing brace." } + { line: 1, column: 8, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 13, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1543,8 +1543,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ImportDeclaration: "always" }], errors: [ - { line: 1, column: 8, message: "Expected a line break after this opening brace." }, - { line: 1, column: 18, message: "Expected a line break before this closing brace." } + { line: 1, column: 8, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 18, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1560,8 +1560,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ImportDeclaration: { multiline: true } }], errors: [ - { line: 1, column: 8, message: "Expected a line break after this opening brace." }, - { line: 2, column: 2, message: "Expected a line break before this closing brace." } + { line: 1, column: 8, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1576,7 +1576,7 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ImportDeclaration: { consistent: true } }], errors: [ - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1589,7 +1589,7 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ImportDeclaration: { consistent: true } }], errors: [ - { line: 2, column: 1, message: "Unexpected line break before this closing brace." } + { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1603,8 +1603,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ImportDeclaration: { minProperties: 2 } }], errors: [ - { line: 1, column: 8, message: "Expected a line break after this opening brace." }, - { line: 1, column: 13, message: "Expected a line break before this closing brace." } + { line: 1, column: 8, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 13, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1618,8 +1618,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ImportDeclaration: { minProperties: 3 } }], errors: [ - { line: 1, column: 8, message: "Unexpected line break after this opening brace." }, - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 8, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1631,8 +1631,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ImportDeclaration: { minProperties: 2 } }], errors: [ - { line: 1, column: 23, message: "Expected a line break after this opening brace." }, - { line: 1, column: 28, message: "Expected a line break before this closing brace." } + { line: 1, column: 23, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 28, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, @@ -1652,8 +1652,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ExportDeclaration: "never" }], errors: [ - { line: 2, column: 8, message: "Unexpected line break after this opening brace." }, - { line: 5, column: 1, message: "Unexpected line break before this closing brace." } + { line: 2, column: 8, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 5, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1667,8 +1667,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ExportDeclaration: "always" }], errors: [ - { line: 1, column: 8, message: "Expected a line break after this opening brace." }, - { line: 1, column: 18, message: "Expected a line break before this closing brace." } + { line: 1, column: 8, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 18, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1684,8 +1684,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ExportDeclaration: { multiline: true } }], errors: [ - { line: 1, column: 8, message: "Expected a line break after this opening brace." }, - { line: 2, column: 2, message: "Expected a line break before this closing brace." } + { line: 1, column: 8, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 2, column: 2, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1700,7 +1700,7 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ExportDeclaration: { consistent: true } }], errors: [ - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1713,7 +1713,7 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ExportDeclaration: { consistent: true } }], errors: [ - { line: 2, column: 1, message: "Unexpected line break before this closing brace." } + { line: 2, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] }, { @@ -1727,8 +1727,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ExportDeclaration: { minProperties: 2 } }], errors: [ - { line: 1, column: 8, message: "Expected a line break after this opening brace." }, - { line: 1, column: 14, message: "Expected a line break before this closing brace." } + { line: 1, column: 8, messageId: "expectedLinebreakAfterOpeningBrace" }, + { line: 1, column: 14, messageId: "expectedLinebreakBeforeClosingBrace" } ] }, { @@ -1742,8 +1742,8 @@ ruleTester.run("object-curly-newline", rule, { ].join("\n"), options: [{ ExportDeclaration: { minProperties: 3 } }], errors: [ - { line: 1, column: 8, message: "Unexpected line break after this opening brace." }, - { line: 3, column: 1, message: "Unexpected line break before this closing brace." } + { line: 1, column: 8, messageId: "unexpectedLinebreakAfterOpeningBrace" }, + { line: 3, column: 1, messageId: "unexpectedLinebreakBeforeClosingBrace" } ] } ] diff --git a/tests/lib/rules/object-curly-spacing.js b/tests/lib/rules/object-curly-spacing.js index 7d068f6e7d6..f603832cb37 100644 --- a/tests/lib/rules/object-curly-spacing.js +++ b/tests/lib/rules/object-curly-spacing.js @@ -187,7 +187,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ImportDeclaration", line: 1, column: 8, @@ -195,7 +196,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 9 }, { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ImportDeclaration", line: 1, column: 12, @@ -211,7 +213,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ImportDeclaration", line: 1, column: 18, @@ -227,7 +230,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ImportDeclaration", line: 1, column: 8, @@ -235,7 +239,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 9 }, { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ImportDeclaration", line: 1, column: 17, @@ -251,7 +256,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ImportDeclaration", line: 1, column: 13, @@ -267,7 +273,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ImportDeclaration", line: 1, column: 16, @@ -284,7 +291,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ImportDeclaration", line: 1, column: 21, @@ -300,7 +308,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ImportDeclaration", line: 1, column: 11, @@ -316,7 +325,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ImportDeclaration", line: 1, column: 11, @@ -332,7 +342,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ImportDeclaration", line: 1, column: 21, @@ -349,7 +360,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ImportDeclaration", line: 1, column: 11, @@ -357,7 +369,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 12 }, { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ImportDeclaration", line: 1, column: 15, @@ -374,7 +387,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ImportDeclaration", line: 1, column: 11, @@ -382,7 +396,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 12 }, { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ImportDeclaration", line: 1, column: 20, @@ -398,7 +413,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ImportDeclaration", line: 1, column: 8, @@ -406,7 +422,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 9 }, { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ImportDeclaration", line: 1, column: 13, @@ -423,7 +440,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ImportDeclaration", line: 1, column: 9, @@ -431,7 +449,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 10 }, { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ImportDeclaration", line: 1, column: 14, @@ -447,7 +466,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ImportDeclaration", line: 1, column: 9, @@ -455,7 +475,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 10 }, { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ImportDeclaration", line: 1, column: 26, @@ -471,7 +492,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ExportNamedDeclaration", line: 2, column: 8, @@ -479,7 +501,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 9 }, { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ExportNamedDeclaration", line: 2, column: 12 @@ -493,7 +516,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ExportNamedDeclaration", line: 2, column: 8, @@ -501,7 +525,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 9 }, { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ExportNamedDeclaration", line: 2, column: 24, @@ -517,7 +542,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ExportNamedDeclaration", line: 2, column: 8, @@ -533,7 +559,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ExportNamedDeclaration", line: 2, column: 9, @@ -541,7 +568,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 10 }, { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ExportNamedDeclaration", line: 2, column: 25, @@ -558,7 +586,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["always", { arraysInObjects: false }], errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 28, @@ -573,7 +602,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["always", { arraysInObjects: false }], errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 54, @@ -590,7 +620,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["always", { objectsInObjects: false }], errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 42, @@ -605,7 +636,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["always", { objectsInObjects: false }], errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 60, @@ -623,7 +655,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 9, @@ -639,7 +672,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 8, @@ -655,7 +689,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 9, @@ -671,7 +706,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ObjectPattern", line: 1, column: 6, @@ -679,7 +715,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 7 }, { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 10, @@ -695,7 +732,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ObjectPattern", line: 1, column: 6, @@ -703,7 +741,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 8 }, { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 11, @@ -719,7 +758,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ObjectPattern", line: 1, column: 6, @@ -727,7 +767,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 9 }, { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 12, @@ -744,7 +785,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never", { objectsInObjects: true }], errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 39, @@ -759,7 +801,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never", { objectsInObjects: true }], errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 55, @@ -776,7 +819,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["always"], errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ObjectExpression", line: 1, column: 11, @@ -784,7 +828,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 12 }, { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 30, @@ -799,7 +844,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["always"], errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ObjectExpression", line: 1, column: 11, @@ -814,7 +860,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["always"], errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ObjectExpression", line: 1, column: 11, @@ -829,7 +876,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["always"], errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ObjectExpression", line: 1, column: 11, @@ -844,7 +892,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["always"], errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 31, @@ -859,7 +908,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["always"], errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 36, @@ -874,7 +924,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ObjectExpression", line: 1, column: 12, @@ -882,7 +933,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 13 }, { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 31, @@ -897,7 +949,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ObjectExpression", line: 1, column: 12, @@ -905,7 +958,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 14 }, { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 32, @@ -920,7 +974,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 30, @@ -935,7 +990,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 30, @@ -950,7 +1006,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 36, @@ -965,7 +1022,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ObjectExpression", line: 1, column: 12, @@ -980,7 +1038,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ObjectExpression", line: 1, column: 12, @@ -995,7 +1054,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ObjectExpression", line: 1, column: 12, @@ -1010,7 +1070,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 2, column: 10, @@ -1025,7 +1086,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ObjectExpression", line: 1, column: 12, @@ -1033,7 +1095,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 13 }, { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ObjectExpression", line: 1, column: 19, @@ -1048,7 +1111,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never"], errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 27, @@ -1056,7 +1120,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 28 }, { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 39, @@ -1072,7 +1137,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ObjectExpression", line: 1, column: 22, @@ -1090,7 +1156,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ObjectPattern", line: 1, column: 5, @@ -1098,7 +1165,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 6 }, { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 10, @@ -1114,7 +1182,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 11, @@ -1130,7 +1199,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 16, @@ -1146,7 +1216,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ObjectPattern", line: 1, column: 5, @@ -1162,7 +1233,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ObjectPattern", line: 1, column: 5, @@ -1178,7 +1250,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ObjectPattern", line: 1, column: 6, @@ -1186,7 +1259,8 @@ ruleTester.run("object-curly-spacing", rule, { endColumn: 7 }, { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 11, @@ -1202,7 +1276,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 10, @@ -1218,7 +1293,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 15, @@ -1234,7 +1310,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "There should be no space after '{'.", + messageId: "unexpectedSpaceAfter", + data: { token: "{" }, type: "ObjectPattern", line: 1, column: 6, @@ -1250,7 +1327,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 11, @@ -1266,7 +1344,8 @@ ruleTester.run("object-curly-spacing", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "A space is required after '{'.", + messageId: "requireSpaceAfter", + data: { token: "{" }, type: "ObjectPattern", line: 1, column: 5, @@ -1283,7 +1362,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never", { arraysInObjects: true }], errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 25, @@ -1298,7 +1378,8 @@ ruleTester.run("object-curly-spacing", rule, { options: ["never", { arraysInObjects: true }], errors: [ { - message: "A space is required before '}'.", + messageId: "requireSpaceBefore", + data: { token: "}" }, type: "ObjectExpression", line: 1, column: 49, @@ -1316,7 +1397,8 @@ ruleTester.run("object-curly-spacing", rule, { parser: resolvePath(__dirname, "../../fixtures/parsers/object-curly-spacing/flow-stub-parser-never-invalid"), errors: [ { - message: "There should be no space before '}'.", + messageId: "unexpectedSpaceBefore", + data: { token: "}" }, type: "ObjectPattern", line: 1, column: 20, diff --git a/tests/lib/rules/object-property-newline.js b/tests/lib/rules/object-property-newline.js index 1d60ee9b2a0..132d7a3e868 100644 --- a/tests/lib/rules/object-property-newline.js +++ b/tests/lib/rules/object-property-newline.js @@ -75,13 +75,13 @@ ruleTester.run("object-property-newline", rule, { output: "var obj = { k1: 'val1',\nk2: 'val2',\nk3: 'val3' };", errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 1, column: 25 }, { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 1, column: 37 @@ -93,7 +93,7 @@ ruleTester.run("object-property-newline", rule, { output: "var obj = {\nk1: 'val1',\nk2: 'val2'\n};", errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 2, column: 13 @@ -105,13 +105,13 @@ ruleTester.run("object-property-newline", rule, { output: "var obj = {\nk1: 'val1',\nk2: 'val2',\nk3: 'val3',\nk4: 'val4'\n};", errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 2, column: 13 }, { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 3, column: 13 @@ -123,7 +123,7 @@ ruleTester.run("object-property-newline", rule, { output: "var obj = {k1: ['foo', 'bar'],\nk2: 'val1'};", errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 1, column: 32 @@ -135,7 +135,7 @@ ruleTester.run("object-property-newline", rule, { output: "var obj = {k1: [\n'foo', 'bar'\n],\nk2: 'val1'};", errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 3, column: 4 @@ -147,19 +147,19 @@ ruleTester.run("object-property-newline", rule, { output: "var obj = {\nk1: 'val1',\nk2: {e1: 'foo',\ne2: 'bar'},\nk3: 'val2'\n};", errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 2, column: 13 }, { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 2, column: 29 }, { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 2, column: 41 @@ -171,7 +171,7 @@ ruleTester.run("object-property-newline", rule, { output: "var obj = {\nk1: 'val1',\nk2: {e1: 'foo',\ne2: 'bar'},\nk3: 'val2'\n};", errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 3, column: 17 @@ -183,7 +183,7 @@ ruleTester.run("object-property-newline", rule, { output: "var obj = { k1: 'val1',\nk2: [\n'val2a', 'val2b', 'val2c'\n],\nk3: 'val3' };", errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 4, column: 4 @@ -196,7 +196,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 1, column: 25 @@ -209,7 +209,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 2018 }, errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 1, column: 25 @@ -222,7 +222,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 2018 }, errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 2, column: 13 @@ -234,7 +234,7 @@ ruleTester.run("object-property-newline", rule, { output: "foo({ k1: 'val1',\nk2: 'val2' });", errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 1, column: 19 @@ -246,7 +246,7 @@ ruleTester.run("object-property-newline", rule, { output: "foo({\nk1: 'val1',\nk2: 'val2'\n});", errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 2, column: 13 @@ -259,7 +259,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 1, column: 10 @@ -272,7 +272,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 2, column: 4 @@ -285,7 +285,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 2, column: 11 @@ -298,7 +298,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 2, column: 15 @@ -311,7 +311,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 1, column: 19 @@ -324,7 +324,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 2018 }, errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 1, column: 19 @@ -337,7 +337,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 2018 }, errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 2, column: 13 @@ -349,7 +349,7 @@ ruleTester.run("object-property-newline", rule, { output: "var obj = {\na: {\nb: 1,\nc: 2\n},\nd: 2\n};", errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 5, column: 4 @@ -361,7 +361,7 @@ ruleTester.run("object-property-newline", rule, { output: "({ foo: 1 /* comment */,\nbar: 2 })", errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 1, column: 26 @@ -373,7 +373,7 @@ ruleTester.run("object-property-newline", rule, { output: null, // not fixed due to comment errors: [ { - message: "Object properties must go on a new line.", + messageId: "propertiesOnNewline", type: "ObjectExpression", line: 1, column: 26 @@ -388,7 +388,7 @@ ruleTester.run("object-property-newline", rule, { options: [{ allowAllPropertiesOnSameLine: true }], errors: [ { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 3, column: 13 @@ -401,13 +401,13 @@ ruleTester.run("object-property-newline", rule, { options: [{ allowAllPropertiesOnSameLine: true }], errors: [ { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 3, column: 9 }, { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 3, column: 21 @@ -420,7 +420,7 @@ ruleTester.run("object-property-newline", rule, { options: [{ allowAllPropertiesOnSameLine: true }], errors: [ { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 4, column: 4 @@ -433,7 +433,7 @@ ruleTester.run("object-property-newline", rule, { options: [{ allowAllPropertiesOnSameLine: true }], errors: [ { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 3, column: 4 @@ -446,13 +446,13 @@ ruleTester.run("object-property-newline", rule, { options: [{ allowAllPropertiesOnSameLine: true }], errors: [ { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 2, column: 13 }, { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 4, column: 4 @@ -465,7 +465,7 @@ ruleTester.run("object-property-newline", rule, { options: [{ allowAllPropertiesOnSameLine: true }], errors: [ { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 4, column: 4 @@ -479,7 +479,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 2, column: 14 @@ -493,7 +493,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 2018 }, errors: [ { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 3, column: 13 @@ -507,7 +507,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 2018 }, errors: [ { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 3, column: 13 @@ -521,7 +521,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 2, column: 14 @@ -535,7 +535,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 2018 }, errors: [ { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 3, column: 13 @@ -549,7 +549,7 @@ ruleTester.run("object-property-newline", rule, { parserOptions: { ecmaVersion: 2018 }, errors: [ { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 3, column: 13 @@ -564,7 +564,7 @@ ruleTester.run("object-property-newline", rule, { options: [{ allowMultiplePropertiesPerLine: true }], errors: [ { - message: "Object properties must go on a new line if they aren't all on the same line.", + messageId: "propertiesOnNewlineAll", type: "ObjectExpression", line: 3, column: 13 diff --git a/tests/lib/rules/object-shorthand.js b/tests/lib/rules/object-shorthand.js index 911df1e3a41..b9b81329f91 100644 --- a/tests/lib/rules/object-shorthand.js +++ b/tests/lib/rules/object-shorthand.js @@ -17,13 +17,13 @@ const { unIndent } = require("../_utils"); // Tests //------------------------------------------------------------------------------ -const PROPERTY_ERROR = { message: "Expected property shorthand.", type: "Property" }; -const METHOD_ERROR = { message: "Expected method shorthand.", type: "Property" }; -const LONGFORM_PROPERTY_ERROR = { message: "Expected longform property syntax.", type: "Property" }; -const LONGFORM_METHOD_ERROR = { message: "Expected longform method syntax.", type: "Property" }; -const LONGFORM_METHOD_STRING_LITERAL_ERROR = { message: "Expected longform method syntax for string literal keys.", type: "Property" }; -const ALL_SHORTHAND_ERROR = { message: "Expected shorthand for all properties.", type: "ObjectExpression" }; -const MIXED_SHORTHAND_ERROR = { message: "Unexpected mix of shorthand and non-shorthand properties.", type: "ObjectExpression" }; +const PROPERTY_ERROR = { messageId: "expectedPropertyShorthand", type: "Property" }; +const METHOD_ERROR = { messageId: "expectedMethodShorthand", type: "Property" }; +const LONGFORM_PROPERTY_ERROR = { messageId: "expectedPropertyLongform", type: "Property" }; +const LONGFORM_METHOD_ERROR = { messageId: "expectedMethodLongform", type: "Property" }; +const LONGFORM_METHOD_STRING_LITERAL_ERROR = { messageId: "expectedLiteralMethodLongform", type: "Property" }; +const ALL_SHORTHAND_ERROR = { messageId: "expectedAllPropertiesShorthanded", type: "ObjectExpression" }; +const MIXED_SHORTHAND_ERROR = { messageId: "unexpectedMix", type: "ObjectExpression" }; const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2018 } }); diff --git a/tests/lib/rules/one-var-declaration-per-line.js b/tests/lib/rules/one-var-declaration-per-line.js index c2faa6603fa..59af6205452 100644 --- a/tests/lib/rules/one-var-declaration-per-line.js +++ b/tests/lib/rules/one-var-declaration-per-line.js @@ -25,7 +25,7 @@ const rule = require("../../../lib/rules/one-var-declaration-per-line"), */ function errorAt(line, column) { return { - message: "Expected variable declaration to be on a new line.", + messageId: "expectVarOnNewline", type: "VariableDeclaration", line, column diff --git a/tests/lib/rules/one-var.js b/tests/lib/rules/one-var.js index 83fe567b7a5..f17c0b3c7d7 100644 --- a/tests/lib/rules/one-var.js +++ b/tests/lib/rules/one-var.js @@ -497,7 +497,8 @@ ruleTester.run("one-var", rule, { output: "function foo() { var bar = true; var baz = false; }", options: ["never"], errors: [{ - message: "Split 'var' declarations into multiple statements.", + messageId: "split", + data: { type: "var" }, type: "VariableDeclaration" }] }, @@ -506,7 +507,8 @@ ruleTester.run("one-var", rule, { output: "function foo() { var bar = true, baz = false; }", options: ["always"], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration" }] }, @@ -515,7 +517,8 @@ ruleTester.run("one-var", rule, { output: null, options: ["always"], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration" }] }, @@ -525,7 +528,8 @@ ruleTester.run("one-var", rule, { options: [{ initialized: "never" }], errors: [ { - message: "Split initialized 'var' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "var" }, type: "VariableDeclaration" } ] @@ -536,7 +540,8 @@ ruleTester.run("one-var", rule, { options: [{ uninitialized: "never" }], errors: [ { - message: "Split uninitialized 'var' declarations into multiple statements.", + messageId: "splitUninitialized", + data: { type: "var" }, type: "VariableDeclaration" } ] @@ -547,7 +552,8 @@ ruleTester.run("one-var", rule, { options: [{ uninitialized: "always", initialized: "never" }], errors: [ { - message: "Combine this with the previous 'var' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "var" }, type: "VariableDeclaration" } ] @@ -558,7 +564,9 @@ ruleTester.run("one-var", rule, { options: [{ uninitialized: "never", initialized: "always" }], errors: [ { - message: "Combine this with the previous 'var' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "var" }, + type: "VariableDeclaration" } ] @@ -569,11 +577,13 @@ ruleTester.run("one-var", rule, { options: [{ uninitialized: "never", initialized: "never" }], errors: [ { - message: "Split 'var' declarations into multiple statements.", + messageId: "split", + data: { type: "var" }, type: "VariableDeclaration" }, { - message: "Split 'var' declarations into multiple statements.", + messageId: "split", + data: { type: "var" }, type: "VariableDeclaration" } ] @@ -584,15 +594,18 @@ ruleTester.run("one-var", rule, { options: [{ uninitialized: "always", initialized: "always" }], errors: [ { - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration" }, { - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration" }, { - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration" } ] @@ -602,7 +615,8 @@ ruleTester.run("one-var", rule, { output: "function foo() { var a = [1, 2, 3], [b, c, d] = a; }", options: ["always"], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration" }] }, @@ -611,7 +625,8 @@ ruleTester.run("one-var", rule, { output: "function foo() { let a = 1, b = 2; }", options: ["always"], errors: [{ - message: "Combine this with the previous 'let' statement.", + messageId: "combine", + data: { type: "let" }, type: "VariableDeclaration" }] }, @@ -620,7 +635,8 @@ ruleTester.run("one-var", rule, { output: "function foo() { const a = 1, b = 2; }", options: ["always"], errors: [{ - message: "Combine this with the previous 'const' statement.", + messageId: "combine", + data: { type: "const" }, type: "VariableDeclaration" }] }, @@ -629,7 +645,8 @@ ruleTester.run("one-var", rule, { output: "function foo() { let a = 1, b = 2; }", options: [{ let: "always" }], errors: [{ - message: "Combine this with the previous 'let' statement.", + messageId: "combine", + data: { type: "let" }, type: "VariableDeclaration" }] }, @@ -638,7 +655,8 @@ ruleTester.run("one-var", rule, { output: "function foo() { const a = 1, b = 2; }", options: [{ const: "always" }], errors: [{ - message: "Combine this with the previous 'const' statement.", + messageId: "combine", + data: { type: "const" }, type: "VariableDeclaration" }] }, @@ -647,7 +665,8 @@ ruleTester.run("one-var", rule, { output: "function foo() { let a = 1; let b = 2; }", options: [{ let: "never" }], errors: [{ - message: "Split 'let' declarations into multiple statements.", + messageId: "split", + data: { type: "let" }, type: "VariableDeclaration" }] }, @@ -656,7 +675,8 @@ ruleTester.run("one-var", rule, { output: "function foo() { let a = 1; let b = 2; }", options: [{ initialized: "never" }], errors: [{ - message: "Split initialized 'let' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "let" }, type: "VariableDeclaration" }] }, @@ -665,7 +685,8 @@ ruleTester.run("one-var", rule, { output: "function foo() { let a; let b; }", options: [{ uninitialized: "never" }], errors: [{ - message: "Split uninitialized 'let' declarations into multiple statements.", + messageId: "splitUninitialized", + data: { type: "let" }, type: "VariableDeclaration" }] }, @@ -674,7 +695,8 @@ ruleTester.run("one-var", rule, { output: "function foo() { const a = 1; const b = 2; }", options: [{ initialized: "never" }], errors: [{ - message: "Split initialized 'const' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "const" }, type: "VariableDeclaration" }] }, @@ -683,7 +705,8 @@ ruleTester.run("one-var", rule, { output: "function foo() { const a = 1; const b = 2; }", options: [{ const: "never" }], errors: [{ - message: "Split 'const' declarations into multiple statements.", + messageId: "split", + data: { type: "const" }, type: "VariableDeclaration" }] }, @@ -692,7 +715,8 @@ ruleTester.run("one-var", rule, { output: null, options: [{ var: "always", let: "always", const: "never" }], errors: [{ - message: "Combine this with the previous 'let' statement.", + messageId: "combine", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 74 @@ -703,7 +727,8 @@ ruleTester.run("one-var", rule, { output: "var one = 1, two = 2,\n three;", options: ["always"], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 2, column: 1 @@ -714,7 +739,8 @@ ruleTester.run("one-var", rule, { output: "var i = [0]; var j;", options: [{ initialized: "never" }], errors: [{ - message: "Split initialized 'var' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "var" }, type: "VariableDeclaration" }] }, @@ -723,7 +749,8 @@ ruleTester.run("one-var", rule, { output: "var i = [0]; var j;", options: [{ uninitialized: "never" }], errors: [{ - message: "Split uninitialized 'var' declarations into multiple statements.", + messageId: "splitUninitialized", + data: { type: "var" }, type: "VariableDeclaration" }] }, @@ -732,7 +759,8 @@ ruleTester.run("one-var", rule, { output: null, options: ["always"], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration" }] }, @@ -741,7 +769,8 @@ ruleTester.run("one-var", rule, { output: null, options: ["always"], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration" }] }, @@ -749,7 +778,8 @@ ruleTester.run("one-var", rule, { code: "var foo = function() { var bar = true; var baz = false; }", output: "var foo = function() { var bar = true, baz = false; }", errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 40 @@ -759,12 +789,14 @@ ruleTester.run("one-var", rule, { code: "function foo() { var bar = true; if (qux) { var baz = false; } else { var quxx = 42; } }", output: null, errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 45 }, { - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 71 @@ -775,7 +807,8 @@ ruleTester.run("one-var", rule, { output: "var foo = () => { var bar = true, baz = false; }", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 35 @@ -785,7 +818,8 @@ ruleTester.run("one-var", rule, { code: "var foo = function() { var bar = true; if (qux) { var baz = false; } }", output: null, errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 51 @@ -795,7 +829,8 @@ ruleTester.run("one-var", rule, { code: "var foo; var bar;", output: "var foo, bar;", errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 10 @@ -806,7 +841,8 @@ ruleTester.run("one-var", rule, { output: "var x = 1; var y = 2; for (var z in foo) {}", options: [{ initialized: "never", uninitialized: "always" }], errors: [{ - message: "Split initialized 'var' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 1 @@ -817,7 +853,8 @@ ruleTester.run("one-var", rule, { output: "var x = 1; var y = 2; for (var z of foo) {}", options: [{ initialized: "never", uninitialized: "always" }], errors: [{ - message: "Split initialized 'var' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 1 @@ -828,7 +865,8 @@ ruleTester.run("one-var", rule, { output: "var x, y; for (var z in foo) {}", options: [{ initialized: "never", uninitialized: "always" }], errors: [{ - message: "Combine this with the previous 'var' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 8 @@ -839,7 +877,8 @@ ruleTester.run("one-var", rule, { output: "var x, y; for (var z of foo) {}", options: [{ initialized: "never", uninitialized: "always" }], errors: [{ - message: "Combine this with the previous 'var' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 8 @@ -850,7 +889,8 @@ ruleTester.run("one-var", rule, { output: "var x; for (var y in foo) {var bar = y, a; for (var z of bar) {}}", options: [{ initialized: "never", uninitialized: "always" }], errors: [{ - message: "Combine this with the previous 'var' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 41 @@ -861,7 +901,8 @@ ruleTester.run("one-var", rule, { output: "var a = 1; var b = 2; var x, y; for (var z of foo) {var c = 3; var baz = z; for (var d in baz) {}}", options: [{ initialized: "never", uninitialized: "always" }], errors: [{ - message: "Split initialized 'var' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 53 @@ -873,7 +914,8 @@ ruleTester.run("one-var", rule, { options: [{ initialized: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Split initialized 'var' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 1 @@ -885,7 +927,8 @@ ruleTester.run("one-var", rule, { options: [{ initialized: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Split initialized 'const' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 1 @@ -896,7 +939,8 @@ ruleTester.run("one-var", rule, { output: "var foo = 1;\n var bar = 2;", options: [{ initialized: "never" }], errors: [{ - message: "Split initialized 'var' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 1 @@ -907,7 +951,8 @@ ruleTester.run("one-var", rule, { output: "var foo = 1; // comment\n var bar = 2;", options: [{ initialized: "never" }], errors: [{ - message: "Split initialized 'var' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 1 @@ -918,7 +963,8 @@ ruleTester.run("one-var", rule, { output: "var f; var k /* test */; var l;", options: ["never"], errors: [{ - message: "Split 'var' declarations into multiple statements.", + messageId: "split", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 1 @@ -929,7 +975,8 @@ ruleTester.run("one-var", rule, { output: "var f; /* test */ var l;", options: ["never"], errors: [{ - message: "Split 'var' declarations into multiple statements.", + messageId: "split", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 1 @@ -940,7 +987,8 @@ ruleTester.run("one-var", rule, { output: "var f; var k /* test \n some more comment \n even more */; var l = 1; var P;", options: ["never"], errors: [{ - message: "Split 'var' declarations into multiple statements.", + messageId: "split", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 1 @@ -951,7 +999,8 @@ ruleTester.run("one-var", rule, { output: "var a = 1; var b = 2", options: ["never"], errors: [{ - message: "Split 'var' declarations into multiple statements.", + messageId: "split", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 1 @@ -962,7 +1011,7 @@ ruleTester.run("one-var", rule, { output: null, options: [{ separateRequires: true, var: "always" }], errors: [{ - message: "Split requires to be separated into a single block.", + messageId: "splitRequires", type: "VariableDeclaration", line: 1, column: 1 @@ -973,7 +1022,7 @@ ruleTester.run("one-var", rule, { output: null, options: [{ separateRequires: true, var: "always" }], errors: [{ - message: "Split requires to be separated into a single block.", + messageId: "splitRequires", type: "VariableDeclaration", line: 1, column: 1 @@ -984,7 +1033,7 @@ ruleTester.run("one-var", rule, { output: null, options: [{ separateRequires: true, let: "always" }], errors: [{ - message: "Split requires to be separated into a single block.", + messageId: "splitRequires", type: "VariableDeclaration", line: 1, column: 1 @@ -995,7 +1044,7 @@ ruleTester.run("one-var", rule, { output: null, options: [{ separateRequires: true, const: "always" }], errors: [{ - message: "Split requires to be separated into a single block.", + messageId: "splitRequires", type: "VariableDeclaration", line: 1, column: 1 @@ -1006,7 +1055,8 @@ ruleTester.run("one-var", rule, { output: "const foo = require('foo'), bar = require('bar');", options: [{ separateRequires: true, const: "always" }], errors: [{ - message: "Combine this with the previous 'const' statement.", + messageId: "combine", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 29 @@ -1019,7 +1069,8 @@ ruleTester.run("one-var", rule, { output: "var a = 1, b, c;", options: ["consecutive"], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 15 @@ -1030,7 +1081,8 @@ ruleTester.run("one-var", rule, { output: "var a = 0, b = 1, c = 2;", options: ["consecutive"], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 19 @@ -1042,7 +1094,8 @@ ruleTester.run("one-var", rule, { options: ["consecutive"], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement.", + messageId: "combine", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 15 @@ -1054,7 +1107,8 @@ ruleTester.run("one-var", rule, { options: ["consecutive"], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement.", + messageId: "combine", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 19 @@ -1066,7 +1120,8 @@ ruleTester.run("one-var", rule, { options: ["consecutive"], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'const' statement.", + messageId: "combine", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 21 @@ -1078,7 +1133,8 @@ ruleTester.run("one-var", rule, { options: ["consecutive"], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 25 @@ -1089,7 +1145,8 @@ ruleTester.run("one-var", rule, { output: "var a = true, b = false;", options: [{ separateRequires: true, var: "always" }], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 15 @@ -1101,7 +1158,8 @@ ruleTester.run("one-var", rule, { options: ["consecutive"], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement.", + messageId: "combine", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 25 @@ -1113,7 +1171,8 @@ ruleTester.run("one-var", rule, { options: ["consecutive"], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'const' statement.", + messageId: "combine", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 25 @@ -1124,7 +1183,8 @@ ruleTester.run("one-var", rule, { output: "var a = 0; var b, c; var d = 1", options: [{ initialized: "consecutive", uninitialized: "always" }], errors: [{ - message: "Combine this with the previous 'var' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 19 @@ -1135,13 +1195,15 @@ ruleTester.run("one-var", rule, { output: "var a = 0, b = 1; var c, d;", options: [{ initialized: "consecutive", uninitialized: "always" }], errors: [{ - message: "Combine this with the previous 'var' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 12 }, { - message: "Combine this with the previous 'var' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 30 @@ -1153,7 +1215,8 @@ ruleTester.run("one-var", rule, { options: [{ initialized: "consecutive", uninitialized: "always" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 19 @@ -1165,13 +1228,15 @@ ruleTester.run("one-var", rule, { options: [{ initialized: "consecutive", uninitialized: "always" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 12 }, { - message: "Combine this with the previous 'let' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 30 @@ -1183,7 +1248,8 @@ ruleTester.run("one-var", rule, { options: [{ initialized: "consecutive", uninitialized: "always" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 21 @@ -1195,13 +1261,14 @@ ruleTester.run("one-var", rule, { options: [{ initialized: "consecutive", uninitialized: "always" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'const' statement with initialized variables.", + messageId: "combineInitialized", type: "VariableDeclaration", line: 1, column: 14 }, { - message: "Combine this with the previous 'let' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 34 @@ -1212,13 +1279,15 @@ ruleTester.run("one-var", rule, { output: "var a = 0, b = 1; var c; var d;", options: [{ initialized: "consecutive", uninitialized: "never" }], errors: [{ - message: "Combine this with the previous 'var' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 12 }, { - message: "Split uninitialized 'var' declarations into multiple statements.", + messageId: "splitUninitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 23 @@ -1229,7 +1298,8 @@ ruleTester.run("one-var", rule, { output: "var a = 0; var b; var c; var d = 1;", options: [{ initialized: "consecutive", uninitialized: "never" }], errors: [{ - message: "Split uninitialized 'var' declarations into multiple statements.", + messageId: "splitUninitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 12 @@ -1241,13 +1311,15 @@ ruleTester.run("one-var", rule, { options: [{ initialized: "consecutive", uninitialized: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 12 }, { - message: "Split uninitialized 'let' declarations into multiple statements.", + messageId: "splitUninitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 23 @@ -1259,7 +1331,8 @@ ruleTester.run("one-var", rule, { options: [{ initialized: "consecutive", uninitialized: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Split uninitialized 'let' declarations into multiple statements.", + messageId: "splitUninitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 12 @@ -1271,13 +1344,15 @@ ruleTester.run("one-var", rule, { options: [{ initialized: "consecutive", uninitialized: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'const' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 14 }, { - message: "Split uninitialized 'let' declarations into multiple statements.", + messageId: "splitUninitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 27 @@ -1289,7 +1364,8 @@ ruleTester.run("one-var", rule, { options: [{ initialized: "consecutive", uninitialized: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Split uninitialized 'let' declarations into multiple statements.", + messageId: "splitUninitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 14 @@ -1300,13 +1376,15 @@ ruleTester.run("one-var", rule, { output: "var a, b; var c = 0, d = 1;", options: [{ uninitialized: "consecutive", initialized: "always" }], errors: [{ - message: "Combine this with the previous 'var' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 8 }, { - message: "Combine this with the previous 'var' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 26 @@ -1317,7 +1395,8 @@ ruleTester.run("one-var", rule, { output: "var a; var b = 0, c = 1; var d;", options: [{ uninitialized: "consecutive", initialized: "always" }], errors: [{ - message: "Combine this with the previous 'var' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 19 @@ -1329,13 +1408,15 @@ ruleTester.run("one-var", rule, { options: [{ uninitialized: "consecutive", initialized: "always" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 8 }, { - message: "Combine this with the previous 'let' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 26 @@ -1347,7 +1428,8 @@ ruleTester.run("one-var", rule, { options: [{ uninitialized: "consecutive", initialized: "always" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 19 @@ -1359,13 +1441,15 @@ ruleTester.run("one-var", rule, { options: [{ uninitialized: "consecutive", initialized: "always" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 8 }, { - message: "Combine this with the previous 'const' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 28 @@ -1377,7 +1461,8 @@ ruleTester.run("one-var", rule, { options: [{ uninitialized: "consecutive", initialized: "always" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'const' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 21 @@ -1388,13 +1473,15 @@ ruleTester.run("one-var", rule, { output: "var a, b; var c = 0; var d = 1;", options: [{ uninitialized: "consecutive", initialized: "never" }], errors: [{ - message: "Combine this with the previous 'var' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 8 }, { - message: "Split initialized 'var' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 15 @@ -1405,7 +1492,8 @@ ruleTester.run("one-var", rule, { output: "var a; var b = 0; var c = 1; var d;", options: [{ uninitialized: "consecutive", initialized: "never" }], errors: [{ - message: "Split initialized 'var' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 8 @@ -1417,13 +1505,15 @@ ruleTester.run("one-var", rule, { options: [{ uninitialized: "consecutive", initialized: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 8 }, { - message: "Split initialized 'let' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 15 @@ -1435,7 +1525,8 @@ ruleTester.run("one-var", rule, { options: [{ uninitialized: "consecutive", initialized: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Split initialized 'let' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 8 @@ -1447,13 +1538,15 @@ ruleTester.run("one-var", rule, { options: [{ uninitialized: "consecutive", initialized: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement with uninitialized variables.", + messageId: "combineUninitialized", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 8 }, { - message: "Split initialized 'const' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 15 @@ -1465,7 +1558,8 @@ ruleTester.run("one-var", rule, { options: [{ uninitialized: "consecutive", initialized: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Split initialized 'const' declarations into multiple statements.", + messageId: "splitInitialized", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 8 @@ -1476,7 +1570,8 @@ ruleTester.run("one-var", rule, { output: "var a = 0, b = 1;", options: [{ var: "consecutive" }], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 12 @@ -1488,7 +1583,8 @@ ruleTester.run("one-var", rule, { options: [{ let: "consecutive" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement.", + messageId: "combine", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 12 @@ -1500,7 +1596,8 @@ ruleTester.run("one-var", rule, { options: [{ const: "consecutive" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'const' statement.", + messageId: "combine", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 14 @@ -1512,13 +1609,15 @@ ruleTester.run("one-var", rule, { options: [{ let: "consecutive", const: "always" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement.", + messageId: "combine", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 8 }, { - message: "Combine this with the previous 'const' statement.", + messageId: "combine", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 28 @@ -1530,7 +1629,8 @@ ruleTester.run("one-var", rule, { options: [{ let: "consecutive", const: "always" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'const' statement.", + messageId: "combine", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 21 @@ -1542,13 +1642,15 @@ ruleTester.run("one-var", rule, { options: [{ let: "consecutive", const: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement.", + messageId: "combine", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 8 }, { - message: "Split 'const' declarations into multiple statements.", + messageId: "split", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 15 @@ -1560,7 +1662,8 @@ ruleTester.run("one-var", rule, { options: [{ let: "consecutive", const: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Split 'const' declarations into multiple statements.", + messageId: "split", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 8 @@ -1572,13 +1675,15 @@ ruleTester.run("one-var", rule, { options: [{ const: "consecutive", let: "always" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'const' statement.", + messageId: "combine", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 14 }, { - message: "Combine this with the previous 'let' statement.", + messageId: "combine", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 34 @@ -1590,7 +1695,8 @@ ruleTester.run("one-var", rule, { options: [{ const: "consecutive", let: "always" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement.", + messageId: "combine", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 21 @@ -1602,13 +1708,15 @@ ruleTester.run("one-var", rule, { options: [{ const: "consecutive", let: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'const' statement.", + messageId: "combine", + data: { type: "const" }, type: "VariableDeclaration", line: 1, column: 14 }, { - message: "Split 'let' declarations into multiple statements.", + messageId: "split", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 27 @@ -1620,7 +1728,8 @@ ruleTester.run("one-var", rule, { options: [{ const: "consecutive", let: "never" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Split 'let' declarations into multiple statements.", + messageId: "split", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 14 @@ -1631,7 +1740,8 @@ ruleTester.run("one-var", rule, { output: "var bar, baz;", options: ["consecutive"], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 10 @@ -1642,13 +1752,15 @@ ruleTester.run("one-var", rule, { output: "var bar = 1, baz = 2; qux(); var qux = 3, quux;", options: ["consecutive"], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 14 }, { - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 47 @@ -1660,13 +1772,15 @@ ruleTester.run("one-var", rule, { options: [{ var: "never", let: "consecutive", const: "consecutive" }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Combine this with the previous 'let' statement.", + messageId: "combine", + data: { type: "let" }, type: "VariableDeclaration", line: 1, column: 11 }, { - message: "Split 'var' declarations into multiple statements.", + messageId: "split", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 18 @@ -1677,7 +1791,8 @@ ruleTester.run("one-var", rule, { output: "var a, b;", options: [{ var: "consecutive" }], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 8 @@ -1688,19 +1803,22 @@ ruleTester.run("one-var", rule, { output: "var a = 1, b = 2; var c; var d; var e = 3, f = 4;", options: [{ initialized: "consecutive", uninitialized: "never" }], errors: [{ - message: "Combine this with the previous 'var' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 12 }, { - message: "Split uninitialized 'var' declarations into multiple statements.", + messageId: "splitUninitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 23 }, { - message: "Combine this with the previous 'var' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 44 @@ -1711,13 +1829,15 @@ ruleTester.run("one-var", rule, { output: "var a = 1, b = 2; foo(); var c = 3, d = 4;", options: [{ initialized: "consecutive" }], errors: [{ - message: "Combine this with the previous 'var' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 12 }, { - message: "Combine this with the previous 'var' statement with initialized variables.", + messageId: "combineInitialized", + data: { type: "var" }, type: "VariableDeclaration", line: 1, column: 41 @@ -1728,7 +1848,8 @@ ruleTester.run("one-var", rule, { output: "var a,\n b", options: ["always"], errors: [{ - message: "Combine this with the previous 'var' statement.", + messageId: "combine", + data: { type: "var" }, type: "VariableDeclaration", line: 2, column: 1 diff --git a/tests/lib/rules/operator-linebreak.js b/tests/lib/rules/operator-linebreak.js index ec618c597ca..780083ccc24 100644 --- a/tests/lib/rules/operator-linebreak.js +++ b/tests/lib/rules/operator-linebreak.js @@ -8,15 +8,9 @@ // Requirements //------------------------------------------------------------------------------ -const util = require("util"); const rule = require("../../../lib/rules/operator-linebreak"), { RuleTester } = require("../../../lib/rule-tester"); -const BAD_LN_BRK_MSG = "Bad line breaking before and after '%s'.", - BEFORE_MSG = "'%s' should be placed at the beginning of the line.", - AFTER_MSG = "'%s' should be placed at the end of the line.", - NONE_MSG = "There should be no line break before or after '%s'."; - //------------------------------------------------------------------------------ // Tests //------------------------------------------------------------------------------ @@ -71,7 +65,8 @@ ruleTester.run("operator-linebreak", rule, { code: "1\n+ 1", output: "1 +\n1", errors: [{ - message: util.format(AFTER_MSG, "+"), + messageId: "operatorAtEnd", + data: { operator: "+" }, type: "BinaryExpression", line: 2, column: 2 @@ -81,7 +76,8 @@ ruleTester.run("operator-linebreak", rule, { code: "1 + 2 \n + 3", output: "1 + 2 + \n 3", errors: [{ - message: util.format(AFTER_MSG, "+"), + messageId: "operatorAtEnd", + data: { operator: "+" }, type: "BinaryExpression", line: 2, column: 3 @@ -91,7 +87,8 @@ ruleTester.run("operator-linebreak", rule, { code: "1\n+\n1", output: "1+\n1", errors: [{ - message: util.format(BAD_LN_BRK_MSG, "+"), + messageId: "badLinebreak", + data: { operator: "+" }, type: "BinaryExpression", line: 2, column: 2 @@ -101,7 +98,8 @@ ruleTester.run("operator-linebreak", rule, { code: "1 + (1\n+ 1)", output: "1 + (1 +\n1)", errors: [{ - message: util.format(AFTER_MSG, "+"), + messageId: "operatorAtEnd", + data: { operator: "+" }, type: "BinaryExpression", line: 2, column: 2 @@ -111,7 +109,8 @@ ruleTester.run("operator-linebreak", rule, { code: "f(1\n+ 1);", output: "f(1 +\n1);", errors: [{ - message: util.format(AFTER_MSG, "+"), + messageId: "operatorAtEnd", + data: { operator: "+" }, type: "BinaryExpression", line: 2, column: 2 @@ -121,7 +120,8 @@ ruleTester.run("operator-linebreak", rule, { code: "1 \n || 1", output: "1 || \n 1", errors: [{ - message: util.format(AFTER_MSG, "||"), + messageId: "operatorAtEnd", + data: { operator: "||" }, type: "LogicalExpression", line: 2, column: 4 @@ -131,7 +131,8 @@ ruleTester.run("operator-linebreak", rule, { code: "a\n += 1", output: "a +=\n 1", errors: [{ - message: util.format(AFTER_MSG, "+="), + messageId: "operatorAtEnd", + data: { operator: "+=" }, type: "AssignmentExpression", line: 2, column: 4 @@ -141,7 +142,8 @@ ruleTester.run("operator-linebreak", rule, { code: "var a\n = 1", output: "var a =\n 1", errors: [{ - message: util.format(AFTER_MSG, "="), + messageId: "operatorAtEnd", + data: { operator: "=" }, type: "VariableDeclarator", line: 2, column: 3 @@ -151,7 +153,8 @@ ruleTester.run("operator-linebreak", rule, { code: "(b)\n*\n(c)", output: "(b)*\n(c)", errors: [{ - message: util.format(BAD_LN_BRK_MSG, "*"), + messageId: "badLinebreak", + data: { operator: "*" }, type: "BinaryExpression", line: 2, column: 2 @@ -161,13 +164,15 @@ ruleTester.run("operator-linebreak", rule, { code: "answer = everything ?\n 42 :\n foo;", output: "answer = everything\n ? 42\n : foo;", errors: [{ - message: util.format(BEFORE_MSG, "?"), + messageId: "operatorAtBeginning", + data: { operator: "?" }, type: "ConditionalExpression", line: 1, column: 22 }, { - message: util.format(BEFORE_MSG, ":"), + messageId: "operatorAtBeginning", + data: { operator: ":" }, type: "ConditionalExpression", line: 2, column: 7 @@ -179,13 +184,15 @@ ruleTester.run("operator-linebreak", rule, { output: "answer = everything ? \n42 : \nfoo;", options: ["after"], errors: [{ - message: util.format(AFTER_MSG, "?"), + messageId: "operatorAtEnd", + data: { operator: "?" }, type: "ConditionalExpression", line: 2, column: 2 }, { - message: util.format(AFTER_MSG, ":"), + messageId: "operatorAtEnd", + data: { operator: ":" }, type: "ConditionalExpression", line: 3, column: 2 @@ -197,7 +204,8 @@ ruleTester.run("operator-linebreak", rule, { output: "1\n+ 1", options: ["before"], errors: [{ - message: util.format(BEFORE_MSG, "+"), + messageId: "operatorAtBeginning", + data: { operator: "+" }, type: "BinaryExpression", line: 1, column: 4 @@ -208,7 +216,8 @@ ruleTester.run("operator-linebreak", rule, { output: "f(1\n+ 1);", options: ["before"], errors: [{ - message: util.format(BEFORE_MSG, "+"), + messageId: "operatorAtBeginning", + data: { operator: "+" }, type: "BinaryExpression", line: 1, column: 6 @@ -219,7 +228,8 @@ ruleTester.run("operator-linebreak", rule, { output: "1 \n || 1", options: ["before"], errors: [{ - message: util.format(BEFORE_MSG, "||"), + messageId: "operatorAtBeginning", + data: { operator: "||" }, type: "LogicalExpression", line: 1, column: 5 @@ -230,7 +240,8 @@ ruleTester.run("operator-linebreak", rule, { output: "a \n+= 1", options: ["before"], errors: [{ - message: util.format(BEFORE_MSG, "+="), + messageId: "operatorAtBeginning", + data: { operator: "+=" }, type: "AssignmentExpression", line: 1, column: 5 @@ -241,7 +252,8 @@ ruleTester.run("operator-linebreak", rule, { output: "var a \n= 1", options: ["before"], errors: [{ - message: util.format(BEFORE_MSG, "="), + messageId: "operatorAtBeginning", + data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 8 @@ -252,13 +264,15 @@ ruleTester.run("operator-linebreak", rule, { output: "answer = everything\n ? 42\n : foo;", options: ["before"], errors: [{ - message: util.format(BEFORE_MSG, "?"), + messageId: "operatorAtBeginning", + data: { operator: "?" }, type: "ConditionalExpression", line: 1, column: 22 }, { - message: util.format(BEFORE_MSG, ":"), + messageId: "operatorAtBeginning", + data: { operator: ":" }, type: "ConditionalExpression", line: 2, column: 7 @@ -270,7 +284,8 @@ ruleTester.run("operator-linebreak", rule, { output: "1 +1", options: ["none"], errors: [{ - message: util.format(NONE_MSG, "+"), + messageId: "noLinebreak", + data: { operator: "+" }, type: "BinaryExpression", line: 1, column: 4 @@ -281,7 +296,8 @@ ruleTester.run("operator-linebreak", rule, { output: "1+1", options: ["none"], errors: [{ - message: util.format(NONE_MSG, "+"), + messageId: "noLinebreak", + data: { operator: "+" }, type: "BinaryExpression", line: 2, column: 2 @@ -292,7 +308,8 @@ ruleTester.run("operator-linebreak", rule, { output: "f(1 +1);", options: ["none"], errors: [{ - message: util.format(NONE_MSG, "+"), + messageId: "noLinebreak", + data: { operator: "+" }, type: "BinaryExpression", line: 1, column: 6 @@ -303,7 +320,8 @@ ruleTester.run("operator-linebreak", rule, { output: "f(1+ 1);", options: ["none"], errors: [{ - message: util.format(NONE_MSG, "+"), + messageId: "noLinebreak", + data: { operator: "+" }, type: "BinaryExpression", line: 2, column: 2 @@ -314,7 +332,8 @@ ruleTester.run("operator-linebreak", rule, { output: "1 || 1", options: ["none"], errors: [{ - message: util.format(NONE_MSG, "||"), + messageId: "noLinebreak", + data: { operator: "||" }, type: "LogicalExpression", line: 1, column: 5 @@ -325,7 +344,8 @@ ruleTester.run("operator-linebreak", rule, { output: "1 || 1", options: ["none"], errors: [{ - message: util.format(NONE_MSG, "||"), + messageId: "noLinebreak", + data: { operator: "||" }, type: "LogicalExpression", line: 2, column: 4 @@ -336,7 +356,8 @@ ruleTester.run("operator-linebreak", rule, { output: "a += 1", options: ["none"], errors: [{ - message: util.format(NONE_MSG, "+="), + messageId: "noLinebreak", + data: { operator: "+=" }, type: "AssignmentExpression", line: 1, column: 5 @@ -347,7 +368,8 @@ ruleTester.run("operator-linebreak", rule, { output: "a += 1", options: ["none"], errors: [{ - message: util.format(NONE_MSG, "+="), + messageId: "noLinebreak", + data: { operator: "+=" }, type: "AssignmentExpression", line: 2, column: 3 @@ -358,7 +380,8 @@ ruleTester.run("operator-linebreak", rule, { output: "var a = 1", options: ["none"], errors: [{ - message: util.format(NONE_MSG, "="), + messageId: "noLinebreak", + data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 8 @@ -369,7 +392,8 @@ ruleTester.run("operator-linebreak", rule, { output: "var a = 1", options: ["none"], errors: [{ - message: util.format(NONE_MSG, "="), + messageId: "noLinebreak", + data: { operator: "=" }, type: "VariableDeclarator", line: 2, column: 3 @@ -380,13 +404,15 @@ ruleTester.run("operator-linebreak", rule, { output: "answer = everything ? 42 : foo;", options: ["none"], errors: [{ - message: util.format(NONE_MSG, "?"), + messageId: "noLinebreak", + data: { operator: "?" }, type: "ConditionalExpression", line: 1, column: 22 }, { - message: util.format(NONE_MSG, ":"), + messageId: "noLinebreak", + data: { operator: ":" }, type: "ConditionalExpression", line: 3, column: 2 @@ -397,13 +423,15 @@ ruleTester.run("operator-linebreak", rule, { output: "answer = everything?42 + 43:foo;", options: ["none"], errors: [{ - message: util.format(BAD_LN_BRK_MSG, "?"), + messageId: "badLinebreak", + data: { operator: "?" }, type: "ConditionalExpression", line: 2, column: 2 }, { - message: util.format(BAD_LN_BRK_MSG, ":"), + messageId: "badLinebreak", + data: { operator: ":" }, type: "ConditionalExpression", line: 4, column: 2 @@ -414,7 +442,8 @@ ruleTester.run("operator-linebreak", rule, { output: "foo +=42;\nbar -=\n12\n+ 5;", options: ["after", { overrides: { "+=": "none", "+": "before" } }], errors: [{ - message: util.format(NONE_MSG, "+="), + messageId: "noLinebreak", + data: { operator: "+=" }, type: "AssignmentExpression", line: 1, column: 7 @@ -425,7 +454,8 @@ ruleTester.run("operator-linebreak", rule, { output: "answer = everything\n?\n42\n:foo;", options: ["after", { overrides: { "?": "ignore", ":": "before" } }], errors: [{ - message: util.format(BAD_LN_BRK_MSG, ":"), + messageId: "badLinebreak", + data: { operator: ":" }, type: "ConditionalExpression", line: 4, column: 2 @@ -437,34 +467,70 @@ ruleTester.run("operator-linebreak", rule, { code: "foo+\n+bar", output: "foo\n+ +bar", options: ["before"], - errors: [{ message: util.format(BEFORE_MSG, "+"), type: "BinaryExpression", line: 1, column: 5 }] + errors: [{ + messageId: "operatorAtBeginning", + data: { operator: "+" }, + type: "BinaryExpression", + line: 1, + column: 5 + }] }, { code: "foo //comment\n&& bar", output: "foo && //comment\nbar", - errors: [{ message: util.format(AFTER_MSG, "&&"), type: "LogicalExpression", line: 2, column: 3 }] + errors: [{ + messageId: "operatorAtEnd", + data: { operator: "&&" }, + type: "LogicalExpression", + line: 2, + column: 3 + }] }, { code: "foo//comment\n+\nbar", output: null, - errors: [{ message: util.format(BAD_LN_BRK_MSG, "+"), type: "BinaryExpression", line: 2, column: 2 }] + errors: [{ + messageId: "badLinebreak", + data: { operator: "+" }, + type: "BinaryExpression", + line: 2, + column: 2 + }] }, { code: "foo\n+//comment\nbar", output: null, options: ["before"], - errors: [{ message: util.format(BAD_LN_BRK_MSG, "+"), type: "BinaryExpression", line: 2, column: 2 }] + errors: [{ + messageId: "badLinebreak", + data: { operator: "+" }, + type: "BinaryExpression", + line: 2, + column: 2 + }] }, { code: "foo /* a */ \n+ /* b */ bar", output: null, // Not fixed because there is a comment on both sides - errors: [{ message: util.format(AFTER_MSG, "+"), type: "BinaryExpression", line: 2, column: 2 }] + errors: [{ + messageId: "operatorAtEnd", + data: { operator: "+" }, + type: "BinaryExpression", + line: 2, + column: 2 + }] }, { code: "foo /* a */ +\n /* b */ bar", output: null, // Not fixed because there is a comment on both sides options: ["before"], - errors: [{ message: util.format(BEFORE_MSG, "+"), type: "BinaryExpression", line: 1, column: 14 }] + errors: [{ + messageId: "operatorAtBeginning", + data: { operator: "+" }, + type: "BinaryExpression", + line: 1, + column: 14 + }] } ] }); diff --git a/tests/lib/rules/padded-blocks.js b/tests/lib/rules/padded-blocks.js index 6dfe30ecb37..99d2e0a53e2 100644 --- a/tests/lib/rules/padded-blocks.js +++ b/tests/lib/rules/padded-blocks.js @@ -16,9 +16,7 @@ const rule = require("../../../lib/rules/padded-blocks"), // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(), - ALWAYS_MESSAGE = "Block must be padded by blank lines.", - NEVER_MESSAGE = "Block must not be padded by blank lines."; +const ruleTester = new RuleTester(); ruleTester.run("padded-blocks", rule, { valid: [ @@ -95,7 +93,7 @@ ruleTester.run("padded-blocks", rule, { output: "{\n\n//comment\na();\n\n}", errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1, column: 1 } @@ -106,7 +104,7 @@ ruleTester.run("padded-blocks", rule, { output: "{ //comment\n\na();\n\n}", errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1, column: 3 } @@ -117,7 +115,7 @@ ruleTester.run("padded-blocks", rule, { output: "{\n\na();\n//comment\n\n}", errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 5, column: 1 } @@ -128,7 +126,7 @@ ruleTester.run("padded-blocks", rule, { output: "{\n\na()\n//comment\n\n}", errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 5, column: 1 } @@ -139,7 +137,7 @@ ruleTester.run("padded-blocks", rule, { output: "{\n\na();\n\n}", errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1 } ] @@ -149,7 +147,7 @@ ruleTester.run("padded-blocks", rule, { output: "{\n\na();\n\n}", errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 4 } ] @@ -159,11 +157,11 @@ ruleTester.run("padded-blocks", rule, { output: "{\n\na();\n\n}", errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1 }, { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 3 } ] @@ -173,11 +171,11 @@ ruleTester.run("padded-blocks", rule, { output: "{\n\r\na();\r\n\n}", errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1 }, { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 3 } ] @@ -187,11 +185,11 @@ ruleTester.run("padded-blocks", rule, { output: "{\n\na();\n}", errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1 }, { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 2 } ] @@ -201,11 +199,11 @@ ruleTester.run("padded-blocks", rule, { output: "{\na();\n\n}", errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1 }, { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 2 } ] @@ -216,11 +214,11 @@ ruleTester.run("padded-blocks", rule, { options: [{ blocks: "always" }], errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1 }, { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 2 } ] @@ -231,12 +229,12 @@ ruleTester.run("padded-blocks", rule, { options: ["always"], errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1, column: 12 }, { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 4, column: 1 } @@ -248,12 +246,12 @@ ruleTester.run("padded-blocks", rule, { options: [{ switches: "always" }], errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1, column: 12 }, { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 4, column: 1 } @@ -265,12 +263,12 @@ ruleTester.run("padded-blocks", rule, { options: [{ switches: "always" }], errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1, column: 12 }, { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 4, column: 1 } @@ -283,12 +281,12 @@ ruleTester.run("padded-blocks", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1, column: 9 }, { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 3, column: 1 } @@ -301,12 +299,12 @@ ruleTester.run("padded-blocks", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1, column: 9 }, { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 3, column: 1 } @@ -317,11 +315,11 @@ ruleTester.run("padded-blocks", rule, { output: "{\na();\n}", errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1 }, { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1 } ] @@ -332,7 +330,7 @@ ruleTester.run("padded-blocks", rule, { options: ["never"], errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 5 } ] @@ -343,11 +341,11 @@ ruleTester.run("padded-blocks", rule, { options: ["never"], errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 1 }, { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 5 } ] @@ -358,11 +356,11 @@ ruleTester.run("padded-blocks", rule, { options: ["never"], errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 1 }, { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 5 } ] @@ -373,11 +371,11 @@ ruleTester.run("padded-blocks", rule, { options: ["never"], errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 1 }, { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 7 } ] @@ -388,7 +386,7 @@ ruleTester.run("padded-blocks", rule, { options: ["never"], errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 1 } ] @@ -399,7 +397,7 @@ ruleTester.run("padded-blocks", rule, { options: ["never"], errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 1 } ] @@ -410,7 +408,7 @@ ruleTester.run("padded-blocks", rule, { options: ["never"], errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 4 } ] @@ -421,7 +419,7 @@ ruleTester.run("padded-blocks", rule, { options: ["never"], errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 4 } ] @@ -432,7 +430,7 @@ ruleTester.run("padded-blocks", rule, { options: ["always"], errors: [ { - message: ALWAYS_MESSAGE, + messageId: "alwaysPadBlock", line: 1, column: 1 } @@ -444,7 +442,7 @@ ruleTester.run("padded-blocks", rule, { options: ["never"], errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 1, column: 1 } @@ -456,7 +454,7 @@ ruleTester.run("padded-blocks", rule, { options: [{ blocks: "never" }], errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 1, column: 1 } @@ -468,12 +466,12 @@ ruleTester.run("padded-blocks", rule, { options: ["never"], errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 1, column: 12 }, { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 5, column: 1 } @@ -485,7 +483,7 @@ ruleTester.run("padded-blocks", rule, { options: [{ switches: "never" }], errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 1, column: 12 } @@ -497,7 +495,7 @@ ruleTester.run("padded-blocks", rule, { options: [{ switches: "never" }], errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 4, column: 3 } @@ -510,19 +508,19 @@ ruleTester.run("padded-blocks", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 1 }, { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 3 }, { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 7 }, { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 9 } ] @@ -534,11 +532,11 @@ ruleTester.run("padded-blocks", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 1 }, { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 9 } ] @@ -550,19 +548,19 @@ ruleTester.run("padded-blocks", rule, { parserOptions: { ecmaVersion: 6 }, errors: [ { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 1 }, { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 3 }, { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 7 }, { - message: NEVER_MESSAGE, + messageId: "neverPadBlock", line: 9 } ] @@ -571,37 +569,37 @@ ruleTester.run("padded-blocks", rule, { code: "function foo() { // a\n\n b;\n}", output: "function foo() { // a\n b;\n}", options: ["never"], - errors: [NEVER_MESSAGE] + errors: [{ messageId: "neverPadBlock" }] }, { code: "function foo() { /* a\n */\n\n bar;\n}", output: "function foo() { /* a\n */\n bar;\n}", options: ["never"], - errors: [NEVER_MESSAGE] + errors: [{ messageId: "neverPadBlock" }] }, { code: "function foo() {\n\n bar;\n/* a\n */}", output: "function foo() {\n\n bar;\n\n/* a\n */}", options: ["always"], - errors: [ALWAYS_MESSAGE] + errors: [{ messageId: "alwaysPadBlock" }] }, { code: "function foo() { /* a\n */\n/* b\n */\n bar;\n}", output: "function foo() { /* a\n */\n\n/* b\n */\n bar;\n\n}", options: ["always"], - errors: [ALWAYS_MESSAGE, ALWAYS_MESSAGE] + errors: [{ messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" }] }, { code: "function foo() { /* a\n */ /* b\n */\n bar;\n}", output: "function foo() { /* a\n */ /* b\n */\n\n bar;\n\n}", options: ["always"], - errors: [ALWAYS_MESSAGE, ALWAYS_MESSAGE] + errors: [{ messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" }] }, { code: "function foo() { /* a\n */ /* b\n */\n bar;\n/* c\n *//* d\n */}", output: "function foo() { /* a\n */ /* b\n */\n\n bar;\n\n/* c\n *//* d\n */}", options: ["always"], - errors: [ALWAYS_MESSAGE, ALWAYS_MESSAGE] + errors: [{ messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" }] } ] }); diff --git a/tests/lib/rules/padding-line-between-statements.js b/tests/lib/rules/padding-line-between-statements.js index 17ffcc9afc4..e553610e353 100644 --- a/tests/lib/rules/padding-line-between-statements.js +++ b/tests/lib/rules/padding-line-between-statements.js @@ -16,9 +16,6 @@ const { RuleTester } = require("../../../lib/rule-tester"); // Tests //------------------------------------------------------------------------------ -const MESSAGE_NEVER = "Unexpected blank line before this statement."; -const MESSAGE_ALWAYS = "Expected blank line before this statement."; - const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2017 } }); ruleTester.run("padding-line-between-statements", rule, { @@ -2643,7 +2640,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "foo();\n\n//comment\nfoo();", @@ -2651,7 +2648,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: " foo();\n \n //comment\n foo();", @@ -2659,7 +2656,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "if (a) {}\n\nfor (;;) {}", @@ -2667,7 +2664,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "foo();\nfoo();", @@ -2675,7 +2672,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: " function a() {}\n do {} while (a)", @@ -2683,7 +2680,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "foo();//trailing-comment\n//comment\n//comment\nfoo();", @@ -2691,7 +2688,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -2704,7 +2701,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "block-like", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "{}\nfoo()", @@ -2712,7 +2709,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "if(a){}\nfoo()", @@ -2720,7 +2717,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "if(a){}else{}\nfoo()", @@ -2728,7 +2725,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "if(a){}else if(b){}\nfoo()", @@ -2736,7 +2733,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "if(a){}else if(b){}else{}\nfoo()", @@ -2744,7 +2741,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "switch(a){}\nfoo()", @@ -2752,7 +2749,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "switch(a){case 0:}\nfoo()", @@ -2760,7 +2757,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "try{}catch(e){}\nfoo()", @@ -2768,7 +2765,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "try{}finally{}\nfoo()", @@ -2776,7 +2773,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "try{}catch(e){}finally{}\nfoo()", @@ -2784,7 +2781,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "while(a){}\nfoo()", @@ -2792,7 +2789,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "do{}while(a)\nfoo()", @@ -2800,7 +2797,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "for(;;){}\nfoo()", @@ -2808,7 +2805,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "for(a in b){}\nfoo()", @@ -2816,7 +2813,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "for(a of b){}\nfoo()", @@ -2824,7 +2821,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "a=function(){}\nfoo()", @@ -2832,7 +2829,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "a=()=>{}\nfoo()", @@ -2840,7 +2837,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a(){}\nfoo()", @@ -2848,7 +2845,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "let a=function(){}\nfoo()", @@ -2856,7 +2853,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -2869,7 +2866,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "cjs-export", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "module.exports=1\nfoo()", @@ -2877,7 +2874,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "cjs-export", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "module.exports.foo=1\nfoo()", @@ -2885,7 +2882,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "cjs-export", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "module.exports[foo]=1\nfoo()", @@ -2893,7 +2890,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "cjs-export", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "exports.foo=1\nfoo()", @@ -2901,7 +2898,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "cjs-export", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "exports[foo]=1\nfoo()", @@ -2909,7 +2906,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "cjs-export", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -2922,7 +2919,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "cjs-import", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "const foo=require(\"foo\")\nfoo()", @@ -2930,7 +2927,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "cjs-import", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "const foo=require(\"foo\").Foo\nfoo()", @@ -2938,7 +2935,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "cjs-import", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "const foo=require(\"foo\")[a]\nfoo()", @@ -2946,7 +2943,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "cjs-import", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -2959,7 +2956,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "directive", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "\"use strict\"\nfoo()", @@ -2967,7 +2964,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "directive", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "'use strict'\nfoo()", @@ -2975,7 +2972,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "directive", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "'use asm'\nfoo()", @@ -2983,7 +2980,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "directive", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -2996,7 +2993,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "block-like", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "{\n}\nfoo()", @@ -3004,7 +3001,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "if(a){\n}\nfoo()", @@ -3012,7 +3009,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "if(a){\n}else{\n}\nfoo()", @@ -3020,7 +3017,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "if(a){\n}else if(b){\n}\nfoo()", @@ -3028,7 +3025,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "if(a){\n}else if(b){\n}else{\n}\nfoo()", @@ -3036,7 +3033,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "switch(a){\n}\nfoo()", @@ -3044,7 +3041,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "try{\n}catch(e){\n}\nfoo()", @@ -3052,7 +3049,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "try{\n}finally{\n}\nfoo()", @@ -3060,7 +3057,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "try{\n}catch(e){\n}finally{\n}\nfoo()", @@ -3068,7 +3065,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "while(a){\n}\nfoo()", @@ -3076,7 +3073,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "do{\n}while(a)\nfoo()", @@ -3084,7 +3081,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "for(;;){\n}\nfoo()", @@ -3092,7 +3089,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "for(a in b){\n}\nfoo()", @@ -3100,7 +3097,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "for(a of b){\n}\nfoo()", @@ -3108,7 +3105,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "a=function(){\n}\nfoo()", @@ -3116,7 +3113,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "a=()=>{\n}\nfoo()", @@ -3124,7 +3121,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a(){\n}\nfoo()", @@ -3132,7 +3129,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "let a=function(){\n}\nfoo()", @@ -3140,7 +3137,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3153,7 +3150,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "block", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "{}\nfoo()", @@ -3161,7 +3158,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3174,7 +3171,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "empty", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: ";\nfoo()", @@ -3182,7 +3179,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "empty", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3195,7 +3192,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "expression", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "foo()\nfoo()", @@ -3203,7 +3200,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "expression", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3216,7 +3213,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: "multiline-expression" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "foo()\nfoo(\n\tx,\n\ty\n)", @@ -3224,7 +3221,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "multiline-expression" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "() => {\n\tsomeArray.forEach(\n\t\tx => doSomething(x)\n\t);\n\treturn theThing;\n}", @@ -3232,7 +3229,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "multiline-expression", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3245,7 +3242,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "break", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "switch(a){case 0:break\n\nfoo()}", @@ -3253,7 +3250,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "break", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "while(a){break\nfoo()}", @@ -3261,7 +3258,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "break", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "switch(a){case 0:break\nfoo()}", @@ -3269,7 +3266,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "break", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3282,7 +3279,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "case", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "switch(a){case 0:\nfoo()\ndefault:}", @@ -3290,7 +3287,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "case", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3303,7 +3300,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "class", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "class A{}\nfoo()", @@ -3311,7 +3308,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "class", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3324,7 +3321,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "const", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "const a=1\nfoo()", @@ -3332,7 +3329,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "const", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3345,7 +3342,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "continue", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "while(a){continue\nfoo()}", @@ -3353,7 +3350,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "continue", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3366,7 +3363,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "debugger", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "debugger\nfoo()", @@ -3374,7 +3371,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "debugger", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3387,7 +3384,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "default", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "switch(a){default:\nfoo()\ncase 0:}", @@ -3395,7 +3392,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "default", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3408,7 +3405,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "do", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "do;while(a)\nfoo()", @@ -3416,7 +3413,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "do", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3430,7 +3427,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "export", next: "*" } ], parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "export let a=1\n\nfoo()", @@ -3439,7 +3436,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "export", next: "*" } ], parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var a = 0;export {a}\n\nfoo()", @@ -3448,7 +3445,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "export", next: "*" } ], parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "export default 1\nfoo()", @@ -3457,7 +3454,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: "export", next: "*" } ], parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "export let a=1\nfoo()", @@ -3466,7 +3463,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: "export", next: "*" } ], parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var a = 0;export {a}\nfoo()", @@ -3475,7 +3472,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: "export", next: "*" } ], parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3488,7 +3485,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "for", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "for(a in b);\n\nfoo()", @@ -3496,7 +3493,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "for", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "for(a of b);\n\nfoo()", @@ -3504,7 +3501,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "for", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "for(;;);\nfoo()", @@ -3512,7 +3509,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "for", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "for(a in b);\nfoo()", @@ -3520,7 +3517,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "for", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "for(a of b);\nfoo()", @@ -3528,7 +3525,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "for", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3541,7 +3538,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "function", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "function foo(){}\nfoo()", @@ -3549,7 +3546,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "function", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "async function foo(){}\nfoo()", @@ -3558,7 +3555,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: "*" }, { blankLine: "always", prev: "function", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3571,7 +3568,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "if", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "if(a);else;\n\nfoo()", @@ -3579,7 +3576,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "if", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "if(a);\nfoo()", @@ -3587,7 +3584,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "if", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "if(a);else;\nfoo()", @@ -3595,7 +3592,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "if", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3608,7 +3605,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "iife", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "+(function(){\n})()\n\nvar a = 2;", @@ -3616,7 +3613,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "iife", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "(function(){\n})()\nvar a = 2;", @@ -3624,7 +3621,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "iife", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "+(function(){\n})()\nvar a = 2;", @@ -3632,7 +3629,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "iife", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3646,7 +3643,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "import", next: "*" } ], parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "import * as a from 'a'\n\nfoo()", @@ -3655,7 +3652,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "import", next: "*" } ], parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "import {a} from 'a'\n\nfoo()", @@ -3664,7 +3661,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "import", next: "*" } ], parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "import a from 'a'\nfoo()", @@ -3673,7 +3670,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: "import", next: "*" } ], parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "import * as a from 'a'\nfoo()", @@ -3682,7 +3679,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: "import", next: "*" } ], parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "import {a} from 'a'\nfoo()", @@ -3691,7 +3688,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: "import", next: "*" } ], parserOptions: { ecmaVersion: 6, sourceType: "module" }, - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3704,7 +3701,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "let", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "let a\nfoo()", @@ -3712,7 +3709,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "let", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3725,7 +3722,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "return", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "function foo(){return\nfoo()}", @@ -3733,7 +3730,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "return", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3746,7 +3743,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "switch", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "switch(a){}\nfoo()", @@ -3754,7 +3751,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "switch", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3767,7 +3764,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "throw", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "throw a\nfoo()", @@ -3775,7 +3772,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "throw", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3788,7 +3785,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "try", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "try{}finally{}\n\nfoo()", @@ -3796,7 +3793,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "try", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "try{}catch(e){}finally{}\n\nfoo()", @@ -3804,7 +3801,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "try", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "try{}catch(e){}\nfoo()", @@ -3812,7 +3809,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "try", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "try{}finally{}\nfoo()", @@ -3820,7 +3817,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "try", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "try{}catch(e){}finally{}\nfoo()", @@ -3828,7 +3825,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "try", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3841,7 +3838,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "var", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var a\nfoo()", @@ -3849,7 +3846,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "var", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3862,7 +3859,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "while", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "while(a);\nfoo()", @@ -3870,7 +3867,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "while", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3883,7 +3880,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "with", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "with(a);\nfoo()", @@ -3891,7 +3888,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "with", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3904,7 +3901,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "multiline-const", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "const a={\nb:1,\nc:2\n}\nconst d=3", @@ -3912,7 +3909,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "multiline-const", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "const a=1\n\nconst b={\nc:2,\nd:3\n}", @@ -3920,7 +3917,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: "multiline-const" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "const a=1\nconst b={\nc:2,\nd:3\n}", @@ -3928,7 +3925,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "multiline-const" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3941,7 +3938,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "multiline-let", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "let a={\nb:1,\nc:2\n}\nlet d=3", @@ -3949,7 +3946,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "multiline-let", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "let a=1\n\nlet b={\nc:2,\nd:3\n}", @@ -3957,7 +3954,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: "multiline-let" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "let a=1\nlet b={\nc:2,\nd:3\n}", @@ -3965,7 +3962,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "multiline-let" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -3978,7 +3975,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "multiline-var", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var a={\nb:1,\nc:2\n}\nvar d=3", @@ -3986,7 +3983,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "multiline-var", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var a=1\n\nvar b={\nc:2,\nd:3\n}", @@ -3994,7 +3991,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: "multiline-var" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var a=1\nvar b={\nc:2,\nd:3\n}", @@ -4002,7 +3999,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "multiline-var" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -4015,7 +4012,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "singleline-const", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "const a=1\nconst b=2", @@ -4023,7 +4020,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "singleline-const", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "const a=1\n\nconst b=2", @@ -4031,7 +4028,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: "singleline-const" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "const a=1\nconst b=2", @@ -4039,7 +4036,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "singleline-const" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -4052,7 +4049,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "singleline-let", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "let a=1\nlet b=2", @@ -4060,7 +4057,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "singleline-let", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "let a=1\n\nlet b=2", @@ -4068,7 +4065,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: "singleline-let" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "let a=1\nlet b=2", @@ -4076,7 +4073,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "singleline-let" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -4089,7 +4086,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "singleline-var", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var a=1\nvar b=2", @@ -4097,7 +4094,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "singleline-var", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var a=1\n\nvar b=2", @@ -4105,7 +4102,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: "singleline-var" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var a=1\nvar b=2", @@ -4113,7 +4110,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "singleline-var" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -4128,7 +4125,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var greet = 'hello';var name = 'world';console.log(greet, name);", @@ -4137,7 +4134,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var greet = 'hello', name = 'world';console.log(greet, name);", @@ -4146,7 +4143,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, // should disallow no blank line in "always" mode @@ -4157,7 +4154,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var greet = 'hello'; \nconsole.log(greet);", @@ -4166,7 +4163,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var greet = 'hello'; // inline comment\nconsole.log(greet);", @@ -4175,7 +4172,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var greet = 'hello';\nvar name = 'world';\nconsole.log(greet, name);", @@ -4184,7 +4181,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var greet = 'hello', name = 'world';\nconsole.log(greet, name);", @@ -4193,7 +4190,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var greet = 'hello',\nname = 'world';\nconsole.log(greet, name);", @@ -4202,7 +4199,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "let greet = 'hello';\nconsole.log(greet);", @@ -4211,7 +4208,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "const greet = 'hello';\nconsole.log(greet);", @@ -4220,7 +4217,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function example() {\nvar greet = 'hello';\nconsole.log(greet);\n}", @@ -4229,7 +4226,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var f = function() {\nvar greet = 'hello';\nconsole.log(greet);\n};", @@ -4238,7 +4235,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "() => {\nvar greet = 'hello';\nconsole.log(greet);\n}", @@ -4247,7 +4244,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, // should disallow blank lines in "never" mode @@ -4258,7 +4255,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var greet = 'hello';\n\n\nconsole.log(greet);", @@ -4267,7 +4264,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var greet = 'hello';\n\n\n\nconsole.log(greet);", @@ -4276,7 +4273,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var greet = 'hello'; \n\nconsole.log(greet);", @@ -4285,7 +4282,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var greet = 'hello'; // inline comment\n\nconsole.log(greet);", @@ -4294,7 +4291,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var greet = 'hello';\nvar name = 'world';\n\nconsole.log(greet, name);", @@ -4303,7 +4300,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var greet = 'hello', name = 'world';\n\nconsole.log(greet, name);", @@ -4312,7 +4309,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var greet = 'hello',\nname = 'world';\n\nconsole.log(greet, name);", @@ -4321,7 +4318,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var greet = 'hello', // inline comment\nname = 'world'; // inline comment\n\nconsole.log(greet, name);", @@ -4330,7 +4327,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "let greet = 'hello';\n\nconsole.log(greet);", @@ -4339,7 +4336,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "const greet = 'hello';\n\nconsole.log(greet);", @@ -4348,7 +4345,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, // should disallow a comment on the next line that's not in turn followed by a blank in "always" mode @@ -4359,7 +4356,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var greet = 'hello';\n/* block comment\nblock comment */\nconsole.log(greet);", @@ -4368,7 +4365,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var greet = 'hello',\nname = 'world';\n// next-line comment\nconsole.log(greet);", @@ -4377,7 +4374,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var greet = 'hello',\nname = 'world';\n/* block comment\nblock comment */\nconsole.log(greet);", @@ -4386,7 +4383,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var greet = 'hello';\n// next-line comment\n// second-line comment\nconsole.log(greet);", @@ -4395,7 +4392,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var greet = 'hello';\n// next-line comment\n/* block comment\nblock comment */\nconsole.log(greet);", @@ -4404,7 +4401,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, // https://github.com/eslint/eslint/issues/6834 @@ -4422,7 +4419,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: ` @@ -4438,7 +4435,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: ["const", "let", "var"], next: "*" }, { blankLine: "any", prev: ["const", "let", "var"], next: ["const", "let", "var"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -4451,7 +4448,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nvar b;\nreturn;\n}", @@ -4459,7 +4456,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne();\nreturn d;\n}\n}", @@ -4467,7 +4464,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nif (b) return b;\nelse if (c) return c;\nelse {\ne(); return d;\n}\n}", @@ -4475,7 +4472,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\n while (b) {\nc();\nreturn;\n}\n}", @@ -4483,7 +4480,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\ndo {\nc();\nreturn;\n} while (b);\n}", @@ -4491,7 +4488,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nfor (var b; b < c; b++) {\nc();\nreturn;\n}\n}", @@ -4499,7 +4496,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nfor (b in c) {\nd();\nreturn;\n}\n}", @@ -4507,7 +4504,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nfor (b of c) {\nd();\nreturn;\n}\n}", @@ -4515,7 +4512,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nif (b) {\nc();\n}\n//comment\nreturn b;\n}", @@ -4523,7 +4520,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { 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}", @@ -4531,7 +4528,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS, MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }, { messageId: "expectedBlankLine" }] }, { code: "function a() {\nif (b) { return; } //comment\nreturn c;\n}", @@ -4539,7 +4536,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nif (b) { return; } /*multi-line\ncomment*/\nreturn c;\n}", @@ -4547,7 +4544,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nif (b) { return; }\n/*multi-line\ncomment*/ return c;\n}", @@ -4555,7 +4552,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nif (b) { return; } /*multi-line\ncomment*/ return c;\n}", @@ -4563,7 +4560,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var a;\nreturn;", @@ -4572,7 +4569,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: "*", next: "return" } ], parserOptions: { ecmaFeatures: { globalReturn: true } }, - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var a; return;", @@ -4581,7 +4578,7 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: "*", next: "return" } ], parserOptions: { ecmaFeatures: { globalReturn: true } }, - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\n{\n//comment\n}\nreturn\n}", @@ -4589,7 +4586,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\n{\n//comment\n} return\n}", @@ -4597,7 +4594,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nvar c;\nwhile (b) {\n c = d; //comment\n}\nreturn c;\n}", @@ -4605,7 +4602,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nfor (var b; b < c; b++) {\nif (d) {\nbreak; //comment\n}\nreturn;\n}\n}", @@ -4613,7 +4610,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nvar b; /*multi-line\ncomment*/\nreturn c;\n}", @@ -4621,7 +4618,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nvar b;\n/*multi-line\ncomment*/ return c;\n}", @@ -4629,7 +4626,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nvar b; /*multi-line\ncomment*/ return c;\n}", @@ -4637,7 +4634,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nvar b;\n//comment\nreturn;\n}", @@ -4645,7 +4642,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nvar b; //comment\nreturn;\n}", @@ -4653,7 +4650,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nvar b;\n/* comment */ return;\n}", @@ -4661,7 +4658,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nvar b;\n//comment\n/* comment */ return;\n}", @@ -4669,7 +4666,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nvar b; /* comment */ return;\n}", @@ -4677,7 +4674,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nvar b; /* comment */\nreturn;\n}", @@ -4685,7 +4682,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nvar b;\nreturn; //comment\n}", @@ -4693,7 +4690,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function a() {\nvar b; return; //comment\n}", @@ -4701,7 +4698,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "return" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -4715,7 +4712,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "block-like", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "if(true){\nif(true) {}\n\nvar a = 2;}", @@ -4723,7 +4720,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "block-like", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "(function(){\n})()\n\nvar a = 2;", @@ -4731,7 +4728,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "block-like", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "+(function(){\n})()\n\nvar a = 2;", @@ -4739,7 +4736,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "block-like", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "var a = function() {};\n\nvar b = 2;", @@ -4747,7 +4744,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "block-like", next: "*" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -4761,7 +4758,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: "cjs-export" } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -4775,7 +4772,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "function x() { var a = true;\n\nif (a) { a = !a; }; }", @@ -4783,7 +4780,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "function x() { var a = true;\n\nfor (var i = 0; i < 10; i++) { a = !a; }; }", @@ -4791,7 +4788,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] } ], - errors: [MESSAGE_NEVER] + errors: [{ messageId: "unexpectedBlankLine" }] }, { code: "function x() { var y = true;\n\nswitch (\"Oranges\") { case \"Oranges\": y = !y;\n\nbreak;\n\ncase \"Apples\": y = !y;\n\nbreak; default: y = !y; } }", @@ -4800,10 +4797,10 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] } ], errors: [ - MESSAGE_NEVER, - MESSAGE_NEVER, - MESSAGE_NEVER, - MESSAGE_NEVER + { messageId: "unexpectedBlankLine" }, + { messageId: "unexpectedBlankLine" }, + { messageId: "unexpectedBlankLine" }, + { messageId: "unexpectedBlankLine" } ] }, { @@ -4813,8 +4810,8 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] } ], errors: [ - MESSAGE_NEVER, - MESSAGE_NEVER + { messageId: "unexpectedBlankLine" }, + { messageId: "unexpectedBlankLine" } ] }, { @@ -4824,9 +4821,9 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "never", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw"] } ], errors: [ - MESSAGE_NEVER, - MESSAGE_NEVER, - MESSAGE_NEVER + { messageId: "unexpectedBlankLine" }, + { messageId: "unexpectedBlankLine" }, + { messageId: "unexpectedBlankLine" } ] }, @@ -4841,7 +4838,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var a = function() {\n};\nvar b = 2;", @@ -4849,7 +4846,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "if(true){\nif(true) {}\nvar a = 2;}", @@ -4857,7 +4854,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "(function(){\n})()\nvar a = 2;", @@ -4865,7 +4862,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "var a = function() {\n};\nvar b = 2;", @@ -4873,7 +4870,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "multiline-block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "(function(){\n})()\nvar a = 2;", @@ -4881,7 +4878,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "multiline-block-like", next: "*" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -4895,7 +4892,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: "cjs-export" } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, //---------------------------------------------------------------------- @@ -4909,7 +4906,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function x() { var a = true; for (var i = 0; i < 10; i++) { a = !a; }; }", @@ -4917,7 +4914,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function x() { var y = true; switch (\"Oranges\") { case \"Oranges\": y = !y; break; case \"Apples\": y = !y; break; default: y = !y; } }", @@ -4926,11 +4923,11 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] } ], errors: [ - MESSAGE_ALWAYS, - MESSAGE_ALWAYS, - MESSAGE_ALWAYS, - MESSAGE_ALWAYS, - MESSAGE_ALWAYS + { messageId: "expectedBlankLine" }, + { messageId: "expectedBlankLine" }, + { messageId: "expectedBlankLine" }, + { messageId: "expectedBlankLine" }, + { messageId: "expectedBlankLine" } ] }, { @@ -4939,7 +4936,7 @@ ruleTester.run("padding-line-between-statements", rule, { options: [ { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] } ], - errors: [MESSAGE_ALWAYS] + errors: [{ messageId: "expectedBlankLine" }] }, { code: "function x() {try { var a; throw 0; } catch (e) { var b = 0; throw e; } }", @@ -4948,8 +4945,8 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] } ], errors: [ - MESSAGE_ALWAYS, - MESSAGE_ALWAYS + { messageId: "expectedBlankLine" }, + { messageId: "expectedBlankLine" } ] }, { @@ -4959,9 +4956,9 @@ ruleTester.run("padding-line-between-statements", rule, { { blankLine: "always", prev: "*", next: ["if", "for", "return", "switch", "case", "break", "throw", "while", "default"] } ], errors: [ - MESSAGE_ALWAYS, - MESSAGE_ALWAYS, - MESSAGE_ALWAYS + { messageId: "expectedBlankLine" }, + { messageId: "expectedBlankLine" }, + { messageId: "expectedBlankLine" } ] } ] diff --git a/tests/lib/rules/prefer-arrow-callback.js b/tests/lib/rules/prefer-arrow-callback.js index 4d1b420d159..cb380de251d 100644 --- a/tests/lib/rules/prefer-arrow-callback.js +++ b/tests/lib/rules/prefer-arrow-callback.js @@ -17,7 +17,7 @@ const { RuleTester } = require("../../../lib/rule-tester"); //------------------------------------------------------------------------------ const errors = [{ - message: "Unexpected function expression.", + messageId: "preferArrowCallback", type: "FunctionExpression" }]; diff --git a/tests/lib/rules/prefer-destructuring.js b/tests/lib/rules/prefer-destructuring.js index 53ef6f0a32f..6f1b6e3a1be 100644 --- a/tests/lib/rules/prefer-destructuring.js +++ b/tests/lib/rules/prefer-destructuring.js @@ -149,7 +149,8 @@ ruleTester.run("prefer-destructuring", rule, { code: "var foo = array[0];", output: null, errors: [{ - message: "Use array destructuring.", + messageId: "preferDestructuring", + data: { type: "array" }, type: "VariableDeclarator" }] }, @@ -157,7 +158,8 @@ ruleTester.run("prefer-destructuring", rule, { code: "foo = array[0];", output: null, errors: [{ - message: "Use array destructuring.", + messageId: "preferDestructuring", + data: { type: "array" }, type: "AssignmentExpression" }] }, @@ -165,7 +167,8 @@ ruleTester.run("prefer-destructuring", rule, { code: "var foo = object.foo;", output: "var {foo} = object;", errors: [{ - message: "Use object destructuring.", + messageId: "preferDestructuring", + data: { type: "object" }, type: "VariableDeclarator" }] }, @@ -173,7 +176,8 @@ ruleTester.run("prefer-destructuring", rule, { code: "var foo = object.bar.foo;", output: "var {foo} = object.bar;", errors: [{ - message: "Use object destructuring.", + messageId: "preferDestructuring", + data: { type: "object" }, type: "VariableDeclarator" }] }, @@ -182,7 +186,8 @@ ruleTester.run("prefer-destructuring", rule, { output: null, options: [{ VariableDeclarator: { object: true } }, { enforceForRenamedProperties: true }], errors: [{ - message: "Use object destructuring.", + messageId: "preferDestructuring", + data: { type: "object" }, type: "VariableDeclarator" }] }, @@ -191,7 +196,8 @@ ruleTester.run("prefer-destructuring", rule, { output: null, options: [{ object: true }, { enforceForRenamedProperties: true }], errors: [{ - message: "Use object destructuring.", + messageId: "preferDestructuring", + data: { type: "object" }, type: "VariableDeclarator" }] }, @@ -200,7 +206,8 @@ ruleTester.run("prefer-destructuring", rule, { output: null, options: [{ VariableDeclarator: { object: true } }, { enforceForRenamedProperties: true }], errors: [{ - message: "Use object destructuring.", + messageId: "preferDestructuring", + data: { type: "object" }, type: "VariableDeclarator" }] }, @@ -209,7 +216,8 @@ ruleTester.run("prefer-destructuring", rule, { output: null, options: [{ object: true }, { enforceForRenamedProperties: true }], errors: [{ - message: "Use object destructuring.", + messageId: "preferDestructuring", + data: { type: "object" }, type: "VariableDeclarator" }] }, @@ -217,7 +225,8 @@ ruleTester.run("prefer-destructuring", rule, { code: "var foo = object['foo'];", output: null, errors: [{ - message: "Use object destructuring.", + messageId: "preferDestructuring", + data: { type: "object" }, type: "VariableDeclarator" }] }, @@ -225,7 +234,8 @@ ruleTester.run("prefer-destructuring", rule, { code: "foo = object.foo;", output: null, errors: [{ - message: "Use object destructuring.", + messageId: "preferDestructuring", + data: { type: "object" }, type: "AssignmentExpression" }] }, @@ -233,7 +243,8 @@ ruleTester.run("prefer-destructuring", rule, { code: "foo = object['foo'];", output: null, errors: [{ - message: "Use object destructuring.", + messageId: "preferDestructuring", + data: { type: "object" }, type: "AssignmentExpression" }] }, @@ -242,7 +253,8 @@ ruleTester.run("prefer-destructuring", rule, { output: null, options: [{ VariableDeclarator: { array: true } }, { enforceForRenamedProperties: true }], errors: [{ - message: "Use array destructuring.", + messageId: "preferDestructuring", + data: { type: "array" }, type: "VariableDeclarator" }] }, @@ -251,7 +263,8 @@ ruleTester.run("prefer-destructuring", rule, { output: null, options: [{ AssignmentExpression: { array: true } }], errors: [{ - message: "Use array destructuring.", + messageId: "preferDestructuring", + data: { type: "array" }, type: "AssignmentExpression" }] }, @@ -266,7 +279,8 @@ ruleTester.run("prefer-destructuring", rule, { { enforceForRenamedProperties: true } ], errors: [{ - message: "Use array destructuring.", + messageId: "preferDestructuring", + data: { type: "array" }, type: "VariableDeclarator" }] }, @@ -280,7 +294,8 @@ ruleTester.run("prefer-destructuring", rule, { } ], errors: [{ - message: "Use array destructuring.", + messageId: "preferDestructuring", + data: { type: "array" }, type: "VariableDeclarator" }] }, @@ -294,7 +309,8 @@ ruleTester.run("prefer-destructuring", rule, { } ], errors: [{ - message: "Use array destructuring.", + messageId: "preferDestructuring", + data: { type: "array" }, type: "AssignmentExpression" }] }, @@ -308,7 +324,8 @@ ruleTester.run("prefer-destructuring", rule, { } ], errors: [{ - message: "Use object destructuring.", + messageId: "preferDestructuring", + data: { type: "object" }, type: "AssignmentExpression" }] }, @@ -316,7 +333,8 @@ ruleTester.run("prefer-destructuring", rule, { code: "class Foo extends Bar { static foo() {var bar = super.foo.bar} }", output: "class Foo extends Bar { static foo() {var {bar} = super.foo} }", errors: [{ - message: "Use object destructuring.", + messageId: "preferDestructuring", + data: { type: "object" }, type: "VariableDeclarator" }] } diff --git a/tests/lib/rules/prefer-exponentiation-operator.js b/tests/lib/rules/prefer-exponentiation-operator.js index 03d6d57480b..0c7890ea921 100644 --- a/tests/lib/rules/prefer-exponentiation-operator.js +++ b/tests/lib/rules/prefer-exponentiation-operator.js @@ -212,13 +212,12 @@ ruleTester.run("prefer-exponentiation-operator", rule, { invalid("+Math.pow(++a, b)", "+(++a**b)"), invalid("Math.pow(a, b + c)in d", "a**(b + c)in d"), - // multiple invalid and full message and location test { code: "Math.pow(a, b) + Math.pow(c,\n d)", output: "a**b + c**d", errors: [ { - message: "Use the '**' operator instead of 'Math.pow'.", + messageId: "useExponentiation", type: "CallExpression", line: 1, column: 1, @@ -226,7 +225,7 @@ ruleTester.run("prefer-exponentiation-operator", rule, { endColumn: 15 }, { - message: "Use the '**' operator instead of 'Math.pow'.", + messageId: "useExponentiation", type: "CallExpression", line: 1, column: 18, diff --git a/tests/lib/rules/prefer-promise-reject-errors.js b/tests/lib/rules/prefer-promise-reject-errors.js index 7a4ee2614c9..012e44ce7a5 100644 --- a/tests/lib/rules/prefer-promise-reject-errors.js +++ b/tests/lib/rules/prefer-promise-reject-errors.js @@ -89,7 +89,7 @@ ruleTester.run("prefer-promise-reject-errors", rule, { "new Promise(({}, reject) => reject(5))", "new Promise((resolve, reject, somethingElse = reject(5)) => {})" ].map(invalidCase => { - const errors = { errors: [{ message: "Expected the Promise rejection reason to be an Error.", type: "CallExpression" }] }; + const errors = { errors: [{ messageId: "rejectAnError", type: "CallExpression" }] }; return Object.assign({}, errors, typeof invalidCase === "string" ? { code: invalidCase } : invalidCase); }) diff --git a/tests/lib/rules/prefer-reflect.js b/tests/lib/rules/prefer-reflect.js index fac72e40531..5da4261b9ca 100644 --- a/tests/lib/rules/prefer-reflect.js +++ b/tests/lib/rules/prefer-reflect.js @@ -74,7 +74,8 @@ ruleTester.run("prefer-reflect", rule, { code: "(function(){}).apply(null, [1, 2])", errors: [ { - message: "Avoid using Function.prototype.apply, instead use Reflect.apply.", + messageId: "preferReflect", + data: { existing: "Function.prototype.apply", substitute: "Reflect.apply" }, type: "CallExpression" } ] @@ -84,7 +85,8 @@ ruleTester.run("prefer-reflect", rule, { options: [{ exceptions: ["defineProperty"] }], errors: [ { - message: "Avoid using Function.prototype.apply, instead use Reflect.apply.", + messageId: "preferReflect", + data: { existing: "Function.prototype.apply", substitute: "Reflect.apply" }, type: "CallExpression" } ] @@ -93,7 +95,8 @@ ruleTester.run("prefer-reflect", rule, { code: "(function(){}).call(null, 1, 2)", errors: [ { - message: "Avoid using Function.prototype.call, instead use Reflect.apply.", + messageId: "preferReflect", + data: { existing: "Function.prototype.call", substitute: "Reflect.apply" }, type: "CallExpression" } ] @@ -103,7 +106,8 @@ ruleTester.run("prefer-reflect", rule, { options: [{ exceptions: ["defineProperty"] }], errors: [ { - message: "Avoid using Function.prototype.call, instead use Reflect.apply.", + messageId: "preferReflect", + data: { existing: "Function.prototype.call", substitute: "Reflect.apply" }, type: "CallExpression" } ] @@ -112,7 +116,8 @@ ruleTester.run("prefer-reflect", rule, { code: "Object.defineProperty({}, 'foo', { value: 1 })", errors: [ { - message: "Avoid using Object.defineProperty, instead use Reflect.defineProperty.", + messageId: "preferReflect", + data: { existing: "Object.defineProperty", substitute: "Reflect.defineProperty" }, type: "CallExpression" } ] @@ -122,7 +127,8 @@ ruleTester.run("prefer-reflect", rule, { options: [{ exceptions: ["apply"] }], errors: [ { - message: "Avoid using Object.defineProperty, instead use Reflect.defineProperty.", + messageId: "preferReflect", + data: { existing: "Object.defineProperty", substitute: "Reflect.defineProperty" }, type: "CallExpression" } ] @@ -131,7 +137,8 @@ ruleTester.run("prefer-reflect", rule, { code: "Object.getOwnPropertyDescriptor({}, 'foo')", errors: [ { - message: "Avoid using Object.getOwnPropertyDescriptor, instead use Reflect.getOwnPropertyDescriptor.", + messageId: "preferReflect", + data: { existing: "Object.getOwnPropertyDescriptor", substitute: "Reflect.getOwnPropertyDescriptor" }, type: "CallExpression" } ] @@ -141,7 +148,8 @@ ruleTester.run("prefer-reflect", rule, { options: [{ exceptions: ["apply"] }], errors: [ { - message: "Avoid using Object.getOwnPropertyDescriptor, instead use Reflect.getOwnPropertyDescriptor.", + messageId: "preferReflect", + data: { existing: "Object.getOwnPropertyDescriptor", substitute: "Reflect.getOwnPropertyDescriptor" }, type: "CallExpression" } ] @@ -150,7 +158,8 @@ ruleTester.run("prefer-reflect", rule, { code: "Object.getPrototypeOf({})", errors: [ { - message: "Avoid using Object.getPrototypeOf, instead use Reflect.getPrototypeOf.", + messageId: "preferReflect", + data: { existing: "Object.getPrototypeOf", substitute: "Reflect.getPrototypeOf" }, type: "CallExpression" } ] @@ -160,7 +169,8 @@ ruleTester.run("prefer-reflect", rule, { options: [{ exceptions: ["apply"] }], errors: [ { - message: "Avoid using Object.getPrototypeOf, instead use Reflect.getPrototypeOf.", + messageId: "preferReflect", + data: { existing: "Object.getPrototypeOf", substitute: "Reflect.getPrototypeOf" }, type: "CallExpression" } ] @@ -169,7 +179,8 @@ ruleTester.run("prefer-reflect", rule, { code: "Object.setPrototypeOf({}, Object.prototype)", errors: [ { - message: "Avoid using Object.setPrototypeOf, instead use Reflect.setPrototypeOf.", + messageId: "preferReflect", + data: { existing: "Object.setPrototypeOf", substitute: "Reflect.setPrototypeOf" }, type: "CallExpression" } ] @@ -179,7 +190,8 @@ ruleTester.run("prefer-reflect", rule, { options: [{ exceptions: ["apply"] }], errors: [ { - message: "Avoid using Object.setPrototypeOf, instead use Reflect.setPrototypeOf.", + messageId: "preferReflect", + data: { existing: "Object.setPrototypeOf", substitute: "Reflect.setPrototypeOf" }, type: "CallExpression" } ] @@ -188,7 +200,8 @@ ruleTester.run("prefer-reflect", rule, { code: "Object.isExtensible({})", errors: [ { - message: "Avoid using Object.isExtensible, instead use Reflect.isExtensible.", + messageId: "preferReflect", + data: { existing: "Object.isExtensible", substitute: "Reflect.isExtensible" }, type: "CallExpression" } ] @@ -198,7 +211,8 @@ ruleTester.run("prefer-reflect", rule, { options: [{ exceptions: ["apply"] }], errors: [ { - message: "Avoid using Object.isExtensible, instead use Reflect.isExtensible.", + messageId: "preferReflect", + data: { existing: "Object.isExtensible", substitute: "Reflect.isExtensible" }, type: "CallExpression" } ] @@ -207,7 +221,8 @@ ruleTester.run("prefer-reflect", rule, { code: "Object.getOwnPropertyNames({})", errors: [ { - message: "Avoid using Object.getOwnPropertyNames, instead use Reflect.getOwnPropertyNames.", + messageId: "preferReflect", + data: { existing: "Object.getOwnPropertyNames", substitute: "Reflect.getOwnPropertyNames" }, type: "CallExpression" } ] @@ -217,7 +232,8 @@ ruleTester.run("prefer-reflect", rule, { options: [{ exceptions: ["apply"] }], errors: [ { - message: "Avoid using Object.getOwnPropertyNames, instead use Reflect.getOwnPropertyNames.", + messageId: "preferReflect", + data: { existing: "Object.getOwnPropertyNames", substitute: "Reflect.getOwnPropertyNames" }, type: "CallExpression" } ] @@ -226,7 +242,8 @@ ruleTester.run("prefer-reflect", rule, { code: "Object.preventExtensions({})", errors: [ { - message: "Avoid using Object.preventExtensions, instead use Reflect.preventExtensions.", + messageId: "preferReflect", + data: { existing: "Object.preventExtensions", substitute: "Reflect.preventExtensions" }, type: "CallExpression" } ] @@ -236,7 +253,8 @@ ruleTester.run("prefer-reflect", rule, { options: [{ exceptions: ["apply"] }], errors: [ { - message: "Avoid using Object.preventExtensions, instead use Reflect.preventExtensions.", + messageId: "preferReflect", + data: { existing: "Object.preventExtensions", substitute: "Reflect.preventExtensions" }, type: "CallExpression" } ] @@ -245,7 +263,8 @@ ruleTester.run("prefer-reflect", rule, { code: "delete ({}).foo", errors: [ { - message: "Avoid using the delete keyword, instead use Reflect.deleteProperty.", + messageId: "preferReflect", + data: { existing: "the delete keyword", substitute: "Reflect.deleteProperty" }, type: "UnaryExpression" } ] @@ -255,7 +274,8 @@ ruleTester.run("prefer-reflect", rule, { options: [{ exceptions: ["apply"] }], errors: [ { - message: "Avoid using the delete keyword, instead use Reflect.deleteProperty.", + messageId: "preferReflect", + data: { existing: "the delete keyword", substitute: "Reflect.deleteProperty" }, type: "UnaryExpression" } ] diff --git a/tests/lib/rules/prefer-rest-params.js b/tests/lib/rules/prefer-rest-params.js index 1d0cdb448e9..3ab3fc531c9 100644 --- a/tests/lib/rules/prefer-rest-params.js +++ b/tests/lib/rules/prefer-rest-params.js @@ -25,9 +25,9 @@ ruleTester.run("prefer-rest-params", rule, { "function foo() { arguments.callee; }" ], invalid: [ - { code: "function foo() { arguments; }", errors: [{ type: "Identifier", message: "Use the rest parameters instead of 'arguments'." }] }, - { code: "function foo() { arguments[0]; }", errors: [{ type: "Identifier", message: "Use the rest parameters instead of 'arguments'." }] }, - { code: "function foo() { arguments[1]; }", errors: [{ type: "Identifier", message: "Use the rest parameters instead of 'arguments'." }] }, - { code: "function foo() { arguments[Symbol.iterator]; }", errors: [{ type: "Identifier", message: "Use the rest parameters instead of 'arguments'." }] } + { code: "function foo() { arguments; }", errors: [{ type: "Identifier", messageId: "preferRestParams" }] }, + { code: "function foo() { arguments[0]; }", errors: [{ type: "Identifier", messageId: "preferRestParams" }] }, + { code: "function foo() { arguments[1]; }", errors: [{ type: "Identifier", messageId: "preferRestParams" }] }, + { code: "function foo() { arguments[Symbol.iterator]; }", errors: [{ type: "Identifier", messageId: "preferRestParams" }] } ] }); diff --git a/tests/lib/rules/prefer-spread.js b/tests/lib/rules/prefer-spread.js index 6bb5631bd90..580d7faeba9 100644 --- a/tests/lib/rules/prefer-spread.js +++ b/tests/lib/rules/prefer-spread.js @@ -16,7 +16,7 @@ const { RuleTester } = require("../../../lib/rule-tester"); // Tests //------------------------------------------------------------------------------ -const errors = [{ message: "Use the spread operator instead of '.apply()'.", type: "CallExpression" }]; +const errors = [{ messageId: "preferSpread", type: "CallExpression" }]; const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); diff --git a/tests/lib/rules/prefer-template.js b/tests/lib/rules/prefer-template.js index 439b261cc1a..3ac3879d636 100644 --- a/tests/lib/rules/prefer-template.js +++ b/tests/lib/rules/prefer-template.js @@ -17,7 +17,7 @@ const { RuleTester } = require("../../../lib/rule-tester"); //------------------------------------------------------------------------------ const errors = [{ - message: "Unexpected string concatenation.", + messageId: "unexpectedStringConcatenation", type: "BinaryExpression" }]; diff --git a/tests/lib/rules/quote-props.js b/tests/lib/rules/quote-props.js index 9d033dfb85a..136e12fea9e 100644 --- a/tests/lib/rules/quote-props.js +++ b/tests/lib/rules/quote-props.js @@ -85,70 +85,88 @@ ruleTester.run("quote-props", rule, { code: "({ a: 0 })", output: "({ \"a\": 0 })", errors: [{ - message: "Unquoted property 'a' found.", type: "Property" + messageId: "unquotedPropertyFound", + data: { property: "a" }, + type: "Property" }] }, { code: "({ 0: '0' })", output: "({ \"0\": '0' })", errors: [{ - message: "Unquoted property '0' found.", type: "Property" + messageId: "unquotedPropertyFound", + data: { property: "0" }, + type: "Property" }] }, { code: "({ 'a': 0 })", output: "({ a: 0 })", options: ["as-needed"], errors: [{ - message: "Unnecessarily quoted property 'a' found.", type: "Property" + messageId: "unnecessarilyQuotedProperty", + data: { property: "a" }, + type: "Property" }] }, { code: "({ 'null': 0 })", output: "({ null: 0 })", options: ["as-needed"], errors: [{ - message: "Unnecessarily quoted property 'null' found.", type: "Property" + messageId: "unnecessarilyQuotedProperty", + data: { property: "null" }, + type: "Property" }] }, { code: "({ 'true': 0 })", output: "({ true: 0 })", options: ["as-needed"], errors: [{ - message: "Unnecessarily quoted property 'true' found.", type: "Property" + messageId: "unnecessarilyQuotedProperty", + data: { property: "true" }, + type: "Property" }] }, { code: "({ '0': 0 })", output: "({ 0: 0 })", options: ["as-needed"], errors: [{ - message: "Unnecessarily quoted property '0' found.", type: "Property" + messageId: "unnecessarilyQuotedProperty", + data: { property: "0" }, + type: "Property" }] }, { code: "({ '-a': 0, b: 0 })", output: "({ '-a': 0, \"b\": 0 })", options: ["consistent"], errors: [{ - message: "Inconsistently quoted property 'b' found.", type: "Property" + messageId: "inconsistentlyQuotedProperty", + data: { key: "b" }, + type: "Property" }] }, { code: "({ a: 0, 'b': 0 })", output: "({ \"a\": 0, 'b': 0 })", options: ["consistent"], errors: [{ - message: "Inconsistently quoted property 'a' found.", type: "Property" + messageId: "inconsistentlyQuotedProperty", + data: { key: "a" }, + type: "Property" }] }, { code: "({ '-a': 0, b: 0 })", output: "({ '-a': 0, \"b\": 0 })", options: ["consistent-as-needed"], errors: [{ - message: "Inconsistently quoted property 'b' found.", type: "Property" + messageId: "inconsistentlyQuotedProperty", + data: { key: "b" }, + type: "Property" }] }, { code: "({ 'a': 0, 'b': 0 })", output: "({ a: 0, b: 0 })", options: ["consistent-as-needed"], errors: [ - { message: "Properties shouldn't be quoted as all quotes are redundant.", type: "Property" }, - { message: "Properties shouldn't be quoted as all quotes are redundant.", type: "Property" } + { messageId: "redundantQuoting", type: "Property" }, + { messageId: "redundantQuoting", type: "Property" } ] }, { code: "({ 'a': 0, [x]: 0 })", @@ -156,7 +174,7 @@ ruleTester.run("quote-props", rule, { options: ["consistent-as-needed"], env: { es6: true }, errors: [ - { message: "Properties shouldn't be quoted as all quotes are redundant.", type: "Property" } + { messageId: "redundantQuoting", type: "Property" } ] }, { code: "({ 'a': 0, x })", @@ -164,52 +182,65 @@ ruleTester.run("quote-props", rule, { options: ["consistent-as-needed"], env: { es6: true }, errors: [{ - message: "Properties shouldn't be quoted as all quotes are redundant.", type: "Property" + messageId: "redundantQuoting", type: "Property" }] }, { code: "({ 'true': 0, 'null': 0 })", output: "({ true: 0, null: 0 })", options: ["consistent-as-needed"], errors: [ - { message: "Properties shouldn't be quoted as all quotes are redundant.", type: "Property" }, - { message: "Properties shouldn't be quoted as all quotes are redundant.", type: "Property" } + { messageId: "redundantQuoting", type: "Property" }, + { messageId: "redundantQuoting", type: "Property" } ] }, { code: "({ true: 0, 'null': 0 })", output: "({ \"true\": 0, 'null': 0 })", options: ["consistent"], errors: [{ - message: "Inconsistently quoted property 'true' found.", type: "Property" + messageId: "inconsistentlyQuotedProperty", + data: { key: "true" }, + type: "Property" }] }, { code: "({ 'a': 0, 'b': 0 })", output: "({ a: 0, b: 0 })", options: ["consistent-as-needed", { keywords: true }], errors: [ - { message: "Properties shouldn't be quoted as all quotes are redundant.", type: "Property" }, - { message: "Properties shouldn't be quoted as all quotes are redundant.", type: "Property" } + { messageId: "redundantQuoting", type: "Property" }, + { messageId: "redundantQuoting", type: "Property" } ] }, { code: "({ while: 0, b: 0 })", output: "({ \"while\": 0, \"b\": 0 })", options: ["consistent-as-needed", { keywords: true }], errors: [ - { message: "Properties should be quoted as 'while' is a reserved word.", type: "Property" }, - { message: "Properties should be quoted as 'while' is a reserved word.", type: "Property" } + { + messageId: "requireQuotesDueToReservedWord", + data: { property: "while" }, + type: "Property" + }, + { + messageId: "requireQuotesDueToReservedWord", + data: { property: "while" }, + type: "Property" + } ] }, { code: "({ while: 0, 'b': 0 })", output: "({ \"while\": 0, 'b': 0 })", options: ["consistent-as-needed", { keywords: true }], errors: [{ - message: "Properties should be quoted as 'while' is a reserved word.", type: "Property" + messageId: "requireQuotesDueToReservedWord", + data: { property: "while" }, + type: "Property" + }] }, { code: "({ foo: 0, 'bar': 0 })", output: "({ foo: 0, bar: 0 })", options: ["consistent-as-needed", { keywords: true }], errors: [ - { message: "Properties shouldn't be quoted as all quotes are redundant.", type: "Property" } + { messageId: "redundantQuoting", type: "Property" } ] }, { code: @@ -226,7 +257,9 @@ ruleTester.run("quote-props", rule, { "})", options: ["consistent"], errors: [{ - message: "Inconsistently quoted property 'prop2' found.", type: "Property" + messageId: "inconsistentlyQuotedProperty", + data: { key: "prop2" }, + type: "Property" }] }, { code: @@ -243,84 +276,109 @@ ruleTester.run("quote-props", rule, { "})", options: ["consistent-as-needed"], errors: [ - { message: "Properties shouldn't be quoted as all quotes are redundant.", type: "Property" }, - { message: "Properties shouldn't be quoted as all quotes are redundant.", type: "Property" }, - { message: "Properties shouldn't be quoted as all quotes are redundant.", type: "Property" } + { messageId: "redundantQuoting", type: "Property" }, + { messageId: "redundantQuoting", type: "Property" }, + { messageId: "redundantQuoting", type: "Property" } ] }, { code: "({'if': 0})", output: "({if: 0})", options: ["as-needed"], errors: [{ - message: "Unnecessarily quoted property 'if' found.", type: "Property" + messageId: "unnecessarilyQuotedProperty", + data: { property: "if" }, + type: "Property" }] }, { code: "({'synchronized': 0})", output: "({synchronized: 0})", options: ["as-needed"], errors: [{ - message: "Unnecessarily quoted property 'synchronized' found.", type: "Property" + messageId: "unnecessarilyQuotedProperty", + data: { property: "synchronized" }, + type: "Property" }] }, { code: "({while: 0})", output: "({\"while\": 0})", options: ["as-needed", { keywords: true }], errors: [{ - message: "Unquoted reserved word 'while' used as key.", type: "Property" + messageId: "unquotedReservedProperty", + data: { property: "while" }, + type: "Property" }] }, { code: "({'unnecessary': 1, if: 0})", output: "({'unnecessary': 1, \"if\": 0})", options: ["as-needed", { keywords: true, unnecessary: false }], errors: [{ - message: "Unquoted reserved word 'if' used as key.", type: "Property" + messageId: "unquotedReservedProperty", + data: { property: "if" }, + type: "Property" }] }, { code: "({1: 1})", output: "({\"1\": 1})", options: ["as-needed", { numbers: true }], errors: [{ - message: "Unquoted number literal '1' used as key.", type: "Property" + messageId: "unquotedNumericProperty", + data: { property: "1" }, + type: "Property" }] }, { code: "({1: 1})", output: "({\"1\": 1})", options: ["always", { numbers: false }], errors: [{ - message: "Unquoted property '1' found.", type: "Property" + messageId: "unquotedPropertyFound", + data: { property: "1" }, + type: "Property" }] }, { code: "({0x123: 1})", output: "({\"291\": 1})", // 0x123 === 291 options: ["always"], errors: [{ - message: "Unquoted property '291' found." + messageId: "unquotedPropertyFound", + data: { property: "291" } + }] }, { code: "({1e2: 1})", output: "({\"100\": 1})", options: ["always", { numbers: false }], errors: [{ - message: "Unquoted property '100' found." + messageId: "unquotedPropertyFound", + data: { property: "100" } + }] }, { code: "({5.: 1})", output: "({\"5\": 1})", options: ["always", { numbers: false }], errors: [{ - message: "Unquoted property '5' found." + messageId: "unquotedPropertyFound", + data: { property: "5" } + }] }, { code: "({ 1n: 1 })", output: "({ \"1\": 1 })", options: ["always"], parserOptions: { ecmaVersion: 2020 }, - errors: [{ message: "Unquoted property '1' found." }] + errors: [{ + messageId: "unquotedPropertyFound", + data: { property: "1" } + } + ] }, { code: "({ 1n: 1 })", output: "({ \"1\": 1 })", options: ["as-needed", { numbers: true }], parserOptions: { ecmaVersion: 2020 }, - errors: [{ message: "Unquoted number literal '1' used as key." }] + errors: [{ + messageId: "unquotedNumericProperty", + data: { property: "1" } + }] }] }); diff --git a/tests/lib/rules/radix.js b/tests/lib/rules/radix.js index 6c0bed80a19..2766e80b597 100644 --- a/tests/lib/rules/radix.js +++ b/tests/lib/rules/radix.js @@ -61,84 +61,84 @@ ruleTester.run("radix", rule, { code: "parseInt();", options: ["as-needed"], errors: [{ - message: "Missing parameters.", + messageId: "missingParameters", type: "CallExpression" }] }, { code: "parseInt();", errors: [{ - message: "Missing parameters.", + messageId: "missingParameters", type: "CallExpression" }] }, { code: "parseInt(\"10\");", errors: [{ - message: "Missing radix parameter.", + messageId: "missingRadix", type: "CallExpression" }] }, { code: "parseInt(\"10\", null);", errors: [{ - message: "Invalid radix parameter, must be an integer between 2 and 36.", + messageId: "invalidRadix", type: "CallExpression" }] }, { code: "parseInt(\"10\", undefined);", errors: [{ - message: "Invalid radix parameter, must be an integer between 2 and 36.", + messageId: "invalidRadix", type: "CallExpression" }] }, { code: "parseInt(\"10\", true);", errors: [{ - message: "Invalid radix parameter, must be an integer between 2 and 36.", + messageId: "invalidRadix", type: "CallExpression" }] }, { code: "parseInt(\"10\", \"foo\");", errors: [{ - message: "Invalid radix parameter, must be an integer between 2 and 36.", + messageId: "invalidRadix", type: "CallExpression" }] }, { code: "parseInt(\"10\", \"123\");", errors: [{ - message: "Invalid radix parameter, must be an integer between 2 and 36.", + messageId: "invalidRadix", type: "CallExpression" }] }, { code: "parseInt(\"10\", 1);", errors: [{ - message: "Invalid radix parameter, must be an integer between 2 and 36.", + messageId: "invalidRadix", type: "CallExpression" }] }, { code: "parseInt(\"10\", 37);", errors: [{ - message: "Invalid radix parameter, must be an integer between 2 and 36.", + messageId: "invalidRadix", type: "CallExpression" }] }, { code: "parseInt(\"10\", 10.5);", errors: [{ - message: "Invalid radix parameter, must be an integer between 2 and 36.", + messageId: "invalidRadix", type: "CallExpression" }] }, { code: "Number.parseInt();", errors: [{ - message: "Missing parameters.", + messageId: "missingParameters", type: "CallExpression" }] }, @@ -146,35 +146,35 @@ ruleTester.run("radix", rule, { code: "Number.parseInt();", options: ["as-needed"], errors: [{ - message: "Missing parameters.", + messageId: "missingParameters", type: "CallExpression" }] }, { code: "Number.parseInt(\"10\");", errors: [{ - message: "Missing radix parameter.", + messageId: "missingRadix", type: "CallExpression" }] }, { code: "Number.parseInt(\"10\", 1);", errors: [{ - message: "Invalid radix parameter, must be an integer between 2 and 36.", + messageId: "invalidRadix", type: "CallExpression" }] }, { code: "Number.parseInt(\"10\", 37);", errors: [{ - message: "Invalid radix parameter, must be an integer between 2 and 36.", + messageId: "invalidRadix", type: "CallExpression" }] }, { code: "Number.parseInt(\"10\", 10.5);", errors: [{ - message: "Invalid radix parameter, must be an integer between 2 and 36.", + messageId: "invalidRadix", type: "CallExpression" }] }, @@ -182,7 +182,7 @@ ruleTester.run("radix", rule, { code: "parseInt(\"10\", 10);", options: ["as-needed"], errors: [{ - message: "Redundant radix parameter.", + messageId: "redundantRadix", type: "CallExpression" }] } diff --git a/tests/lib/rules/require-jsdoc.js b/tests/lib/rules/require-jsdoc.js index a4b1109fe87..603ece2357b 100644 --- a/tests/lib/rules/require-jsdoc.js +++ b/tests/lib/rules/require-jsdoc.js @@ -232,7 +232,7 @@ ruleTester.run("require-jsdoc", rule, { { code: "function myFunction() {}", errors: [{ - message: "Missing JSDoc comment.", + messageId: "missingJSDocComment", type: "FunctionDeclaration" }] }, @@ -254,7 +254,7 @@ ruleTester.run("require-jsdoc", rule, { }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Missing JSDoc comment.", + messageId: "missingJSDocComment", type: "FunctionExpression" }] }, @@ -277,7 +277,7 @@ ruleTester.run("require-jsdoc", rule, { }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Missing JSDoc comment.", + messageId: "missingJSDocComment", type: "ClassDeclaration" }] }, @@ -300,7 +300,7 @@ ruleTester.run("require-jsdoc", rule, { }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Missing JSDoc comment.", + messageId: "missingJSDocComment", type: "ClassDeclaration" }] }, @@ -323,7 +323,7 @@ ruleTester.run("require-jsdoc", rule, { }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ - message: "Missing JSDoc comment.", + messageId: "missingJSDocComment", type: "ClassDeclaration" }] }, @@ -346,7 +346,7 @@ ruleTester.run("require-jsdoc", rule, { }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [{ - message: "Missing JSDoc comment.", + messageId: "missingJSDocComment", type: "ClassDeclaration" }] }, @@ -359,7 +359,7 @@ ruleTester.run("require-jsdoc", rule, { }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Missing JSDoc comment.", + messageId: "missingJSDocComment", type: "ArrowFunctionExpression" }] }, @@ -372,7 +372,7 @@ ruleTester.run("require-jsdoc", rule, { }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Missing JSDoc comment.", + messageId: "missingJSDocComment", type: "ArrowFunctionExpression" }] }, @@ -384,7 +384,7 @@ ruleTester.run("require-jsdoc", rule, { } }], errors: [{ - message: "Missing JSDoc comment.", + messageId: "missingJSDocComment", type: "FunctionExpression" }] }, @@ -397,7 +397,7 @@ ruleTester.run("require-jsdoc", rule, { }], parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Missing JSDoc comment.", + messageId: "missingJSDocComment", type: "FunctionExpression" }] }, @@ -409,7 +409,7 @@ ruleTester.run("require-jsdoc", rule, { } }], errors: [{ - message: "Missing JSDoc comment.", + messageId: "missingJSDocComment", type: "FunctionExpression" }] } diff --git a/tests/lib/rules/require-yield.js b/tests/lib/rules/require-yield.js index ab7281ae4c6..c80f4246539 100644 --- a/tests/lib/rules/require-yield.js +++ b/tests/lib/rules/require-yield.js @@ -16,8 +16,6 @@ const { RuleTester } = require("../../../lib/rule-tester"); // Tests //------------------------------------------------------------------------------ -const errorMessage = "This generator function does not have 'yield'."; - const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); ruleTester.run("require-yield", rule, { @@ -35,24 +33,24 @@ ruleTester.run("require-yield", rule, { invalid: [ { code: "function* foo() { return 0; }", - errors: [{ message: errorMessage, type: "FunctionDeclaration" }] + errors: [{ messageId: "missingYield", type: "FunctionDeclaration" }] }, { code: "(function* foo() { return 0; })();", - errors: [{ message: errorMessage, type: "FunctionExpression" }] + errors: [{ messageId: "missingYield", type: "FunctionExpression" }] }, { code: "var obj = { *foo() { return 0; } }", - errors: [{ message: errorMessage, type: "FunctionExpression" }] + errors: [{ messageId: "missingYield", type: "FunctionExpression" }] }, { code: "class A { *foo() { return 0; } }", - errors: [{ message: errorMessage, type: "FunctionExpression" }] + errors: [{ messageId: "missingYield", type: "FunctionExpression" }] }, { code: "function* foo() { function* bar() { yield 0; } }", errors: [{ - message: errorMessage, + messageId: "missingYield", type: "FunctionDeclaration", column: 1 }] @@ -60,7 +58,7 @@ ruleTester.run("require-yield", rule, { { code: "function* foo() { function* bar() { return 0; } yield 0; }", errors: [{ - message: errorMessage, + messageId: "missingYield", type: "FunctionDeclaration", column: 19 }] diff --git a/tests/lib/rules/rest-spread-spacing.js b/tests/lib/rules/rest-spread-spacing.js index 397eb79de13..9e38502a000 100644 --- a/tests/lib/rules/rest-spread-spacing.js +++ b/tests/lib/rules/rest-spread-spacing.js @@ -56,7 +56,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 7, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -66,7 +67,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 7, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -76,7 +78,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 7, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -87,7 +90,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 7, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -98,7 +102,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 7, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -109,7 +114,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 7, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -120,7 +126,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 7, - message: "Expected whitespace after spread operator.", + messageId: "expectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -130,7 +137,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 7, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -140,7 +148,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 7, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -151,7 +160,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 7, - message: "Expected whitespace after spread operator.", + messageId: "expectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -162,7 +172,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 7, - message: "Expected whitespace after spread operator.", + messageId: "expectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -172,7 +183,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 5, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -182,7 +194,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 5, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -192,7 +205,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 5, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -203,7 +217,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 5, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -214,7 +229,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 5, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -225,7 +241,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 5, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -236,7 +253,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 5, - message: "Expected whitespace after spread operator.", + messageId: "expectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -246,7 +264,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 5, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -256,7 +275,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 5, - message: "Unexpected whitespace after spread operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -267,7 +287,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 5, - message: "Expected whitespace after spread operator.", + messageId: "expectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -278,7 +299,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 5, - message: "Expected whitespace after spread operator.", + messageId: "expectedWhitespace", + data: { type: "spread" }, type: "SpreadElement" }] }, @@ -288,7 +310,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 15, - message: "Unexpected whitespace after rest operator.", + messageId: "unexpectedWhitespace", + data: { type: "rest" }, type: "RestElement" }] }, @@ -298,7 +321,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 15, - message: "Unexpected whitespace after rest operator.", + messageId: "unexpectedWhitespace", + data: { type: "rest" }, type: "RestElement" }] }, @@ -308,7 +332,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 15, - message: "Unexpected whitespace after rest operator.", + messageId: "unexpectedWhitespace", + data: { type: "rest" }, type: "RestElement" }] }, @@ -319,7 +344,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 15, - message: "Unexpected whitespace after rest operator.", + messageId: "unexpectedWhitespace", + data: { type: "rest" }, type: "RestElement" }] }, @@ -330,7 +356,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 15, - message: "Unexpected whitespace after rest operator.", + messageId: "unexpectedWhitespace", + data: { type: "rest" }, type: "RestElement" }] }, @@ -341,7 +368,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 15, - message: "Unexpected whitespace after rest operator.", + messageId: "unexpectedWhitespace", + data: { type: "rest" }, type: "RestElement" }] }, @@ -352,7 +380,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 15, - message: "Expected whitespace after rest operator.", + messageId: "expectedWhitespace", + data: { type: "rest" }, type: "RestElement" }] }, @@ -363,7 +392,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 20, - message: "Unexpected whitespace after spread property operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread property" }, type: "SpreadElement" }] }, @@ -374,7 +404,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 20, - message: "Unexpected whitespace after spread property operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread property" }, type: "SpreadElement" }] }, @@ -385,7 +416,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 20, - message: "Unexpected whitespace after spread property operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread property" }, type: "SpreadElement" }] }, @@ -397,7 +429,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 20, - message: "Unexpected whitespace after spread property operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread property" }, type: "SpreadElement" }] }, @@ -409,7 +442,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 20, - message: "Unexpected whitespace after spread property operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread property" }, type: "SpreadElement" }] }, @@ -421,7 +455,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 20, - message: "Unexpected whitespace after spread property operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread property" }, type: "SpreadElement" }] }, @@ -433,7 +468,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 20, - message: "Expected whitespace after spread property operator.", + messageId: "expectedWhitespace", + data: { type: "spread property" }, type: "SpreadElement" }] }, @@ -445,7 +481,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 20, - message: "Unexpected whitespace after spread property operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread property" }, type: "SpreadElement" }] }, @@ -457,7 +494,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 20, - message: "Unexpected whitespace after spread property operator.", + messageId: "unexpectedWhitespace", + data: { type: "spread property" }, type: "SpreadElement" }] }, @@ -469,7 +507,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 20, - message: "Expected whitespace after spread property operator.", + messageId: "expectedWhitespace", + data: { type: "spread property" }, type: "SpreadElement" }] }, @@ -481,7 +520,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 20, - message: "Expected whitespace after spread property operator.", + messageId: "expectedWhitespace", + data: { type: "spread property" }, type: "SpreadElement" }] }, @@ -492,7 +532,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 16, - message: "Unexpected whitespace after rest property operator.", + messageId: "unexpectedWhitespace", + data: { type: "rest property" }, type: "RestElement" }] }, @@ -503,7 +544,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 16, - message: "Unexpected whitespace after rest property operator.", + messageId: "unexpectedWhitespace", + data: { type: "rest property" }, type: "RestElement" }] }, @@ -514,7 +556,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 16, - message: "Unexpected whitespace after rest property operator.", + messageId: "unexpectedWhitespace", + data: { type: "rest property" }, type: "RestElement" }] }, @@ -526,7 +569,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 16, - message: "Unexpected whitespace after rest property operator.", + messageId: "unexpectedWhitespace", + data: { type: "rest property" }, type: "RestElement" }] }, @@ -538,7 +582,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 16, - message: "Unexpected whitespace after rest property operator.", + messageId: "unexpectedWhitespace", + data: { type: "rest property" }, type: "RestElement" }] }, @@ -550,7 +595,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 16, - message: "Unexpected whitespace after rest property operator.", + messageId: "unexpectedWhitespace", + data: { type: "rest property" }, type: "RestElement" }] }, @@ -562,7 +608,8 @@ ruleTester.run("rest-spread-spacing", rule, { errors: [{ line: 1, column: 16, - message: "Expected whitespace after rest property operator.", + messageId: "expectedWhitespace", + data: { type: "rest property" }, type: "RestElement" }] } diff --git a/tests/lib/rules/semi-spacing.js b/tests/lib/rules/semi-spacing.js index 4f154958818..c1098df6f8e 100644 --- a/tests/lib/rules/semi-spacing.js +++ b/tests/lib/rules/semi-spacing.js @@ -61,89 +61,89 @@ ruleTester.run("semi-spacing", rule, { { code: "var a = 'b' ;", output: "var a = 'b';", - errors: [{ message: "Unexpected whitespace before semicolon.", type: "VariableDeclaration", line: 1, column: 13 }] + errors: [{ messageId: "unexpectedWhitespaceBefore", type: "VariableDeclaration", line: 1, column: 13 }] }, { code: "var a = 'b',\nc = 'd' ;", output: "var a = 'b',\nc = 'd';", - errors: [{ message: "Unexpected whitespace before semicolon.", type: "VariableDeclaration", line: 2, column: 9 }] + errors: [{ messageId: "unexpectedWhitespaceBefore", type: "VariableDeclaration", line: 2, column: 9 }] }, { code: "var a = function() {} ;", output: "var a = function() {};", - errors: [{ message: "Unexpected whitespace before semicolon.", type: "VariableDeclaration", line: 1, column: 23 }] + errors: [{ messageId: "unexpectedWhitespaceBefore", type: "VariableDeclaration", line: 1, column: 23 }] }, { code: "var a = function() {\n} ;", output: "var a = function() {\n};", - errors: [{ message: "Unexpected whitespace before semicolon.", type: "VariableDeclaration", line: 2, column: 3 }] + errors: [{ messageId: "unexpectedWhitespaceBefore", type: "VariableDeclaration", line: 2, column: 3 }] }, { code: "/^a$/.test('b') ;", output: "/^a$/.test('b');", - errors: [{ message: "Unexpected whitespace before semicolon.", type: "ExpressionStatement", line: 1, column: 17 }] + errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ExpressionStatement", line: 1, column: 17 }] }, { code: ";(function(){}()) ;", output: ";(function(){}());", - errors: [{ message: "Unexpected whitespace before semicolon.", type: "ExpressionStatement", line: 1, column: 19 }] + errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ExpressionStatement", line: 1, column: 19 }] }, { code: "while (true) { break ; }", output: "while (true) { break; }", - errors: [{ message: "Unexpected whitespace before semicolon.", type: "BreakStatement", line: 1, column: 22 }] + errors: [{ messageId: "unexpectedWhitespaceBefore", type: "BreakStatement", line: 1, column: 22 }] }, { code: "while (true) { continue ; }", output: "while (true) { continue; }", - errors: [{ message: "Unexpected whitespace before semicolon.", type: "ContinueStatement", line: 1, column: 25 }] + errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ContinueStatement", line: 1, column: 25 }] }, { code: "debugger ;", output: "debugger;", - errors: [{ message: "Unexpected whitespace before semicolon.", type: "DebuggerStatement", line: 1, column: 10 }] + errors: [{ messageId: "unexpectedWhitespaceBefore", type: "DebuggerStatement", line: 1, column: 10 }] }, { code: "function foo() { return ; }", output: "function foo() { return; }", - errors: [{ message: "Unexpected whitespace before semicolon.", type: "ReturnStatement", line: 1, column: 25 }] + errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ReturnStatement", line: 1, column: 25 }] }, { code: "throw new Error('foo') ;", output: "throw new Error('foo');", - errors: [{ message: "Unexpected whitespace before semicolon.", type: "ThrowStatement", line: 1, column: 24 }] + errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ThrowStatement", line: 1, column: 24 }] }, { code: "for (var i = 0 ; i < 10 ; i++) {}", output: "for (var i = 0; i < 10; i++) {}", errors: [ - { message: "Unexpected whitespace before semicolon.", type: "ForStatement", line: 1, column: 16 }, - { message: "Unexpected whitespace before semicolon.", type: "ForStatement", line: 1, column: 25 } + { messageId: "unexpectedWhitespaceBefore", type: "ForStatement", line: 1, column: 16 }, + { messageId: "unexpectedWhitespaceBefore", type: "ForStatement", line: 1, column: 25 } ] }, { code: "var a = 'b';c = 'd';", output: "var a = 'b'; c = 'd';", - errors: [{ message: "Missing whitespace after semicolon.", type: "VariableDeclaration", line: 1, column: 12 }] + errors: [{ messageId: "missingWhitespaceAfter", type: "VariableDeclaration", line: 1, column: 12 }] }, { code: "var a = 'b';", output: "var a = 'b' ;", options: [{ before: true, after: true }], - errors: [{ message: "Missing whitespace before semicolon.", type: "VariableDeclaration", line: 1, column: 12 }] + errors: [{ messageId: "missingWhitespaceBefore", type: "VariableDeclaration", line: 1, column: 12 }] }, { code: "var a = 'b'; c = 'd';", output: "var a = 'b';c = 'd';", options: [{ before: false, after: false }], - errors: [{ message: "Unexpected whitespace after semicolon.", type: "VariableDeclaration", line: 1, column: 12 }] + errors: [{ messageId: "unexpectedWhitespaceAfter", type: "VariableDeclaration", line: 1, column: 12 }] }, { code: "for (var i = 0;i < 10;i++) {}", output: "for (var i = 0; i < 10; i++) {}", errors: [ - { message: "Missing whitespace after semicolon.", type: "ForStatement", line: 1, column: 15 }, - { message: "Missing whitespace after semicolon.", type: "ForStatement", line: 1, column: 22 } + { messageId: "missingWhitespaceAfter", type: "ForStatement", line: 1, column: 15 }, + { messageId: "missingWhitespaceAfter", type: "ForStatement", line: 1, column: 22 } ] }, { @@ -151,8 +151,8 @@ ruleTester.run("semi-spacing", rule, { output: "for (var i = 0 ; i < 10 ; i++) {}", options: [{ before: true, after: true }], errors: [ - { message: "Missing whitespace before semicolon.", type: "ForStatement", line: 1, column: 15 }, - { message: "Missing whitespace before semicolon.", type: "ForStatement", line: 1, column: 23 } + { messageId: "missingWhitespaceBefore", type: "ForStatement", line: 1, column: 15 }, + { messageId: "missingWhitespaceBefore", type: "ForStatement", line: 1, column: 23 } ] }, { @@ -160,8 +160,8 @@ ruleTester.run("semi-spacing", rule, { output: "for (var i = 0;i < 10;i++) {}", options: [{ before: false, after: false }], errors: [ - { message: "Unexpected whitespace after semicolon.", type: "ForStatement", line: 1, column: 15 }, - { message: "Unexpected whitespace after semicolon.", type: "ForStatement", line: 1, column: 23 } + { messageId: "unexpectedWhitespaceAfter", type: "ForStatement", line: 1, column: 15 }, + { messageId: "unexpectedWhitespaceAfter", type: "ForStatement", line: 1, column: 23 } ] }, { @@ -170,7 +170,7 @@ ruleTester.run("semi-spacing", rule, { options: [{ before: false, after: true }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ - { message: "Unexpected whitespace before semicolon.", type: "ImportDeclaration", line: 1, column: 23 } + { messageId: "unexpectedWhitespaceBefore", type: "ImportDeclaration", line: 1, column: 23 } ] }, { @@ -179,7 +179,7 @@ ruleTester.run("semi-spacing", rule, { options: [{ before: false, after: true }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ - { message: "Unexpected whitespace before semicolon.", type: "ImportDeclaration", line: 1, column: 28 } + { messageId: "unexpectedWhitespaceBefore", type: "ImportDeclaration", line: 1, column: 28 } ] }, { @@ -188,7 +188,7 @@ ruleTester.run("semi-spacing", rule, { options: [{ before: false, after: true }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ - { message: "Unexpected whitespace before semicolon.", type: "ExportNamedDeclaration", line: 1, column: 27 } + { messageId: "unexpectedWhitespaceBefore", type: "ExportNamedDeclaration", line: 1, column: 27 } ] }, { @@ -197,7 +197,7 @@ ruleTester.run("semi-spacing", rule, { options: [{ before: false, after: true }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ - { message: "Unexpected whitespace before semicolon.", type: "ExportAllDeclaration", line: 1, column: 21 } + { messageId: "unexpectedWhitespaceBefore", type: "ExportAllDeclaration", line: 1, column: 21 } ] }, { @@ -206,7 +206,7 @@ ruleTester.run("semi-spacing", rule, { options: [{ before: false, after: true }], parserOptions: { ecmaVersion: 6, sourceType: "module" }, errors: [ - { message: "Unexpected whitespace before semicolon.", type: "ExportDefaultDeclaration", line: 1, column: 20 } + { messageId: "unexpectedWhitespaceBefore", type: "ExportDefaultDeclaration", line: 1, column: 20 } ] } ] diff --git a/tests/lib/rules/semi-style.js b/tests/lib/rules/semi-style.js index d985293b175..319a80c9b4b 100644 --- a/tests/lib/rules/semi-style.js +++ b/tests/lib/rules/semi-style.js @@ -129,141 +129,261 @@ ruleTester.run("semi-style", rule, { { code: "foo\n;bar", output: "foo;\nbar", - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "if(a)foo\n;bar", output: "if(a)foo;\nbar", - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "var foo\n;bar", output: "var foo;\nbar", - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "foo\n;\nbar", output: "foo;\nbar", - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "for(a\n;b;c)d", output: "for(a;\nb;c)d", - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "for(a;b\n;c)d", output: "for(a;b;\nc)d", - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "do;while(a)\n;b", output: "do;while(a);\nb", - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "foo\n;bar", output: "foo;\nbar", options: ["last"], - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "if(a)foo\n;bar", output: "if(a)foo;\nbar", options: ["last"], - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "var foo\n;bar", output: "var foo;\nbar", options: ["last"], - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "foo\n;\nbar", output: "foo;\nbar", options: ["last"], - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "for(a\n;b;c)d", output: "for(a;\nb;c)d", options: ["last"], - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "for(a;b\n;c)d", output: "for(a;b;\nc)d", options: ["last"], - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "foo()\n;", output: "foo();\n", options: ["last"], - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "foo;\nbar", output: "foo\n;bar", options: ["first"], - errors: ["Expected this semicolon to be at the beginning of the next line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the beginning of the next line" + } + }] }, { code: "if(a)foo;\nbar", output: "if(a)foo\n;bar", options: ["first"], - errors: ["Expected this semicolon to be at the beginning of the next line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the beginning of the next line" + } + }] }, { code: "var foo;\nbar", output: "var foo\n;bar", options: ["first"], - errors: ["Expected this semicolon to be at the beginning of the next line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the beginning of the next line" + } + }] }, { code: "foo\n;\nbar", output: "foo\n;bar", options: ["first"], - errors: ["Expected this semicolon to be at the beginning of the next line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the beginning of the next line" + } + }] }, { code: "for(a\n;b;c)d", output: "for(a;\nb;c)d", options: ["first"], - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "for(a;b\n;c)d", output: "for(a;b;\nc)d", options: ["first"], - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "foo\n;/**/bar", output: null, - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "foo\n/**/;bar", output: null, - errors: ["Expected this semicolon to be at the end of the previous line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the end of the previous line" + } + }] }, { code: "foo;\n/**/bar", output: null, options: ["first"], - errors: ["Expected this semicolon to be at the beginning of the next line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the beginning of the next line" + } + }] }, { code: "foo/**/;\nbar", output: null, options: ["first"], - errors: ["Expected this semicolon to be at the beginning of the next line."] + errors: [{ + messageId: "expectedSemiColon", + data: { + pos: "the beginning of the next line" + } + }] } ] }); diff --git a/tests/lib/rules/sort-imports.js b/tests/lib/rules/sort-imports.js index 54cdf371611..51f3ee3a804 100644 --- a/tests/lib/rules/sort-imports.js +++ b/tests/lib/rules/sort-imports.js @@ -18,7 +18,7 @@ const rule = require("../../../lib/rules/sort-imports"), const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6, sourceType: "module" } }), expectedError = { - message: "Imports should be sorted alphabetically.", + messageId: "sortImportsAlphabetically", type: "ImportDeclaration" }, ignoreCaseArgs = [{ ignoreCase: true }]; @@ -138,7 +138,11 @@ ruleTester.run("sort-imports", rule, { "import {b, c} from 'bar.js';", output: null, errors: [{ - message: "Expected 'multiple' syntax before 'single' syntax.", + messageId: "unexpectedSyntaxOrder", + data: { + syntaxA: "multiple", + syntaxB: "single" + }, type: "ImportDeclaration" }] }, @@ -148,7 +152,11 @@ ruleTester.run("sort-imports", rule, { "import * as b from 'bar.js';", output: null, errors: [{ - message: "Expected 'all' syntax before 'single' syntax.", + messageId: "unexpectedSyntaxOrder", + data: { + syntaxA: "all", + syntaxB: "single" + }, type: "ImportDeclaration" }] }, @@ -158,7 +166,11 @@ ruleTester.run("sort-imports", rule, { "import 'bar.js';", output: null, errors: [{ - message: "Expected 'none' syntax before 'single' syntax.", + messageId: "unexpectedSyntaxOrder", + data: { + syntaxA: "none", + syntaxB: "single" + }, type: "ImportDeclaration" }] }, @@ -171,7 +183,11 @@ ruleTester.run("sort-imports", rule, { memberSyntaxSortOrder: ["all", "single", "multiple", "none"] }], errors: [{ - message: "Expected 'all' syntax before 'single' syntax.", + messageId: "unexpectedSyntaxOrder", + data: { + syntaxA: "all", + syntaxB: "single" + }, type: "ImportDeclaration" }] }, @@ -179,7 +195,8 @@ ruleTester.run("sort-imports", rule, { code: "import {b, a, d, c} from 'foo.js';", output: "import {a, b, c, d} from 'foo.js';", errors: [{ - message: "Member 'a' of the import declaration should be sorted alphabetically.", + messageId: "sortMembersAlphabetically", + data: { memberName: "a" }, type: "ImportSpecifier" }] }, @@ -194,7 +211,8 @@ ruleTester.run("sort-imports", rule, { ignoreDeclarationSort: true }], errors: [{ - message: "Member 'a' of the import declaration should be sorted alphabetically.", + messageId: "sortMembersAlphabetically", + data: { memberName: "a" }, type: "ImportSpecifier" }] }, @@ -202,7 +220,8 @@ ruleTester.run("sort-imports", rule, { code: "import {a, B, c, D} from 'foo.js';", output: "import {B, D, a, c} from 'foo.js';", errors: [{ - message: "Member 'B' of the import declaration should be sorted alphabetically.", + messageId: "sortMembersAlphabetically", + data: { memberName: "B" }, type: "ImportSpecifier" }] }, @@ -210,7 +229,8 @@ ruleTester.run("sort-imports", rule, { code: "import {zzzzz, /* comment */ aaaaa} from 'foo.js';", output: null, // not fixed due to comment errors: [{ - message: "Member 'aaaaa' of the import declaration should be sorted alphabetically.", + messageId: "sortMembersAlphabetically", + data: { memberName: "aaaaa" }, type: "ImportSpecifier" }] }, @@ -218,7 +238,8 @@ ruleTester.run("sort-imports", rule, { code: "import {zzzzz /* comment */, aaaaa} from 'foo.js';", output: null, // not fixed due to comment errors: [{ - message: "Member 'aaaaa' of the import declaration should be sorted alphabetically.", + messageId: "sortMembersAlphabetically", + data: { memberName: "aaaaa" }, type: "ImportSpecifier" }] }, @@ -226,7 +247,8 @@ ruleTester.run("sort-imports", rule, { code: "import {/* comment */ zzzzz, aaaaa} from 'foo.js';", output: null, // not fixed due to comment errors: [{ - message: "Member 'aaaaa' of the import declaration should be sorted alphabetically.", + messageId: "sortMembersAlphabetically", + data: { memberName: "aaaaa" }, type: "ImportSpecifier" }] }, @@ -234,7 +256,8 @@ ruleTester.run("sort-imports", rule, { code: "import {zzzzz, aaaaa /* comment */} from 'foo.js';", output: null, // not fixed due to comment errors: [{ - message: "Member 'aaaaa' of the import declaration should be sorted alphabetically.", + messageId: "sortMembersAlphabetically", + data: { memberName: "aaaaa" }, type: "ImportSpecifier" }] }, @@ -260,7 +283,8 @@ ruleTester.run("sort-imports", rule, { } from 'foo.js'; `, errors: [{ - message: "Member 'qux' of the import declaration should be sorted alphabetically.", + messageId: "sortMembersAlphabetically", + data: { memberName: "qux" }, type: "ImportSpecifier" }] } diff --git a/tests/lib/rules/sort-keys.js b/tests/lib/rules/sort-keys.js index 31ca1c2ac21..ff6482747ad 100644 --- a/tests/lib/rules/sort-keys.js +++ b/tests/lib/rules/sort-keys.js @@ -170,45 +170,155 @@ ruleTester.run("sort-keys", rule, { // default (asc) { code: "var obj = {a:1, '':2} // default", - errors: ["Expected object keys to be in ascending order. '' should be before 'a'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "", + prevName: "a" + } + } + ] }, { code: "var obj = {a:1, [``]:2} // default", parserOptions: { ecmaVersion: 6 }, - errors: ["Expected object keys to be in ascending order. '' should be before 'a'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "", + prevName: "a" + } + } + ] }, { code: "var obj = {a:1, _:2, b:3} // default", - errors: ["Expected object keys to be in ascending order. '_' should be before 'a'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "_", + prevName: "a" + } + } + ] }, { code: "var obj = {a:1, c:2, b:3}", - errors: ["Expected object keys to be in ascending order. 'b' should be before 'c'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "b", + prevName: "c" + } + } + ] }, { code: "var obj = {b_:1, a:2, b:3}", - errors: ["Expected object keys to be in ascending order. 'a' should be before 'b_'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "a", + prevName: "b_" + } + } + ] }, { code: "var obj = {b_:1, c:2, C:3}", - errors: ["Expected object keys to be in ascending order. 'C' should be before 'c'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "C", + prevName: "c" + } + } + ] }, { code: "var obj = {$:1, _:2, A:3, a:4}", - errors: ["Expected object keys to be in ascending order. 'A' should be before '_'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "A", + prevName: "_" + } + } + ] }, { code: "var obj = {1:1, 2:4, A:3, '11':2}", - errors: ["Expected object keys to be in ascending order. '11' should be before 'A'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "11", + prevName: "A" + } + } + ] }, { code: "var obj = {'#':1, À:3, 'Z':2, è:4}", - errors: ["Expected object keys to be in ascending order. 'Z' should be before 'À'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "Z", + prevName: "À" + } + } + ] }, { code: "var obj = { null: 1, [/(?0)/]: 2 }", parserOptions: { ecmaVersion: 2018 }, - errors: ["Expected object keys to be in ascending order. '/(?0)/' should be before 'null'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "/(?0)/", + prevName: "null" + } + } + ] }, // not ignore properties not separated by spread properties @@ -216,86 +326,243 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {...z, c:1, b:1}", options: [], parserOptions: { ecmaVersion: 2018 }, - errors: ["Expected object keys to be in ascending order. 'b' should be before 'c'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "b", + prevName: "c" + } + } + ] }, { code: "var obj = {...z, ...c, d:4, b:1, ...y, ...f, e:2, a:1}", options: [], parserOptions: { ecmaVersion: 2018 }, errors: [ - "Expected object keys to be in ascending order. 'b' should be before 'd'.", - "Expected object keys to be in ascending order. 'a' should be before 'e'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "b", + prevName: "d" + } + }, + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "a", + prevName: "e" + } + } ] }, { code: "var obj = {c:1, b:1, ...a}", options: [], parserOptions: { ecmaVersion: 2018 }, - errors: ["Expected object keys to be in ascending order. 'b' should be before 'c'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "b", + prevName: "c" + } + } + ] }, { code: "var obj = {...z, ...a, c:1, b:1}", options: [], parserOptions: { ecmaVersion: 2018 }, - errors: ["Expected object keys to be in ascending order. 'b' should be before 'c'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "b", + prevName: "c" + } + } + ] }, { code: "var obj = {...z, b:1, a:1, ...d, ...c}", options: [], parserOptions: { ecmaVersion: 2018 }, - errors: ["Expected object keys to be in ascending order. 'a' should be before 'b'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "a", + prevName: "b" + } + } + ] }, { code: "var obj = {...z, a:2, b:0, ...x, ...c}", options: ["desc"], parserOptions: { ecmaVersion: 2018 }, - errors: ["Expected object keys to be in descending order. 'b' should be before 'a'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "b", + prevName: "a" + } + } + ] }, { code: "var obj = {...z, a:2, b:0, ...x}", options: ["desc"], parserOptions: { ecmaVersion: 2018 }, - errors: ["Expected object keys to be in descending order. 'b' should be before 'a'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "b", + prevName: "a" + } + } + ] }, { code: "var obj = {...z, '':1, a:2}", options: ["desc"], parserOptions: { ecmaVersion: 2018 }, - errors: ["Expected object keys to be in descending order. 'a' should be before ''."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "a", + prevName: "" + } + } + ] }, // ignore non-simple computed properties, but their position shouldn't affect other comparisons. { code: "var obj = {a:1, [b+c]:2, '':3}", parserOptions: { ecmaVersion: 6 }, - errors: ["Expected object keys to be in ascending order. '' should be before 'a'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "", + prevName: "a" + } + } + ] }, { code: "var obj = {'':1, [b+c]:2, a:3}", options: ["desc"], parserOptions: { ecmaVersion: 6 }, - errors: ["Expected object keys to be in descending order. 'a' should be before ''."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "a", + prevName: "" + } + } + ] }, { code: "var obj = {b:1, [f()]:2, '':3, a:4}", options: ["desc"], parserOptions: { ecmaVersion: 6 }, - errors: ["Expected object keys to be in descending order. 'a' should be before ''."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "a", + prevName: "" + } + } + ] }, // not ignore simple computed properties. { code: "var obj = {a:1, b:3, [a]: -1, c:2}", parserOptions: { ecmaVersion: 6 }, - errors: ["Expected object keys to be in ascending order. 'a' should be before 'b'."] + errors: [ + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "a", + prevName: "b" + } + } + ] }, // nested { code: "var obj = {a:1, c:{y:1, x:1}, b:1}", errors: [ - "Expected object keys to be in ascending order. 'x' should be before 'y'.", - "Expected object keys to be in ascending order. 'b' should be before 'c'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "x", + prevName: "y" + } + }, + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "b", + prevName: "c" + } + } ] }, @@ -304,49 +571,112 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3} // asc", options: ["asc"], errors: [ - "Expected object keys to be in ascending order. '_' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "_", + prevName: "a" + } + } ] }, { code: "var obj = {a:1, c:2, b:3}", options: ["asc"], errors: [ - "Expected object keys to be in ascending order. 'b' should be before 'c'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "b", + prevName: "c" + } + } ] }, { code: "var obj = {b_:1, a:2, b:3}", options: ["asc"], errors: [ - "Expected object keys to be in ascending order. 'a' should be before 'b_'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "a", + prevName: "b_" + } + } ] }, { code: "var obj = {b_:1, c:2, C:3}", options: ["asc"], errors: [ - "Expected object keys to be in ascending order. 'C' should be before 'c'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "C", + prevName: "c" + } + } ] }, { code: "var obj = {$:1, _:2, A:3, a:4}", options: ["asc"], errors: [ - "Expected object keys to be in ascending order. 'A' should be before '_'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "A", + prevName: "_" + } + } ] }, { code: "var obj = {1:1, 2:4, A:3, '11':2}", options: ["asc"], errors: [ - "Expected object keys to be in ascending order. '11' should be before 'A'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "11", + prevName: "A" + } + } ] }, { code: "var obj = {'#':1, À:3, 'Z':2, è:4}", options: ["asc"], errors: [ - "Expected object keys to be in ascending order. 'Z' should be before 'À'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "Z", + prevName: "À" + } + } ] }, @@ -355,7 +685,16 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3}", options: ["asc", { minKeys: 3 }], errors: [ - "Expected object keys to be in ascending order. '_' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "asc", + thisName: "_", + prevName: "a" + } + } ] }, @@ -364,42 +703,96 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3} // asc, insensitive", options: ["asc", { caseSensitive: false }], errors: [ - "Expected object keys to be in insensitive ascending order. '_' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "asc", + thisName: "_", + prevName: "a" + } + } ] }, { code: "var obj = {a:1, c:2, b:3}", options: ["asc", { caseSensitive: false }], errors: [ - "Expected object keys to be in insensitive ascending order. 'b' should be before 'c'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "asc", + thisName: "b", + prevName: "c" + } + } ] }, { code: "var obj = {b_:1, a:2, b:3}", options: ["asc", { caseSensitive: false }], errors: [ - "Expected object keys to be in insensitive ascending order. 'a' should be before 'b_'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "asc", + thisName: "a", + prevName: "b_" + } + } ] }, { code: "var obj = {$:1, A:3, _:2, a:4}", options: ["asc", { caseSensitive: false }], errors: [ - "Expected object keys to be in insensitive ascending order. '_' should be before 'A'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "asc", + thisName: "_", + prevName: "A" + } + } ] }, { code: "var obj = {1:1, 2:4, A:3, '11':2}", options: ["asc", { caseSensitive: false }], errors: [ - "Expected object keys to be in insensitive ascending order. '11' should be before 'A'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "asc", + thisName: "11", + prevName: "A" + } + } ] }, { code: "var obj = {'#':1, À:3, 'Z':2, è:4}", options: ["asc", { caseSensitive: false }], errors: [ - "Expected object keys to be in insensitive ascending order. 'Z' should be before 'À'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "asc", + thisName: "Z", + prevName: "À" + } + } ] }, @@ -408,7 +801,16 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3}", options: ["asc", { caseSensitive: false, minKeys: 3 }], errors: [ - "Expected object keys to be in insensitive ascending order. '_' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "asc", + thisName: "_", + prevName: "a" + } + } ] }, @@ -417,49 +819,112 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3} // asc, natural", options: ["asc", { natural: true }], errors: [ - "Expected object keys to be in natural ascending order. '_' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "asc", + thisName: "_", + prevName: "a" + } + } ] }, { code: "var obj = {a:1, c:2, b:3}", options: ["asc", { natural: true }], errors: [ - "Expected object keys to be in natural ascending order. 'b' should be before 'c'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "asc", + thisName: "b", + prevName: "c" + } + } ] }, { code: "var obj = {b_:1, a:2, b:3}", options: ["asc", { natural: true }], errors: [ - "Expected object keys to be in natural ascending order. 'a' should be before 'b_'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "asc", + thisName: "a", + prevName: "b_" + } + } ] }, { code: "var obj = {b_:1, c:2, C:3}", options: ["asc", { natural: true }], errors: [ - "Expected object keys to be in natural ascending order. 'C' should be before 'c'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "asc", + thisName: "C", + prevName: "c" + } + } ] }, { code: "var obj = {$:1, A:3, _:2, a:4}", options: ["asc", { natural: true }], errors: [ - "Expected object keys to be in natural ascending order. '_' should be before 'A'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "asc", + thisName: "_", + prevName: "A" + } + } ] }, { code: "var obj = {1:1, 2:4, A:3, '11':2}", options: ["asc", { natural: true }], errors: [ - "Expected object keys to be in natural ascending order. '11' should be before 'A'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "asc", + thisName: "11", + prevName: "A" + } + } ] }, { code: "var obj = {'#':1, À:3, 'Z':2, è:4}", options: ["asc", { natural: true }], errors: [ - "Expected object keys to be in natural ascending order. 'Z' should be before 'À'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "asc", + thisName: "Z", + prevName: "À" + } + } ] }, @@ -468,7 +933,16 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3}", options: ["asc", { natural: true, minKeys: 2 }], errors: [ - "Expected object keys to be in natural ascending order. '_' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "asc", + thisName: "_", + prevName: "a" + } + } ] }, @@ -477,42 +951,96 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3} // asc, natural, insensitive", options: ["asc", { natural: true, caseSensitive: false }], errors: [ - "Expected object keys to be in natural insensitive ascending order. '_' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "asc", + thisName: "_", + prevName: "a" + } + } ] }, { code: "var obj = {a:1, c:2, b:3}", options: ["asc", { natural: true, caseSensitive: false }], errors: [ - "Expected object keys to be in natural insensitive ascending order. 'b' should be before 'c'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "asc", + thisName: "b", + prevName: "c" + } + } ] }, { code: "var obj = {b_:1, a:2, b:3}", options: ["asc", { natural: true, caseSensitive: false }], errors: [ - "Expected object keys to be in natural insensitive ascending order. 'a' should be before 'b_'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "asc", + thisName: "a", + prevName: "b_" + } + } ] }, { code: "var obj = {$:1, A:3, _:2, a:4}", options: ["asc", { natural: true, caseSensitive: false }], errors: [ - "Expected object keys to be in natural insensitive ascending order. '_' should be before 'A'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "asc", + thisName: "_", + prevName: "A" + } + } ] }, { code: "var obj = {1:1, '11':2, 2:4, A:3}", options: ["asc", { natural: true, caseSensitive: false }], errors: [ - "Expected object keys to be in natural insensitive ascending order. '2' should be before '11'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "asc", + thisName: "2", + prevName: "11" + } + } ] }, { code: "var obj = {'#':1, À:3, 'Z':2, è:4}", options: ["asc", { natural: true, caseSensitive: false }], errors: [ - "Expected object keys to be in natural insensitive ascending order. 'Z' should be before 'À'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "asc", + thisName: "Z", + prevName: "À" + } + } ] }, @@ -521,7 +1049,16 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3}", options: ["asc", { natural: true, caseSensitive: false, minKeys: 3 }], errors: [ - "Expected object keys to be in natural insensitive ascending order. '_' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "asc", + thisName: "_", + prevName: "a" + } + } ] }, @@ -530,7 +1067,16 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {'':1, a:'2'} // desc", options: ["desc"], errors: [ - "Expected object keys to be in descending order. 'a' should be before ''." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "a", + prevName: "" + } + } ] }, { @@ -538,59 +1084,158 @@ ruleTester.run("sort-keys", rule, { options: ["desc"], parserOptions: { ecmaVersion: 6 }, errors: [ - "Expected object keys to be in descending order. 'a' should be before ''." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "a", + prevName: "" + } + } ] }, { code: "var obj = {a:1, _:2, b:3} // desc", options: ["desc"], errors: [ - "Expected object keys to be in descending order. 'b' should be before '_'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "b", + prevName: "_" + } + } ] }, { code: "var obj = {a:1, c:2, b:3}", options: ["desc"], errors: [ - "Expected object keys to be in descending order. 'c' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "c", + prevName: "a" + } + } ] }, { code: "var obj = {b_:1, a:2, b:3}", options: ["desc"], errors: [ - "Expected object keys to be in descending order. 'b' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "b", + prevName: "a" + } + } ] }, { code: "var obj = {b_:1, c:2, C:3}", options: ["desc"], errors: [ - "Expected object keys to be in descending order. 'c' should be before 'b_'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "c", + prevName: "b_" + } + } ] }, { code: "var obj = {$:1, _:2, A:3, a:4}", options: ["desc"], errors: [ - "Expected object keys to be in descending order. '_' should be before '$'.", - "Expected object keys to be in descending order. 'a' should be before 'A'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "_", + prevName: "$" + } + }, + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "a", + prevName: "A" + } + } ] }, { code: "var obj = {1:1, 2:4, A:3, '11':2}", options: ["desc"], errors: [ - "Expected object keys to be in descending order. '2' should be before '1'.", - "Expected object keys to be in descending order. 'A' should be before '2'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "2", + prevName: "1" + } + }, + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "A", + prevName: "2" + } + } ] }, { code: "var obj = {'#':1, À:3, 'Z':2, è:4}", options: ["desc"], errors: [ - "Expected object keys to be in descending order. 'À' should be before '#'.", - "Expected object keys to be in descending order. 'è' should be before 'Z'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "À", + prevName: "#" + } + }, + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "è", + prevName: "Z" + } + } ] }, @@ -599,7 +1244,16 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3}", options: ["desc", { minKeys: 3 }], errors: [ - "Expected object keys to be in descending order. 'b' should be before '_'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "", + order: "desc", + thisName: "b", + prevName: "_" + } + } ] }, @@ -608,52 +1262,142 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3} // desc, insensitive", options: ["desc", { caseSensitive: false }], errors: [ - "Expected object keys to be in insensitive descending order. 'b' should be before '_'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "desc", + thisName: "b", + prevName: "_" + } + } ] }, { code: "var obj = {a:1, c:2, b:3}", options: ["desc", { caseSensitive: false }], errors: [ - "Expected object keys to be in insensitive descending order. 'c' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "desc", + thisName: "c", + prevName: "a" + } + } ] }, { code: "var obj = {b_:1, a:2, b:3}", options: ["desc", { caseSensitive: false }], errors: [ - "Expected object keys to be in insensitive descending order. 'b' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "desc", + thisName: "b", + prevName: "a" + } + } ] }, { code: "var obj = {b_:1, c:2, C:3}", options: ["desc", { caseSensitive: false }], errors: [ - "Expected object keys to be in insensitive descending order. 'c' should be before 'b_'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "desc", + thisName: "c", + prevName: "b_" + } + } ] }, { code: "var obj = {$:1, _:2, A:3, a:4}", options: ["desc", { caseSensitive: false }], errors: [ - "Expected object keys to be in insensitive descending order. '_' should be before '$'.", - "Expected object keys to be in insensitive descending order. 'A' should be before '_'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "desc", + thisName: "_", + prevName: "$" + } + }, + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "desc", + thisName: "A", + prevName: "_" + } + } ] }, { code: "var obj = {1:1, 2:4, A:3, '11':2}", options: ["desc", { caseSensitive: false }], errors: [ - "Expected object keys to be in insensitive descending order. '2' should be before '1'.", - "Expected object keys to be in insensitive descending order. 'A' should be before '2'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "desc", + thisName: "2", + prevName: "1" + } + }, + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "desc", + thisName: "A", + prevName: "2" + } + } ] }, { code: "var obj = {'#':1, À:3, 'Z':2, è:4}", options: ["desc", { caseSensitive: false }], errors: [ - "Expected object keys to be in insensitive descending order. 'À' should be before '#'.", - "Expected object keys to be in insensitive descending order. 'è' should be before 'Z'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "desc", + thisName: "À", + prevName: "#" + } + }, + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "desc", + thisName: "è", + prevName: "Z" + } + } ] }, @@ -662,7 +1406,16 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3}", options: ["desc", { caseSensitive: false, minKeys: 2 }], errors: [ - "Expected object keys to be in insensitive descending order. 'b' should be before '_'." + { + messageId: "sortKeys", + data: { + natural: "", + insensitive: "insensitive ", + order: "desc", + thisName: "b", + prevName: "_" + } + } ] }, @@ -671,53 +1424,152 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3} // desc, natural", options: ["desc", { natural: true }], errors: [ - "Expected object keys to be in natural descending order. 'b' should be before '_'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "desc", + thisName: "b", + prevName: "_" + } + } ] }, { code: "var obj = {a:1, c:2, b:3}", options: ["desc", { natural: true }], errors: [ - "Expected object keys to be in natural descending order. 'c' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "desc", + thisName: "c", + prevName: "a" + } + } ] }, { code: "var obj = {b_:1, a:2, b:3}", options: ["desc", { natural: true }], errors: [ - "Expected object keys to be in natural descending order. 'b' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "desc", + thisName: "b", + prevName: "a" + } + } ] }, { code: "var obj = {b_:1, c:2, C:3}", options: ["desc", { natural: true }], errors: [ - "Expected object keys to be in natural descending order. 'c' should be before 'b_'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "desc", + thisName: "c", + prevName: "b_" + } + } ] }, { code: "var obj = {$:1, _:2, A:3, a:4}", options: ["desc", { natural: true }], errors: [ - "Expected object keys to be in natural descending order. '_' should be before '$'.", - "Expected object keys to be in natural descending order. 'A' should be before '_'.", - "Expected object keys to be in natural descending order. 'a' should be before 'A'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "desc", + thisName: "_", + prevName: "$" + } + }, + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "desc", + thisName: "A", + prevName: "_" + } + }, + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "desc", + thisName: "a", + prevName: "A" + } + } ] }, { code: "var obj = {1:1, 2:4, A:3, '11':2}", options: ["desc", { natural: true }], errors: [ - "Expected object keys to be in natural descending order. '2' should be before '1'.", - "Expected object keys to be in natural descending order. 'A' should be before '2'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "desc", + thisName: "2", + prevName: "1" + } + }, + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "desc", + thisName: "A", + prevName: "2" + } + } ] }, { code: "var obj = {'#':1, À:3, 'Z':2, è:4}", options: ["desc", { natural: true }], errors: [ - "Expected object keys to be in natural descending order. 'À' should be before '#'.", - "Expected object keys to be in natural descending order. 'è' should be before 'Z'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "desc", + thisName: "À", + prevName: "#" + } + }, + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "desc", + thisName: "è", + prevName: "Z" + } + } ] }, @@ -726,7 +1578,16 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3}", options: ["desc", { natural: true, minKeys: 3 }], errors: [ - "Expected object keys to be in natural descending order. 'b' should be before '_'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "", + order: "desc", + thisName: "b", + prevName: "_" + } + } ] }, @@ -735,53 +1596,152 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3} // desc, natural, insensitive", options: ["desc", { natural: true, caseSensitive: false }], errors: [ - "Expected object keys to be in natural insensitive descending order. 'b' should be before '_'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "desc", + thisName: "b", + prevName: "_" + } + } ] }, { code: "var obj = {a:1, c:2, b:3}", options: ["desc", { natural: true, caseSensitive: false }], errors: [ - "Expected object keys to be in natural insensitive descending order. 'c' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "desc", + thisName: "c", + prevName: "a" + } + } ] }, { code: "var obj = {b_:1, a:2, b:3}", options: ["desc", { natural: true, caseSensitive: false }], errors: [ - "Expected object keys to be in natural insensitive descending order. 'b' should be before 'a'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "desc", + thisName: "b", + prevName: "a" + } + } ] }, { code: "var obj = {b_:1, c:2, C:3}", options: ["desc", { natural: true, caseSensitive: false }], errors: [ - "Expected object keys to be in natural insensitive descending order. 'c' should be before 'b_'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "desc", + thisName: "c", + prevName: "b_" + } + } ] }, { code: "var obj = {$:1, _:2, A:3, a:4}", options: ["desc", { natural: true, caseSensitive: false }], errors: [ - "Expected object keys to be in natural insensitive descending order. '_' should be before '$'.", - "Expected object keys to be in natural insensitive descending order. 'A' should be before '_'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "desc", + thisName: "_", + prevName: "$" + } + }, + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "desc", + thisName: "A", + prevName: "_" + } + } ] }, { code: "var obj = {1:1, 2:4, '11':2, A:3}", options: ["desc", { natural: true, caseSensitive: false }], errors: [ - "Expected object keys to be in natural insensitive descending order. '2' should be before '1'.", - "Expected object keys to be in natural insensitive descending order. '11' should be before '2'.", - "Expected object keys to be in natural insensitive descending order. 'A' should be before '11'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "desc", + thisName: "2", + prevName: "1" + } + }, + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "desc", + thisName: "11", + prevName: "2" + } + }, + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "desc", + thisName: "A", + prevName: "11" + } + } ] }, { code: "var obj = {'#':1, À:3, 'Z':2, è:4}", options: ["desc", { natural: true, caseSensitive: false }], errors: [ - "Expected object keys to be in natural insensitive descending order. 'À' should be before '#'.", - "Expected object keys to be in natural insensitive descending order. 'è' should be before 'Z'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "desc", + thisName: "À", + prevName: "#" + } + }, + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "desc", + thisName: "è", + prevName: "Z" + } + } ] }, @@ -790,7 +1750,16 @@ ruleTester.run("sort-keys", rule, { code: "var obj = {a:1, _:2, b:3}", options: ["desc", { natural: true, caseSensitive: false, minKeys: 2 }], errors: [ - "Expected object keys to be in natural insensitive descending order. 'b' should be before '_'." + { + messageId: "sortKeys", + data: { + natural: "natural ", + insensitive: "insensitive ", + order: "desc", + thisName: "b", + prevName: "_" + } + } ] } ] diff --git a/tests/lib/rules/sort-vars.js b/tests/lib/rules/sort-vars.js index dfe50103598..fb12b1fc33d 100644 --- a/tests/lib/rules/sort-vars.js +++ b/tests/lib/rules/sort-vars.js @@ -18,7 +18,7 @@ const rule = require("../../../lib/rules/sort-vars"), const ruleTester = new RuleTester(), expectedError = { - message: "Variables within the same declaration block should be sorted alphabetically.", + messageId: "sortVars", type: "VariableDeclarator" }, ignoreCaseArgs = [{ ignoreCase: true }]; diff --git a/tests/lib/rules/space-before-blocks.js b/tests/lib/rules/space-before-blocks.js index e5eaa73119b..7b36d9f30ee 100644 --- a/tests/lib/rules/space-before-blocks.js +++ b/tests/lib/rules/space-before-blocks.js @@ -27,10 +27,8 @@ const ruleTester = new RuleTester(), functionsNeverOthersOffArgs = [{ functions: "never", keywords: "off", classes: "off" }], keywordNeverOthersOffArgs = [{ functions: "off", keywords: "never", classes: "off" }], classesNeverOthersOffArgs = [{ functions: "off", keywords: "off", classes: "never" }], - expectedSpacingErrorMessage = "Missing space before opening brace.", - expectedSpacingError = { message: expectedSpacingErrorMessage }, - expectedNoSpacingErrorMessage = "Unexpected space before opening brace.", - expectedNoSpacingError = { message: "Unexpected space before opening brace." }; + expectedSpacingError = { messageId: "missingSpace" }, + expectedNoSpacingError = { messageId: "unexpectedSpace" }; ruleTester.run("space-before-blocks", rule, { valid: [ @@ -200,7 +198,7 @@ ruleTester.run("space-before-blocks", rule, { { code: "if(a){}", output: "if(a) {}", - errors: [{ message: expectedSpacingErrorMessage, line: 1, column: 6 }] + errors: [{ messageId: "missingSpace", line: 1, column: 6 }] }, { code: "if(a){}", @@ -218,13 +216,13 @@ ruleTester.run("space-before-blocks", rule, { code: "if(a) { function a() {} }", output: "if(a){ function a() {} }", options: functionsOnlyArgs, - errors: [{ message: expectedNoSpacingErrorMessage, line: 1, column: 7 }] + errors: [{ messageId: "unexpectedSpace", line: 1, column: 7 }] }, { code: "if(a) { function a() {} }", output: "if(a) { function a(){} }", options: keywordOnlyArgs, - errors: [{ message: expectedNoSpacingErrorMessage, line: 1, column: 22 }] + errors: [{ messageId: "unexpectedSpace", line: 1, column: 22 }] }, { code: "if(a) {}", @@ -253,13 +251,13 @@ ruleTester.run("space-before-blocks", rule, { code: "function a(){ if (a){} }", output: "function a() { if (a){} }", options: functionsOnlyArgs, - errors: [{ message: expectedSpacingErrorMessage, line: 1, column: 13 }] + errors: [{ messageId: "missingSpace", line: 1, column: 13 }] }, { code: "function a() { if (a) {} }", output: "function a(){ if (a) {} }", options: keywordOnlyArgs, - errors: [{ message: expectedNoSpacingErrorMessage, line: 1, column: 14 }] + errors: [{ messageId: "unexpectedSpace", line: 1, column: 14 }] }, { code: "function a(){}", @@ -328,13 +326,13 @@ ruleTester.run("space-before-blocks", rule, { code: "try { function b() {} } catch(a) {}", output: "try { function b(){} } catch(a) {}", options: keywordOnlyArgs, - errors: [{ message: expectedNoSpacingErrorMessage, line: 1, column: 20 }] + errors: [{ messageId: "unexpectedSpace", line: 1, column: 20 }] }, { code: "try{ function b(){} }catch(a){}", output: "try{ function b() {} }catch(a){}", options: functionsOnlyArgs, - errors: [{ message: expectedSpacingErrorMessage, line: 1, column: 18 }] + errors: [{ messageId: "missingSpace", line: 1, column: 18 }] }, { code: "for(;;){}", diff --git a/tests/lib/rules/space-before-function-paren.js b/tests/lib/rules/space-before-function-paren.js index 961d6895adc..bc192393979 100644 --- a/tests/lib/rules/space-before-function-paren.js +++ b/tests/lib/rules/space-before-function-paren.js @@ -134,7 +134,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionDeclaration", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 1, column: 13 } @@ -146,7 +146,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionDeclaration", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 1, column: 13 } @@ -158,7 +158,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 1, column: 19 } @@ -170,7 +170,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 1, column: 23 } @@ -182,13 +182,13 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 1, column: 20 }, { type: "FunctionExpression", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 1, column: 34 } @@ -201,7 +201,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 1, column: 16 } @@ -214,7 +214,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionDeclaration", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 1, column: 14 } @@ -228,7 +228,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionDeclaration", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 13 } @@ -241,7 +241,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionDeclaration", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 13 } @@ -254,7 +254,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionDeclaration", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 13 } @@ -267,7 +267,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionDeclaration", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 13 } @@ -280,7 +280,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionDeclaration", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 13 } @@ -293,7 +293,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionDeclaration", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 13 } @@ -306,7 +306,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionDeclaration", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 13 } @@ -319,7 +319,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 19 } @@ -332,7 +332,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 23 } @@ -345,13 +345,13 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 20 }, { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 35 } @@ -365,7 +365,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 16 } @@ -379,7 +379,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionDeclaration", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 14 } @@ -402,31 +402,31 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionDeclaration", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 13 }, { type: "FunctionExpression", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 2, column: 19 }, { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 3, column: 20 }, { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 3, column: 35 }, { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 3, column: 49 } @@ -440,13 +440,13 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 24 }, { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 38 } @@ -460,7 +460,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 16 } @@ -482,31 +482,31 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionDeclaration", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 1, column: 13 }, { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 2, column: 19 }, { type: "FunctionExpression", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 3, column: 20 }, { type: "FunctionExpression", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 3, column: 34 }, { type: "FunctionExpression", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 3, column: 47 } @@ -519,7 +519,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 1, column: 19 } @@ -532,7 +532,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 19 } @@ -545,7 +545,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Missing space before function parentheses.", + messageId: "missingSpace", line: 1, column: 23 } @@ -558,7 +558,7 @@ ruleTester.run("space-before-function-paren", rule, { errors: [ { type: "FunctionExpression", - message: "Unexpected space before function parentheses.", + messageId: "unexpectedSpace", line: 1, column: 23 } @@ -584,21 +584,21 @@ ruleTester.run("space-before-function-paren", rule, { code: "async() => 1", output: "async () => 1", parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Missing space before function parentheses.", type: "ArrowFunctionExpression" }] + errors: [{ messageId: "missingSpace", type: "ArrowFunctionExpression" }] }, { code: "async() => 1", output: "async () => 1", options: ["always"], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Missing space before function parentheses.", type: "ArrowFunctionExpression" }] + errors: [{ messageId: "missingSpace", type: "ArrowFunctionExpression" }] }, { code: "async () => 1", output: "async() => 1", options: ["never"], parserOptions: { ecmaVersion: 8 }, - errors: [{ message: "Unexpected space before function parentheses.", type: "ArrowFunctionExpression" }] + errors: [{ messageId: "unexpectedSpace", type: "ArrowFunctionExpression" }] } ] }); diff --git a/tests/lib/rules/space-infix-ops.js b/tests/lib/rules/space-infix-ops.js index 5906743452c..65c1e562002 100644 --- a/tests/lib/rules/space-infix-ops.js +++ b/tests/lib/rules/space-infix-ops.js @@ -54,7 +54,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a+b", output: "a + b", errors: [{ - message: "Operator '+' must be spaced.", + messageId: "missingSpace", + data: { operator: "+" }, type: "BinaryExpression", line: 1, column: 2, @@ -65,7 +66,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a +b", output: "a + b", errors: [{ - message: "Operator '+' must be spaced.", + messageId: "missingSpace", + data: { operator: "+" }, type: "BinaryExpression", line: 1, column: 3, @@ -76,7 +78,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a+ b", output: "a + b", errors: [{ - message: "Operator '+' must be spaced.", + messageId: "missingSpace", + data: { operator: "+" }, type: "BinaryExpression", line: 1, column: 2, @@ -87,7 +90,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a||b", output: "a || b", errors: [{ - message: "Operator '||' must be spaced.", + messageId: "missingSpace", + data: { operator: "||" }, type: "LogicalExpression", line: 1, column: 2, @@ -98,7 +102,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a ||b", output: "a || b", errors: [{ - message: "Operator '||' must be spaced.", + messageId: "missingSpace", + data: { operator: "||" }, type: "LogicalExpression", line: 1, column: 3, @@ -109,7 +114,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a|| b", output: "a || b", errors: [{ - message: "Operator '||' must be spaced.", + messageId: "missingSpace", + data: { operator: "||" }, type: "LogicalExpression", line: 1, column: 2, @@ -120,7 +126,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a=b", output: "a = b", errors: [{ - message: "Operator '=' must be spaced.", + messageId: "missingSpace", + data: { operator: "=" }, type: "AssignmentExpression", line: 1, column: 2 @@ -130,7 +137,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a= b", output: "a = b", errors: [{ - message: "Operator '=' must be spaced.", + messageId: "missingSpace", + data: { operator: "=" }, type: "AssignmentExpression", line: 1, column: 2 @@ -140,7 +148,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a =b", output: "a = b", errors: [{ - message: "Operator '=' must be spaced.", + messageId: "missingSpace", + data: { operator: "=" }, type: "AssignmentExpression", line: 1, column: 3 @@ -150,7 +159,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a?b:c", output: "a ? b:c", errors: [{ - message: "Operator '?' must be spaced.", + messageId: "missingSpace", + data: { operator: "?" }, type: "ConditionalExpression", line: 1, column: 2, @@ -161,7 +171,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a?b : c", output: "a ? b : c", errors: [{ - message: "Operator '?' must be spaced.", + messageId: "missingSpace", + data: { operator: "?" }, type: "ConditionalExpression", line: 1, column: 2, @@ -172,7 +183,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a ? b:c", output: "a ? b : c", errors: [{ - message: "Operator ':' must be spaced.", + messageId: "missingSpace", + data: { operator: ":" }, type: "ConditionalExpression", line: 1, column: 6, @@ -183,7 +195,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a? b : c", output: "a ? b : c", errors: [{ - message: "Operator '?' must be spaced.", + messageId: "missingSpace", + data: { operator: "?" }, type: "ConditionalExpression", line: 1, column: 2, @@ -194,7 +207,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a ?b : c", output: "a ? b : c", errors: [{ - message: "Operator '?' must be spaced.", + messageId: "missingSpace", + data: { operator: "?" }, type: "ConditionalExpression", line: 1, column: 3, @@ -205,7 +219,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a ? b: c", output: "a ? b : c", errors: [{ - message: "Operator ':' must be spaced.", + messageId: "missingSpace", + data: { operator: ":" }, type: "ConditionalExpression", line: 1, column: 6, @@ -216,7 +231,8 @@ ruleTester.run("space-infix-ops", rule, { code: "a ? b :c", output: "a ? b : c", errors: [{ - message: "Operator ':' must be spaced.", + messageId: "missingSpace", + data: { operator: ":" }, type: "ConditionalExpression", line: 1, column: 7, @@ -227,7 +243,8 @@ ruleTester.run("space-infix-ops", rule, { code: "var a=b;", output: "var a = b;", errors: [{ - message: "Operator '=' must be spaced.", + messageId: "missingSpace", + data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 6 @@ -237,7 +254,8 @@ ruleTester.run("space-infix-ops", rule, { code: "var a= b;", output: "var a = b;", errors: [{ - message: "Operator '=' must be spaced.", + messageId: "missingSpace", + data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 6 @@ -247,7 +265,8 @@ ruleTester.run("space-infix-ops", rule, { code: "var a =b;", output: "var a = b;", errors: [{ - message: "Operator '=' must be spaced.", + messageId: "missingSpace", + data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 7 @@ -257,7 +276,8 @@ ruleTester.run("space-infix-ops", rule, { code: "var a = b, c=d;", output: "var a = b, c = d;", errors: [{ - message: "Operator '=' must be spaced.", + messageId: "missingSpace", + data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 13 @@ -270,7 +290,8 @@ ruleTester.run("space-infix-ops", rule, { int32Hint: true }], errors: [{ - message: "Operator '|' must be spaced.", + messageId: "missingSpace", + data: { operator: "|" }, type: "BinaryExpression", line: 1, column: 2 @@ -280,7 +301,8 @@ ruleTester.run("space-infix-ops", rule, { code: "var output = test || (test && test.value) ||(test2 && test2.value);", output: "var output = test || (test && test.value) || (test2 && test2.value);", errors: [{ - message: "Operator '||' must be spaced.", + messageId: "missingSpace", + data: { operator: "||" }, type: "LogicalExpression", line: 1, column: 43 @@ -290,7 +312,8 @@ ruleTester.run("space-infix-ops", rule, { code: "var output = a ||(b && c.value) || (d && e.value);", output: "var output = a || (b && c.value) || (d && e.value);", errors: [{ - message: "Operator '||' must be spaced.", + messageId: "missingSpace", + data: { operator: "||" }, type: "LogicalExpression", line: 1, column: 16 @@ -300,7 +323,8 @@ ruleTester.run("space-infix-ops", rule, { code: "var output = a|| (b && c.value) || (d && e.value);", output: "var output = a || (b && c.value) || (d && e.value);", errors: [{ - message: "Operator '||' must be spaced.", + messageId: "missingSpace", + data: { operator: "||" }, type: "LogicalExpression", line: 1, column: 15 @@ -311,7 +335,8 @@ ruleTester.run("space-infix-ops", rule, { output: "const my_object = {key: 'value'}", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Operator '=' must be spaced.", + messageId: "missingSpace", + data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 16 @@ -322,12 +347,14 @@ ruleTester.run("space-infix-ops", rule, { output: "var {a = 0} = bar;", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Operator '=' must be spaced.", + messageId: "missingSpace", + data: { operator: "=" }, line: 1, column: 7, type: "AssignmentPattern" }, { - message: "Operator '=' must be spaced.", + messageId: "missingSpace", + data: { operator: "=" }, line: 1, column: 10, type: "VariableDeclarator" @@ -338,7 +365,8 @@ ruleTester.run("space-infix-ops", rule, { output: "function foo(a = 0) { }", parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Operator '=' must be spaced.", + messageId: "missingSpace", + data: { operator: "=" }, line: 1, column: 15, type: "AssignmentPattern" @@ -349,7 +377,8 @@ ruleTester.run("space-infix-ops", rule, { output: "a ** b", parserOptions: { ecmaVersion: 7 }, errors: [{ - message: "Operator '**' must be spaced.", + messageId: "missingSpace", + data: { operator: "**" }, line: 1, column: 2, type: "BinaryExpression" @@ -359,7 +388,8 @@ ruleTester.run("space-infix-ops", rule, { code: "'foo'in{}", output: "'foo' in {}", errors: [{ - message: "Operator 'in' must be spaced.", + messageId: "missingSpace", + data: { operator: "in" }, line: 1, column: 6, type: "BinaryExpression" @@ -369,7 +399,8 @@ ruleTester.run("space-infix-ops", rule, { code: "'foo'instanceof{}", output: "'foo' instanceof {}", errors: [{ - message: "Operator 'instanceof' must be spaced.", + messageId: "missingSpace", + data: { operator: "instanceof" }, line: 1, column: 6, type: "BinaryExpression" @@ -383,7 +414,8 @@ ruleTester.run("space-infix-ops", rule, { output: "var a: Foo = b;", parser: parser("type-annotations/variable-declaration-init-type-annotation-no-space"), errors: [{ - message: "Operator '=' must be spaced.", + messageId: "missingSpace", + data: { operator: "=" }, type: "VariableDeclarator", line: 1, column: 11 @@ -395,7 +427,8 @@ ruleTester.run("space-infix-ops", rule, { parser: parser("type-annotations/function-declaration-type-annotation-no-space"), parserOptions: { ecmaVersion: 6 }, errors: [{ - message: "Operator '=' must be spaced.", + messageId: "missingSpace", + data: { operator: "=" }, line: 1, column: 23, type: "AssignmentPattern" diff --git a/tests/lib/rules/spaced-comment.js b/tests/lib/rules/spaced-comment.js index ee28203d10e..68258214c19 100644 --- a/tests/lib/rules/spaced-comment.js +++ b/tests/lib/rules/spaced-comment.js @@ -351,7 +351,8 @@ ruleTester.run("spaced-comment", rule, { output: "// An invalid comment NOT starting with space\nvar a = 1;", options: ["always"], errors: [{ - message: "Expected space or tab after '//' in comment.", + messageId: "expectedSpaceAfter", + data: { refChar: "//" }, type: "Line" }] }, @@ -360,7 +361,8 @@ ruleTester.run("spaced-comment", rule, { output: "//An invalid comment starting with space\nvar a = 2;", options: ["never"], errors: [{ - message: "Unexpected space or tab after '//' in comment.", + messageId: "unexpectedSpaceAfter", + data: { refChar: "//" }, type: "Line" }] }, @@ -369,7 +371,8 @@ ruleTester.run("spaced-comment", rule, { output: "//An invalid comment starting with tab\nvar a = 2;", options: ["never"], errors: [{ - message: "Unexpected space or tab after '//' in comment.", + messageId: "unexpectedSpaceAfter", + data: { refChar: "//" }, type: "Line" }] }, @@ -386,7 +389,8 @@ ruleTester.run("spaced-comment", rule, { exceptions: ["-", "=", "*", "#", "!@#"] }], errors: [{ - message: "Expected exception block, space or tab after '//*' in comment.", + messageId: "expectedExceptionAfter", + data: { refChar: "//*" }, type: "Line" }] }, @@ -398,11 +402,13 @@ ruleTester.run("spaced-comment", rule, { }], errors: [ { - message: "Expected exception block, space or tab after '//' in comment.", + messageId: "expectedExceptionAfter", + data: { refChar: "//" }, type: "Line" }, { - message: "Expected exception block, space or tab after '//' in comment.", + messageId: "expectedExceptionAfter", + data: { refChar: "//" }, type: "Line" } ] @@ -428,7 +434,8 @@ ruleTester.run("spaced-comment", rule, { output: "var a = 1; /*A valid comment starting with space */", options: ["never"], errors: [{ - message: "Unexpected space or tab after '/*' in comment.", + messageId: "unexpectedSpaceAfter", + data: { refChar: "/*" }, type: "Block" }] }, @@ -439,7 +446,8 @@ ruleTester.run("spaced-comment", rule, { exceptions: ["-", "=", "*", "!@#"] }], errors: [{ - message: "Expected exception block, space or tab after '/*' in comment.", + messageId: "expectedExceptionAfter", + data: { refChar: "/*" }, type: "Block" }] }, @@ -448,7 +456,8 @@ ruleTester.run("spaced-comment", rule, { output: "var a = 1; /* A valid comment NOT starting with space */", options: ["always"], errors: [{ - message: "Expected space or tab after '/*' in comment.", + messageId: "expectedSpaceAfter", + data: { refChar: "/*" }, type: "Block" }] }, @@ -457,7 +466,8 @@ ruleTester.run("spaced-comment", rule, { output: "function foo(/*height */a) { \n }", options: ["never"], errors: [{ - message: "Unexpected space or tab after '/*' in comment.", + messageId: "unexpectedSpaceAfter", + data: { refChar: "/*" }, type: "Block" }] }, @@ -466,7 +476,8 @@ ruleTester.run("spaced-comment", rule, { output: "function foo(/* height */a) { \n }", options: ["always"], errors: [{ - message: "Expected space or tab after '/*' in comment.", + messageId: "expectedSpaceAfter", + data: { refChar: "/*" }, type: "Block" }] }, @@ -475,7 +486,8 @@ ruleTester.run("spaced-comment", rule, { output: "function foo(a/* height */) { \n }", options: ["always"], errors: [{ - message: "Expected space or tab after '/*' in comment.", + messageId: "expectedSpaceAfter", + data: { refChar: "/*" }, type: "Block" }] }, @@ -484,7 +496,8 @@ ruleTester.run("spaced-comment", rule, { output: "/*\n *Test\n */", options: ["never"], errors: [{ - message: "Unexpected space or tab after '/*' in comment.", + messageId: "unexpectedSpaceAfter", + data: { refChar: "/*" }, type: "Block" }] }, @@ -495,8 +508,8 @@ ruleTester.run("spaced-comment", rule, { block: { exceptions: ["-", "=", "*", "#", "!@#"] } }], errors: [ - { message: "Expected space or tab after '//' in comment.", type: "Line" }, - { message: "Expected space or tab after '//' in comment.", type: "Line" } + { messageId: "expectedSpaceAfter", data: { refChar: "//" }, type: "Line" }, + { messageId: "expectedSpaceAfter", data: { refChar: "//" }, type: "Line" } ] }, { @@ -506,7 +519,8 @@ ruleTester.run("spaced-comment", rule, { line: { exceptions: ["-", "=", "*", "#", "!@#"] } }], errors: [{ - message: "Expected space or tab after '/*' in comment.", + messageId: "expectedSpaceAfter", + data: { refChar: "/*" }, type: "Block" }] }, @@ -517,7 +531,8 @@ ruleTester.run("spaced-comment", rule, { block: { markers: ["/", "!<"] } }], errors: [{ - message: "Expected space or tab after '//' in comment.", + messageId: "expectedSpaceAfter", + data: { refChar: "//" }, type: "Line" }] }, @@ -526,7 +541,8 @@ ruleTester.run("spaced-comment", rule, { output: "/* !\n *comment\n */", options: ["always", { line: { markers: ["!"] } }], errors: [{ - message: "Expected space or tab after '/*' in comment.", + messageId: "expectedSpaceAfter", + data: { refChar: "/*" }, type: "Block" }] }, @@ -535,7 +551,8 @@ ruleTester.run("spaced-comment", rule, { output: "///--------\r\n/// test\r\n///--------\r\n/* / blah *//*-----*/", options: ["always", { markers: ["/"], exceptions: ["-"], block: { markers: [] } }], errors: [{ - message: "Expected exception block, space or tab after '/*' in comment.", + messageId: "expectedExceptionAfter", + data: { refChar: "/*" }, type: "Block" }] }, @@ -544,12 +561,14 @@ ruleTester.run("spaced-comment", rule, { output: "///--------\r\n/// test\r\n///--------\r\n/* / blah */ /* -----*/", options: ["always", { line: { markers: ["/"], exceptions: ["-"] } }], errors: [{ - message: "Expected space or tab after '/*' in comment.", + messageId: "expectedSpaceAfter", + data: { refChar: "/*" }, type: "Block", line: 4, column: 1 }, { - message: "Expected space or tab after '/*' in comment.", + messageId: "expectedSpaceAfter", + data: { refChar: "/*" }, type: "Block", line: 4, column: 13 @@ -562,7 +581,8 @@ ruleTester.run("spaced-comment", rule, { output: "var a = 1; /* A balanced comment starting with space */", options: ["always", { block: { balanced: true } }], errors: [{ - message: "Expected space or tab before '*/' in comment.", + messageId: "expectedSpaceBefore", + data: { refChar: "/**" }, type: "Block" }] }, @@ -571,7 +591,8 @@ ruleTester.run("spaced-comment", rule, { output: "var a = 1; /*A balanced comment NOT starting with space*/", options: ["never", { block: { balanced: true } }], errors: [{ - message: "Unexpected space or tab before '*/' in comment.", + messageId: "unexpectedSpaceBefore", + data: { refChar: "*/" }, type: "Block" }] }, @@ -580,7 +601,8 @@ ruleTester.run("spaced-comment", rule, { output: "function foo(/* height */a) { \n }", options: ["always", { block: { balanced: true } }], errors: [{ - message: "Expected space or tab before '*/' in comment.", + messageId: "expectedSpaceBefore", + data: { refChar: "/**" }, type: "Block" }] }, @@ -589,7 +611,8 @@ ruleTester.run("spaced-comment", rule, { output: "function foo(/*height*/a) { \n }", options: ["never", { block: { balanced: true } }], errors: [{ - message: "Unexpected space or tab before '*/' in comment.", + messageId: "unexpectedSpaceBefore", + data: { refChar: "*/" }, type: "Block" }] }, @@ -598,7 +621,8 @@ ruleTester.run("spaced-comment", rule, { output: "/*! comment */", options: ["always", { markers: ["!"], block: { balanced: true } }], errors: [{ - message: "Expected space or tab before '*/' in comment.", + messageId: "expectedSpaceBefore", + data: { refChar: "/**" }, type: "Block" }] }, @@ -607,7 +631,8 @@ ruleTester.run("spaced-comment", rule, { output: "/*!comment*/", options: ["never", { markers: ["!"], block: { balanced: true } }], errors: [{ - message: "Unexpected space or tab before '*/' in comment.", + messageId: "unexpectedSpaceBefore", + data: { refChar: "*/" }, type: "Block" }] }, @@ -632,7 +657,8 @@ ruleTester.run("spaced-comment", rule, { output: "//#endregion foo", options: ["always", { line: { markers: ["#endregion"] } }], errors: [{ - message: "Expected space or tab after '//#endregion' in comment.", + messageId: "expectedSpaceAfter", + data: { refChar: "//#endregion" }, type: "Line" }] }, @@ -641,7 +667,8 @@ ruleTester.run("spaced-comment", rule, { output: "/* #endregion*/", // not an allowed marker for block comments options: ["always", { line: { markers: ["#endregion"] } }], errors: [{ - message: "Expected space or tab after '/*' in comment.", + messageId: "expectedSpaceAfter", + data: { refChar: "/*" }, type: "Block" }] }, @@ -650,7 +677,8 @@ ruleTester.run("spaced-comment", rule, { output: "/** **/", options: ["always"], errors: [{ - message: "Expected space or tab after '/**' in comment.", + messageId: "expectedSpaceAfter", + data: { refChar: "/**" }, type: "Block" }] }, @@ -660,11 +688,13 @@ ruleTester.run("spaced-comment", rule, { options: ["always", { block: { balanced: true } }], errors: [ { - message: "Expected space or tab after '/**' in comment.", + messageId: "expectedSpaceAfter", + data: { refChar: "/**" }, type: "Block" }, { - message: "Expected space or tab before '*/' in comment.", + messageId: "expectedSpaceBefore", + data: { refChar: "*/" }, type: "Block" } ] @@ -675,11 +705,13 @@ ruleTester.run("spaced-comment", rule, { options: ["never", { block: { markers: ["foo"], balanced: true } }], // not " foo " errors: [ { - message: "Unexpected space or tab after '/*' in comment.", + messageId: "unexpectedSpaceAfter", + data: { refChar: "/*" }, type: "Block" }, { - message: "Unexpected space or tab before '*/' in comment.", + messageId: "unexpectedSpaceBefore", + data: { refChar: "*/" }, type: "Block" } ] diff --git a/tests/lib/rules/wrap-regex.js b/tests/lib/rules/wrap-regex.js index db1820fef40..0ac92f2d848 100644 --- a/tests/lib/rules/wrap-regex.js +++ b/tests/lib/rules/wrap-regex.js @@ -31,19 +31,19 @@ ruleTester.run("wrap-regex", rule, { { code: "/foo/.test(bar);", output: "(/foo/).test(bar);", - errors: [{ message: "Wrap the regexp literal in parens to disambiguate the slash.", type: "Literal" }] + errors: [{ messageId: "requireParens", type: "Literal" }] }, { code: "/foo/ig.test(bar);", output: "(/foo/ig).test(bar);", - errors: [{ message: "Wrap the regexp literal in parens to disambiguate the slash.", type: "Literal" }] + errors: [{ messageId: "requireParens", type: "Literal" }] }, // https://github.com/eslint/eslint/issues/10573 { code: "if(/foo/ig.test(bar));", output: "if((/foo/ig).test(bar));", - errors: [{ message: "Wrap the regexp literal in parens to disambiguate the slash.", type: "Literal" }] + errors: [{ messageId: "requireParens", type: "Literal" }] } ] });