Skip to content

Latest commit

 

History

History
42 lines (27 loc) · 619 Bytes

wrap-regex.md

File metadata and controls

42 lines (27 loc) · 619 Bytes
规则名 规则类型
wrap-regex
layout

When a regular expression is used in certain situations, it can end up looking like a division operator. For example:

function a() {
    return /foo/.test("bar");
}

规则详解

This is used to disambiguate the slash operator and facilitates more readable code.

Example of incorrect code for this rule:

/*eslint wrap-regex: "error"*/

function a() {
    return /foo/.test("bar");
}

Example of correct code for this rule:

::: correct

/*eslint wrap-regex: "error"*/

function a() {
    return (/foo/).test("bar");
}