Skip to content

Commit 5ba7585

Browse files
committed
Add scope checking to template-no-arguments-for-html-elements
1 parent 49dccef commit 5ba7585

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

lib/rules/template-no-arguments-for-html-elements.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module.exports = {
1818
},
1919

2020
create(context) {
21+
const sourceCode = context.sourceCode;
2122
const HTML_ELEMENTS = new Set([
2223
'a',
2324
'abbr',
@@ -137,6 +138,13 @@ module.exports = {
137138
return;
138139
}
139140

141+
// If the tag name is a variable in scope, it's being used as a component, not an HTML element
142+
const scope = sourceCode.getScope(node.parent);
143+
const isVariable = scope.references.some((ref) => ref.identifier === node.parts[0]);
144+
if (isVariable) {
145+
return;
146+
}
147+
140148
// Check for @arguments
141149
for (const attr of node.attributes) {
142150
if (attr.type === 'GlimmerAttrNode' && attr.name.startsWith('@')) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ 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+
`let div = <template>{{@greeting}}</template>
17+
18+
<template>
19+
<div @greeting="hello" />
20+
</template>`
1621
],
1722

1823
invalid: [

0 commit comments

Comments
 (0)