Skip to content

Post-merge-review: Fix template-no-action-modifiers autofix: skip when hash pairs are present#2654

Merged
NullVoxPopuli merged 3 commits intoember-cli:masterfrom
johanrd:night_fix/template-no-action-modifiers
Apr 14, 2026
Merged

Post-merge-review: Fix template-no-action-modifiers autofix: skip when hash pairs are present#2654
NullVoxPopuli merged 3 commits intoember-cli:masterfrom
johanrd:night_fix/template-no-action-modifiers

Conversation

@johanrd
Copy link
Copy Markdown
Contributor

@johanrd johanrd commented Apr 13, 2026

What's broken on master

The autofix uses fixer.replaceTextRange([node.path.range[0], lastParam.range[1]], ...) which only replaces text from action through the last positional param. Hash pairs (on="click", preventDefault=false, etc.) appear after the last positional param and are left in place, producing broken output:

{{action this.handleClick on="click"}}{{on "click" this.handleClick on="click"}}

Fix

Disable autofix when any hash pair is present on the {{action}} modifier. Detection still reports the error.

Why not a smarter autofix

Upstream's fix uses ember-template-recast AST mutation (no-action-modifiers.js L55–61) and doesn't translate on= hash into {{on "eventName"}} either — so it would inherit the same issue. A smarter fix (converting on="submit" into the first arg to {{on}}) is possible but out of scope for a regression fix.

Test plan

  • 16/16 tests pass on the branch
  • 2 new invalid test cases ({{action this.handleClick on="click"}}, {{action this.handleSubmit on="submit"}}) fail on master with the exact broken output shown above

Co-written by Claude.

The autofix replaced only the path and positional params, leaving hash
pairs like on="click" behind. This produced broken output such as
{{on "click" this.handleClick on="click"}}. Suppress autofix whenever
hash pairs exist to avoid emitting invalid code.
@johanrd johanrd marked this pull request as ready for review April 13, 2026 10:27
},
{
// Path expression with hash pair (on="click") — no autofix to avoid leaving behind stale hash
code: '<template><button {{action this.handleClick on="click"}}>Save</button></template>',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we know what to do here tho, we can autofix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, thanks, tried a fix now

johanrd added 2 commits April 13, 2026 20:25
When the modifier has a path-expression handler and the only hash pair is
`on="<string>"`, we now read the event name from that pair and produce
`{{on "<event>" handler}}`, dropping the hash pair in the output.

Non-`on` hash pairs still suppress the fix since they have no clean
mapping to the `on` modifier's argument list.
@NullVoxPopuli NullVoxPopuli merged commit 1bec1a2 into ember-cli:master Apr 14, 2026
10 of 11 checks passed
@johanrd johanrd deleted the night_fix/template-no-action-modifiers branch April 14, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants