sbdchd / eslint-plugin-cake

:cake: Sweet rules for ESLint
MIT License
1 stars 0 forks source link

new rule: no unnecessary break #26

Closed chdsbd closed 3 years ago

chdsbd commented 3 years ago
# bad
switch (foo) {
  case "up": {
    return 0
    break
  }
}

# okay
switch (foo) {
  case "up": {
    return 0
  }
}
sbdchd commented 3 years ago

This might be covered by https://eslint.org/docs/rules/no-unreachable

Testing it out, I get an error from typescript and an error from eslint

function foo(f: string) {
  switch (f) {
    case 'bar':
      return 1
      break
    default:
      return 2
  }
}
Unreachable code detected. ts(7027)
Unreachable code. eslint no-unreachable