Skip to content

Commit 3ad09ef

Browse files
waynzhFloEdelmann
andauthored
feat(require-toggle-inside-transition): check directive (#2487)
Co-authored-by: Flo Edelmann <[email protected]>
1 parent bfc72a4 commit 3ad09ef

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

Diff for: lib/rules/require-toggle-inside-transition.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66

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

9+
/**
10+
* @param {VDirective} vBindAppear
11+
*/
12+
function isValidBindAppear(vBindAppear) {
13+
if (
14+
vBindAppear.value?.expression &&
15+
vBindAppear.value.expression.type === 'Literal'
16+
) {
17+
return vBindAppear.value.expression?.value !== false
18+
}
19+
20+
return true
21+
}
22+
923
module.exports = {
1024
meta: {
1125
type: 'problem',
@@ -35,7 +49,11 @@ module.exports = {
3549

3650
/** @type VElement */ // @ts-expect-error
3751
const parent = element.parent
38-
if (utils.hasAttribute(parent, 'appear')) {
52+
const vBindAppear = utils.getDirective(parent, 'bind', 'appear')
53+
if (
54+
utils.hasAttribute(parent, 'appear') ||
55+
(vBindAppear && isValidBindAppear(vBindAppear))
56+
) {
3957
return
4058
}
4159

Diff for: tests/lib/rules/require-toggle-inside-transition.js

+19
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ tester.run('require-toggle-inside-transition', rule, {
6868
{
6969
filename: 'test.vue',
7070
code: '<template><transition appear><div /></transition></template>'
71+
},
72+
{
73+
// https://github.com/vuejs/eslint-plugin-vue/issues/2467
74+
filename: 'test.vue',
75+
code: '<template><transition :appear="foo"><div /></transition></template>'
76+
},
77+
{
78+
filename: 'test.vue',
79+
code: '<template><transition :appear="true"><div /></transition></template>'
7180
}
7281
],
7382
invalid: [
@@ -113,6 +122,16 @@ tester.run('require-toggle-inside-transition', rule, {
113122
filename: 'test.vue',
114123
code: '<template><Transition> <div /></Transition></template>',
115124
errors: [{ messageId: 'expected' }]
125+
},
126+
{
127+
filename: 'test.vue',
128+
code: '<template><transition :appear="false"><div /></transition></template>',
129+
errors: [{ messageId: 'expected' }]
130+
},
131+
{
132+
filename: 'test.vue',
133+
code: '<template><transition @appear="isLoaded"><div /></transition></template>',
134+
errors: [{ messageId: 'expected' }]
116135
}
117136
]
118137
})

0 commit comments

Comments
 (0)