gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 786 forks source link

Add ignore last-else hint #923

Closed fgerschau closed 4 years ago

fgerschau commented 4 years ago

Closes #781

This is my first contribution here. I'm not sure using this.currentState for this is the best way to do it but I'm open to suggestions :)

zakjan commented 4 years ago

Such feature would be really helpful. As #781 shows, there is currently missing a straightforward way to ignore the last else block of a if/elseif/else. In my case, I usually list all possible states explicitly for readability, and use else block for invalid state. Even though in theory it's impossible to reach such block by code, it could reached be by a bug elsewhere in code.

// type is allowed to be X or Y only here
if (type instanceof X) {
    // do something
} else if (type instanceof Y) {
    // do something
} else {
    throw new Error("Invalid state");
}
fgerschau commented 4 years ago

wrong repository (this one is not being maintained)

zakjan commented 4 years ago

@fgerschau Could you please port the PR to the correct repository? Thanks a lot!

fgerschau commented 4 years ago

@zakjan it's basically an entire different codebase. Check out v2. Unfortunately I doubt I will have time to do that any time soon