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

[feature](istanbul-lib-instrument): update ignore regex for "legal" comments #693

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/istanbul-lib-instrument/src/visitor.js
Expand Up @@ -5,9 +5,9 @@ const { SourceCoverage } = require('./source-coverage');
const { SHA, MAGIC_KEY, MAGIC_VALUE } = require('./constants');

// pattern for istanbul to ignore a section
const COMMENT_RE = /^\s*istanbul\s+ignore\s+(if|else|next)(?=\W|$)/;
const COMMENT_RE = /^!?\s*istanbul\s+ignore\s+(if|else|next)(?=\W|$)/;
// pattern for istanbul to ignore the whole file
const COMMENT_FILE_RE = /^\s*istanbul\s+ignore\s+(file)(?=\W|$)/;
const COMMENT_FILE_RE = /^!?\s*istanbul\s+ignore\s+(file)(?=\W|$)/;
// source map URL pattern
const SOURCE_MAP_RE = /[#@]\s*sourceMappingURL=(.*)\s*$/m;

Expand Down
14 changes: 14 additions & 0 deletions packages/istanbul-lib-instrument/test/specs/if-hints.yaml
Expand Up @@ -26,6 +26,20 @@ tests:
branches: {'0': [1]}
statements: {'0': 1, '1': 1 }

---
name: ignore if legal
code: |
output = -1;
/*! istanbul ignore if */
if (args[0] > args [1])
output = args[0];
tests:
- args: [10, 20]
out: -1
lines: {'1': 1, '3': 1 }
branches: {'0': [1]}
statements: {'0': 1, '1': 1 }

---
name: ignore else with if block
code: |
Expand Down
9 changes: 9 additions & 0 deletions packages/istanbul-lib-instrument/test/specs/ignore-legal.yaml
@@ -0,0 +1,9 @@
---
name: ignore file legal comment
code: |
/*! istanbul ignore file */
output = true === true ? "works" : "doesn't work"
opts:
noCoverage: true
tests:
- name: file is ignored