Extract rule: template-no-yield-only#2596
Conversation
NullVoxPopuli-ai-agent
left a comment
There was a problem hiding this comment.
Review: template-no-yield-only (PR #2596)
Comparison with ember-template-lint no-yield-only.js
General correctness:
-
Logic difference in what counts as "empty": The original's
isEmptyNodeconsidersMustacheCommentStatement,CommentStatement, and whitespace-onlyTextNodeas empty. The PR'sIGNORABLE_TYPESset only includesGlimmerTextNodeandGlimmerMustacheCommentStatement, but theisMeaningfulContentfunction also handlesGlimmerTextNodespecially (checking if trimmed content is non-empty). Missing:GlimmerCommentStatement(HTML comments like<!-- ... -->) is not inIGNORABLE_TYPES, so an HTML comment + yield would NOT trigger the rule, whereas in the original it would. Consider adding'GlimmerCommentStatement'toIGNORABLE_TYPES. -
isYieldOnlyvsisBareYield: The original checksnode.params.length === 0but does not checknode.hash. The PR additionally checks!node.hash || !node.hash.pairs || node.hash.pairs.length === 0. This is actually stricter —{{yield to="inverse"}}has zero params but has hash pairs, and the original would consider it a "yield only" while the PR would not. Looking at the test cases,{{yield (hash someProp=someValue)}}is valid in both, which has params. The PR's extra hash check seems correct/desirable since{{yield to="inverse"}}is not really a "bare yield".Wait — actually re-reading the original: it checks
node.params.length === 0which would be true for{{yield to="inverse"}}(hash pairs are not params). So the original would flag{{yield to="inverse"}}as yield-only, which seems like a bug in the original. The PR's stricter check that also requires no hash pairs is actually an improvement. -
GlimmerTemplate visitor: The PR handles both gjs (where
body[0]is aGlimmerElementNodefor<template>) and hbs (wherebodydirectly contains nodes). This is a reasonable approach though the heuristic of checkingfirstChild.type === 'GlimmerElementNode'could theoretically be fragile if the parser representation changes. Consider adding a comment explaining this distinction.
Scope analysis (gjs/gts):
The rule checks node.path.original === 'yield'. yield is a Glimmer keyword and cannot be shadowed. No scope analysis needed.
Overall: Good migration with one minor gap — consider adding GlimmerCommentStatement to IGNORABLE_TYPES to match the original's treatment of HTML comments as empty content.
🤖 Automated review comparing with ember-template-lint source
805a524 to
6bc2977
Compare
Split from #2371.