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