diff --git a/README.md b/README.md index be7bb4e3..2df52944 100644 --- a/README.md +++ b/README.md @@ -554,18 +554,22 @@ Other Style Guides ## Functions - - [7.1](#functions--declarations) Use function declarations instead of function expressions. eslint: [`func-style`](http://eslint.org/docs/rules/func-style) jscs: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations) + - [7.1](#functions--declarations) Use named function expressions instead of function declarations. eslint: [`func-style`](http://eslint.org/docs/rules/func-style) jscs: [`requireFunctionDeclarations`](http://jscs.info/rule/requireFunctionDeclarations) - > Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use [Arrow Functions](#arrow-functions) in place of function expressions. ([discussion](https://github.com/airbnb/javascript/issues/794)) + > Why? Function declarations are hoisted, which means that it’s easy - too easy - to reference the function before it is defined in the file. This harms readability and maintainability. If you find that a function’s definition is large or complex enough that it is interfering with understanding the rest of the file, then perhaps it’s time to extract it to its own module! Don’t forget to name the expression - anonymous functions can make it harder to locate the problem in an Error's call stack. ```javascript // bad const foo = function () { }; - // good + // bad function foo() { } + + // good + const foo = function bar() { + }; ``` diff --git a/packages/eslint-config-airbnb-base/rules/style.js b/packages/eslint-config-airbnb-base/rules/style.js index c46e510a..243d3141 100644 --- a/packages/eslint-config-airbnb-base/rules/style.js +++ b/packages/eslint-config-airbnb-base/rules/style.js @@ -36,7 +36,9 @@ module.exports = { 'func-names': 'warn', // enforces use of function declarations or expressions - 'func-style': 'off', + // http://eslint.org/docs/rules/func-style + // TODO: enable + 'func-style': ['off', 'expression'], // Blacklist certain identifiers to prevent them being used // http://eslint.org/docs/rules/id-blacklist