|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.7 KB
|
| Line | |
|---|
| 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 | /** @type {import('../shared/types').Rule} */
|
|---|
| 12 | module.exports = {
|
|---|
| 13 | meta: {
|
|---|
| 14 | type: "suggestion",
|
|---|
| 15 |
|
|---|
| 16 | docs: {
|
|---|
| 17 | description: "Disallow `void` operators",
|
|---|
| 18 | recommended: false,
|
|---|
| 19 | url: "https://eslint.org/docs/latest/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 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.