|
1 | 1 | # ember/template-require-has-block-helper |
2 | 2 |
|
3 | | -> **HBS Only**: This rule applies to classic `.hbs` template files only (loose mode). It is not relevant for `gjs`/`gts` files (strict mode), where these patterns cannot occur. |
| 3 | +🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). |
4 | 4 |
|
5 | 5 | <!-- end auto-generated rule header --> |
6 | 6 |
|
7 | | -Requires usage of the `(has-block)` helper instead of the `hasBlock` property. |
| 7 | +In Ember 3.26 the properties `hasBlock` and `hasBlockParams` were deprecated. Their replacement is to use `has-block` and `has-block-params` helpers instead. |
8 | 8 |
|
9 | | -## Rule Details |
| 9 | +This rule prevents the usage of `hasBlock` and `hasBlockParams` and suggests using `has-block` or `has-block-params` instead. |
10 | 10 |
|
11 | | -The `(has-block)` helper is the preferred way to check if a block was provided to a component. |
| 11 | +For more information about this deprecation you can view the [RFC](https://github.com/emberjs/rfcs/blob/master/text/0689-deprecate-has-block.md) or its entry on the [Deprecations page](https://deprecations.emberjs.com/v3.x/#toc_has-block-and-has-block-params). |
12 | 12 |
|
13 | 13 | ## Examples |
14 | 14 |
|
15 | | -Examples of **incorrect** code for this rule: |
| 15 | +This rule **forbids** the following: |
16 | 16 |
|
17 | | -```hbs |
18 | | -{{#if hasBlock}} |
19 | | - {{yield}} |
20 | | -{{/if}} |
| 17 | +```gjs |
| 18 | +<template> |
| 19 | + {{hasBlock}} |
| 20 | + {{#if hasBlock}} |
| 21 | +
|
| 22 | + {{/if}} |
| 23 | +</template> |
21 | 24 | ``` |
22 | 25 |
|
23 | | -```hbs |
24 | | -{{#if this.hasBlock}} |
25 | | - {{yield}} |
26 | | -{{/if}} |
| 26 | +```gjs |
| 27 | +<template> |
| 28 | + {{hasBlockParams}} |
| 29 | + {{#if hasBlockParams}} |
| 30 | +
|
| 31 | + {{/if}} |
| 32 | +</template> |
27 | 33 | ``` |
28 | 34 |
|
29 | | -Examples of **correct** code for this rule: |
| 35 | +This rule **allows** the following: |
30 | 36 |
|
31 | | -```hbs |
32 | | -{{#if (has-block)}} |
33 | | - {{yield}} |
34 | | -{{/if}} |
| 37 | +```gjs |
| 38 | +<template> |
| 39 | + {{has-block}} |
| 40 | + {{#if (has-block)}} |
| 41 | +
|
| 42 | + {{/if}} |
| 43 | +</template> |
35 | 44 | ``` |
36 | 45 |
|
37 | | -```hbs |
38 | | -{{#if (has-block 'inverse')}} |
39 | | - {{yield to='inverse'}} |
40 | | -{{/if}} |
| 46 | +```gjs |
| 47 | +<template> |
| 48 | + {{has-block-params}} |
| 49 | + {{#if (has-block-params)}} |
| 50 | +
|
| 51 | + {{/if}} |
| 52 | +</template> |
41 | 53 | ``` |
42 | 54 |
|
43 | 55 | ## Migration |
44 | 56 |
|
45 | | -- `{{hasBlock}}`-> `{{has-block}} |
46 | | -- `{{hasBlockParams}}`-> `{{has-block-params}} |
47 | | -- `{{#if hasBlock}} {{/if}}`-> `{{#if (has-block)}} {{/if}}` |
48 | | -- `{{#if (hasBlock "inverse")}} {{/if}}`-> `{{#if (has-block "inverse")}} {{/if}}` |
49 | | -- `{{#if hasBlockParams}} {{/if}}`-> `{{#if (has-block-params)}} {{/if}}` |
50 | | -- `{{#if (hasBlockParams "inverse")}} {{/if}}`-> `{{#if (has-block-params "inverse")}} {{/if}}` |
| 57 | +- `{{hasBlock}}` -> `{{has-block}}` |
| 58 | +- `{{hasBlockParams}}` -> `{{has-block-params}}` |
| 59 | +- `{{#if hasBlock}} {{/if}}` -> `{{#if (has-block)}} {{/if}}` |
| 60 | +- `{{#if (hasBlock "inverse")}} {{/if}}` -> `{{#if (has-block "inverse")}} {{/if}}` |
| 61 | +- `{{#if hasBlockParams}} {{/if}}` -> `{{#if (has-block-params)}} {{/if}}` |
| 62 | +- `{{#if (hasBlockParams "inverse")}} {{/if}}` -> `{{#if (has-block-params "inverse")}} {{/if}}` |
51 | 63 |
|
52 | 64 | ## References |
53 | 65 |
|
54 | | -- [eslint-plugin-ember template-require-has-block-helper](https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/template-require-has-block-helper.md) |
| 66 | +- [RFC](https://github.com/emberjs/rfcs/blob/master/text/0689-deprecate-has-block.md) |
| 67 | +- [Deprecation information](https://deprecations.emberjs.com/v3.x/#toc_has-block-and-has-block-params) |
0 commit comments