forked from avajs/eslint-plugin-ava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathno-commented-tests.js
More file actions
57 lines (50 loc) · 1.17 KB
/
Copy pathno-commented-tests.js
File metadata and controls
57 lines (50 loc) · 1.17 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
import createAvaRule from '../create-ava-rule.js';
import util from '../util.js';
const MESSAGE_ID = 'no-commented-tests';
const commentedTestPattern = /^\s*\*?\s*(?:test|serial)\s*(?:\.\s*\w+\s*)*\(/;
const create = context => {
const ava = createAvaRule(context);
return ava.merge({
'Program:exit'() {
if (!ava.isInTestFile()) {
return;
}
for (const comment of context.sourceCode.getAllComments()) {
if (
comment.type === 'Block'
&& context.sourceCode.getText(comment).startsWith('/**')
) {
continue;
}
const lines = comment.value.split('\n');
for (const [index, line] of lines.entries()) {
if (commentedTestPattern.test(line)) {
context.report({
loc: {
line: comment.loc.start.line + index,
column: 0,
},
messageId: MESSAGE_ID,
});
break;
}
}
}
},
});
};
export default {
create,
meta: {
type: 'suggestion',
docs: {
description: 'Disallow commented-out tests.',
recommended: true,
url: util.getDocsUrl(import.meta.filename),
},
schema: [],
messages: {
[MESSAGE_ID]: 'Use `test.skip()` instead of commenting out a test.',
},
},
};