Skip to content
Merged
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
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,16 @@ 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-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-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-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-capital-arguments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# ember/template-no-capital-arguments

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

Disallow capital letters in argument names. Use lowercase argument names (e.g., `@arg` instead of `@Arg`).

## Rule Details

This rule enforces the convention that argument names should start with lowercase letters.

## Examples

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

```gjs
<template>
<div>{{@Arg}}</div>
</template>
```

```gjs
<template>
<div>{{@MyArgument}}</div>
</template>
```

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

```gjs
<template>
<div>{{@arg}}</div>
</template>
```

```gjs
<template>
<div>{{@myArgument}}</div>
</template>
```

## References

- [Ember Style Guide](https://github.com/ember-cli/ember-styleguide)
47 changes: 47 additions & 0 deletions lib/rules/template-no-capital-arguments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'disallow capital arguments (use lowercase @arg instead of @Arg)',
category: 'Best Practices',
recommended: false,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-capital-arguments.md',
},
fixable: null,
schema: [],
messages: {
noCapitalArguments:
'Argument names should start with lowercase. Use @{{lowercase}} instead of @{{name}}.',
},
strictGjs: true,
strictGts: true,
},

create(context) {
function checkPath(node, path) {
if (!path || !path.head) {
return;
}

const name = path.head.name || path.head;
if (typeof name === 'string' && name.startsWith('@') && /^@[A-Z]/.test(name)) {
const lowercase = name.charAt(0) + name.charAt(1).toLowerCase() + name.slice(2);
context.report({
node,
messageId: 'noCapitalArguments',
data: {
name,
lowercase,
},
});
}
}

return {
GlimmerPathExpression(node) {
checkPath(node, node);
},
};
},
};
73 changes: 73 additions & 0 deletions tests/lib/rules/template-no-capital-arguments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const { RuleTester } = require('eslint');
const rule = require('../../../lib/rules/template-no-capital-arguments');

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

ruleTester.run('template-no-capital-arguments', rule, {
valid: [
{
filename: 'my-component.gjs',
code: `
import Component from '@glimmer/component';
export default class MyComponent extends Component {
<template>
<div>{{@arg}}</div>
</template>
}
`,
output: null,
},
{
filename: 'my-component.gjs',
code: `
import Component from '@glimmer/component';
export default class MyComponent extends Component {
<template>
<div>{{@myArgument}}</div>
</template>
}
`,
output: null,
},
],

invalid: [
{
filename: 'my-component.gjs',
code: `
import Component from '@glimmer/component';
export default class MyComponent extends Component {
<template>
<div>{{@Arg}}</div>
</template>
}
`,
output: null,
errors: [
{
messageId: 'noCapitalArguments',
},
],
},
{
filename: 'my-component.gjs',
code: `
import Component from '@glimmer/component';
export default class MyComponent extends Component {
<template>
<div>{{@MyArgument}}</div>
</template>
}
`,
output: null,
errors: [
{
messageId: 'noCapitalArguments',
},
],
},
],
});
Loading