diff --git a/README.md b/README.md index ae2c7b3b6c..0d94893c9b 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,7 @@ rules in templates can be disabled with eslint directives with mustache or html | [template-no-capital-arguments](docs/rules/template-no-capital-arguments.md) | disallow capital arguments (use lowercase @arg instead of @Arg) | | | | | [template-no-debugger](docs/rules/template-no-debugger.md) | disallow {{debugger}} in templates | | | | | [template-no-element-event-actions](docs/rules/template-no-element-event-actions.md) | disallow element event actions (use {{on}} modifier instead) | | | | +| [template-no-input-block](docs/rules/template-no-input-block.md) | disallow block usage of {{input}} helper | | | | | [template-no-log](docs/rules/template-no-log.md) | disallow {{log}} in templates | | | | ### Components diff --git a/docs/rules/template-no-input-block.md b/docs/rules/template-no-input-block.md new file mode 100644 index 0000000000..656894f47c --- /dev/null +++ b/docs/rules/template-no-input-block.md @@ -0,0 +1,24 @@ +# ember/template-no-input-block + + + +Use of the block form of the handlebars `input` helper will result in an error at runtime. + +## Examples + +This rule **forbids** the following: + +```gjs + +``` + +This rule **allows** the following: + +```gjs + +``` + +## References + +- [Ember api/input component](https://api.emberjs.com/ember/release/classes/Ember.Templates.components/methods/Input?anchor=Input) +- [rfcs/built in components](https://emberjs.github.io/rfcs/0459-angle-bracket-built-in-components.html) diff --git a/lib/rules/template-no-input-block.js b/lib/rules/template-no-input-block.js new file mode 100644 index 0000000000..ced42bbaec --- /dev/null +++ b/lib/rules/template-no-input-block.js @@ -0,0 +1,24 @@ +/** @type {import('eslint').Rule.RuleModule} */ +module.exports = { + meta: { + type: 'problem', + docs: { + description: 'disallow block usage of {{input}} helper', + category: 'Best Practices', + strictGjs: true, + strictGts: true, + url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-input-block.md', + }, + schema: [], + messages: { blockUsage: 'Unexpected block usage. The input helper may only be used inline.' }, + }, + create(context) { + return { + GlimmerBlockStatement(node) { + if (node.path?.type === 'GlimmerPathExpression' && node.path.original === 'input') { + context.report({ node, messageId: 'blockUsage' }); + } + }, + }; + }, +}; diff --git a/tests/lib/rules/template-no-input-block.js b/tests/lib/rules/template-no-input-block.js new file mode 100644 index 0000000000..4abf4e3c27 --- /dev/null +++ b/tests/lib/rules/template-no-input-block.js @@ -0,0 +1,23 @@ +const rule = require('../../../lib/rules/template-no-input-block'); +const RuleTester = require('eslint').RuleTester; + +const ruleTester = new RuleTester({ + parser: require.resolve('ember-eslint-parser'), + parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, +}); +ruleTester.run('template-no-input-block', rule, { + valid: [ + '', + // Test cases ported from ember-template-lint + '', + '', + '', + ], + invalid: [ + { + code: '', + output: null, + errors: [{ messageId: 'blockUsage' }], + }, + ], +});