diff --git a/lib/rules/no-bare-strings-in-template.js b/lib/rules/no-bare-strings-in-template.js index 3f46607a5..1c75f5092 100644 --- a/lib/rules/no-bare-strings-in-template.js +++ b/lib/rules/no-bare-strings-in-template.js @@ -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' ) diff --git a/tests/lib/rules/no-bare-strings-in-template.js b/tests/lib/rules/no-bare-strings-in-template.js index 6c8497531..4c6c89c7c 100644 --- a/tests/lib/rules/no-bare-strings-in-template.js +++ b/tests/lib/rules/no-bare-strings-in-template.js @@ -114,7 +114,25 @@ tester.run('no-bare-strings-in-template', rule, { title="( ) , . & + - = * / # % ! ? : [ ] { } < > • — | ( ) , . & & + − = * * / # % ! ? : [ [ ] ] { { } } < < > > • • — –   | | |" /> - ` + `, + { + // https://github.com/vuejs/eslint-plugin-vue/issues/2681 + code: ` + + `, + options: [{ allowlist: ['foo', 'foo_bar'] }] + }, + { + code: ` + + `, + options: [{ allowlist: ['@@'] }] + } ], invalid: [ { @@ -227,6 +245,24 @@ tester.run('no-bare-strings-in-template', rule, { } ] }, + { + code: ` + + `, + options: [{ allowlist: ['foo'] }], + errors: [ + { + messageId: 'unexpected', + line: 4, + column: 13, + endLine: 4, + endColumn: 20 + } + ] + }, { code: `