]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/wrap-regex.md
first commit
[pve-eslint.git] / eslint / docs / rules / wrap-regex.md
1 # Require Regex Literals to be Wrapped (wrap-regex)
2
3 When a regular expression is used in certain situations, it can end up looking like a division operator. For example:
4
5 ```js
6 function a() {
7 return /foo/.test("bar");
8 }
9 ```
10
11 ## Rule Details
12
13 This is used to disambiguate the slash operator and facilitates more readable code.
14
15 Example of **incorrect** code for this rule:
16
17 ```js
18 /*eslint wrap-regex: "error"*/
19
20 function a() {
21 return /foo/.test("bar");
22 }
23 ```
24
25 Example of **correct** code for this rule:
26
27 ```js
28 /*eslint wrap-regex: "error"*/
29
30 function a() {
31 return (/foo/).test("bar");
32 }
33 ```