]>
Commit | Line | Data |
---|---|---|
8f9d1d4d DC |
1 | --- |
2 | title: wrap-regex | |
8f9d1d4d DC |
3 | rule_type: layout |
4 | --- | |
5 | ||
6 | ||
eb39fafa DC |
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 | ||
8f9d1d4d DC |
22 | ::: incorrect |
23 | ||
eb39fafa DC |
24 | ```js |
25 | /*eslint wrap-regex: "error"*/ | |
26 | ||
27 | function a() { | |
28 | return /foo/.test("bar"); | |
29 | } | |
30 | ``` | |
31 | ||
8f9d1d4d DC |
32 | ::: |
33 | ||
eb39fafa DC |
34 | Example of **correct** code for this rule: |
35 | ||
8f9d1d4d DC |
36 | ::: correct |
37 | ||
eb39fafa DC |
38 | ```js |
39 | /*eslint wrap-regex: "error"*/ | |
40 | ||
41 | function a() { | |
42 | return (/foo/).test("bar"); | |
43 | } | |
44 | ``` | |
8f9d1d4d DC |
45 | |
46 | ::: |