Skip to content

Commit 5f1b6ee

Browse files
committed
feat(prettier): switch arrowParens to "always"
1 parent ec805aa commit 5f1b6ee

File tree

5 files changed

+4645
-4597
lines changed

5 files changed

+4645
-4597
lines changed

docs/decisions/006-arrow-parens.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Arrow Parens
2+
3+
Date: 2024-06-13
4+
5+
Status: accepted
6+
7+
## Context
8+
9+
Prettier has a configuration option called `arrowParens` which decides whether
10+
to add parentheses around the arguments of arrow functions. The available
11+
options are:
12+
13+
- "always" - Add parentheses around the arguments of arrow functions.
14+
- "avoid" - Only add parentheses around the arguments of arrow functions if it
15+
improves readability.
16+
17+
The "always" option adds parentheses around the arguments of arrow functions,
18+
even if there's only one argument. This can result in unnecessary parentheses in
19+
the code.
20+
21+
The "avoid" option removes parentheses around the arguments if there is only one
22+
argument (and that one argument is not being destructured or defaulted). This
23+
means that if the argument is a single identifier, it will be printed without
24+
parentheses. However, if the argument is a more complex expression, parentheses
25+
will be added due to syntax requirements.
26+
27+
Just reading those descriptions demonstrates that the rules around when it's ok
28+
to avoid parentheses are more complicated than the simple rule of: "always have
29+
parentheses".
30+
31+
Additionally, consider this: if you have a single argument in an arrow function,
32+
you will not have parentheses around it. If you then decide to destructure it,
33+
add an additional argument, add a type, or add a default value, you will have to
34+
add parentheses.
35+
36+
We want to avoid the extra work required to refactor code as much as possible.
37+
Additionally, simpler rules are often better. The simple rule of "always have
38+
parentheses" around the arguments of arrow functions is much simpler.
39+
40+
## Decision
41+
42+
Update the prettier config from "avoid" to "always."
43+
44+
## Consequences
45+
46+
People will need to reformat their code when they update `@epic-web/config`. In
47+
accordance to our [semver policy](./003-semver.md), we will not be treating this
48+
as a major version bump.

eslint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
const ERROR = 'error'
88
const WARN = 'warn'
99

10-
const has = pkg => {
10+
const has = (pkg) => {
1111
try {
1212
import.meta.resolve(pkg, import.meta.url)
1313
return true

fixture/react.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import { useState } from 'react'
22

33
export function Counter() {
44
const [count, setCount] = useState(0)
5-
const increment = () => setCount(c => c + 1)
5+
const increment = () => setCount((c) => c + 1)
66
return <button onClick={increment}>{count}</button>
77
}

0 commit comments

Comments
 (0)