Skip to content

Commit 0330147

Browse files
authored
Fix false positives for target instance is given, in no-lifecycle-after-await rule. (#1139)
1 parent d191481 commit 0330147

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/rules/no-lifecycle-after-await.js

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ module.exports = {
8080
}
8181

8282
if (lifecycleHookCallNodes.has(node)) {
83+
if (node.arguments.length >= 2) {
84+
// Has target instance. e.g. `onMounted(() => {}, instance)`
85+
return
86+
}
8387
context.report({
8488
node,
8589
messageId: 'forbidden'

tests/lib/rules/no-lifecycle-after-await.js

+30-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ tester.run('no-lifecycle-after-await', rule, {
2727
}
2828
</script>
2929
`
30-
}, {
30+
},
31+
{
3132
filename: 'test.vue',
3233
code: `
3334
<script>
@@ -39,7 +40,8 @@ tester.run('no-lifecycle-after-await', rule, {
3940
}
4041
</script>
4142
`
42-
}, {
43+
},
44+
{
4345
filename: 'test.vue',
4446
code: `
4547
<script>
@@ -78,6 +80,32 @@ tester.run('no-lifecycle-after-await', rule, {
7880
}
7981
</script>
8082
`
83+
},
84+
// has target
85+
{
86+
filename: 'test.vue',
87+
code: `
88+
<script>
89+
import {onBeforeMount, onBeforeUnmount, onBeforeUpdate, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onUnmounted, onUpdated, onActivated, onDeactivated} from 'vue'
90+
export default {
91+
async setup() {
92+
await doSomething()
93+
94+
onBeforeMount(() => { /* ... */ }, instance)
95+
onBeforeUnmount(() => { /* ... */ }, instance)
96+
onBeforeUpdate(() => { /* ... */ }, instance)
97+
onErrorCaptured(() => { /* ... */ }, instance)
98+
onMounted(() => { /* ... */ }, instance)
99+
onRenderTracked(() => { /* ... */ }, instance)
100+
onRenderTriggered(() => { /* ... */ }, instance)
101+
onUnmounted(() => { /* ... */ }, instance)
102+
onUpdated(() => { /* ... */ }, instance)
103+
onActivated(() => { /* ... */ }, instance)
104+
onDeactivated(() => { /* ... */ }, instance)
105+
}
106+
}
107+
</script>
108+
`
81109
}
82110
],
83111
invalid: [

0 commit comments

Comments
 (0)