2 * @fileoverview Rule to flag use of an empty block statement
3 * @author Nicholas C. Zakas
4 * @copyright Nicholas C. Zakas. All rights reserved.
5 * @copyright 2015 Dieter Oberkofler. All rights reserved.
9 //------------------------------------------------------------------------------
11 //------------------------------------------------------------------------------
13 module.exports = function(context) {
17 "BlockStatement": function(node) {
18 var parent = node.parent,
19 parentType = parent.type,
23 // if the body is not empty, we can just return immediately
24 if (node.body.length !== 0) {
28 // a function is generally allowed to be empty
29 if (parentType === "FunctionDeclaration" || parentType === "FunctionExpression" || parentType === "ArrowFunctionExpression") {
33 // any other block is only allowed to be empty, if it contains an empty comment
34 comments = context.getComments(node).trailing;
35 for (i = 0; i < comments.length; i++) {
36 if (comments[i].value.trim() === "empty") {
41 context.report(node, "Empty block statement.");
44 "SwitchStatement": function(node) {
46 if (typeof node.cases === "undefined" || node.cases.length === 0) {
47 context.report(node, "Empty switch statement.");