Skip to content

Commit 3c969e5

Browse files
Port template-no-args-paths rule from PR #2371
Co-authored-by: NullVoxPopuli <[email protected]>
1 parent d2fecbd commit 3c969e5

6 files changed

Lines changed: 14133 additions & 4 deletions

File tree

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,11 @@ rules in templates can be disabled with eslint directives with mustache or html
176176

177177
### Best Practices
178178

179-
| Name | Description | 💼 | 🔧 | 💡 |
180-
| :--------------------------------------------------------- | :--------------------------------- | :- | :- | :- |
181-
| [template-no-debugger](docs/rules/template-no-debugger.md) | disallow {{debugger}} in templates | | | |
182-
| [template-no-log](docs/rules/template-no-log.md) | disallow {{log}} in templates | | | |
179+
| Name | Description | 💼 | 🔧 | 💡 |
180+
| :----------------------------------------------------------- | :--------------------------------- | :- | :- | :- |
181+
| [template-no-args-paths](docs/rules/template-no-args-paths.md) | disallow @args in paths | | | |
182+
| [template-no-debugger](docs/rules/template-no-debugger.md) | disallow {{debugger}} in templates | | | |
183+
| [template-no-log](docs/rules/template-no-log.md) | disallow {{log}} in templates | | | |
183184

184185
### Components
185186

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# ember/template-no-args-paths
2+
3+
<!-- end auto-generated rule header -->
4+
5+
Disallow the use of `@args` in template paths. Instead of accessing arguments through `@args.foo`, use `@foo` directly.
6+
7+
## Rule Details
8+
9+
This rule prevents the use of `@args.` prefix in template paths. In Ember templates, arguments should be accessed directly using `@argName` syntax rather than through the `@args` object.
10+
11+
## Examples
12+
13+
Examples of **incorrect** code for this rule:
14+
15+
```gjs
16+
<template>
17+
{{@args.foo}}
18+
</template>
19+
```
20+
21+
```gts
22+
<template>
23+
<div>{{@args.name}}</div>
24+
</template>
25+
```
26+
27+
Examples of **correct** code for this rule:
28+
29+
```gjs
30+
<template>
31+
{{@foo}}
32+
</template>
33+
```
34+
35+
```gts
36+
<template>
37+
<div>{{@name}}</div>
38+
</template>
39+
```
40+
41+
## References
42+
43+
- [ember-template-lint no-args-paths](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-args-paths.md)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/** @type {import('eslint').Rule.RuleModule} */
2+
module.exports = {
3+
meta: {
4+
type: 'problem',
5+
docs: {
6+
description: 'disallow @args in paths',
7+
category: 'Best Practices',
8+
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-args-paths.md',
9+
},
10+
schema: [],
11+
messages: { argsPath: 'Do not use paths with @args, use @argName directly instead.' },
12+
},
13+
create(context) {
14+
return {
15+
GlimmerPathExpression(node) {
16+
if (node.original?.startsWith('@args.')) {
17+
context.report({ node, messageId: 'argsPath' });
18+
}
19+
},
20+
};
21+
},
22+
};

0 commit comments

Comments
 (0)