Skip to content

Commit

Permalink
Ensure blank line b4 function return statements
Browse files Browse the repository at this point in the history
DEFRA/water-abstraction-team#115

This has been an unwritten convention we often pick up in the PRs of those new to the team. We like to see a blank line before the `return` statement in a function.

```javascript
// Bad
function rubbishNameGenerator () {
  const firstName = 'John'
  const lastName = 'Doe'
  return `${firstName} ${lastName}`
}

// Good
function rubbishNameGenerator () {
  const firstName = 'John'
  const lastName = 'Doe'

  return `${firstName} ${lastName}`
}
```

But we don't want to see it all the time!

// Bad
function rubbishNameGeneratorV2 (useAlternate = false) {
  if (useAlternate) {

    return 'Jane Doe'
  }

  return 'John Doe'
}

// Good
function rubbishNameGeneratorV2 (useAlternate = false) {
  if (useAlternate) {
    return 'Jane Doe'
  }

  return 'John Doe'
}
```

We weren't sure we could make ESLint see the difference but it turns out we can. So, this change enables and adds an initial configuration for the rule [padding-line-between-statements](https://eslint.style/rules/js/padding-line-between-statements).

> We expect to expand the config to cover some more unwritten conventions regarding white space in our code. But those will come separately!
  • Loading branch information
Cruikshanks committed May 12, 2024
1 parent 2ff8986 commit 8ad4e5b
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit 8ad4e5b

Please sign in to comment.