-
Notifications
You must be signed in to change notification settings - Fork 227
/
no-commented-out-tests.ts
45 lines (39 loc) · 1.03 KB
/
no-commented-out-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { TSESTree } from '@typescript-eslint/experimental-utils';
import { createRule } from './utils';
function hasTests(node: TSESTree.Comment) {
return /^\s*(x|f)?(test|it|describe)(\.\w+|\[['"]\w+['"]\])?\s*\(/m.test(
node.value,
);
}
export default createRule({
name: __filename,
meta: {
docs: {
category: 'Best Practices',
description:
"This rule raises a warning about commented out tests. It's similar to no-disabled-tests rule.",
recommended: false,
},
messages: {
commentedTests: 'Some tests seem to be commented',
},
schema: [],
type: 'suggestion',
} as const,
defaultOptions: [],
create(context) {
const sourceCode = context.getSourceCode();
function checkNode(node: TSESTree.Comment) {
if (!hasTests(node)) {
return;
}
context.report({ messageId: 'commentedTests', node });
}
return {
Program() {
const comments = sourceCode.getAllComments();
comments.forEach(checkNode);
},
};
},
});