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-block-params-for-html-elements.js
More file actions
50 lines (45 loc) · 1.41 KB
/
template-no-block-params-for-html-elements.js
File metadata and controls
50 lines (45 loc) · 1.41 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
/** @type {import('eslint').Rule.RuleModule} */
const htmlTags = require('html-tags');
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow block params on HTML elements',
category: 'Best Practices',
strictGjs: true,
strictGts: true,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-block-params-for-html-elements.md',
},
fixable: null,
schema: [],
messages: {
noBlockParamsForHtmlElements:
'Block params can only be used with components, not HTML elements.',
},
},
create(context) {
const sourceCode = context.sourceCode;
const HTML_ELEMENTS = new Set(htmlTags);
return {
GlimmerElementNode(node) {
// Check if this is an HTML element (lowercase)
if (!HTML_ELEMENTS.has(node.tag)) {
return;
}
// If the tag name is a variable in scope, it's being used as a component, not an HTML element
const scope = sourceCode.getScope(node.parent);
const isVariable = scope.references.some((ref) => ref.identifier === node.parts[0]);
if (isVariable) {
return;
}
// Check for block params
if (node.blockParams && node.blockParams.length > 0) {
context.report({
node,
messageId: 'noBlockParamsForHtmlElements',
});
}
},
};
},
};