Skip to content

Commit

Permalink
Skip conditional expressions in vue/valid-next-tick (#1777)
Browse files Browse the repository at this point in the history
  • Loading branch information
FloEdelmann committed Jan 25, 2022
1 parent 0ca5f9d commit 9fa8ede
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/rules/valid-next-tick.js
Expand Up @@ -142,7 +142,12 @@ module.exports = {
return
}

const parentNode = nextTickNode.parent
let parentNode = nextTickNode.parent

// skip conditional expressions like `foo ? nextTick : bar`
if (parentNode.type === 'ConditionalExpression') {
parentNode = parentNode.parent
}

if (
parentNode.type === 'CallExpression' &&
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/rules/valid-next-tick.js
Expand Up @@ -129,6 +129,19 @@ tester.run('valid-next-tick', rule, {
},
}
}</script>`
},

// https://github.com/vuejs/eslint-plugin-vue/issues/1776
{
filename: 'test.vue',
code: `<script>import { nextTick as nt } from 'vue';
export default {
mounted() {
let foo = bar ? nt : undefined;
foo = bar ? Vue.nextTick : undefined;
foo = bar ? this.$nextTick : undefined;
}
}</script>`
}
],
invalid: [
Expand Down

0 comments on commit 9fa8ede

Please sign in to comment.