From 4ef335e24276a6c2a46fe7a0674f49cfcff79796 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 10 Jan 2016 15:11:05 -0800 Subject: [PATCH] [eslint config] [breaking] require outer IIFE wrapping; flesh out guide section. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was lots of discussion [here](https://github.com/airbnb/javascript/issues/21#issuecomment-10203921), but now that we have both a modern build system and an eslint rule requiring terminating semicolons, the concerns with the “crockford” style no longer apply. --- README.md | 10 +++++++--- packages/eslint-config-airbnb/rules/best-practices.js | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b465162e..8654faf1 100644 --- a/README.md +++ b/README.md @@ -506,13 +506,17 @@ Other Style Guides } ``` - - [7.2](#7.2) Function expressions: + - [7.2](#7.2) Immediately invoked function expressions: + + > Why? An immediately invoked function expression is a single unit - wrapping both it, and its invocation parens, in parens, cleanly expresses this. Note that in a world with modules everywhere, you almost never need an IIFE. + + eslint rules: [`wrap-iife`](http://eslint.org/docs/rules/wrap-iife.html). ```javascript // immediately-invoked function expression (IIFE) - (() => { + (function () { console.log('Welcome to the Internet. Please follow me.'); - })(); + }()); ``` - [7.3](#7.3) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. diff --git a/packages/eslint-config-airbnb/rules/best-practices.js b/packages/eslint-config-airbnb/rules/best-practices.js index 82e5f9e2..1b64cdeb 100644 --- a/packages/eslint-config-airbnb/rules/best-practices.js +++ b/packages/eslint-config-airbnb/rules/best-practices.js @@ -108,7 +108,8 @@ module.exports = { // requires to declare all vars on top of their containing scope 'vars-on-top': 2, // require immediate function invocation to be wrapped in parentheses - 'wrap-iife': [2, 'any'], + // http://eslint.org/docs/rules/wrap-iife.html + 'wrap-iife': [2, 'outside'], // require or disallow Yoda conditions 'yoda': 2 }