Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/rules/no-bare-strings-in-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ module.exports = {
const directives = opts.directives || DEFAULT_DIRECTIVES

const allowlistRe = new RegExp(
allowlist.map((w) => regexp.escape(w)).join('|'),
allowlist
.map((w) => regexp.escape(w))
.sort((a, b) => b.length - a.length)
.join('|'),
'gu'
)

Expand Down
38 changes: 37 additions & 1 deletion tests/lib/rules/no-bare-strings-in-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,25 @@ tester.run('no-bare-strings-in-template', rule, {
title="( ) , . & + - = * / # % ! ? : [ ] { } < > • — | &lpar; &rpar; &comma; &period; &amp; &AMP; &plus; &minus; &equals; &ast; &midast; &sol; &num; &percnt; &excl; &quest; &colon; &lsqb; &lbrack; &rsqb; &rbrack; &lcub; &lbrace; &rcub; &rbrace; &lt; &LT; &gt; &GT; &bull; &bullet; &mdash; &ndash; &nbsp; &Tab; &NewLine; &verbar; &vert; &VerticalLine;"
/>
</template>
`
`,
{
// https://github.com/vuejs/eslint-plugin-vue/issues/2681
code: `
<template>
<h1> foo </h1>
<h1> foo_bar </h1>
</template>
`,
options: [{ allowlist: ['foo', 'foo_bar'] }]
},
{
code: `
<template>
<h1>@@</h1>
</template>
`,
options: [{ allowlist: ['@@'] }]
}
],
invalid: [
{
Expand Down Expand Up @@ -227,6 +245,24 @@ tester.run('no-bare-strings-in-template', rule, {
}
]
},
{
code: `
<template>
<h1>foo</h1>
<h1>foo_bar</h1>
</template>
`,
options: [{ allowlist: ['foo'] }],
errors: [
{
messageId: 'unexpected',
line: 4,
column: 13,
endLine: 4,
endColumn: 20
}
]
},
{
code: `
<template>
Expand Down
Loading