unreachable-code
What it does
Section titled “What it does”Reports a statement that can never run: after return, throw, break or continue, after an if/else or try that always jumps, or after a loop that never ends. Only the first statement of such a run is reported. Where the language has a flow layer (C#) it also covers constant conditions and calls that do not return (does_not_return in semantics:, the option non_returning_calls). Hoisted declarations and empty statements are left out. Removing the statement is offered as an editor quick fix only, because unreachable code usually signals a bug.
Why it matters
Section titled “Why it matters”Code that cannot run is either a leftover or a sign that an earlier return or throw is in the wrong place, in which case what the author expected to run does not.
To fix, delete the statement, or move the jump that makes it unreachable.
Example
Section titled “Example”...
func h(a bool) int { return 1 g()}
func k(a bool) int {... } else { return 2 } g()}
func m(a bool) int {...Configuration
Section titled “Configuration”c: lint: rules: unreachable-code: level: warn # off, warn (default), error options: non_returning_calls: truecpp: lint: rules: unreachable-code: level: warn # off, warn (default), error options: non_returning_calls: truecsharp: lint: rules: unreachable-code: level: warn # off, warn (default), error options: non_returning_calls: truego: lint: rules: unreachable-code: level: warn # off, warn (default), error options: non_returning_calls: truejava: lint: rules: unreachable-code: level: warn # off, warn (default), error options: non_returning_calls: truejs: lint: rules: unreachable-code: level: warn # off, warn (default), error options: non_returning_calls: truekotlin: lint: rules: unreachable-code: level: warn # off, warn (default), error options: non_returning_calls: truephp: lint: rules: unreachable-code: level: warn # off, warn (default), error options: non_returning_calls: truepython: lint: rules: unreachable-code: level: warn # off, warn (default), error options: non_returning_calls: trueruby: lint: rules: unreachable-code: level: warn # off, warn (default), error options: non_returning_calls: true| Option | Type | Default | Description |
|---|---|---|---|
non_returning_calls |
bool | true |
With a flow layer, treat the code after a call that never returns ([DoesNotReturn], does_not_return in semantics:) as unreachable. A compiler does not, so turn this off to report exactly what it reports. |
Enabled by the presets: go/revive, js/eslint-recommended, js/biome-recommended, js/oxlint.
Suppress one line with sudsy-disable-next-line unreachable-code in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| eslint | no-unreachable |
full | |
| revive | unreachable-code |
partial | the code after panic, os.Exit, log.Fatal* and t.Fatal* is not read as unreachable |
| Roslynator | RCS1148 |
full |