Skip to content

Commit 029a956

Browse files
Make regex more readable.
1 parent 14c44f0 commit 029a956

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/util/labelUtils.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@ const isInsideLabelTag = (context: TSESLint.RuleContext<string, unknown[]>): boo
2929
* Capture groups (when the alternation matches) are in positions 2..6
3030
* (group 1 is the element/tag capture used in some surrounding regexes).
3131
*/
32-
// FIXED: typo in identifier character class (A-ZaLign -> A-Za-z)
33-
const idOrExprRegex = /(?:"([^"]*)"|'([^']*)'|\{\s*"([^"]*)"\s*\}|\{\s*'([^']*)'\s*\}|\{\s*([A-Za-z_$][A-Za-z0-9_$]*)\s*\})/i;
32+
const idLiteralDouble = '"([^"]*)"';
33+
const idLiteralSingle = "'([^']*)'";
34+
const exprStringDouble = '\\{\\s*"([^"]*)"\\s*\\}';
35+
const exprStringSingle = "\\{\\s*'([^']*)'\\s*\\}";
36+
const exprIdentifier = "\\{\\s*([A-Za-z_$][A-Za-z0-9_$]*)\\s*\\}";
37+
38+
const idOrExprRegex = new RegExp(
39+
`(?:${idLiteralDouble}|${idLiteralSingle}|${exprStringDouble}|${exprStringSingle}|${exprIdentifier})`,
40+
"i"
41+
);
3442

3543
const escapeForRegExp = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3644

0 commit comments

Comments
 (0)