Skip to content

no-empty-character-class

Reports [] in a regex literal. [^] (any character) and a [] in the string given to new RegExp are not reported.

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.

Reported
...
var r = /a[]/, s = /[]]/, t = /[^]/, u = /\[]/, v = /[\]]/, w = new RegExp("[]");
js:
lint:
rules:
no-empty-character-class: warn # off, warn (default), error

Enabled 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.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint no-empty-character-class full