-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
95 lines (87 loc) · 2.68 KB
/
index.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const chalk = require('chalk');
function getObjectName(node) {
let iterations = 0;
let objectName = null;
let nodeObject = node.object;
while (objectName === null) {
if (nodeObject.type === 'Identifier') {
objectName = nodeObject.name;
}
if (nodeObject.type === 'TaggedTemplateExpression') {
objectName = nodeObject.tag.name;
}
if (nodeObject.type === 'CallExpression') {
iterations += 1;
if (nodeObject.callee.object === undefined) {
nodeObject = nodeObject.callee;
} else {
nodeObject = nodeObject.callee.object;
}
}
}
return { identifier: objectName, iterations };
}
module.exports = {
configs: {
recommended: {
env: {
browser: true,
node: true,
},
globals: {
fixture: false,
test: false,
},
rules: {
'testcafe-extended/no-only-statements': ['error'],
'testcafe-extended/no-debug-statements': ['error'],
// TestCafe actions need to start with `await`, just in case you want to run an `await t.<action>` inside
// a loop, we set the following eslint rule to 'off'
'no-await-in-loop': ['off'],
},
},
},
rules: {
'no-debug-statements': {
create: function(context) {
return {
CallExpression(node) {
const calleeProperty = node.callee.property || { type: null, name: null };
if (calleeProperty.type === 'Identifier' && calleeProperty.name === 'debug') {
context.report({
node: node,
message: `${chalk.italic('TestController')}${chalk.bold.yellow(
'.debug()',
)} is restricted from being used other than during development`,
});
}
},
};
},
},
'no-only-statements': {
create: function(context) {
return {
MemberExpression(node) {
const nodeProperty = node.property || { type: null, name: null };
if (nodeProperty.type === 'Identifier' && nodeProperty.name === 'only') {
if (node.object !== undefined) {
const objectName = getObjectName(node);
context.report({
node: node,
message: `${chalk.bold.white('{{ identifier }}')}${chalk.bold.yellow(
'.only',
)} is restricted from being used other than during development`,
data: {
identifier: objectName.identifier,
iterations: objectName.iterations,
},
});
}
}
},
};
},
},
},
};