Skip to content

Commit

Permalink
feat(require-toggle-inside-transition): check directive (#2487)
Browse files Browse the repository at this point in the history
Co-authored-by: Flo Edelmann <git@flo-edelmann.de>
  • Loading branch information
waynzh and FloEdelmann committed Jul 2, 2024
1 parent bfc72a4 commit 3ad09ef
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/rules/require-toggle-inside-transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@

const utils = require('../utils')

/**
* @param {VDirective} vBindAppear
*/
function isValidBindAppear(vBindAppear) {
if (
vBindAppear.value?.expression &&
vBindAppear.value.expression.type === 'Literal'
) {
return vBindAppear.value.expression?.value !== false
}

return true
}

module.exports = {
meta: {
type: 'problem',
Expand Down Expand Up @@ -35,7 +49,11 @@ module.exports = {

/** @type VElement */ // @ts-expect-error
const parent = element.parent
if (utils.hasAttribute(parent, 'appear')) {
const vBindAppear = utils.getDirective(parent, 'bind', 'appear')
if (
utils.hasAttribute(parent, 'appear') ||
(vBindAppear && isValidBindAppear(vBindAppear))
) {
return
}

Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rules/require-toggle-inside-transition.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ tester.run('require-toggle-inside-transition', rule, {
{
filename: 'test.vue',
code: '<template><transition appear><div /></transition></template>'
},
{
// https://github.com/vuejs/eslint-plugin-vue/issues/2467
filename: 'test.vue',
code: '<template><transition :appear="foo"><div /></transition></template>'
},
{
filename: 'test.vue',
code: '<template><transition :appear="true"><div /></transition></template>'
}
],
invalid: [
Expand Down Expand Up @@ -113,6 +122,16 @@ tester.run('require-toggle-inside-transition', rule, {
filename: 'test.vue',
code: '<template><Transition> <div /></Transition></template>',
errors: [{ messageId: 'expected' }]
},
{
filename: 'test.vue',
code: '<template><transition :appear="false"><div /></transition></template>',
errors: [{ messageId: 'expected' }]
},
{
filename: 'test.vue',
code: '<template><transition @appear="isLoaded"><div /></transition></template>',
errors: [{ messageId: 'expected' }]
}
]
})

0 comments on commit 3ad09ef

Please sign in to comment.