Skip to content

fix: async-currenttarget/preventdefault doesn’t consider nested scopes #567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: async-currenttarget/preventdefault doesn’t consider nested scopes
  • Loading branch information
kurtextrem committed Oct 31, 2024
commit 2dbf02ab89551a23322b98239c320d728c7fc8e6
15 changes: 11 additions & 4 deletions lib/rules/async-currenttarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ module.exports = {

return {
AwaitExpression() {
scopeDidWait.add(context.getScope(), true)
scopeDidWait.add(context.getScope())
},
MemberExpression(node) {
if (node.property && node.property.name === 'currentTarget') {
const scope = context.getScope()
if (scope.block.async && scopeDidWait.has(scope)) {
context.report({node, message: 'event.currentTarget inside an async function is error prone'})
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
}
}
},
Expand Down
15 changes: 11 additions & 4 deletions lib/rules/async-preventdefault.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ module.exports = {

return {
AwaitExpression() {
scopeDidWait.add(context.getScope(), true)
scopeDidWait.add(context.getScope())
},
CallExpression(node) {
if (node.callee.property && node.callee.property.name === 'preventDefault') {
const scope = context.getScope()
if (scope.block.async && scopeDidWait.has(scope)) {
context.report({node, message: 'event.preventDefault() inside an async function is error prone'})
let scope = context.getScope()
while (scope) {
if (scopeDidWait.has(scope)) {
context.report({
node,
message: "event.preventDefault() inside an async function is error prone",
})
break
}
scope = scope.upper
}
}
},
Expand Down