From e6cab778acebd693f26869894a1a5fd66e34e188 Mon Sep 17 00:00:00 2001 From: williamc Date: Fri, 27 Oct 2023 15:11:25 +0800 Subject: [PATCH 1/3] fix(require-toggle-inside-transition): should respect and v-bind:key --- lib/rules/require-toggle-inside-transition.js | 10 ++++------ tests/lib/rules/require-toggle-inside-transition.js | 12 ++++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/rules/require-toggle-inside-transition.js b/lib/rules/require-toggle-inside-transition.js index bdbb5c2dd..fb12783ef 100644 --- a/lib/rules/require-toggle-inside-transition.js +++ b/lib/rules/require-toggle-inside-transition.js @@ -33,8 +33,10 @@ module.exports = { return } if ( + element.name !== 'slot' && !utils.hasDirective(element, 'if') && - !utils.hasDirective(element, 'show') + !utils.hasDirective(element, 'show') && + !utils.hasDirective(element, 'bind', 'key') ) { context.report({ node: element.startTag, @@ -47,12 +49,8 @@ module.exports = { return utils.defineTemplateBodyVisitor(context, { /** @param {VElement} node */ "VElement[name='transition'] > VElement"(node) { - const child = node.parent.children.find(utils.isVElement) - if (child !== node) { - return - } verifyInsideElement(node) - } + }, }) } } diff --git a/tests/lib/rules/require-toggle-inside-transition.js b/tests/lib/rules/require-toggle-inside-transition.js index 0b64daaa3..13c0c8909 100644 --- a/tests/lib/rules/require-toggle-inside-transition.js +++ b/tests/lib/rules/require-toggle-inside-transition.js @@ -57,7 +57,15 @@ tester.run('require-toggle-inside-transition', rule, { { filename: 'test.vue', code: '' - } + }, + { + filename: 'test.vue', + code: '' + }, + { + filename: 'test.vue', + code: '' + }, ], invalid: [ { @@ -81,7 +89,7 @@ tester.run('require-toggle-inside-transition', rule, { { filename: 'test.vue', code: '', - errors: [{ messageId: 'expected' }] + errors: [{ messageId: 'expected' }, { messageId: 'expected' }] }, { filename: 'test.vue', From e2f1a8d36bd540a842efe61c29bace7ba480d454 Mon Sep 17 00:00:00 2001 From: williamc Date: Fri, 27 Oct 2023 15:26:02 +0800 Subject: [PATCH 2/3] fix(require-toggle-inside-transition): should respect the attribute "appear" --- lib/rules/require-toggle-inside-transition.js | 9 ++++++++- tests/lib/rules/require-toggle-inside-transition.js | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/rules/require-toggle-inside-transition.js b/lib/rules/require-toggle-inside-transition.js index fb12783ef..64972db6c 100644 --- a/lib/rules/require-toggle-inside-transition.js +++ b/lib/rules/require-toggle-inside-transition.js @@ -32,6 +32,13 @@ module.exports = { if (utils.isCustomComponent(element)) { return } + + /** @type VElement */ // @ts-expect-error + const parent = element.parent + if (utils.hasAttribute(parent, 'appear')) { + return + } + if ( element.name !== 'slot' && !utils.hasDirective(element, 'if') && @@ -50,7 +57,7 @@ module.exports = { /** @param {VElement} node */ "VElement[name='transition'] > VElement"(node) { verifyInsideElement(node) - }, + } }) } } diff --git a/tests/lib/rules/require-toggle-inside-transition.js b/tests/lib/rules/require-toggle-inside-transition.js index 13c0c8909..3d2966309 100644 --- a/tests/lib/rules/require-toggle-inside-transition.js +++ b/tests/lib/rules/require-toggle-inside-transition.js @@ -66,6 +66,10 @@ tester.run('require-toggle-inside-transition', rule, { filename: 'test.vue', code: '' }, + { + filename: 'test.vue', + code: '' + } ], invalid: [ { From 497a9c27e0477c87b7cf3b62f5ef1f0e86933d1e Mon Sep 17 00:00:00 2001 From: williamc Date: Fri, 27 Oct 2023 16:22:48 +0800 Subject: [PATCH 3/3] test(require-toggle-inside-transition): add case --- lib/rules/require-toggle-inside-transition.js | 5 +++++ tests/lib/rules/require-toggle-inside-transition.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/rules/require-toggle-inside-transition.js b/lib/rules/require-toggle-inside-transition.js index 64972db6c..fc46f75f9 100644 --- a/lib/rules/require-toggle-inside-transition.js +++ b/lib/rules/require-toggle-inside-transition.js @@ -56,6 +56,11 @@ module.exports = { return utils.defineTemplateBodyVisitor(context, { /** @param {VElement} node */ "VElement[name='transition'] > VElement"(node) { + const child = node.parent.children.find(utils.isVElement) + if (child !== node) { + return + } + verifyInsideElement(node) } }) diff --git a/tests/lib/rules/require-toggle-inside-transition.js b/tests/lib/rules/require-toggle-inside-transition.js index 3d2966309..18a33aa3e 100644 --- a/tests/lib/rules/require-toggle-inside-transition.js +++ b/tests/lib/rules/require-toggle-inside-transition.js @@ -93,7 +93,7 @@ tester.run('require-toggle-inside-transition', rule, { { filename: 'test.vue', code: '', - errors: [{ messageId: 'expected' }, { messageId: 'expected' }] + errors: [{ messageId: 'expected' }] }, { filename: 'test.vue',