main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
2.0 KB
|
Line | |
---|
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/latest/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 | const sourceCode = context.sourceCode;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Reports if node does not conform the rule in case rule is set to
|
---|
42 | * report missing description
|
---|
43 | * @param {ASTNode} node A CallExpression node to check.
|
---|
44 | * @returns {void}
|
---|
45 | */
|
---|
46 | function checkArgument(node) {
|
---|
47 | if (node.arguments.length === 0) {
|
---|
48 | context.report({
|
---|
49 | node,
|
---|
50 | messageId: "expected"
|
---|
51 | });
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | return {
|
---|
56 | "Program:exit"(node) {
|
---|
57 | const scope = sourceCode.getScope(node);
|
---|
58 | const variable = astUtils.getVariableByName(scope, "Symbol");
|
---|
59 |
|
---|
60 | if (variable && variable.defs.length === 0) {
|
---|
61 | variable.references.forEach(reference => {
|
---|
62 | const idNode = reference.identifier;
|
---|
63 |
|
---|
64 | if (astUtils.isCallee(idNode)) {
|
---|
65 | checkArgument(idNode.parent);
|
---|
66 | }
|
---|
67 | });
|
---|
68 | }
|
---|
69 | }
|
---|
70 | };
|
---|
71 |
|
---|
72 | }
|
---|
73 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.