Skip to content

Commit d0b15ef

Browse files
committed
Progress with PR review
1 parent 6126d35 commit d0b15ef

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

lib/rules/no-unregistered-components.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ const casing = require('eslint-plugin-vue/lib/utils/casing')
1515
// Rule helpers
1616
// ------------------------------------------------------------------------------
1717

18+
const VUE_BUILT_IN_COMPONENTS = [
19+
'component',
20+
'suspense',
21+
'teleport',
22+
'transition',
23+
'transition-group',
24+
'keep-alive',
25+
'slot'
26+
]
1827
/**
1928
* Check whether the given node is a built-in component or not.
2029
*
@@ -24,12 +33,10 @@ const casing = require('eslint-plugin-vue/lib/utils/casing')
2433
* @returns {boolean} `true` if the node is a built-in component.
2534
*/
2635
const isBuiltInComponent = (node) => {
27-
const rawName = node && node.rawName.toLowerCase()
36+
const rawName = node && casing.kebabCase(node.rawName)
2837
return utils.isHtmlElementNode(node) &&
2938
!utils.isHtmlWellKnownElementName(node.rawName) &&
30-
(rawName === 'component' ||
31-
rawName === 'suspense' ||
32-
rawName === 'teleport')
39+
VUE_BUILT_IN_COMPONENTS.indexOf(rawName) > -1
3340
}
3441

3542
// ------------------------------------------------------------------------------
@@ -96,11 +103,6 @@ module.exports = {
96103
templateLocation = templateLocation || rootNode.loc.start
97104
},
98105
"VElement[name='template']:exit" (rootNode) {
99-
if (
100-
rootNode.loc.start !== templateLocation ||
101-
utils.hasAttribute(rootNode, 'src')
102-
) return
103-
104106
const registeredComponentNames = registeredComponents.map(({ name }) => casing.kebabCase(name))
105107

106108
usedComponentNodes

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

+23
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,29 @@ tester.run('no-unregistered-components', rule, {
319319
</Suspense>
320320
</template>
321321
`
322+
},
323+
{
324+
filename: 'test.vue',
325+
code: `
326+
<template>
327+
<transition />
328+
<transition-group />
329+
<keep-alive />
330+
<transition>
331+
<div>Text</div>
332+
</transition>
333+
<TransitionGroup />
334+
<KeepAlive />
335+
<Transition>
336+
<div>Text</div>
337+
</Transition>
338+
<Slot />
339+
<slot />
340+
<slot>
341+
foo
342+
</slot>
343+
</template>
344+
`
322345
}
323346
],
324347
invalid: [

0 commit comments

Comments
 (0)