Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(no-useless-mustaches): escape < in fixes #2389

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rules/no-useless-mustaches.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@
// It doesn't autofix because another rule like indent or eol space might remove spaces.
return null
}
const escaped = text.replace(/\</g, '&lt;');

Check failure on line 145 in lib/rules/no-useless-mustaches.js

View workflow job for this annotation

GitHub Actions / Lint

/\</g can be optimized to /</g

Check failure on line 145 in lib/rules/no-useless-mustaches.js

View workflow job for this annotation

GitHub Actions / Lint

Delete `;`

return fixer.replaceText(node, text.replace(/\\([\S\s])/g, '$1'))
return fixer.replaceText(node, escaped.replace(/\\([\S\s])/g, '$1'))
}
})
}
Expand Down
48 changes: 48 additions & 0 deletions tests/lib/rules/no-useless-mustaches.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,54 @@
'Unexpected mustache interpolation with a string literal value.'
]
},
{
code: `
<template>
{{ '&lt;' }}
{{ '&gt;' }}
{{ '&amp;' }}
{{ '&#8212;' }}
</template>
`,
output: `
<template>
&lt;
&gt;
&amp;
&#8212;
</template>
`,
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.',

Check failure on line 210 in tests/lib/rules/no-useless-mustaches.js

View workflow job for this annotation

GitHub Actions / Lint

Delete `,`
]
},
{
code: `
<template>
{{ '<' }}
{{ '<<' }}
{{ 'can be < anywhere' }}
{{ '<tag>' }}
</template>
`,
output: `
<template>
&lt;
&lt;&lt;
can be &lt; anywhere
&lt;tag>
</template>
`,
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.',

Check failure on line 234 in tests/lib/rules/no-useless-mustaches.js

View workflow job for this annotation

GitHub Actions / Lint

Delete `,`
]
},
{
code: `
<template>
Expand Down