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 }