From 2567f1639ca896b98f4ec77608a0b4b318670e29 Mon Sep 17 00:00:00 2001 From: enzo360 <55434771+enzo360@users.noreply.github.com> Date: Fri, 18 Dec 2020 09:12:37 +0100 Subject: [PATCH] Fix multiple reporting of same warnings in `vue/no-unregistered-component` (#1382) * fix multiple reporting of unregistered components * add tests * fix linter error --- lib/rules/no-unregistered-components.js | 2 +- tests/lib/rules/no-unregistered-components.js | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-unregistered-components.js b/lib/rules/no-unregistered-components.js index 3ae283284..6e6cb2ada 100644 --- a/lib/rules/no-unregistered-components.js +++ b/lib/rules/no-unregistered-components.js @@ -126,7 +126,7 @@ module.exports = { usedComponentNodes.push({ node, name: node.value.value }) }, /** @param {VElement} node */ - "VElement[name='template']:exit"() { + "VElement[name='template'][parent.type='VDocumentFragment']:exit"() { // All registered components, transformed to kebab-case const registeredComponentNames = registeredComponents.map( ({ name }) => casing.kebabCase(name) diff --git a/tests/lib/rules/no-unregistered-components.js b/tests/lib/rules/no-unregistered-components.js index a50e3c0f0..27739b78a 100644 --- a/tests/lib/rules/no-unregistered-components.js +++ b/tests/lib/rules/no-unregistered-components.js @@ -458,6 +458,25 @@ tester.run('no-unregistered-components', rule, { } ` + }, + { + filename: 'test.vue', + code: ` + + + ` } ], invalid: [ @@ -668,6 +687,25 @@ tester.run('no-unregistered-components', rule, { line: 3 } ] + }, + { + filename: 'test.vue', + code: ` + + `, + errors: [ + { + message: + 'The "CustomComponentWithNamedSlots" component has been used but not registered.', + line: 3 + } + ] } ] })