Skip to content

Commit 9018b60

Browse files
committed
Fix template-no-whitespace-for-layout false positive on attribute values
The rule's GlimmerTextNode visitor fired on attribute value text nodes (e.g. `<div class="foo bar">`), reporting layout-whitespace violations for consecutive spaces inside class lists and other attribute values. Upstream ember-template-lint only visits body text, since its HBS parser exposes attribute values differently. Skip GlimmerTextNodes whose parent is a GlimmerAttrNode.
1 parent b705850 commit 9018b60

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/rules/template-no-whitespace-for-layout.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ module.exports = {
2727

2828
return {
2929
GlimmerTextNode(node) {
30+
// Ember's Glimmer parser emits attribute values (e.g. `class="foo bar"`)
31+
// as GlimmerTextNode children of a GlimmerAttrNode. Whitespace there is
32+
// part of the attribute value, not layout whitespace between words.
33+
if (node.parent?.type === 'GlimmerAttrNode') {
34+
return;
35+
}
36+
3037
const text = sourceCode.getText(node);
3138
if (!text) {
3239
return;

tests/lib/rules/template-no-whitespace-for-layout.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const validHbs = [
1818
>
1919
example
2020
</div>`,
21+
// Whitespace inside attribute values (e.g. Tailwind class lists) is not layout whitespace.
22+
'<div class="foo bar"></div>',
23+
'<div class="min-h-dvh bg-gray-200 "></div>',
2124
];
2225

2326
const invalidHbs = [

0 commit comments

Comments
 (0)