Skip to content

Commit a603614

Browse files
committed
fix(no-useless-mustaches): escape < in fixes
1 parent 32da3e4 commit a603614

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

lib/rules/no-useless-mustaches.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ module.exports = {
143143
// It doesn't autofix because another rule like indent or eol space might remove spaces.
144144
return null
145145
}
146+
const escaped = text.replace(/\</g, '&lt;');
146147

147-
return fixer.replaceText(node, text.replace(/\\([\S\s])/g, '$1'))
148+
return fixer.replaceText(node, escaped.replace(/\\([\S\s])/g, '$1'))
148149
}
149150
})
150151
}

tests/lib/rules/no-useless-mustaches.js

+48
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,54 @@ tester.run('no-useless-mustaches', rule, {
194194
'Unexpected mustache interpolation with a string literal value.'
195195
]
196196
},
197+
{
198+
code: `
199+
<template>
200+
{{ '&lt;' }}
201+
{{ '&gt;' }}
202+
{{ '&amp;' }}
203+
{{ '&#8212;' }}
204+
</template>
205+
`,
206+
output: `
207+
<template>
208+
&lt;
209+
&gt;
210+
&amp;
211+
&#8212;
212+
</template>
213+
`,
214+
errors: [
215+
'Unexpected mustache interpolation with a string literal value.',
216+
'Unexpected mustache interpolation with a string literal value.',
217+
'Unexpected mustache interpolation with a string literal value.',
218+
'Unexpected mustache interpolation with a string literal value.',
219+
]
220+
},
221+
{
222+
code: `
223+
<template>
224+
{{ '<' }}
225+
{{ '<<' }}
226+
{{ 'can be < anywhere' }}
227+
{{ '<tag>' }}
228+
</template>
229+
`,
230+
output: `
231+
<template>
232+
&lt;
233+
&lt;&lt;
234+
can be &lt; anywhere
235+
&lt;tag>
236+
</template>
237+
`,
238+
errors: [
239+
'Unexpected mustache interpolation with a string literal value.',
240+
'Unexpected mustache interpolation with a string literal value.',
241+
'Unexpected mustache interpolation with a string literal value.',
242+
'Unexpected mustache interpolation with a string literal value.',
243+
]
244+
},
197245
{
198246
code: `
199247
<template>

0 commit comments

Comments
 (0)