|
| 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. |
0 commit comments