UNPKG

764 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag when IIFE is not wrapped in parens
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 "CallExpression": function(node) {
17 if (node.callee.type === "FunctionExpression") {
18 var tokens = context.getTokens(node.callee, 1, 1);
19 if (tokens[0].value !== "(" && tokens[tokens.length - 1].value !== ")") {
20 context.report(node, "Wrap an immediate function invocation in parentheses.");
21 }
22 }
23 }
24 };
25
26};