]>
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 //------------------------------------------------------------------------------
17 /** @type {import('../shared/types').Rule} */
24 description
: "Disallow empty block statements",
26 url
: "https://eslint.org/docs/latest/rules/no-empty"
38 additionalProperties
: false
43 unexpected
: "Empty {{type}} statement.",
44 suggestComment
: "Add comment inside empty {{type}} statement."
49 const options
= context
.options
[0] || {},
50 allowEmptyCatch
= options
.allowEmptyCatch
|| false;
52 const sourceCode
= context
.sourceCode
;
55 BlockStatement(node
) {
57 // if the body is not empty, we can just return immediately
58 if (node
.body
.length
!== 0) {
62 // a function is generally allowed to be empty
63 if (astUtils
.isFunction(node
.parent
)) {
67 if (allowEmptyCatch
&& node
.parent
.type
=== "CatchClause") {
71 // any other block is only allowed to be empty, if it contains a comment
72 if (sourceCode
.getCommentsInside(node
).length
> 0) {
78 messageId
: "unexpected",
79 data
: { type
: "block" },
82 messageId
: "suggestComment",
83 data
: { type
: "block" },
85 const range
= [node
.range
[0] + 1, node
.range
[1] - 1];
87 return fixer
.replaceTextRange(range
, " /* empty */ ");
94 SwitchStatement(node
) {
96 if (typeof node
.cases
=== "undefined" || node
.cases
.length
=== 0) {
97 context
.report({ node
, messageId
: "unexpected", data
: { type
: "switch" } });