Empty character classes should not be used in regular expressions

  • BAD_REGEXP
  • Error
  • Medium
  • No tags

This rule applies when a regular expression has empty character classes.

Because empty character classes '[]' in regular expressions do not match anything, they are not likely to be a programmer's intent.

Noncompliant Code Example

View with compliant examples side by side
var foo = /^abc[]/;

Compliant Code Example

View with noncompliant examples side by side
var foo = /^abc\[\]/;

Version

This rule was introduced in DeepScan 1.0.0-alpha.

See

Was this documentation helpful?