Skip to content

Commit

Permalink
Drop "eslint-plugin-istanbul" and implement as internal ESLint rule (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Nov 28, 2021
1 parent 82ff653 commit 0fb6afc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 30 deletions.
10 changes: 1 addition & 9 deletions .eslintrc.yml
Expand Up @@ -8,7 +8,6 @@ reportUnusedDisableDirectives: true
plugins:
- internal-rules
- node
- istanbul
- import
settings:
node:
Expand All @@ -23,14 +22,7 @@ rules:
internal-rules/only-ascii: error
internal-rules/no-dir-import: error
internal-rules/require-to-string-tag: off

##############################################################################
# `eslint-plugin-istanbul` rule list based on `v0.1.2`
# https://github.com/istanbuljs/eslint-plugin-istanbul#rules
##############################################################################

istanbul/no-ignore-file: error
istanbul/prefer-ignore-reason: error
internal-rules/require-coverage-ignore-reason: error

##############################################################################
# `eslint-plugin-node` rule list based on `v11.1.x`
Expand Down
20 changes: 0 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -66,7 +66,6 @@
"eslint": "7.32.0",
"eslint-plugin-import": "2.25.2",
"eslint-plugin-internal-rules": "file:./resources/eslint-internal-rules",
"eslint-plugin-istanbul": "0.1.2",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-tsdoc": "0.2.14",
"mocha": "9.1.3",
Expand Down
2 changes: 2 additions & 0 deletions resources/eslint-internal-rules/index.js
Expand Up @@ -3,11 +3,13 @@
const onlyASCII = require('./only-ascii.js');
const noDirImport = require('./no-dir-import.js');
const requireToStringTag = require('./require-to-string-tag.js');
const requireCoverageIgnoreReason = require('./require-coverage-ignore-reason.js');

module.exports = {
rules: {
'only-ascii': onlyASCII,
'no-dir-import': noDirImport,
'require-to-string-tag': requireToStringTag,
'require-coverage-ignore-reason': requireCoverageIgnoreReason,
},
};
24 changes: 24 additions & 0 deletions resources/eslint-internal-rules/require-coverage-ignore-reason.js
@@ -0,0 +1,24 @@
'use strict';

module.exports = function requireCoverageIgnoreReason(context) {
const istanbulRegExp = /^\s*istanbul\s+ignore\s+(if|else|next|file)\s+/;
return {
Program() {
const sourceCode = context.getSourceCode();

for (const node of sourceCode.getAllComments()) {
const comment = node.value;

if (comment.match(istanbulRegExp)) {
const reason = comment.replace(istanbulRegExp, '');
if (!reason.match(/\(.+\)$/)) {
context.report({
message: 'Add a reason why code coverage should be ignored',
node,
});
}
}
}
},
};
};

0 comments on commit 0fb6afc

Please sign in to comment.