Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Ignore implied "else" #946

Open
tremby opened this issue Nov 5, 2021 · 0 comments
Open

Ignore implied "else" #946

tremby opened this issue Nov 5, 2021 · 0 comments

Comments

@tremby
Copy link

tremby commented Nov 5, 2021

I have a couple of if statements which if matched return. One of the two will return in all real-world cases so I want to ignore the fallback return statement.

I'm reading the docs at https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md and it looks like the following should do what I want:

if (diff > 0) return 1;
/* istanbul ignore else */
if (diff < 0) return -1;
return 0;

But I'm getting told that the return 0 line is not covered. If I instead use a /* instanbul ignore next */ just before the return 0 line, now it tells me that the if (diff < 0) line is uncovered.

I found that I need to include both ignore statements:

if (diff > 0) return 1;
/* istanbul ignore else */
if (diff < 0) return -1;
/* istanbul ignore next */
return 0;

Is this as intended?

I found I can also do this, but I don't like the code:

if (diff > 0) return 1;
/* istanbul ignore else */
if (diff < 0) return -1;
else return 0;
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant