Skip to content

Commit bcd00c7

Browse files
NullVoxPopuliclaude
andcommitted
Fix ESLint autofix: clean stale node props, add template tag tokens
Two fixes for ESLint autofix compatibility: 1. When replacing JS nodes (TemplateLiteral/StaticBlock) with GlimmerTemplate via Object.assign, delete leftover properties (quasis, expressions, etc.) that confuse ESLint rules. 2. Add tokens for <template> and </template> tags to the token stream so ESLint's SourceCode has full token coverage over the template range. Without these, autofixes like arrow-body-style produced mangled output. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent f27fc6e commit bcd00c7

2 files changed

Lines changed: 64 additions & 221 deletions

File tree

src/parser/transforms.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,29 @@ export function preprocessGlimmerTemplates(info, code) {
198198
end: codeLines.offsetToPosition(tpl.utf16Range[1]),
199199
};
200200

201+
// Add tokens for the <template> and </template> tags so ESLint's
202+
// SourceCode has proper token coverage for the full range.
203+
const openEnd = tpl.contentRange[0];
204+
const closeStart = tpl.contentRange[1];
205+
const openTag = code.slice(tpl.utf16Range[0], openEnd);
206+
const closeTag = code.slice(closeStart, tpl.utf16Range[1]);
207+
const makeToken = (value, range) => ({
208+
type: 'Punctuator',
209+
value,
210+
range,
211+
start: range[0],
212+
end: range[1],
213+
loc: {
214+
start: codeLines.offsetToPosition(range[0]),
215+
end: codeLines.offsetToPosition(range[1]),
216+
},
217+
});
218+
ast.tokens = [
219+
makeToken(openTag, [tpl.utf16Range[0], openEnd]),
220+
...(ast.tokens || []),
221+
makeToken(closeTag, [closeStart, tpl.utf16Range[1]]),
222+
];
223+
201224
ast.content = code.slice(...tpl.utf16Range);
202225
allComments.push(...comments);
203226
tpl.ast = ast;
@@ -261,6 +284,13 @@ export function convertAst(result, preprocessedResult, visitorKeys) {
261284
}
262285
counter++;
263286
const ast = template.ast;
287+
// Remove properties from the original node type (TemplateLiteral, StaticBlock, etc.)
288+
// that would confuse ESLint rules after we overwrite with the GlimmerTemplate AST.
289+
for (const key of Object.keys(node)) {
290+
if (!(key in ast) && key !== 'parent') {
291+
delete node[key];
292+
}
293+
}
264294
Object.assign(node, ast);
265295
}
266296

0 commit comments

Comments
 (0)