]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/symbol-description.js
9f5d9358f00253a40fe2db201ef093b61f700637
[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 module.exports = {
20 meta: {
21 type: "suggestion",
22
23 docs: {
24 description: "require symbol descriptions",
25 recommended: false,
26 url: "https://eslint.org/docs/rules/symbol-description"
27 },
28 fixable: null,
29 schema: [],
30 messages: {
31 expected: "Expected Symbol to have a description."
32 }
33 },
34
35 create(context) {
36
37 /**
38 * Reports if node does not conform the rule in case rule is set to
39 * report missing description
40 * @param {ASTNode} node A CallExpression node to check.
41 * @returns {void}
42 */
43 function checkArgument(node) {
44 if (node.arguments.length === 0) {
45 context.report({
46 node,
47 messageId: "expected"
48 });
49 }
50 }
51
52 return {
53 "Program:exit"() {
54 const scope = context.getScope();
55 const variable = astUtils.getVariableByName(scope, "Symbol");
56
57 if (variable && variable.defs.length === 0) {
58 variable.references.forEach(reference => {
59 const node = reference.identifier;
60
61 if (astUtils.isCallee(node)) {
62 checkArgument(node.parent);
63 }
64 });
65 }
66 }
67 };
68
69 }
70 };