Skip to content

Commit 65e70d1

Browse files
AriPerkkiobcoe
andauthored
feat: ignore hint more now accepts more suffixes (#203)
Co-authored-by: Benjamin E. Coe <[email protected]>
1 parent 04247fd commit 65e70d1

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

lib/source.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ module.exports = class CovSource {
5151
* @return {{count?: number, start?: boolean, stop?: boolean}|undefined}
5252
*/
5353
_parseIgnore (lineStr) {
54-
const testIgnoreNextLines = lineStr.match(/^\W*\/\* c8 ignore next (?<count>[0-9]+) *\*\/\W*$/)
54+
const testIgnoreNextLines = lineStr.match(/^\W*\/\* c8 ignore next (?<count>[0-9]+)/)
5555
if (testIgnoreNextLines) {
5656
return { count: Number(testIgnoreNextLines.groups.count) }
5757
}
5858

5959
// Check if comment is on its own line.
60-
if (lineStr.match(/^\W*\/\* c8 ignore next *\*\/\W*$/)) {
60+
if (lineStr.match(/^\W*\/\* c8 ignore next/)) {
6161
return { count: 1 }
6262
}
6363

64-
if (lineStr.match(/\/\* c8 ignore next \*\//)) {
64+
if (lineStr.match(/\/\* c8 ignore next/)) {
6565
// Won't ignore successive lines, but the current line will be ignored.
6666
return { count: 0 }
6767
}
6868

69-
const testIgnoreStartStop = lineStr.match(/\/\* c8 ignore (?<mode>start|stop) *\*\//)
69+
const testIgnoreStartStop = lineStr.match(/\/\* c8 ignore (?<mode>start|stop)/)
7070
if (testIgnoreStartStop) {
7171
if (testIgnoreStartStop.groups.mode === 'start') return { start: true }
7272
if (testIgnoreStartStop.groups.mode === 'stop') return { stop: true }

test/source.js

+38
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,43 @@ describe('Source', () => {
128128
source.lines[8].ignore.should.equal(false)
129129
source.lines[9].ignore.should.equal(false)
130130
})
131+
132+
it('ignore hint accepts other text content', () => {
133+
const sourceRaw = `
134+
const a = 33
135+
136+
/* c8 ignore next -- reasoning why this is ignored */
137+
const b = 99
138+
139+
/* c8 ignore start: reasoning here */
140+
function ignoreMe() {
141+
// ...
142+
}
143+
/* c8 ignore stop -- @preserve */
144+
145+
const c = a ? true /* c8 ignore next reasoning here */ : false
146+
147+
/* c8 ignore next 2 -- ignores next two lines */
148+
const a = 33
149+
const a = 99
150+
`
151+
const source = new CovSource(sourceRaw, 0)
152+
source.lines[1].ignore.should.equal(false)
153+
source.lines[2].ignore.should.equal(false)
154+
source.lines[3].ignore.should.equal(true)
155+
source.lines[4].ignore.should.equal(true)
156+
source.lines[5].ignore.should.equal(false)
157+
source.lines[6].ignore.should.equal(true)
158+
source.lines[7].ignore.should.equal(true)
159+
source.lines[8].ignore.should.equal(true)
160+
source.lines[9].ignore.should.equal(true)
161+
source.lines[10].ignore.should.equal(true)
162+
source.lines[11].ignore.should.equal(false)
163+
source.lines[12].ignore.should.equal(true)
164+
source.lines[13].ignore.should.equal(false)
165+
source.lines[14].ignore.should.equal(true)
166+
source.lines[15].ignore.should.equal(true)
167+
source.lines[16].ignore.should.equal(true)
168+
})
131169
})
132170
})

0 commit comments

Comments
 (0)