Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant