Skip to content

Commit f6dcffa

Browse files
committed
Fix template-no-block-params-for-html-elements: align HTML-element detection with upstream
Replace static htmlTags package check with inverse-of-component-detection (reject tags with : / . / uppercase / @ / -). Custom elements like <my-element as |x|> are no longer false-flagged.
1 parent 56f913d commit f6dcffa

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

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

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
/** @type {import('eslint').Rule.RuleModule} */
2-
const htmlTags = require('html-tags');
2+
3+
// Mirror upstream ember-template-lint's inverse-of-isAngleBracketComponent logic.
4+
// A tag is treated as an HTML element only when it:
5+
// - does NOT contain ':' (named blocks like <:slot>)
6+
// - does NOT contain '.' (path/namespaced invocations like <foo.bar>)
7+
// - does NOT start with '@' (argument invocations like <@foo>)
8+
// - has NO uppercase letters (component invocations like <MyThing>)
9+
// - does NOT contain '-' (HTML custom elements like <my-element>)
10+
// Everything else is a component / custom-element / slot — not a plain HTML element.
11+
function isHtmlElement(tagName) {
12+
if (!tagName) {
13+
return false;
14+
}
15+
if (tagName.startsWith('@')) {
16+
return false;
17+
}
18+
if (tagName.includes(':')) {
19+
return false;
20+
}
21+
if (tagName.includes('.')) {
22+
return false;
23+
}
24+
if (tagName.includes('-')) {
25+
return false;
26+
}
27+
if (tagName !== tagName.toLowerCase()) {
28+
return false;
29+
}
30+
return true;
31+
}
332

433
module.exports = {
534
meta: {
@@ -20,12 +49,11 @@ module.exports = {
2049

2150
create(context) {
2251
const sourceCode = context.sourceCode;
23-
const HTML_ELEMENTS = new Set(htmlTags);
2452

2553
return {
2654
GlimmerElementNode(node) {
27-
// Check if this is an HTML element (lowercase)
28-
if (!HTML_ELEMENTS.has(node.tag)) {
55+
// Check if this is an HTML element (not a component / custom element / slot)
56+
if (!isHtmlElement(node.tag)) {
2957
return;
3058
}
3159

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 (with a dash) are not HTML elements per upstream's
21+
// isAngleBracketComponent inverse; they should not be flagged.
22+
'<template><my-element as |x|>{{x}}</my-element></template>',
23+
// Namespaced/path component invocations should not be treated as HTML elements.
24+
'<template><NS.Foo as |x|>{{x}}</NS.Foo></template>',
2025
],
2126

2227
invalid: [

0 commit comments

Comments
 (0)