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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ npm-debug.log

# eslint-remote-tester
eslint-remote-tester-results
package-lock.json
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ rules in templates can be disabled with eslint directives with mustache or html

### Best Practices

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

### Components

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

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

Disallow the use of `@args` in template paths. Instead of accessing arguments through `@args.foo`, use `@foo` directly.

## Rule Details

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.

## Examples

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

```gjs
<template>
{{@args.foo}}
</template>
```

```gts
<template>
<div>{{@args.name}}</div>
</template>
```

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

```gjs
<template>
{{@foo}}
</template>
```

```gts
<template>
<div>{{@name}}</div>
</template>
```

## References

- [ember-template-lint no-args-paths](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-args-paths.md)
22 changes: 22 additions & 0 deletions lib/rules/template-no-args-paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow @args in paths',
category: 'Best Practices',
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-args-paths.md',
},
schema: [],
messages: { argsPath: 'Do not use paths with @args, use @argName directly instead.' },
},
create(context) {
return {
GlimmerPathExpression(node) {
if (node.original?.startsWith('@args.')) {
context.report({ node, messageId: 'argsPath' });
}
},
};
},
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
},
"dependencies": {
"@ember-data/rfc395-data": "^0.0.4",
"@glimmer/env": "^0.1.7",
"css-tree": "^3.0.1",
"ember-eslint-parser": "^0.5.9",
"ember-rfc176-data": "^0.3.18",
Expand Down
17 changes: 17 additions & 0 deletions tests/lib/rules/template-no-args-paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const rule = require('../../../lib/rules/template-no-args-paths');
const RuleTester = require('eslint').RuleTester;

const ruleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser'),
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
});
ruleTester.run('template-no-args-paths', rule, {
valid: ['<template>{{@foo}}</template>'],
invalid: [
{
code: '<template>{{@args.foo}}</template>',
output: null,
errors: [{ messageId: 'argsPath' }],
},
],
});