UNPKG

825 BJavaScriptView Raw
1/**
2 * @fileoverview Require spaces following return, throw, and case
3 * @author Michael Ficarra
4 */
5"use strict";
6
7//------------------------------------------------------------------------------
8// Rule Definition
9//------------------------------------------------------------------------------
10
11module.exports = function(context) {
12
13 function check(node) {
14 var tokens = context.getTokens(node),
15 value = tokens[0].value;
16
17 if(tokens[0].range[1] >= tokens[1].range[0]) {
18 context.report(node, "Keyword \"" + value + "\" must be followed by whitespace.");
19 }
20 }
21
22 return {
23 "ReturnStatement": function(node) { if(node.argument) { check(node); } },
24 "SwitchCase": function(node) { if(node.test) { check(node); } },
25 "ThrowStatement": check
26 };
27
28};