From 958ff4e8a5102f204f1484d09985e28a79790996 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Fri, 28 May 2021 07:57:09 +0530 Subject: [PATCH] Docs: add note for arrow functions in no-seq rule (#14578) --- docs/rules/no-sequences.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/rules/no-sequences.md b/docs/rules/no-sequences.md index d4efc1c5ba5..87ba3c4b9b8 100644 --- a/docs/rules/no-sequences.md +++ b/docs/rules/no-sequences.md @@ -39,8 +39,6 @@ switch (val = foo(), val) {} while (val = foo(), val < 42); with (doSomething(), val) {} - -const foo = (val) => (console.log('bar'), val); ``` Examples of **correct** code for this rule: @@ -63,8 +61,32 @@ switch ((val = foo(), val)) {} while ((val = foo(), val < 42)); with ((doSomething(), val)) {} +``` + +### Note about arrow function bodies + +If an arrow function body is a statement rather than a block, and that statement contains a sequence, you need to use double parentheses around the statement to indicate that the sequence is intentional. + +Examples of **incorrect** code for arrow functions: + +```js +/*eslint no-sequences: "error"*/ +const foo = (val) => (console.log('bar'), val); + +const foo = () => ((bar = 123), 10)); + +const foo = () => { return (bar = 123), 10 } +``` + +Examples of **correct** code for arrow functions: +```js +/*eslint no-sequences: "error"*/ const foo = (val) => ((console.log('bar'), val)); + +const foo = () => (((bar = 123), 10)); + +const foo = () => { return ((bar = 123), 10) } ``` ## Options