Skip to content

Files

Latest commit

 

History

History
45 lines (31 loc) · 924 Bytes

no-else-after-return.md

File metadata and controls

45 lines (31 loc) · 924 Bytes

Pattern: Unnecessary else for block with return

Issue: -

Description

If an if block contains a return statement, the else block becomes unnecessary. Its contents can be placed outside of the block.

Options

"allow-else-if"

Example config:

"no-else-after-return": {
  "options": "allow-else-if"
}

// or

"no-else-after-return": [true, "allow-else-if"]

Enable this option if you prefer else if blocks after return statements:

if (condition) {
  return 'foo';
} else if (otherCondition) { // this is allowed with the option
  return 'bar';
}

if (condition) {
  return 'foo';
} else if (otherCondition) {
  return 'bar';
} else { // this is still not allowed with the option
  return 'baz';
}

Further Reading