Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 935 Bytes

no-else-after-return.md

File metadata and controls

41 lines (29 loc) · 935 Bytes

no-else-after-return

Works like no-else-return from eslint. This rule can automatically fix errors.

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

If you like this rule, I recommend you try no-unnecessary-else for some bonus features.

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';
}