-
-
Notifications
You must be signed in to change notification settings - Fork 681
/
Copy pathno-restricted-html-elements.js
74 lines (69 loc) · 1.75 KB
/
no-restricted-html-elements.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @author Doug Wade <[email protected]>
*/
'use strict'
const utils = require('../utils')
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'disallow specific HTML elements',
categories: undefined,
url: 'https://eslint.vuejs.org/rules/no-restricted-html-elements.html'
},
fixable: null,
schema: {
type: 'array',
items: {
oneOf: [
{ type: 'string' },
{
type: 'object',
properties: {
element: { type: 'string' },
message: { type: 'string', minLength: 1 }
},
required: ['element'],
additionalProperties: false
}
]
},
uniqueItems: true,
minItems: 0
},
messages: {
forbiddenElement: 'Unexpected use of forbidden HTML element {{name}}.',
// eslint-disable-next-line eslint-plugin/report-message-format
customMessage: '{{message}}'
}
},
/**
* @param {RuleContext} context - The rule context.
* @returns {RuleListener} AST event handlers.
*/
create(context) {
return utils.defineTemplateBodyVisitor(context, {
/**
* @param {VElement} node
*/
VElement(node) {
if (!utils.isHtmlElementNode(node)) {
return
}
for (const option of context.options) {
const element = option.element || option
if (element === node.rawName) {
context.report({
messageId: option.message ? 'customMessage' : 'forbiddenElement',
data: {
name: node.rawName,
message: option.message
},
node: node.startTag
})
}
}
}
})
}
}