Skip to content

Commit

Permalink
Fix multiple reporting of same warnings in `vue/no-unregistered-compo…
Browse files Browse the repository at this point in the history
…nent` (#1382)

* fix multiple reporting of unregistered components

* add tests

* fix linter error
  • Loading branch information
enzo360 committed Dec 18, 2020
1 parent b617e71 commit 2567f16
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-unregistered-components.js
Expand Up @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions tests/lib/rules/no-unregistered-components.js
Expand Up @@ -458,6 +458,25 @@ tester.run('no-unregistered-components', rule, {
}
</script>
`
},
{
filename: 'test.vue',
code: `
<template>
<CustomComponentWithNamedSlots>
<template #slotA>
<div>Text</div>
</template>
</CustomComponentWithNamedSlots>
</template>
<script>
export default {
components: {
CustomComponentWithNamedSlots
}
}
</script>
`
}
],
invalid: [
Expand Down Expand Up @@ -668,6 +687,25 @@ tester.run('no-unregistered-components', rule, {
line: 3
}
]
},
{
filename: 'test.vue',
code: `
<template>
<CustomComponentWithNamedSlots>
<template #slotA>
<div>Text</div>
</template>
</CustomComponentWithNamedSlots>
</template>
`,
errors: [
{
message:
'The "CustomComponentWithNamedSlots" component has been used but not registered.',
line: 3
}
]
}
]
})

0 comments on commit 2567f16

Please sign in to comment.