Skip to content

Commit f812d80

Browse files
Merge pull request #2656 from johanrd/night_fix/template-no-chained-this
Post-merge-review: Fix `template-no-chained-this` autofix: also update the closing tag
2 parents 9aebe30 + ee41f06 commit f812d80

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

lib/rules/template-no-chained-this.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,20 @@ module.exports = {
5757
node,
5858
messageId: 'noChainedThis',
5959
fix(fixer) {
60+
const fixes = [];
61+
6062
// Replace the tag name after '<'
6163
const openStart = node.range[0] + 1;
62-
return fixer.replaceTextRange([openStart, openStart + node.tag.length], fixedTag);
64+
fixes.push(fixer.replaceTextRange([openStart, openStart + node.tag.length], fixedTag));
65+
66+
// For non-self-closing elements, also fix the closing tag </tag>
67+
if (!node.selfClosing) {
68+
const closingEnd = node.range[1] - 1; // before '>'
69+
const closingStart = closingEnd - node.tag.length; // start of tag name in </tag>
70+
fixes.push(fixer.replaceTextRange([closingStart, closingEnd], fixedTag));
71+
}
72+
73+
return fixes;
6374
},
6475
});
6576
},

tests/lib/rules/template-no-chained-this.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,10 @@ ruleTester.run('template-no-chained-this', rule, {
4747
output: '<template>{{component this.dynamicComponent}}</template>',
4848
errors: [{ messageId: 'noChainedThis' }],
4949
},
50+
{
51+
code: '<template><this.this.Component>content</this.this.Component></template>',
52+
output: '<template><this.Component>content</this.Component></template>',
53+
errors: [{ messageId: 'noChainedThis' }],
54+
},
5055
],
5156
});

0 commit comments

Comments
 (0)