]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-empty.js
2 * @fileoverview Rule to flag use of an empty block statement
3 * @author Nicholas C. Zakas
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
11 const astUtils
= require("./utils/ast-utils");
13 //------------------------------------------------------------------------------
15 //------------------------------------------------------------------------------
22 description
: "disallow empty block statements",
24 url
: "https://eslint.org/docs/rules/no-empty"
36 additionalProperties
: false
41 unexpected
: "Empty {{type}} statement."
46 const options
= context
.options
[0] || {},
47 allowEmptyCatch
= options
.allowEmptyCatch
|| false;
49 const sourceCode
= context
.getSourceCode();
52 BlockStatement(node
) {
54 // if the body is not empty, we can just return immediately
55 if (node
.body
.length
!== 0) {
59 // a function is generally allowed to be empty
60 if (astUtils
.isFunction(node
.parent
)) {
64 if (allowEmptyCatch
&& node
.parent
.type
=== "CatchClause") {
68 // any other block is only allowed to be empty, if it contains a comment
69 if (sourceCode
.getCommentsInside(node
).length
> 0) {
73 context
.report({ node
, messageId
: "unexpected", data
: { type
: "block" } });
76 SwitchStatement(node
) {
78 if (typeof node
.cases
=== "undefined" || node
.cases
.length
=== 0) {
79 context
.report({ node
, messageId
: "unexpected", data
: { type
: "switch" } });