Extract rule: template-no-whitespace-within-word#2593
Extract rule: template-no-whitespace-within-word#2593NullVoxPopuli wants to merge 1 commit intoember-cli:masterfrom
Conversation
NullVoxPopuli-ai-agent
left a comment
There was a problem hiding this comment.
Review: template-no-whitespace-within-word
Compared against the original ember-template-lint rule no-whitespace-within-word.
What's done well
- The
WHITESPACE_ENTITY_LISTis identical to the original -- all 52 entries match exactly. - The regex construction logic is faithfully ported. The 5-alternation pattern
(whitespace)(char)(whitespace)(char)(whitespace)is preserved, including the comment explaining why 5 alternations avoids false positives. - Parent node filtering for
AttrNodeand<style>elements is correctly implemented, matching the original'sparents.some(...)checks. - All original test cases are ported -- both good and bad, including the HTML attribute ignore case (
enable-background="a b c d e f g h i j k l m"), the<style>element case, and the / entity cases. - Both gjs and hbs parser modes are tested.
- Error message matches exactly:
"Excess whitespace in layout detected."
Observations and potential issues
-
Parent traversal approach differs. The original uses
path.parents()(provided by the ember-template-lint traversal API) to walk up the tree. The new rule uses awhile (parent)loop onnode.parent. This is the correct ESLint equivalent and should work, assuming the Glimmer AST nodes haveparentreferences set (which they should in ember-eslint-parser). -
Uses
context.getSourceCode()(deprecated in ESLint 9+). Same note as PR #2592 -- consider usingconst sourceCode = context.sourceCode || context.getSourceCode();for forward compatibility. -
meta.typeis set to'layout'. Note that ESLint deprecated the'layout'type in ESLint 9 in favor of other types. This isn't an immediate issue but worth being aware of for future ESLint version compatibility. The original rule doesn't have an ESLint-stylemeta.typeso there's no direct comparison, but'suggestion'might be more future-proof. -
The regex is compiled at module level (as a constant
WHITESPACE_WITHIN_WORD_REGEX) rather than in the constructor as in the original. This is actually better -- it avoids recompiling the regex on every file. Good optimization. -
CHARACTER_REGEXonly matches ASCII letters[a-zA-Z]. This matches the original, but it means spaced-out Unicode words (e.g., accented characters) would not be caught. This is a pre-existing limitation, not introduced by this port.
Summary
Excellent port. The implementation is arguably slightly improved over the original (module-level regex compilation). All test cases are covered, error messages match, and the parent-node filtering logic is correctly adapted to the ESLint API.
Automated review comparing with ember-template-lint source
f7c847f to
2f764a1
Compare
Split from #2371.