Skip to content
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions docs/rules/template-no-input-block.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ember/template-no-input-block

<!-- end auto-generated rule header -->

Use of the block form of the handlebars `input` helper will result in an error at runtime.

## Examples

This rule **forbids** the following:

```gjs
<template>{{#input}}Some Content{{/input}}</template>
```

This rule **allows** the following:

```gjs
<template>{{input type='text' value=this.firstName disabled=this.entryNotAllowed size='50'}}</template>
```

## 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)
24 changes: 24 additions & 0 deletions lib/rules/template-no-input-block.js
Original file line number Diff line number Diff line change
@@ -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' });
}
},
};
},
};
23 changes: 23 additions & 0 deletions tests/lib/rules/template-no-input-block.js
Original file line number Diff line number Diff line change
@@ -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: [
'<template>{{input value=this.foo}}</template>',
// Test cases ported from ember-template-lint
'<template>{{button}}</template>',
'<template>{{#x-button}}{{/x-button}}</template>',
'<template>{{input}}</template>',
],
invalid: [
{
code: '<template>{{#input}}{{/input}}</template>',
output: null,
errors: [{ messageId: 'blockUsage' }],
},
],
});
Loading