UNPKG

834 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag wrapping none-iffe 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 "FunctionExpression": function(node) {
17
18 var ancestors = context.getAncestors();
19
20 if (!/CallExpression|NewExpression/.test(ancestors.pop().type)) {
21 var tokens = context.getTokens(node, 1, 1);
22 if (tokens[0].value === "(" && tokens[tokens.length - 1].value === ")") {
23 context.report(node, "Wrapping non-IIFE function literals in parens is unnecessary.");
24 }
25 }
26 }
27 };
28
29};