istanbuljs/nyc

Request: Warn when ignored lines are actually reached

Open

#919 opened on Sep 18, 2018

View on GitHub
 (8 comments) (0 reactions) (0 assignees)JavaScript (5,468 stars) (392 forks)batch import
help wantedpinned

Description

I use // istanbul ignore next and friends only to mark code that should never be reached—for instance, internal assertion failures. In the event that one of these ignored elements is reached, this indicates a bug in my code. Ideally, a unit test would catch this, but there are cases when it might not (e.g., an expect-to-throw unit test that throws for the wrong reason, or code that attempts to gracefully recover from the unexpected condition).

It would be nice for the CLI or lcov-report or other interface to indicate to the user when an ignored element is reached. Currently, it is not even possible to discern this from the lcov-report: if a line is marked istanbul ignore if, then it has no execution count annotation even if it was executed.

The docs indicate that an accepted use of ignore-directives, at at least one point in time, was to inflate test coverage numbers by marking reachable code that people simply don’t feel like testing. If this is still the case, then this functionality should presumably raise only a warning, or be opt-in/opt-out.

Contributor guide