Skip to content

Commit 8f4b7b4

Browse files
committed
Sync with ember-template-lint
1 parent c23fa18 commit 8f4b7b4

3 files changed

Lines changed: 17 additions & 18 deletions

File tree

docs/rules/template-no-this-in-template-only-components.md

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,20 @@
44

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

7-
There is no `this` context in template-tag (`<template>`) components that don't extend a class.
8-
9-
## Rule Details
10-
11-
In gjs/gts files with `<template>` tags, this rule flags all `this.*` path expressions and suggests converting them to named arguments (`@*`). The auto-fix replaces `this.foo` with `@foo` (except for built-in component properties like `elementId`, `tagName`, `ariaRole`, `class`, `classNames`, `classNameBindings`, `attributeBindings`, and `isVisible`, which are reported but not auto-fixed).
7+
There is no `this` context in template-only components.
128

139
## Examples
1410

15-
This rule **forbids** the following:
16-
17-
```gjs
18-
<template><h1>Hello {{this.name}}!</h1></template>
19-
```
20-
21-
This rule **allows** the following:
11+
This rule **forbids** `this` in template-only components:
2212

23-
```gjs
24-
<template><h1>Hello {{@name}}!</h1></template>
13+
```hbs
14+
<h1>Hello {{this.name}}!</h1>
2515
```
2616

2717
The `--fix` option will convert to named arguments:
2818

29-
```gjs
30-
<template><h1>Hello {{@name}}!</h1></template>
19+
```hbs
20+
<h1>Hello {{@name}}!</h1>
3121
```
3222

3323
## Migration

lib/rules/template-no-this-in-template-only-components.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ module.exports = {
4949
? sourceCode.getAncestors(node)
5050
: context.getAncestors();
5151
const isInsideClass = ancestors.some(
52-
(ancestor) =>
53-
ancestor.type === 'ClassBody' || ancestor.type === 'ClassDeclaration'
52+
(ancestor) => ancestor.type === 'ClassBody' || ancestor.type === 'ClassDeclaration'
5453
);
5554
if (isInsideClass) {
5655
return;

tests/lib/rules/template-no-this-in-template-only-components.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ hbsRuleTester.run('template-no-this-in-template-only-components', rule, {
6262
'{{my-component model=model}}',
6363
],
6464
invalid: [
65+
{
66+
code: '{{my-component model=this.model}}',
67+
output: '{{my-component model=@model}}',
68+
errors: [
69+
{
70+
message:
71+
"Usage of 'this' in path 'this.model' is not allowed in a template-only component. Use '@model' if it is a named argument.",
72+
},
73+
],
74+
},
6575
{
6676
code: '{{my-component action=(action this.myAction)}}',
6777
output: '{{my-component action=(action @myAction)}}',

0 commit comments

Comments
 (0)