Skip to content

Commit 6308771

Browse files
committed
fix(template-no-block-params-for-html-elements): extend allowlist with svg-tags
Adds svg-tags to the html-tags allowlist so <circle as |x|> etc. are flagged alongside HTML elements. Documents accepted false negatives (custom elements, namespaced components) via new test cases.
1 parent 56f913d commit 6308771

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

lib/rules/template-no-block-params-for-html-elements.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
/** @type {import('eslint').Rule.RuleModule} */
21
const htmlTags = require('html-tags');
2+
const svgTags = require('svg-tags');
3+
4+
const ELEMENT_TAGS = new Set([...htmlTags, ...svgTags]);
35

6+
/** @type {import('eslint').Rule.RuleModule} */
47
module.exports = {
58
meta: {
69
type: 'problem',
@@ -20,23 +23,21 @@ module.exports = {
2023

2124
create(context) {
2225
const sourceCode = context.sourceCode;
23-
const HTML_ELEMENTS = new Set(htmlTags);
2426

2527
return {
2628
GlimmerElementNode(node) {
27-
// Check if this is an HTML element (lowercase)
28-
if (!HTML_ELEMENTS.has(node.tag)) {
29+
if (!ELEMENT_TAGS.has(node.tag)) {
2930
return;
3031
}
3132

32-
// If the tag name is a variable in scope, it's being used as a component, not an HTML element
33+
// A known HTML/SVG tag can still be a component if it's bound in scope
34+
// (block param, import, local).
3335
const scope = sourceCode.getScope(node.parent);
3436
const isVariable = scope.references.some((ref) => ref.identifier === node.parts[0]);
3537
if (isVariable) {
3638
return;
3739
}
3840

39-
// Check for block params
4041
if (node.blockParams && node.blockParams.length > 0) {
4142
context.report({
4243
node,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
"lodash.camelcase": "^4.3.0",
7575
"lodash.kebabcase": "^4.1.1",
7676
"requireindex": "^1.2.0",
77-
"snake-case": "^3.0.3"
77+
"snake-case": "^3.0.3",
78+
"svg-tags": "^1.0.0"
7879
},
7980
"devDependencies": {
8081
"@babel/core": "^7.25.9",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/lib/rules/template-no-block-params-for-html-elements.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ ruleTester.run('template-no-block-params-for-html-elements', rule, {
1717
'<template><MyComponent as |item|>{{item.name}}</MyComponent></template>',
1818
'<template>{{#each this.items as |item|}}<li>{{item}}</li>{{/each}}</template>',
1919
'<template><button>Click</button></template>',
20+
// Custom elements aren't in the html-tags/svg-tags allowlists, so they're
21+
// not flagged. Accepted false negative — web component namespace is open.
22+
'<template><my-element as |x|>{{x}}</my-element></template>',
23+
// Namespaced/path component invocations aren't in the allowlists either.
24+
'<template><NS.Foo as |x|>{{x}}</NS.Foo></template>',
2025
],
2126

2227
invalid: [

0 commit comments

Comments
 (0)