-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1106 from simlu/dev
feat: added c8-prevent-ignore
- Loading branch information
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
create: (context) => { | ||
const sourceCode = context.getSourceCode(); | ||
|
||
const testComment = (node) => { | ||
if (node.value.startsWith(' c8 ignore ')) { | ||
context.report({ node, message: 'Not allowed to ignore coverage in this file.' }); | ||
} | ||
}; | ||
|
||
return { | ||
Program() { | ||
sourceCode.getAllComments().filter((token) => token.type !== 'Shebang').forEach(testComment); | ||
} | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const rule = require('../../src/rules/c8-prevent-ignore'); | ||
const tester = require('./rule-tester'); | ||
|
||
tester.run('c8-prevent-ignore', rule, { | ||
valid: [ | ||
'/* some comment */', | ||
'// c8 ignore' | ||
], | ||
invalid: [ | ||
{ | ||
code: '/* c8 ignore */', | ||
errors: ['Not allowed to ignore coverage in this file.'] | ||
} | ||
] | ||
}); |