]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/symbol-description.js
1c8a364986c8e26bd73450056967b6e59fcfebdc
[pve-eslint.git] / eslint / lib / rules / symbol-description.js
1 /**
2 * @fileoverview Rule to enforce description with the `Symbol` object
3 * @author Jarek Rencz
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const astUtils = require("./utils/ast-utils");
13
14 //------------------------------------------------------------------------------
15 // Rule Definition
16 //------------------------------------------------------------------------------
17
18
19 /** @type {import('../shared/types').Rule} */
20 module.exports = {
21 meta: {
22 type: "suggestion",
23
24 docs: {
25 description: "Require symbol descriptions",
26 recommended: false,
27 url: "https://eslint.org/docs/rules/symbol-description"
28 },
29 fixable: null,
30 schema: [],
31 messages: {
32 expected: "Expected Symbol to have a description."
33 }
34 },
35
36 create(context) {
37
38 /**
39 * Reports if node does not conform the rule in case rule is set to
40 * report missing description
41 * @param {ASTNode} node A CallExpression node to check.
42 * @returns {void}
43 */
44 function checkArgument(node) {
45 if (node.arguments.length === 0) {
46 context.report({
47 node,
48 messageId: "expected"
49 });
50 }
51 }
52
53 return {
54 "Program:exit"() {
55 const scope = context.getScope();
56 const variable = astUtils.getVariableByName(scope, "Symbol");
57
58 if (variable && variable.defs.length === 0) {
59 variable.references.forEach(reference => {
60 const node = reference.identifier;
61
62 if (astUtils.isCallee(node)) {
63 checkArgument(node.parent);
64 }
65 });
66 }
67 }
68 };
69
70 }
71 };