Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(require-toggle-inside-transition): check directive #2487

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' }]
}
]
})
Loading