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