forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-no-inline-event-handlers.js
More file actions
58 lines (56 loc) · 1.35 KB
/
template-no-inline-event-handlers.js
File metadata and controls
58 lines (56 loc) · 1.35 KB
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
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow DOM event handler attributes',
category: 'Best Practices',
strictGjs: true,
strictGts: true,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-inline-event-handlers.md',
},
fixable: null,
schema: [],
messages: {
unexpected:
'Do not use inline event handlers like "{{name}}". Use the (on) modifier instead.',
},
},
create(context) {
const EVENT_HANDLER_ATTRS = new Set([
'onclick',
'ondblclick',
'onmousedown',
'onmouseup',
'onmousemove',
'onmouseout',
'onmouseover',
'onkeydown',
'onkeyup',
'onkeypress',
'onchange',
'oninput',
'onsubmit',
'onfocus',
'onblur',
'onload',
'onerror',
'onscroll',
]);
return {
GlimmerElementNode(node) {
if (node.attributes) {
for (const attr of node.attributes) {
if (attr.name && EVENT_HANDLER_ATTRS.has(attr.name.toLowerCase())) {
context.report({
node: attr,
messageId: 'unexpected',
data: { name: attr.name },
});
}
}
}
},
};
},
};