From 33b67a4ab10606813f51c81ef73a60004dc6da75 Mon Sep 17 00:00:00 2001
From: fnx <966276+DMartens@users.noreply.github.com>
Date: Mon, 19 Feb 2024 00:52:56 +0100
Subject: [PATCH] fix(no-useless-mustaches): escape < in fixes (#2389)
---
lib/rules/no-useless-mustaches.js | 3 +-
tests/lib/rules/no-useless-mustaches.js | 48 +++++++++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/lib/rules/no-useless-mustaches.js b/lib/rules/no-useless-mustaches.js
index f4f858d9e..f4db1a008 100644
--- a/lib/rules/no-useless-mustaches.js
+++ b/lib/rules/no-useless-mustaches.js
@@ -142,8 +142,9 @@ module.exports = {
// It doesn't autofix because another rule like indent or eol space might remove spaces.
return null
}
+ const escaped = text.replace(/
+ {{ '<' }}
+ {{ '>' }}
+ {{ '&' }}
+ {{ '—' }}
+
+ `,
+ output: `
+
+ <
+ >
+ &
+ —
+
+ `,
+ errors: [
+ 'Unexpected mustache interpolation with a string literal value.',
+ 'Unexpected mustache interpolation with a string literal value.',
+ 'Unexpected mustache interpolation with a string literal value.',
+ 'Unexpected mustache interpolation with a string literal value.'
+ ]
+ },
+ {
+ code: `
+
+ {{ '<' }}
+ {{ '<<' }}
+ {{ 'can be < anywhere' }}
+ {{ '' }}
+
+ `,
+ output: `
+
+ <
+ <<
+ can be < anywhere
+ <tag>
+
+ `,
+ errors: [
+ 'Unexpected mustache interpolation with a string literal value.',
+ 'Unexpected mustache interpolation with a string literal value.',
+ 'Unexpected mustache interpolation with a string literal value.',
+ 'Unexpected mustache interpolation with a string literal value.'
+ ]
+ },
{
code: `