no-empty-character-class
JavaScript / TypeScriptsuspiciousno fixdefault: warnjs/eslint-recommendedjs/biome-recommendedjs/oxlint
What it does
Section titled “What it does”Reports [] in a regex literal. [^] (any character) and a [] in the string given to new RegExp are not reported.
Why it matters
Section titled “Why it matters”A character class with no members can match nothing, so a regex that contains it never matches. It is nearly always an escape that was forgotten (\[\] meant) or a class whose content was deleted.
To fix, add the characters, or escape the brackets.
Example
Section titled “Example”...var r = /a[]/, s = /[]]/, t = /[^]/, u = /\[]/, v = /[\]]/, w = new RegExp("[]");Configuration
Section titled “Configuration”js: lint: rules: no-empty-character-class: warn # off, warn (default), errorEnabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.
Suppress one line with sudsy-disable-next-line no-empty-character-class in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| eslint | no-empty-character-class |
full |