Skip to content

Commit 9fa8ede

Browse files
authored
Skip conditional expressions in vue/valid-next-tick (#1777)
1 parent 0ca5f9d commit 9fa8ede

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Diff for: lib/rules/valid-next-tick.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ module.exports = {
142142
return
143143
}
144144

145-
const parentNode = nextTickNode.parent
145+
let parentNode = nextTickNode.parent
146+
147+
// skip conditional expressions like `foo ? nextTick : bar`
148+
if (parentNode.type === 'ConditionalExpression') {
149+
parentNode = parentNode.parent
150+
}
146151

147152
if (
148153
parentNode.type === 'CallExpression' &&

Diff for: tests/lib/rules/valid-next-tick.js

+13
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ tester.run('valid-next-tick', rule, {
129129
},
130130
}
131131
}</script>`
132+
},
133+
134+
// https://github.com/vuejs/eslint-plugin-vue/issues/1776
135+
{
136+
filename: 'test.vue',
137+
code: `<script>import { nextTick as nt } from 'vue';
138+
export default {
139+
mounted() {
140+
let foo = bar ? nt : undefined;
141+
foo = bar ? Vue.nextTick : undefined;
142+
foo = bar ? this.$nextTick : undefined;
143+
}
144+
}</script>`
132145
}
133146
],
134147
invalid: [

0 commit comments

Comments
 (0)