/
no-v-text-v-html-on-component.js
59 lines (54 loc) · 1.64 KB
/
no-v-text-v-html-on-component.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @author Yosuke Ota
* See LICENSE file in root directory for full license.
*/
'use strict'
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
const utils = require('../utils')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow v-text / v-html on component',
// TODO We will change it in the next major version.
// categories: ['essential', 'vue3-essential'],
categories: undefined,
url: 'https://eslint.vuejs.org/rules/no-v-text-v-html-on-component.html'
},
fixable: null,
schema: [],
messages: {
disallow:
"Using {{directiveName}} on component may break component's content."
}
},
/** @param {RuleContext} context */
create(context) {
/**
* Verify for v-text and v-html directive
* @param {VDirective} node
*/
function verify(node) {
const element = node.parent.parent
if (utils.isCustomComponent(element)) {
context.report({
node,
loc: node.loc,
messageId: 'disallow',
data: {
directiveName: `v-${node.key.name.name}`
}
})
}
}
return utils.defineTemplateBodyVisitor(context, {
"VAttribute[directive=true][key.name.name='text']": verify,
"VAttribute[directive=true][key.name.name='html']": verify
})
}
}