deno_lint
deno_lint copied to clipboard
Deno.exit() in switch statement yielts no-fallthrough warning without a break keyword
Lint Name
no-fallthrough
Code Snippet
switch (input) {
case "x":
Deno.exit();
default:
break;
}
Expected Result
No warnings about case fallthroughs
Actual Result
Warns about a fallthrough
Additional Info
deno-lint is not happy until I add break;
after Deno.exit();
, although it's unreachable:
deno-ts(7027) knows and puts a notice about unreachable code:
Version
VS-Code Extension: v3.12.0
deno 1.21.2 (release, x86_64-pc-windows-msvc) v8 10.0.139.17 typescript 4.6.2
This is somewhat of a design limitation at this point... deno lint
is not really aware that Deno.exit()
has a return type of never
. I wonder if we could handle that with @kdy1 control flow analysis?
CC @dsherret
Using never
type requires a good enough type checker
We can use a 'known list' of expression with never type alternatively
Using
never
type requires a good enough type checkerWe can use a 'known list' of expression with never type alternatively
That's a good point, it's much simpler solution than incorporating type checking and should be good enough in this case.