diff --git a/.eslintrc.js b/.eslintrc.js index 9bb665a3c48..b405b82fccd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -67,6 +67,7 @@ module.exports = { "eslint-plugin/consistent-output": "error", "eslint-plugin/no-deprecated-context-methods": "error", "eslint-plugin/no-only-tests": "error", + "eslint-plugin/prefer-message-ids": "error", "eslint-plugin/prefer-output-null": "error", "eslint-plugin/prefer-placeholders": "error", "eslint-plugin/prefer-replace-text": "error", @@ -84,8 +85,7 @@ module.exports = { excludedFiles: ["index.js"], rules: { "eslint-plugin/prefer-object-rule": "error", - "internal-rules/no-invalid-meta": "error", - "internal-rules/consistent-meta-messages": "error" + "internal-rules/no-invalid-meta": "error" } }, { diff --git a/package.json b/package.json index ea08a90ef65..1731ae6e1b5 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,7 @@ "ejs": "^3.0.2", "eslint": "file:.", "eslint-config-eslint": "file:packages/eslint-config-eslint", - "eslint-plugin-eslint-plugin": "^3.4.0", + "eslint-plugin-eslint-plugin": "^3.5.3", "eslint-plugin-internal-rules": "file:tools/internal-rules", "eslint-plugin-jsdoc": "^25.4.3", "eslint-plugin-node": "^11.1.0", diff --git a/tests/tools/internal-rules/consistent-meta-messages.js b/tests/tools/internal-rules/consistent-meta-messages.js deleted file mode 100644 index 4df8be92af2..00000000000 --- a/tests/tools/internal-rules/consistent-meta-messages.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * @fileoverview Tests for consistent-meta-messages rule. - * @author 薛定谔的猫 - */ - -"use strict"; - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -const rule = require("../../../tools/internal-rules/consistent-meta-messages"); -const { RuleTester } = require("../../../lib/rule-tester"); - -//------------------------------------------------------------------------------ -// Tests -//------------------------------------------------------------------------------ - -const ruleTester = new RuleTester(); - -ruleTester.run("consistent-meta-messages", rule, { - valid: [ - `module.exports = { - meta: { - messages: {unexpected: "an error occurs."} - } - };` - ], - invalid: [ - { - code: ` - module.exports = { - meta: {} - };`, - errors: [{ messageId: "expectedMessages" }] - } - ] -}); diff --git a/tools/internal-rules/consistent-meta-messages.js b/tools/internal-rules/consistent-meta-messages.js deleted file mode 100644 index b094c86e884..00000000000 --- a/tools/internal-rules/consistent-meta-messages.js +++ /dev/null @@ -1,80 +0,0 @@ -/** - * @fileoverview A rule to enforce using `meta.messages` property in core rules - * @author 薛定谔的猫 - */ - -"use strict"; - -//------------------------------------------------------------------------------ -// Helpers -//------------------------------------------------------------------------------ - -/** - * Gets the property of the Object node passed in that has the name specified. - * @param {string} property Name of the property to return. - * @param {ASTNode} node The ObjectExpression node. - * @returns {ASTNode} The Property node or null if not found. - */ -function getPropertyFromObject(property, node) { - const properties = node.properties; - - for (let i = 0; i < properties.length; i++) { - if (properties[i].key.name === property) { - return properties[i]; - } - } - - return null; -} - -/** - * Verifies that the meta.messages property is present. - * TODO: check it has the correct value - * @param {RuleContext} context The ESLint rule context. - * @param {ASTNode} exportsNode ObjectExpression node that the rule exports. - * @returns {void} - */ -function checkMetaMessages(context, exportsNode) { - if (exportsNode.type !== "ObjectExpression") { - - // if the exported node is not the correct format, "internal-no-invalid-meta" will already report this. - return; - } - - const metaProperty = getPropertyFromObject("meta", exportsNode); - const messages = metaProperty && getPropertyFromObject("messages", metaProperty.value); - - if (!messages) { - context.report({ - node: metaProperty, - messageId: "expectedMessages" - }); - } -} - -//------------------------------------------------------------------------------ -// Rule Definition -//------------------------------------------------------------------------------ - -module.exports = { - meta: { - docs: { - description: "enforce using `meta.messages` property in core rules", - category: "Internal", - recommended: false - }, - schema: [], - type: "suggestion", - messages: { - expectedMessages: "Expected `meta.messages` property." - } - }, - - create(context) { - return { - "AssignmentExpression[left.object.name='module'][left.property.name='exports']"(node) { - checkMetaMessages(context, node.right); - } - }; - } -};