数通智联化工云平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.7 KiB

2 years ago
/**
* @author Yosuke Ota
* See LICENSE file in root directory for full license.
*/
'use strict'
const utils = require('../utils')
module.exports = {
meta: {
type: 'problem',
docs: {
description:
'require control the display of the content inside `<transition>`',
categories: ['vue3-essential'],
url: 'https://eslint.vuejs.org/rules/require-toggle-inside-transition.html'
},
fixable: null,
schema: [],
messages: {
expected:
'The element inside `<transition>` is expected to have a `v-if` or `v-show` directive.'
}
},
/** @param {RuleContext} context */
create(context) {
/**
* Check if the given element has display control.
* @param {VElement} element The element node to check.
*/
function verifyInsideElement(element) {
if (utils.isCustomComponent(element)) {
return
}
2 years ago
/** @type VElement */ // @ts-expect-error
const parent = element.parent
if (utils.hasAttribute(parent, 'appear')) {
return
}
2 years ago
if (
2 years ago
element.name !== 'slot' &&
2 years ago
!utils.hasDirective(element, 'if') &&
2 years ago
!utils.hasDirective(element, 'show') &&
!utils.hasDirective(element, 'bind', 'key')
2 years ago
) {
context.report({
node: element.startTag,
loc: element.startTag.loc,
messageId: 'expected'
})
}
}
return utils.defineTemplateBodyVisitor(context, {
/** @param {VElement} node */
"VElement[name='transition'] > VElement"(node) {
2 years ago
const child = node.parent.children.find(utils.isVElement)
if (child !== node) {
2 years ago
return
}
2 years ago
2 years ago
verifyInsideElement(node)
}
})
}
}