Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions lib/rules/template-no-block-params-for-html-elements.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
/** @type {import('eslint').Rule.RuleModule} */
const htmlTags = require('html-tags');

// Mirror upstream ember-template-lint's inverse-of-isAngleBracketComponent logic.
// A tag is treated as an HTML element only when it:
// - does NOT contain ':' (named blocks like <:slot>)
// - does NOT contain '.' (path/namespaced invocations like <foo.bar>)
// - does NOT start with '@' (argument invocations like <@foo>)
// - has NO uppercase letters (component invocations like <MyThing>)
// - does NOT contain '-' (HTML custom elements like <my-element>)
// Everything else is a component / custom-element / slot — not a plain HTML element.
function isHtmlElement(tagName) {
if (!tagName) {
return false;
}
if (tagName.startsWith('@')) {
return false;
}
if (tagName.includes(':')) {
return false;
}
if (tagName.includes('.')) {
return false;
}
if (tagName.includes('-')) {
return false;
}
if (tagName !== tagName.toLowerCase()) {
return false;
}
return true;
}

module.exports = {
meta: {
Expand All @@ -20,12 +49,11 @@ module.exports = {

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)) {
// Check if this is an HTML element (not a component / custom element / slot)
if (!isHtmlElement(node.tag)) {
return;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/template-no-block-params-for-html-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ ruleTester.run('template-no-block-params-for-html-elements', rule, {
'<template><MyComponent as |item|>{{item.name}}</MyComponent></template>',
'<template>{{#each this.items as |item|}}<li>{{item}}</li>{{/each}}</template>',
'<template><button>Click</button></template>',
// Custom elements (with a dash) are not HTML elements per upstream's
// isAngleBracketComponent inverse; they should not be flagged.
'<template><my-element as |x|>{{x}}</my-element></template>',
// Namespaced/path component invocations should not be treated as HTML elements.
'<template><NS.Foo as |x|>{{x}}</NS.Foo></template>',
],

invalid: [
Expand Down
Loading