Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion lib/rules/template-no-action-modifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ module.exports = {
node.path.head?.type !== 'ThisHead'
) {
// Only offer autofix when the first param is a path expression
// and there are no hash pairs (e.g. on="submit") which would be left behind
const maybePath = node.params?.[0];
const canFix = maybePath && maybePath.type === 'GlimmerPathExpression';
const hasHashPairs = node.hash?.pairs?.length > 0;
const canFix = maybePath && maybePath.type === 'GlimmerPathExpression' && !hasHashPairs;

context.report({
node,
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/template-no-action-modifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,17 @@ ruleTester.run('template-no-action-modifiers', rule, {
'<template><button {{on "click" (fn this.handleClick "arg1" "arg2")}}>Save</button></template>',
errors: [{ messageId: 'noActionModifier' }],
},
{
// 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

output: null,
errors: [{ messageId: 'noActionModifier' }],
},
{
// Path expression with hash pair (on="submit") — no autofix
code: '<template><form {{action this.handleSubmit on="submit"}}>Submit</form></template>',
output: null,
errors: [{ messageId: 'noActionModifier' }],
},
],
});
Loading