From 3f7c9bf19615122fb776cdd13da532d860bd945a Mon Sep 17 00:00:00 2001 From: Anix Date: Tue, 24 Mar 2020 04:57:29 +0530 Subject: [PATCH] Docs: clarify variables option in no-use-before-define (fixes #12986) (#13017) * Docs: added fn decl example and details for variables option * Docs: added more example for variables options * Chore: refactore variables example * Chore: removed extra EOF line * Chore: update default for nofunc no-use-before-define Co-Authored-By: Kai Cataldo Co-authored-by: Kai Cataldo --- docs/rules/no-use-before-define.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/rules/no-use-before-define.md b/docs/rules/no-use-before-define.md index f053eba3a8e..391c323aed0 100644 --- a/docs/rules/no-use-before-define.md +++ b/docs/rules/no-use-before-define.md @@ -82,7 +82,7 @@ function g() { Default is `true`. This rule accepts `"nofunc"` string as an option. -`"nofunc"` is the same as `{ "functions": false, "classes": true }`. +`"nofunc"` is the same as `{ "functions": false, "classes": true, "variables": true }`. ### functions @@ -95,6 +95,8 @@ f(); function f() {} ``` +This option allows references to function declarations. For function expressions and arrow functions, please see the [`variables`](#variables) option. + ### classes Examples of **incorrect** code for the `{ "classes": false }` option: @@ -131,6 +133,12 @@ Examples of **incorrect** code for the `{ "variables": false }` option: console.log(foo); var foo = 1; + +f(); +const f = () => {}; + +g(); +const g = function() {}; ``` Examples of **correct** code for the `{ "variables": false }` option: @@ -141,6 +149,13 @@ Examples of **correct** code for the `{ "variables": false }` option: function baz() { console.log(foo); } - var foo = 1; + +const a = () => f(); +function b() { return f(); } +const c = function() { return f(); } +const f = () => {}; + +const e = function() { return g(); } +const g = function() {} ```