Skip to content

Commit a98bbca

Browse files
Merge pull request #2681 from johanrd/false_positive/template-no-whitespace-for-layout
Post-merge-review: Fix template-no-whitespace-for-layout false positive on attribute values
2 parents 8f3920b + 5f82118 commit a98bbca

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

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

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

2828
return {
2929
GlimmerTextNode(node) {
30+
// Only flag body text, not attribute values. ember-eslint-parser
31+
// emits attribute values as GlimmerTextNode children of a
32+
// GlimmerAttrNode; skip those so only element body whitespace is
33+
// checked.
34+
if (node.parent?.type === 'GlimmerAttrNode') {
35+
return;
36+
}
37+
3038
const text = sourceCode.getText(node);
3139
if (!text) {
3240
return;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const validHbs = [
1818
>
1919
example
2020
</div>`,
21+
// Attribute values with consecutive spaces must not be flagged (false positive,
22+
// cf. ember-template-lint#2899) — the rule targets element body text only.
23+
'<div class="foo bar"></div>',
24+
'<div style="margin: 0; padding: 0"></div>',
2125
];
2226

2327
const invalidHbs = [

0 commit comments

Comments
 (0)