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
2 changes: 0 additions & 2 deletions docs/rules/template-no-mut-helper.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# ember/template-no-mut-helper

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

Disallow usage of the `(mut)` helper.
Expand Down
10 changes: 8 additions & 2 deletions lib/rules/template-no-mut-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
description: 'disallow usage of (mut) helper',
category: 'Best Practices',
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-mut-helper.md',
templateMode: 'loose',
templateMode: 'both',
},
fixable: null,
schema: [
Expand All @@ -31,7 +31,13 @@ module.exports = {

create(context) {
const options = context.options[0] || {};
const setterAlternative = options.setterAlternative;
const rawSetterAlternative = options.setterAlternative;
// If the user already wrapped their expression in `{{...}}`, strip it so we
// don't end up with `{{{{...}}}}` in the error message.
const setterAlternative =
typeof rawSetterAlternative === 'string'
? rawSetterAlternative.replace(/^{{([\S\s]*)}}$/, '$1').trim()
: rawSetterAlternative;
const message = setterAlternative
? `Do not use the (mut) helper. Consider using a JS action or {{${setterAlternative}}} instead.`
: 'Do not use the (mut) helper. Use regular setters or actions instead.';
Expand Down
37 changes: 37 additions & 0 deletions tests/lib/rules/template-no-mut-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,43 @@ ruleTester.run('template-no-mut-helper', rule, {
output: null,
errors: [{ message: 'Do not use the (mut) helper. Use regular setters or actions instead.' }],
},
// `mut` is a strict-mode ambient keyword — no import needed in .gjs strict
// mode templates.
{
code: '<template>{{mut foo bar}}</template>',
output: null,
errors: [
{
message: 'Do not use the (mut) helper. Use regular setters or actions instead.',
type: 'GlimmerMustacheStatement',
},
],
},
// Config: setterAlternative should produce exactly one `{{...}}` wrapping
// around the user-supplied expression — even when the user accidentally
// included the braces themselves.
{
code: '<template><MyComponent onchange={{action (mut this.val) value="target.value"}}/></template>',
output: null,
options: [{ setterAlternative: '(set this.foo)' }],
errors: [
{
message:
'Do not use the (mut) helper. Consider using a JS action or {{(set this.foo)}} instead.',
},
],
},
{
code: '<template><MyComponent onchange={{action (mut this.val) value="target.value"}}/></template>',
output: null,
options: [{ setterAlternative: '{{(set this.foo)}}' }],
errors: [
{
message:
'Do not use the (mut) helper. Consider using a JS action or {{(set this.foo)}} instead.',
},
],
},
],
});

Expand Down
Loading