Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure blank line b4 function return statements #1007

Merged
merged 4 commits into from
May 13, 2024

Conversation

Cruikshanks
Copy link
Member

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. We believe it helps make the code easier to follow and understand.

// 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.

We expect to expand the config to cover some more unwritten conventions regarding white space in our code. But those will come separately!

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!
@Cruikshanks Cruikshanks added the conventions Changes to tools that enforce our conventions label May 12, 2024
@Cruikshanks Cruikshanks self-assigned this May 12, 2024
@Cruikshanks Cruikshanks marked this pull request as ready for review May 13, 2024 08:18
Copy link
Contributor

@Jozzey Jozzey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cruikshanks Cruikshanks merged commit 71727aa into main May 13, 2024
6 checks passed
@Cruikshanks Cruikshanks deleted the ensure-white-space-between-statements branch May 13, 2024 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conventions Changes to tools that enforce our conventions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants