Skip to content

Commit 3118f91

Browse files
committed
Fix template-no-arguments-for-html-elements: align HTML-element detection with upstream
Replace static htmlTags package check with inverse-of-component-detection (reject tags with : / . / uppercase / @ / -). Matches upstream's isAngleBracketComponent semantics. Custom elements are now correctly excluded.
1 parent 56f913d commit 3118f91

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

lib/rules/template-no-arguments-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-arguments-for-html-elements.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ ruleTester.run('template-no-arguments-for-html-elements', rule, {
1313
'<template><MyComponent @title="Hello" @onClick={{this.handler}} /></template>',
1414
'<template><CustomButton @disabled={{true}} /></template>',
1515
'<template><input value={{this.value}} /></template>',
16+
// Custom elements (with a dash) are not HTML elements per upstream's
17+
// isAngleBracketComponent inverse; they should not be flagged.
18+
'<template><my-element @foo="x" /></template>',
19+
// Namespaced/path component invocations should not be treated as HTML elements.
20+
'<template><NS.Foo @bar="baz" /></template>',
21+
// Named blocks (colon-prefixed) should not be treated as HTML elements.
22+
'<template><Thing><:slot @item="x">content</:slot></Thing></template>',
1623
`let div = <template>{{@greeting}}</template>
1724
1825
<template>

0 commit comments

Comments
 (0)