eslint/rules/regular-expressions
Regular expressions (core rules): The regular expression rules of ESLint, SonarJS and Unicorn; the regexp plugin has its own block. Rules of ESLint, typescript-eslint and SonarJS (the Sonar way profile of SonarQube) on this subject, every rule listed; the TypeScript rules apply to TypeScript files only.
32 rules, 23 on. Source: lint/eslint/rules/regular-expressions.mjs.
| Rule | Setting | Files | What it checks | Why |
|---|---|---|---|---|
no-control-regex | error | JS + TS | Disallow control characters in regular expressions | — |
no-empty-character-class | error | JS + TS | Disallow empty character classes in regular expressions | — |
no-invalid-regexp | error | JS + TS | Disallow invalid regular expression strings in RegExp constructors | — |
no-misleading-character-class | error | JS + TS | Disallow characters which are made with multiple code points in character class syntax | — |
no-useless-backreference | error | JS + TS | Disallow useless backreferences in regular expressions | — |
no-div-regex | error | JS + TS | Disallow equal signs explicitly at the beginning of regular expressions | — |
no-regex-spaces | error | JS + TS | Disallow multiple spaces in regular expressions | — |
prefer-named-capture-group | info | JS + TS | Enforce using named capture group in regular expression | — |
prefer-regex-literals | info, {"disallowRedundantWrapping":true} | JS + TS | Disallow use of the RegExp constructor in favor of regular expression literals | — |
require-unicode-regexp | info, {"requireFlag":"v"} | JS + TS | Enforce the use of u or v flag on regular expressions | — |
sonarjs/no-control-regex | off | JS + TS | Regular expressions should not contain control characters | Off: duplicate of no-control-regex. |
sonarjs/no-empty-character-class | off | JS + TS | Empty character classes should not be used | Off: duplicate of no-empty-character-class. |
sonarjs/no-invalid-regexp | off | JS + TS | Regular expressions should be syntactically valid | Off: duplicate of no-invalid-regexp. |
sonarjs/no-misleading-character-class | off | JS + TS | Unicode Grapheme Clusters should be avoided inside regex character classes | Off: duplicate of no-misleading-character-class. |
sonarjs/no-regex-spaces | off | JS + TS | Regular expressions should not contain multiple spaces | Off: duplicate of no-regex-spaces. |
sonarjs/prefer-regexp-exec | off | JS + TS | "RegExp.exec()" should be preferred over "String.match()" | Off: duplicate of @typescript-eslint/prefer-regexp-exec. |
sonarjs/anchor-precedence | error | JS + TS | Alternatives in regular expressions should be grouped when used with anchors | — |
sonarjs/comment-regex | off | JS + TS | Track comments matching a regular expression | Off: not in the Sonar way profile of SonarQube. |
sonarjs/concise-regex | warn | JS + TS | Regular expression quantifiers and character classes should be used concisely | — |
sonarjs/duplicates-in-character-class | warn | JS + TS | Character classes in regular expressions should not contain the same character twice | — |
sonarjs/existing-groups | error | JS + TS | Replacement strings should reference existing regular expression groups | — |
sonarjs/no-empty-after-reluctant | warn | JS + TS | Reluctant quantifiers in regular expressions should be followed by an expression that can't match the empty string | — |
sonarjs/no-empty-alternatives | error | JS + TS | Alternation in regular expressions should not contain empty alternatives | — |
sonarjs/no-empty-group | warn | JS + TS | Regular expressions should not contain empty groups | — |
sonarjs/regex-complexity | warn | JS + TS | Regular expressions should not be too complicated | — |
sonarjs/shorthand-property-grouping | off | JS + TS | Shorthand object properties should be grouped at the beginning or end of an object declaration | Off: not in the Sonar way profile of SonarQube. |
sonarjs/single-char-in-character-classes | warn | JS + TS | Character classes in regular expressions should not contain only one character | — |
sonarjs/stateful-regex | error | JS + TS | Regular expressions with the global flag should be used with caution | — |
sonarjs/super-linear-regex | warn | JS + TS | Regular expressions should not cause non-linear backtracking | — |
sonarjs/unicode-aware-regex | off | JS + TS | Regular expressions using Unicode character classes or property escapes should enable the unicode flag | Off: not in the Sonar way profile of SonarQube. |
sonarjs/unused-named-groups | warn | JS + TS | Names of regular expressions named groups should be used | — |
@typescript-eslint/prefer-regexp-exec | error | TS | Enforce RegExp#exec over String#match if no global flag is provided | — |