Empty character classes should not be used in regular expressions

  • 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\[\]/;


This rule was introduced in DeepScan 1.0.0-alpha.


Was this documentation helpful?