Extract rule: template-require-splattributes#2612
Conversation
NullVoxPopuli-ai-agent
left a comment
There was a problem hiding this comment.
Review: template-require-splattributes (PR #2612)
Comparison with ember-template-lint source
General correctness:
-
Missing case for non-element-only templates: The original ETL rule reports on ALL templates that lack splattributes — including templates with no element nodes at all (e.g.,
{{yield}}). It has two branches: single root element → report on element, otherwise → report on template node. The ESLint version adds an extra gate:elementNodes.length > 1for the multi-element path, but ifelementNodes.length === 0(template has only text/mustache nodes), no error is reported. The original ETL would still report"At least one element in this template should use ...attributes". This is a behavioral gap — templates like<template>{{yield}}</template>or<template>Hello world</template>would not be flagged in the ESLint version but would be flagged by the original. -
Single element with significant text nodes: The ESLint version has a special check
hasOnlyOneElementthat requiressignificantTextNodes.length === 0. So<template>Hello <div></div></template>would NOT get the "root element" message and would also NOT get the "at least one element" message (sinceelementNodes.lengthis 1, not > 1). The original ETL treats this aselementNodes.length === 1 && nonEmptyTextNodes.length === 0failing, so it falls through to the else branch and reports on the template node. Bug: The ESLint version silently passes for templates with one element + text content. -
messagesis empty object: The rule uses inlinemessagestrings incontext.report()rather thanmessageId. This works but is inconsistent with best practices. Consider usingmessageIdwith themessagesobject. -
Deep traversal for splattributes: The ESLint version does a manual recursive
checkNodetraversal. The original ETL usesAttrNodevisitor which fires for all attribute nodes in the tree. Both achieve the same result — checking all descendants.
Scope analysis (gjs/gts):
Not applicable. This rule checks for ...attributes spread syntax and element structure — no helper/component name matching.
Tests: Missing test cases for templates with no elements (only mustache/text), which is where the behavioral gap exists. Consider adding <template>{{yield}}</template> as an invalid case to match ETL behavior.
🤖 Automated review comparing with ember-template-lint source
67e2360 to
63695f3
Compare
Split from #2371.