forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathno-replace-test-comments.js
More file actions
58 lines (49 loc) · 1.77 KB
/
no-replace-test-comments.js
File metadata and controls
58 lines (49 loc) · 1.77 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
58
'use strict';
const emberUtils = require('../utils/ember');
const ERROR_MESSAGE = "No 'Replace this with your real tests' comments. Add a substantive test.";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: "disallow 'Replace this with your real tests' comments in test files",
category: 'Testing',
recommended: false,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/no-replace-test-comments.md',
},
fixable: null,
schema: [],
},
ERROR_MESSAGE,
create(context) {
//----------------------------------------------------------------------
// Helpers
//----------------------------------------------------------------------
const checkForRealTestsComment = (node) => {
const { value = '' } = node || {};
const regex = /replace this with your real tests/i;
const message = ERROR_MESSAGE;
if (regex.test(value)) {
context.report({ node, message });
}
};
//----------------------------------------------------------------------
// Public
//----------------------------------------------------------------------
if (!emberUtils.isTestFile(context.filename ?? context.getFilename())) {
return {};
}
return {
Program(/* node */) {
const sourceCode = (context.sourceCode ?? context.getSourceCode()) || {};
const comments = sourceCode.getAllComments() || [];
for (const comment of comments) {
checkForRealTestsComment(comment);
}
},
};
},
};