2024-08-09 12:04:48 +00:00
|
|
|
/**
|
|
|
|
* @fileoverview Rule to disallow use of void operator.
|
|
|
|
* @author Mike Sidorov
|
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Rule Definition
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2024-08-21 06:34:30 +00:00
|
|
|
/** @type {import('../shared/types').Rule} */
|
2024-08-09 12:04:48 +00:00
|
|
|
module.exports = {
|
|
|
|
meta: {
|
|
|
|
type: "suggestion",
|
|
|
|
|
|
|
|
docs: {
|
2024-08-21 06:34:30 +00:00
|
|
|
description: "Disallow `void` operators",
|
2024-08-09 12:04:48 +00:00
|
|
|
recommended: false,
|
2024-08-21 06:34:30 +00:00
|
|
|
url: "https://eslint.org/docs/latest/rules/no-void"
|
2024-08-09 12:04:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
messages: {
|
|
|
|
noVoid: "Expected 'undefined' and instead saw 'void'."
|
|
|
|
},
|
|
|
|
|
|
|
|
schema: [
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
allowAsStatement: {
|
|
|
|
type: "boolean",
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
additionalProperties: false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
create(context) {
|
|
|
|
const allowAsStatement =
|
|
|
|
context.options[0] && context.options[0].allowAsStatement;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
// Public
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
|
|
|
|
return {
|
|
|
|
'UnaryExpression[operator="void"]'(node) {
|
|
|
|
if (
|
|
|
|
allowAsStatement &&
|
|
|
|
node.parent &&
|
|
|
|
node.parent.type === "ExpressionStatement"
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
context.report({
|
|
|
|
node,
|
|
|
|
messageId: "noVoid"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|