forked from github/eslint-plugin-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync-currenttarget.js
More file actions
35 lines (33 loc) · 847 Bytes
/
async-currenttarget.js
File metadata and controls
35 lines (33 loc) · 847 Bytes
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
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow `event.currentTarget` calls inside of async functions',
url: require('../url')(module),
},
schema: [],
},
create(context) {
const scopeDidWait = new WeakSet()
return {
AwaitExpression() {
scopeDidWait.add(context.getScope())
},
MemberExpression(node) {
if (node.property && node.property.name === 'currentTarget') {
let scope = context.getScope()
while (scope) {
if (scopeDidWait.has(scope)) {
context.report({
node,
message: "event.currentTarget inside an async function is error prone",
})
break
}
scope = scope.upper
}
}
},
}
},
}