-
Notifications
You must be signed in to change notification settings - Fork 4
/
eslint-local-rules.js
40 lines (40 loc) · 1.19 KB
/
eslint-local-rules.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
module.exports = {
/**
* Lint rule that automatically validates moves use calculateDamage
*
* Because I forget that allll the time
*/
'validate-calculate-damage': {
meta: {
type: 'problem',
},
create(context) {
let causesDamage = false;
let calculatedDamage = false;
return {
// start of use() block
'Property[key.name="use"][value.type="FunctionExpression"]': () => {
causesDamage = false;
calculatedDamage = false;
},
// function calls for scene.causeDamage
'CallExpression[callee.object.name="scene"][callee.property.name="causeDamage"]': () => {
causesDamage = true;
},
// function calls for calculateDamage
'CallExpression[callee.name="calculateDamage"]': () => {
calculatedDamage = true;
},
// end of use() block
'Property[key.name="use"][value.type="FunctionExpression"]:exit': node => {
if (causesDamage && !calculatedDamage) {
context.report({
node,
message: 'This move deals damage without using calculateDamage',
});
}
},
};
},
},
};