UNPKG

699 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag when label is not used for a loop or switch
3 * @author Ilya Volodin
4 */
5
6//------------------------------------------------------------------------------
7// Rule Definition
8//------------------------------------------------------------------------------
9
10module.exports = function(context) {
11
12 "use strict";
13
14 return {
15
16 "LabeledStatement": function(node) {
17 if (node.body.type !== "ForStatement" && node.body.type !== "WhileStatement" && node.body.type !== "DoWhileStatement" && node.body.type !== "SwitchStatement") {
18 context.report(node, "Unexpected label {{l}}", {l: node.label.name});
19 }
20 }
21 };
22
23};