Skip to content

Commit 3f2b669

Browse files
authored
Fix false positives when using <svg> in vue/valid-v-slot and vue/valid-v-model rule (#1367)
1 parent 0c5f2a1 commit 3f2b669

File tree

6 files changed

+36
-45
lines changed

6 files changed

+36
-45
lines changed

Diff for: lib/rules/require-toggle-inside-transition.js

-23
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,6 @@
1010

1111
const utils = require('../utils')
1212

13-
// ------------------------------------------------------------------------------
14-
// Helpers
15-
// ------------------------------------------------------------------------------
16-
17-
/**
18-
* Check whether the given node is an well-known element or not.
19-
* @param {VElement} node The element node to check.
20-
* @returns {boolean} `true` if the name is an well-known element name.
21-
*/
22-
function isWellKnownElement(node) {
23-
if (
24-
(!utils.isHtmlElementNode(node) && !utils.isSvgElementNode(node)) ||
25-
utils.isHtmlWellKnownElementName(node.rawName) ||
26-
utils.isSvgWellKnownElementName(node.rawName)
27-
) {
28-
return true
29-
}
30-
return false
31-
}
32-
3313
// ------------------------------------------------------------------------------
3414
// Rule Definition
3515
// ------------------------------------------------------------------------------
@@ -61,9 +41,6 @@ module.exports = {
6141
if (utils.isCustomComponent(element)) {
6242
return
6343
}
64-
if (!isWellKnownElement(element)) {
65-
return
66-
}
6744
if (
6845
!utils.hasDirective(element, 'if') &&
6946
!utils.hasDirective(element, 'show')

Diff for: lib/rules/valid-v-bind-sync.js

+2-22
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ const utils = require('../utils')
2020
* @returns {boolean} `true` if the node is valid.
2121
*/
2222
function isValidElement(node) {
23-
if (
24-
(!utils.isHtmlElementNode(node) && !utils.isSvgElementNode(node)) ||
25-
utils.isHtmlWellKnownElementName(node.rawName) ||
26-
utils.isSvgWellKnownElementName(node.rawName)
27-
) {
23+
if (!utils.isCustomComponent(node)) {
2824
// non Vue-component
2925
return false
3026
}
@@ -82,22 +78,6 @@ function maybeNullObjectMemberExpression(node) {
8278
return false
8379
}
8480

85-
function isValidIs(node) {
86-
const { attributes } = node
87-
const isAttribute = attributes.some((attr) => {
88-
// check for `VAttribute`
89-
if (attr.type === 'VAttribute') {
90-
// check for `is` attribute
91-
if (attr.key.type === 'VIdentifier' && attr.key.name === 'is') return true
92-
93-
// check for `:is` `bind` attribute
94-
if (attr.key.type === 'VDirectiveKey' && attr.key.argument.name === 'is')
95-
return true
96-
}
97-
})
98-
return isAttribute
99-
}
100-
10181
// ------------------------------------------------------------------------------
10282
// Rule Definition
10383
// ------------------------------------------------------------------------------
@@ -136,7 +116,7 @@ module.exports = {
136116
const element = node.parent.parent
137117
const name = element.name
138118

139-
if (!isValidElement(element) && !isValidIs(node.parent)) {
119+
if (!isValidElement(element)) {
140120
context.report({
141121
node,
142122
loc: node.loc,

Diff for: lib/utils/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@ module.exports = {
590590
return (
591591
(this.isHtmlElementNode(node) &&
592592
!this.isHtmlWellKnownElementName(node.rawName)) ||
593+
(this.isSvgElementNode(node) &&
594+
!this.isSvgWellKnownElementName(node.rawName)) ||
593595
this.hasAttribute(node, 'is') ||
594596
this.hasDirective(node, 'bind', 'is') ||
595597
this.hasDirective(node, 'is')

Diff for: tests/lib/rules/valid-v-bind-sync.js

+12
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,18 @@ tester.run('valid-v-bind-sync', rule, {
428428
filename: 'test.vue',
429429
code: '<template><MyComponent :foo.sync="(a?.b).c.d" /></template>',
430430
errors: ["'.sync' modifier has potential null object property access."]
431+
},
432+
{
433+
filename: 'test.vue',
434+
code:
435+
'<template><tr v-on:is="myRow" :some-prop.sync="somePropValue"></template>',
436+
errors: ["'.sync' modifiers aren't supported on <tr> non Vue-components."]
437+
},
438+
{
439+
filename: 'test.vue',
440+
code:
441+
'<template><tr v-bind="myRow" :some-prop.sync="somePropValue"></template>',
442+
errors: ["'.sync' modifiers aren't supported on <tr> non Vue-components."]
431443
}
432444
]
433445
})

Diff for: tests/lib/rules/valid-v-model.js

+9
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ tester.run('valid-v-model', rule, {
151151
code:
152152
'<template><MyComponent v-model.modifier.modifierTwo="a"></MyComponent></template>'
153153
},
154+
// svg
155+
{
156+
code: `
157+
<template>
158+
<svg>
159+
<MyComponent v-model="slotProps"></MyComponent>
160+
</svg>
161+
</template>`
162+
},
154163
// parsing error
155164
{
156165
filename: 'parsing-error.vue',

Diff for: tests/lib/rules/valid-v-slot.js

+11
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ tester.run('valid-v-slot', rule, {
131131
`,
132132
options: [{ allowModifiers: true }]
133133
},
134+
// svg
135+
{
136+
code: `
137+
<template>
138+
<svg>
139+
<MyComponent v-slot="slotProps">
140+
<MyChildComponent :thing="slotProps.thing" />
141+
</MyComponent>
142+
</svg>
143+
</template>`
144+
},
134145
// parsing error
135146
{
136147
filename: 'parsing-error.vue',

0 commit comments

Comments
 (0)