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
6 changes: 2 additions & 4 deletions docs/rules/template-no-extra-mut-helper-argument.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

馃捈 This rule is enabled in the 馃搵 `template-lint-migration` [config](https://github.com/ember-cli/eslint-plugin-ember#-configurations).

> **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.

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

Disallows passing more than one argument to the `mut` helper.
Expand All @@ -15,13 +13,13 @@ A common mistake when using the Ember handlebars template `mut(attr)` helper is
This rule **forbids** the following:

```hbs
{{my-component click=(action (mut isClicked true))}}
{{my-component click=(fn (mut isClicked true))}}
```

This rule **allows** the following:

```hbs
{{my-component click=(action (mut isClicked) true)}}
{{my-component click=(fn (mut isClicked) true)}}
```

## Related Rules
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/template-no-extra-mut-helper-argument.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
category: 'Possible Errors',
recommended: false,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-extra-mut-helper-argument.md',
templateMode: 'loose',
templateMode: 'both',
},
fixable: null,
schema: [],
Expand All @@ -22,7 +22,7 @@ module.exports = {

create(context) {
const ERROR_MESSAGE =
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(action (mut attr) value)`.';
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(fn (mut attr) value)`.';

return {
GlimmerSubExpression(node) {
Expand Down
48 changes: 30 additions & 18 deletions tests/lib/rules/template-no-extra-mut-helper-argument.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ const ruleTester = new RuleTester({

ruleTester.run('template-no-extra-mut-helper-argument', rule, {
valid: [
'<template>{{my-component click=(action (mut isClicked))}}</template>',
'<template>{{my-component click=(action (mut isClicked) true)}}</template>',
'<template>{{my-component click=(fn (mut isClicked))}}</template>',
'<template>{{my-component click=(fn (mut isClicked) true)}}</template>',
'<template>{{my-component isClickedMutable=(mut isClicked)}}</template>',
'<template><button {{action (mut isClicked)}}></button></template>',
'<template><button {{action (mut isClicked) true}}></button></template>',
'<template><button {{on "click" (fn (mut isClicked))}}></button></template>',
'<template><button {{on "click" (fn (mut isClicked) true)}}></button></template>',
],
invalid: [
{
code: '<template>{{my-component click=(action (mut isClicked true))}}</template>',
code: '<template>{{my-component click=(fn (mut isClicked true))}}</template>',
output: null,
errors: [
{
message:
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(action (mut attr) value)`.',
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(fn (mut attr) value)`.',
},
],
},
Expand All @@ -31,17 +31,29 @@ ruleTester.run('template-no-extra-mut-helper-argument', rule, {
errors: [
{
message:
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(action (mut attr) value)`.',
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(fn (mut attr) value)`.',
},
],
},
{
code: '<template><button {{action (mut isClicked true)}}></button></template>',
code: '<template><button {{on "click" (fn (mut isClicked true))}}></button></template>',
output: null,
errors: [
{
message:
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(action (mut attr) value)`.',
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(fn (mut attr) value)`.',
},
],
},
// `mut` is an ambient strict-mode keyword, so this reports in gjs/gts as well
{
filename: 'test.gjs',
code: '<template>{{yield (mut @a @b)}}</template>',
output: null,
errors: [
{
message:
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(fn (mut attr) value)`.',
},
],
},
Expand All @@ -58,20 +70,20 @@ const hbsRuleTester = new RuleTester({

hbsRuleTester.run('template-no-extra-mut-helper-argument', rule, {
valid: [
'{{my-component click=(action (mut isClicked))}}',
'{{my-component click=(action (mut isClicked) true)}}',
'{{my-component click=(fn (mut isClicked))}}',
'{{my-component click=(fn (mut isClicked) true)}}',
'{{my-component isClickedMutable=(mut isClicked)}}',
'<button {{action (mut isClicked)}}></button>',
'<button {{action (mut isClicked) true}}></button>',
'<button {{on "click" (fn (mut isClicked))}}></button>',
'<button {{on "click" (fn (mut isClicked) true)}}></button>',
],
invalid: [
{
code: '{{my-component click=(action (mut isClicked true))}}',
code: '{{my-component click=(fn (mut isClicked true))}}',
output: null,
errors: [
{
message:
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(action (mut attr) value)`.',
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(fn (mut attr) value)`.',
},
],
},
Expand All @@ -81,17 +93,17 @@ hbsRuleTester.run('template-no-extra-mut-helper-argument', rule, {
errors: [
{
message:
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(action (mut attr) value)`.',
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(fn (mut attr) value)`.',
},
],
},
{
code: '<button {{action (mut isClicked true)}}></button>',
code: '<button {{on "click" (fn (mut isClicked true))}}></button>',
output: null,
errors: [
{
message:
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(action (mut attr) value)`.',
'The handlebars `mut(attr)` helper should only have one argument passed to it. To pass a value, use: `(fn (mut attr) value)`.',
},
],
},
Expand Down
Loading