Skip to content

Commit 2567f16

Browse files
authored
Fix multiple reporting of same warnings in vue/no-unregistered-component (#1382)
* fix multiple reporting of unregistered components * add tests * fix linter error
1 parent b617e71 commit 2567f16

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

lib/rules/no-unregistered-components.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ module.exports = {
126126
usedComponentNodes.push({ node, name: node.value.value })
127127
},
128128
/** @param {VElement} node */
129-
"VElement[name='template']:exit"() {
129+
"VElement[name='template'][parent.type='VDocumentFragment']:exit"() {
130130
// All registered components, transformed to kebab-case
131131
const registeredComponentNames = registeredComponents.map(
132132
({ name }) => casing.kebabCase(name)

tests/lib/rules/no-unregistered-components.js

+38
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,25 @@ tester.run('no-unregistered-components', rule, {
458458
}
459459
</script>
460460
`
461+
},
462+
{
463+
filename: 'test.vue',
464+
code: `
465+
<template>
466+
<CustomComponentWithNamedSlots>
467+
<template #slotA>
468+
<div>Text</div>
469+
</template>
470+
</CustomComponentWithNamedSlots>
471+
</template>
472+
<script>
473+
export default {
474+
components: {
475+
CustomComponentWithNamedSlots
476+
}
477+
}
478+
</script>
479+
`
461480
}
462481
],
463482
invalid: [
@@ -668,6 +687,25 @@ tester.run('no-unregistered-components', rule, {
668687
line: 3
669688
}
670689
]
690+
},
691+
{
692+
filename: 'test.vue',
693+
code: `
694+
<template>
695+
<CustomComponentWithNamedSlots>
696+
<template #slotA>
697+
<div>Text</div>
698+
</template>
699+
</CustomComponentWithNamedSlots>
700+
</template>
701+
`,
702+
errors: [
703+
{
704+
message:
705+
'The "CustomComponentWithNamedSlots" component has been used but not registered.',
706+
line: 3
707+
}
708+
]
671709
}
672710
]
673711
})

0 commit comments

Comments
 (0)