Skip to content

Commit

Permalink
Docs: add note for arrow functions in no-seq rule (#14578)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed May 28, 2021
1 parent e4f111b commit 958ff4e
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions docs/rules/no-sequences.md
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 958ff4e

Please sign in to comment.