Skip to content

Commit

Permalink
Ensure use of block body for arrow functions
Browse files Browse the repository at this point in the history
DEFRA/water-abstraction-team#115

Just like [parens in arrow functions](#1004) how you write an [arrow function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) can differ.

```javascript
const materials = [
  'Hydrogen',
  'Helium',
  'Lithium',
  'Beryllium'
]

// Block body
materials.forEach((material) => {
  console.log(`${material} - ${material.length}`)
})

// Concise body
materials.forEach((material) => console.log(`${material} - ${material.length}`))
```

The _block-body_ version can be applied in all cases. But like with parens where devs will often drop the parens when there is only 1 param, they'll use _concise_ for simple arrow functions and _block-body_ for the rest.

To us though, the argument is the same. For those new or inexperienced with JavaScript this inconsistency can be confusing and a blocker to progressing with the language. The more we can do to keep the code base simple and consistent, the easier new folks will find working with it.

So, this change enables [the rule in ESLint](https://eslint.org/docs/latest/rules/arrow-body-style) that requires all arrow-functions to use the block-body.
  • Loading branch information
Cruikshanks committed May 12, 2024
1 parent 2ff8986 commit ecc7f2c
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit ecc7f2c

Please sign in to comment.