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