-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.coffee
48 lines (43 loc) · 1.09 KB
/
index.coffee
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
CHAI_GETTERS = [
'ok',
'true',
'false',
'null',
'undefined',
'NaN',
'exist',
'empty',
'arguments',
'extensible',
'sealed',
'frozen',
'called',
'calledOnce',
'calledTwice',
'calledThrice',
'calledWithNew',
'alwaysCalledWithNew',
'notCalled'
]
module.exports = class NoChaiGetters
rule:
name: 'no_chai_getters'
level: 'error'
message: 'Using chai matcher without function invocation is forbidden'
description: 'Checks for chai getters at the end of a line'
lintNodeHelper: (node, astApi, inCall) ->
node.eachChild (child) =>
if child.constructor.name == 'Access' and (child.name.value in CHAI_GETTERS) and not inCall
@errors.push astApi.createError {
lineNumber: child.locationData.first_line + 1
}
childInCall = child.constructor.name == 'Call' or (inCall and child.constructor.name != 'Block')
@lintNodeHelper(child, astApi, childInCall)
return
return
lintNode: (node, astApi) ->
@lintNodeHelper node, astApi, false
return
lintAST: (node, astApi) ->
@lintNode node, astApi
return