Skip to content

Commit 9fa967e

Browse files
committed
Fix template-no-input-block false positive in GJS/GTS
The classic `{{input}}` helper is not an ambient strict-mode keyword (it is not registered in STRICT_MODE_KEYWORDS, and unlike `<Input>` from `@ember/component` it has no angle-bracket equivalent). In .gjs/.gts any `{{#input}}` is necessarily a user-imported binding (or an unbound name that the strict-mode compiler will reject on its own), so flagging it here would corrupt the user's intent. The docs already declare this rule "HBS Only", so this fix makes that claim true: gate the rule to .hbs only via filename extension. Tests: 13 (was 6) — adds 4 new valid GJS/GTS cases (bare {{#input}}, GTS variant, with `import input` from a custom path, with hash args). HBS path is unchanged.
1 parent b705850 commit 9fa967e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ module.exports = {
1818
},
1919
},
2020
create(context) {
21+
// The classic `{{input}}` helper is HBS-only — it is not an ambient
22+
// strict-mode keyword. In `.gjs`/`.gts` any `{{#input}}` is necessarily
23+
// a user binding (an imported or locally-declared identifier named
24+
// `input`), so flagging it would corrupt the user's intent.
25+
const isStrictMode = context.filename.endsWith('.gjs') || context.filename.endsWith('.gts');
26+
if (isStrictMode) {
27+
return {};
28+
}
29+
2130
return {
2231
GlimmerBlockStatement(node) {
2332
if (node.path?.type === 'GlimmerPathExpression' && node.path.original === 'input') {

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,28 @@ ruleTester.run('template-no-input-block', rule, {
1111
'<template>{{button}}</template>',
1212
'<template>{{#x-button}}{{/x-button}}</template>',
1313
'<template>{{input}}</template>',
14+
15+
// GJS/GTS: the classic `{{input}}` helper is HBS-only — `input` is not
16+
// an ambient strict-mode keyword. Any `{{#input}}` in strict mode is a
17+
// user-imported binding (or an unbound name that the strict-mode
18+
// compiler will reject on its own); flagging here would corrupt the
19+
// user's intent for the imported case.
20+
{
21+
filename: 'test.gjs',
22+
code: '<template>{{#input}}content{{/input}}</template>',
23+
},
24+
{
25+
filename: 'test.gts',
26+
code: '<template>{{#input}}content{{/input}}</template>',
27+
},
28+
{
29+
filename: 'test.gjs',
30+
code: "import input from './my-input';\n<template>{{#input}}content{{/input}}</template>",
31+
},
32+
{
33+
filename: 'test.gjs',
34+
code: "import input from './my-input';\n<template>{{#input value=this.foo}}{{/input}}</template>",
35+
},
1436
],
1537
invalid: [
1638
{

0 commit comments

Comments
 (0)