Skip to content
Open
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
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,23 @@ rules in templates can be disabled with eslint directives with mustache or html

### Best Practices

| Name                                       | Description | 💼 | 🔧 | 💡 |
| :----------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------- | :- | :- | :- |
| [template-builtin-component-arguments](docs/rules/template-builtin-component-arguments.md) | disallow setting certain attributes on builtin components | | | |
| [template-no-action-modifiers](docs/rules/template-no-action-modifiers.md) | disallow usage of {{action}} modifiers | | | |
| [template-no-arguments-for-html-elements](docs/rules/template-no-arguments-for-html-elements.md) | disallow @arguments on HTML elements | | | |
| [template-no-array-prototype-extensions](docs/rules/template-no-array-prototype-extensions.md) | disallow usage of Ember Array prototype extensions | | | |
| [template-no-block-params-for-html-elements](docs/rules/template-no-block-params-for-html-elements.md) | disallow block params on HTML elements | | | |
| [template-no-capital-arguments](docs/rules/template-no-capital-arguments.md) | disallow capital arguments (use lowercase @arg instead of @Arg) | | | |
| [template-no-chained-this](docs/rules/template-no-chained-this.md) | disallow redundant `this.this` in templates | | 🔧 | |
| [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-inline-event-handlers](docs/rules/template-no-inline-event-handlers.md) | disallow DOM event handler attributes | | | |
| [template-no-inline-styles](docs/rules/template-no-inline-styles.md) | disallow inline styles | | | |
| [template-no-input-placeholder](docs/rules/template-no-input-placeholder.md) | disallow placeholder attribute on input elements | | | |
| [template-no-input-tagname](docs/rules/template-no-input-tagname.md) | disallow tagName attribute on {{input}} helper | | | |
| [template-no-log](docs/rules/template-no-log.md) | disallow {{log}} in templates | | | |
| Name                                       | Description | 💼 | 🔧 | 💡 |
| :----------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------- | :- | :- | :- |
| [template-builtin-component-arguments](docs/rules/template-builtin-component-arguments.md) | disallow setting certain attributes on builtin components | | | |
| [template-no-action-modifiers](docs/rules/template-no-action-modifiers.md) | disallow usage of {{action}} modifiers | | | |
| [template-no-arguments-for-html-elements](docs/rules/template-no-arguments-for-html-elements.md) | disallow @arguments on HTML elements | | | |
| [template-no-array-prototype-extensions](docs/rules/template-no-array-prototype-extensions.md) | disallow usage of Ember Array prototype extensions | | | |
| [template-no-bare-yield](docs/rules/template-no-bare-yield.md) | disallow {{yield}} without parameters outside of contextual components | | | |
| [template-no-block-params-for-html-elements](docs/rules/template-no-block-params-for-html-elements.md) | disallow block params on HTML elements | | | |
| [template-no-capital-arguments](docs/rules/template-no-capital-arguments.md) | disallow capital arguments (use lowercase @arg instead of @Arg) | | | |
| [template-no-chained-this](docs/rules/template-no-chained-this.md) | disallow redundant `this.this` in templates | | 🔧 | |
| [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-inline-event-handlers](docs/rules/template-no-inline-event-handlers.md) | disallow DOM event handler attributes | | | |
| [template-no-inline-styles](docs/rules/template-no-inline-styles.md) | disallow inline styles | | | |
| [template-no-input-placeholder](docs/rules/template-no-input-placeholder.md) | disallow placeholder attribute on input elements | | | |
| [template-no-input-tagname](docs/rules/template-no-input-tagname.md) | disallow tagName attribute on {{input}} helper | | | |
| [template-no-log](docs/rules/template-no-log.md) | disallow {{log}} in templates | | | |

### Components

Expand Down
31 changes: 31 additions & 0 deletions docs/rules/template-no-bare-yield.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ember/template-no-bare-yield

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

Disallow `{{yield}}` without parameters outside of contextual components.

## Rule Details

This rule enforces passing parameters to `{{yield}}` to make component APIs more explicit.

## Examples

Examples of **incorrect** code for this rule:

```gjs
<template>
{{yield}}
</template>
```

Examples of **correct** code for this rule:

```gjs
<template>
{{yield (Object greeting="hello there")}}
</template>

<template>
{{yield @model}}
</template>
```
31 changes: 31 additions & 0 deletions lib/rules/template-no-bare-yield.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow {{yield}} without parameters outside of contextual components',
category: 'Best Practices',
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-bare-yield.md',
templateMode: 'both',
},
schema: [],
messages: {
noBareYield: 'yield should have parameters or be used in contextual components only.',
},
},

create(context) {
return {
GlimmerMustacheStatement(node) {
if (node.path.type === 'GlimmerPathExpression' && node.path.original === 'yield') {
if (!node.params || node.params.length === 0) {
context.report({
node,
messageId: 'noBareYield',
});
}
}
},
};
},
};
36 changes: 36 additions & 0 deletions tests/lib/rules/template-no-bare-yield.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const rule = require('../../../lib/rules/template-no-bare-yield');
const RuleTester = require('eslint').RuleTester;

const ruleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser'),
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
});

ruleTester.run('template-no-bare-yield', rule, {
valid: [
// yield with params inside a class
`import Component from '@glimmer/component';
class MyComponent extends Component {
<template>{{yield this}}</template>
}`,
// yield with params inside a function
`function myComponent() {
return <template>{{yield this}}</template>;
}`,
'<template>{{yield @model}}</template>',
'<template><div>Content</div></template>',
// yield this at module level is allowed by this rule (template-no-unavailable-this handles the `this` part)
'<template>{{yield this}}</template>',
],
invalid: [
{
code: '<template>{{yield}}</template>',
output: null,
errors: [{ messageId: 'noBareYield' }],
},
],
});
Loading