]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-void.js
import 8.3.0 source
[pve-eslint.git] / 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 recommended: false,
18 url: "https://eslint.org/docs/rules/no-void"
19 },
20
21 messages: {
22 noVoid: "Expected 'undefined' and instead saw 'void'."
23 },
24
25 schema: [
26 {
27 type: "object",
28 properties: {
29 allowAsStatement: {
30 type: "boolean",
31 default: false
32 }
33 },
34 additionalProperties: false
35 }
36 ]
37 },
38
39 create(context) {
40 const allowAsStatement =
41 context.options[0] && context.options[0].allowAsStatement;
42
43 //--------------------------------------------------------------------------
44 // Public
45 //--------------------------------------------------------------------------
46
47 return {
48 'UnaryExpression[operator="void"]'(node) {
49 if (
50 allowAsStatement &&
51 node.parent &&
52 node.parent.type === "ExpressionStatement"
53 ) {
54 return;
55 }
56 context.report({
57 node,
58 messageId: "noVoid"
59 });
60 }
61 };
62 }
63 };