.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / eslint / lib / rules / no-void.js
1 /**
2  * @fileoverview Rule to disallow use of void operator.
3  * @author Mike Sidorov
4  */
5 "use strict";
6
7 //------------------------------------------------------------------------------
8 // Rule Definition
9 //------------------------------------------------------------------------------
10
11 module.exports = {
12     meta: {
13         type: "suggestion",
14
15         docs: {
16             description: "disallow `void` operators",
17             category: "Best Practices",
18             recommended: false,
19             url: "https://eslint.org/docs/rules/no-void"
20         },
21
22         messages: {
23             noVoid: "Expected 'undefined' and instead saw 'void'."
24         },
25
26         schema: [
27             {
28                 type: "object",
29                 properties: {
30                     allowAsStatement: {
31                         type: "boolean",
32                         default: false
33                     }
34                 },
35                 additionalProperties: false
36             }
37         ]
38     },
39
40     create(context) {
41         const allowAsStatement =
42             context.options[0] && context.options[0].allowAsStatement;
43
44         //--------------------------------------------------------------------------
45         // Public
46         //--------------------------------------------------------------------------
47
48         return {
49             'UnaryExpression[operator="void"]'(node) {
50                 if (
51                     allowAsStatement &&
52                     node.parent &&
53                     node.parent.type === "ExpressionStatement"
54                 ) {
55                     return;
56                 }
57                 context.report({
58                     node,
59                     messageId: "noVoid"
60                 });
61             }
62         };
63     }
64 };