Skip to content

Commit

Permalink
Fix false positives when using <svg> in vue/valid-v-slot and `vue/v…
Browse files Browse the repository at this point in the history
…alid-v-model` rule
  • Loading branch information
ota-meshi committed Dec 4, 2020
1 parent f1c6789 commit eb1031e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
23 changes: 0 additions & 23 deletions lib/rules/require-toggle-inside-transition.js
Expand Up @@ -10,26 +10,6 @@

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

// ------------------------------------------------------------------------------
// Helpers
// ------------------------------------------------------------------------------

/**
* Check whether the given node is an well-known element or not.
* @param {VElement} node The element node to check.
* @returns {boolean} `true` if the name is an well-known element name.
*/
function isWellKnownElement(node) {
if (
(!utils.isHtmlElementNode(node) && !utils.isSvgElementNode(node)) ||
utils.isHtmlWellKnownElementName(node.rawName) ||
utils.isSvgWellKnownElementName(node.rawName)
) {
return true
}
return false
}

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -61,9 +41,6 @@ module.exports = {
if (utils.isCustomComponent(element)) {
return
}
if (!isWellKnownElement(element)) {
return
}
if (
!utils.hasDirective(element, 'if') &&
!utils.hasDirective(element, 'show')
Expand Down
6 changes: 1 addition & 5 deletions lib/rules/valid-v-bind-sync.js
Expand Up @@ -20,11 +20,7 @@ const utils = require('../utils')
* @returns {boolean} `true` if the node is valid.
*/
function isValidElement(node) {
if (
(!utils.isHtmlElementNode(node) && !utils.isSvgElementNode(node)) ||
utils.isHtmlWellKnownElementName(node.rawName) ||
utils.isSvgWellKnownElementName(node.rawName)
) {
if (!utils.isCustomComponent(node)) {
// non Vue-component
return false
}
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/index.js
Expand Up @@ -590,6 +590,8 @@ module.exports = {
return (
(this.isHtmlElementNode(node) &&
!this.isHtmlWellKnownElementName(node.rawName)) ||
(this.isSvgElementNode(node) &&
!this.isSvgWellKnownElementName(node.rawName)) ||
this.hasAttribute(node, 'is') ||
this.hasDirective(node, 'bind', 'is') ||
this.hasDirective(node, 'is')
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/valid-v-model.js
Expand Up @@ -151,6 +151,15 @@ tester.run('valid-v-model', rule, {
code:
'<template><MyComponent v-model.modifier.modifierTwo="a"></MyComponent></template>'
},
// svg
{
code: `
<template>
<svg>
<MyComponent v-model="slotProps"></MyComponent>
</svg>
</template>`
},
// parsing error
{
filename: 'parsing-error.vue',
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/valid-v-slot.js
Expand Up @@ -107,6 +107,17 @@ tester.run('valid-v-slot', rule, {
`,
options: [{ allowModifiers: true }]
},
// svg
{
code: `
<template>
<svg>
<MyComponent v-slot="slotProps">
<MyChildComponent :thing="slotProps.thing" />
</MyComponent>
</svg>
</template>`
},
// parsing error
{
filename: 'parsing-error.vue',
Expand Down

0 comments on commit eb1031e

Please sign in to comment.