Skip to content

Commit ba16740

Browse files
committed
refactor
1 parent f3a6ad1 commit ba16740

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

lib/rules/no-v-text-v-html-on-component.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,16 @@ module.exports = {
6161
)
6262
}
6363

64-
/** @param {VElement} element */
65-
function isCustomComponent(element) {
66-
if (ignoreElementNamespaces) {
67-
return (
68-
(!utils.isHtmlWellKnownElementName(element.rawName) &&
69-
!utils.isSvgWellKnownElementName(element.rawName) &&
70-
!utils.isMathWellKnownElementName(element.rawName)) ||
71-
utils.hasAttribute(element, 'is') ||
72-
utils.hasDirective(element, 'bind', 'is') ||
73-
utils.hasDirective(element, 'is')
74-
)
75-
}
76-
77-
return utils.isCustomComponent(element)
78-
}
79-
8064
/**
8165
* Verify for v-text and v-html directive
8266
* @param {VDirective} node
8367
*/
8468
function verify(node) {
8569
const element = node.parent.parent
86-
if (isCustomComponent(element) && !isAllowedComponent(element)) {
70+
if (
71+
utils.isCustomComponent(element, ignoreElementNamespaces) &&
72+
!isAllowedComponent(element)
73+
) {
8774
context.report({
8875
node,
8976
loc: node.loc,

lib/utils/index.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -941,19 +941,30 @@ module.exports = {
941941
/**
942942
* Check whether the given node is a custom component or not.
943943
* @param {VElement} node The start tag node to check.
944+
* @param {boolean} [ignoreElementNamespaces=false] If `true`, ignore element namespaces.
944945
* @returns {boolean} `true` if the node is a custom component.
945946
*/
946-
isCustomComponent(node) {
947-
return (
948-
(this.isHtmlElementNode(node) &&
949-
!this.isHtmlWellKnownElementName(node.rawName)) ||
950-
(this.isSvgElementNode(node) &&
951-
!this.isSvgWellKnownElementName(node.rawName)) ||
952-
(this.isMathElementNode(node) &&
953-
!this.isMathWellKnownElementName(node.rawName)) ||
947+
isCustomComponent(node, ignoreElementNamespaces = false) {
948+
if (
954949
hasAttribute(node, 'is') ||
955950
hasDirective(node, 'bind', 'is') ||
956951
hasDirective(node, 'is')
952+
) {
953+
return true
954+
}
955+
956+
const isHtmlName = this.isHtmlWellKnownElementName(node.rawName)
957+
const isSvgName = this.isSvgWellKnownElementName(node.rawName)
958+
const isMathName = this.isMathWellKnownElementName(node.rawName)
959+
960+
if (ignoreElementNamespaces) {
961+
return !isHtmlName && !isSvgName && !isMathName
962+
}
963+
964+
return (
965+
(this.isHtmlElementNode(node) && !isHtmlName) ||
966+
(this.isSvgElementNode(node) && !isSvgName) ||
967+
(this.isMathElementNode(node) && !isMathName)
957968
)
958969
},
959970

0 commit comments

Comments
 (0)