Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8f16fbd

Browse filesBrowse files
committed
fix(no-bare-strings-in-template): resolve regex matching order
1 parent 99bbe07 commit 8f16fbd
Copy full SHA for 8f16fbd

File tree

Expand file treeCollapse file tree

2 files changed

+41
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+41
-2
lines changed

‎lib/rules/no-bare-strings-in-template.js

Copy file name to clipboardExpand all lines: lib/rules/no-bare-strings-in-template.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ module.exports = {
154154
const directives = opts.directives || DEFAULT_DIRECTIVES
155155

156156
const allowlistRe = new RegExp(
157-
allowlist.map((w) => regexp.escape(w)).join('|'),
157+
allowlist
158+
.map((w) => regexp.escape(w))
159+
.sort((a, b) => b.length - a.length)
160+
.join('|'),
158161
'gu'
159162
)
160163

‎tests/lib/rules/no-bare-strings-in-template.js

Copy file name to clipboardExpand all lines: tests/lib/rules/no-bare-strings-in-template.js
+37-1Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,25 @@ tester.run('no-bare-strings-in-template', rule, {
114114
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;"
115115
/>
116116
</template>
117-
`
117+
`,
118+
{
119+
// https://github.com/vuejs/eslint-plugin-vue/issues/2681
120+
code: `
121+
<template>
122+
<h1> foo </h1>
123+
<h1> foo_bar </h1>
124+
</template>
125+
`,
126+
options: [{ allowlist: ['foo', 'foo_bar'] }]
127+
},
128+
{
129+
code: `
130+
<template>
131+
<h1>@@</h1>
132+
</template>
133+
`,
134+
options: [{ allowlist: ['@@'] }]
135+
}
118136
],
119137
invalid: [
120138
{
@@ -227,6 +245,24 @@ tester.run('no-bare-strings-in-template', rule, {
227245
}
228246
]
229247
},
248+
{
249+
code: `
250+
<template>
251+
<h1>foo</h1>
252+
<h1>foo_bar</h1>
253+
</template>
254+
`,
255+
options: [{ allowlist: ['foo'] }],
256+
errors: [
257+
{
258+
messageId: 'unexpected',
259+
line: 4,
260+
column: 13,
261+
endLine: 4,
262+
endColumn: 20
263+
}
264+
]
265+
},
230266
{
231267
code: `
232268
<template>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.