forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-builtin-component-arguments.js
More file actions
45 lines (41 loc) · 1.3 KB
/
template-builtin-component-arguments.js
File metadata and controls
45 lines (41 loc) · 1.3 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
const FORBIDDEN_ATTRIBUTES = {
Input: new Set(['checked', 'type', 'value']),
Textarea: new Set(['value']),
};
function generateErrorMessage(component, attribute) {
return `Setting the \`${attribute}\` attribute on the builtin <${component}> component is not allowed. Did you mean \`@${attribute}\`?`;
}
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'disallow setting certain attributes on builtin components',
category: 'Best Practices',
strictGjs: true,
strictGts: true,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-builtin-component-arguments.md',
},
fixable: null,
schema: [],
messages: {},
},
create(context) {
return {
GlimmerElementNode(node) {
const { tag, attributes } = node;
const forbiddenAttributes = FORBIDDEN_ATTRIBUTES[tag];
if (forbiddenAttributes && attributes) {
for (const attribute of attributes) {
if (attribute.name && forbiddenAttributes.has(attribute.name)) {
context.report({
node: attribute,
message: generateErrorMessage(tag, attribute.name),
});
}
}
}
},
};
},
};