useRegexLiterals
Цей контент ще не доступний вашою мовою.
Summary
Section titled “Summary”- Rule available since: v1.3.0
- Diagnostic Category: lint/complexity/useRegexLiterals
- This rule is recommended, which means is enabled by default.
- This rule has a safe fix.
- The default severity of this rule is warning.
- Sources:
- Same as prefer-regex-literals
 
- Same as 
How to configure
Section titled “How to configure”{  "linter": {    "rules": {      "complexity": {        "useRegexLiterals": "error"      }    }  }}Description
Section titled “Description”Enforce the use of the regular expression literals instead of the RegExp constructor if possible.
There are two ways to create a regular expression:
- Regular expression literals, e.g., /abc/u.
- The RegExp constructor function, e.g., new RegExp("abc", "u").
The constructor function is particularly useful when you want to dynamically generate the pattern, because it takes string arguments.
Using regular expression literals avoids some escaping required in a string literal, and are easier to analyze statically.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”new RegExp("abc", "u");code-block.js:1:1 lint/complexity/useRegexLiterals  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  ⚠ Use a regular expression literal instead of the RegExp constructor.
  
  > 1 │ new RegExp(“abc”, “u”);
      │ ^^^^^^^^^^^^^^^^^^^^^^
    2 │ 
  
  ℹ Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
  
  ℹ Safe fix: Use a literal notation instead.
  
    1   │ - new·RegExp(“abc”,·“u”);
      1 │ + /abc/u;
    2 2 │   
  
/abc/u;
new RegExp("abc", flags);Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.