]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tools/internal-rules/consistent-meta-messages.js
b094c86e8844f48d963af571e68721be57dd7f50
2 * @fileoverview A rule to enforce using `meta.messages` property in core rules
3 * @author 薛定谔的猫<hh_2013@foxmail.com>
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
13 * Gets the property of the Object node passed in that has the name specified.
14 * @param {string} property Name of the property to return.
15 * @param {ASTNode} node The ObjectExpression node.
16 * @returns {ASTNode} The Property node or null if not found.
18 function getPropertyFromObject(property
, node
) {
19 const properties
= node
.properties
;
21 for (let i
= 0; i
< properties
.length
; i
++) {
22 if (properties
[i
].key
.name
=== property
) {
31 * Verifies that the meta.messages property is present.
32 * TODO: check it has the correct value
33 * @param {RuleContext} context The ESLint rule context.
34 * @param {ASTNode} exportsNode ObjectExpression node that the rule exports.
37 function checkMetaMessages(context
, exportsNode
) {
38 if (exportsNode
.type
!== "ObjectExpression") {
40 // if the exported node is not the correct format, "internal-no-invalid-meta" will already report this.
44 const metaProperty
= getPropertyFromObject("meta", exportsNode
);
45 const messages
= metaProperty
&& getPropertyFromObject("messages", metaProperty
.value
);
50 messageId
: "expectedMessages"
55 //------------------------------------------------------------------------------
57 //------------------------------------------------------------------------------
62 description
: "enforce using `meta.messages` property in core rules",
69 expectedMessages
: "Expected `meta.messages` property."
75 "AssignmentExpression[left.object.name='module'][left.property.name='exports']"(node
) {
76 checkMetaMessages(context
, node
.right
);