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

fix: ignore lines have to be dropped from coverage and not to be included as covered #240

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = class CovLine {
this.count = 1

// set by source.js during parsing, if /* c8 ignore next */ is found.
this.ignore = false
// also can be comment or empty line.
this.ignore = /^\s*\/{2}.+\s*$|^\s*$|^\s*\/\*.+\*\/\s*$/.test(lineStr)
}

toIstanbul () {
Expand Down
7 changes: 5 additions & 2 deletions lib/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = class CovSource {
this.lines.push(line)
position += lineStr.length

const ignoreToken = this._parseIgnore(lineStr)
const ignoreToken = this._parseIgnore(lineStr, ignoreAll)
if (!ignoreToken) continue

line.ignore = true
Expand All @@ -51,7 +51,7 @@ module.exports = class CovSource {
* @param {string} lineStr
* @return {{count?: number, start?: boolean, stop?: boolean}|undefined}
*/
_parseIgnore (lineStr) {
_parseIgnore (lineStr, ignoreAll) {
const testIgnoreNextLines = lineStr.match(/^\W*\/\* [c|v]8 ignore next (?<count>[0-9]+)/)
if (testIgnoreNextLines) {
return { count: Number(testIgnoreNextLines.groups.count) }
Expand All @@ -72,6 +72,9 @@ module.exports = class CovSource {
if (testIgnoreStartStop.groups.mode === 'start') return { start: true }
if (testIgnoreStartStop.groups.mode === 'stop') return { stop: true }
}

if (/^\s*\/\*.*(?<!\*\/)\s*$/.test(lineStr)) return { start: true }
if (ignoreAll && /^.*?\*\/\s*$/.test(lineStr)) return { stop: true }
}

// given a start column and end column in absolute offsets within
Expand Down
3 changes: 2 additions & 1 deletion lib/v8-to-istanbul.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,9 @@ module.exports = class V8ToIstanbul {
s: {}
}
source.lines.forEach((line, index) => {
if (line.ignore) return
statements.statementMap[`${index}`] = line.toIstanbul()
statements.s[`${index}`] = line.ignore ? 1 : line.count
statements.s[`${index}`] = line.count
})
return statements
}
Expand Down
Loading