Skip to content

Commit

Permalink
Merge pull request #1106 from simlu/dev
Browse files Browse the repository at this point in the history
feat: added c8-prevent-ignore
  • Loading branch information
simlu authored Feb 10, 2022
2 parents 1b9b59c + 9e17668 commit 26f2e7c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/rules/c8-prevent-ignore.js
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);
}
};
}
};
1 change: 1 addition & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const index = require('../src/index');
describe('Testing index', () => {
it('Test Exported Rules', () => {
expect(Object.keys(index.rules).sort()).to.deep.equal([
'c8-prevent-ignore',
'istanbul-prevent-ignore',
'kebab-case-enforce',
'prevent-typeof-object'
Expand Down
15 changes: 15 additions & 0 deletions test/rules/c8-prevent-ignore.spec.js
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.']
}
]
});

0 comments on commit 26f2e7c

Please sign in to comment.