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
51 lines (44 loc) · 1.42 KB
/
template-no-block-params-for-html-elements.js
File metadata and controls
51 lines (44 loc) · 1.42 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
const htmlTags = require('html-tags');
const svgTags = require('svg-tags');
const { mathmlTagNames } = require('mathml-tag-names');
const ELEMENT_TAGS = new Set([...htmlTags, ...svgTags, ...mathmlTagNames]);
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow block params on HTML elements',
category: 'Best Practices',
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;
return {
GlimmerElementNode(node) {
if (!ELEMENT_TAGS.has(node.tag)) {
return;
}
// A known HTML/SVG tag can still be a component if it's bound in scope
// (block param, import, local).
const scope = sourceCode.getScope(node.parent);
const isVariable = scope.references.some((ref) => ref.identifier === node.parts[0]);
if (isVariable) {
return;
}
if (node.blockParams && node.blockParams.length > 0) {
context.report({
node,
messageId: 'noBlockParamsForHtmlElements',
});
}
},
};
},
};