Skip to content

Commit 2b14e69

Browse files
committed
Fix template-no-input-tagname false positive in GJS/GTS
Add .hbs filename gate so the rule does not fire in GJS/GTS strict-mode templates, where `input` is a user-imported JS identifier rather than the classic resolver-resolved helper, making tagName= a valid custom argument.
1 parent b705850 commit 2b14e69

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

lib/rules/template-no-input-tagname.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ module.exports = {
1212
messages: { unexpected: 'Unexpected tagName usage on input helper.' },
1313
},
1414
create(context) {
15+
const isStrictMode = context.filename.endsWith('.gjs') || context.filename.endsWith('.gts');
16+
if (isStrictMode) {
17+
return {};
18+
}
19+
1520
function check(node) {
1621
if (!node.path) {
1722
return;

tests/lib/rules/template-no-input-tagname.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ const ruleTester = new RuleTester({
55
parser: require.resolve('ember-eslint-parser'),
66
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
77
});
8+
89
ruleTester.run('template-no-input-tagname', rule, {
910
valid: [
1011
'<template>{{input value=this.foo}}</template>',
1112
// Test cases ported from ember-template-lint
1213
'<template>{{input type="text"}}</template>',
1314
'<template>{{component "input" type="text"}}</template>',
1415
'<template>{{yield (component "input" type="text")}}</template>',
16+
// Rule is disabled in GJS/GTS: `input` is a user-imported binding, not the classic helper
17+
{ filename: 'test.gjs', code: '<template>{{input tagName="span"}}</template>' },
18+
{ filename: 'test.gts', code: '<template>{{input tagName="foo"}}</template>' },
1519
],
1620
invalid: [
1721
{
@@ -53,3 +57,57 @@ ruleTester.run('template-no-input-tagname', rule, {
5357
},
5458
],
5559
});
60+
61+
const hbsRuleTester = new RuleTester({
62+
parser: require.resolve('ember-eslint-parser/hbs'),
63+
parserOptions: {
64+
ecmaVersion: 2022,
65+
sourceType: 'module',
66+
},
67+
});
68+
69+
hbsRuleTester.run('template-no-input-tagname', rule, {
70+
valid: [
71+
'{{input value=foo}}',
72+
'{{input type="text"}}',
73+
'{{component "input" type="text"}}',
74+
'{{yield (component "input" type="text")}}',
75+
],
76+
invalid: [
77+
{
78+
code: '{{input tagName="span"}}',
79+
output: null,
80+
errors: [{ messageId: 'unexpected' }],
81+
},
82+
{
83+
code: '{{input tagName="foo"}}',
84+
output: null,
85+
errors: [{ messageId: 'unexpected' }],
86+
},
87+
{
88+
code: '{{input tagName=bar}}',
89+
output: null,
90+
errors: [{ messageId: 'unexpected' }],
91+
},
92+
{
93+
code: '{{component "input" tagName="foo"}}',
94+
output: null,
95+
errors: [{ messageId: 'unexpected' }],
96+
},
97+
{
98+
code: '{{component "input" tagName=bar}}',
99+
output: null,
100+
errors: [{ messageId: 'unexpected' }],
101+
},
102+
{
103+
code: '{{yield (component "input" tagName="foo")}}',
104+
output: null,
105+
errors: [{ messageId: 'unexpected' }],
106+
},
107+
{
108+
code: '{{yield (component "input" tagName=bar)}}',
109+
output: null,
110+
errors: [{ messageId: 'unexpected' }],
111+
},
112+
],
113+
});

0 commit comments

Comments
 (0)