Skip to content
This repository has been archived by the owner on Oct 11, 2021. It is now read-only.

Latest commit

 

History

History
36 lines (25 loc) · 1.16 KB

no-potentially-empty-backreference.md

File metadata and controls

36 lines (25 loc) · 1.16 KB

no-potentially-empty-backreference

Disallow backreferences that reference a group that might not be matched.

configuration in plugin:clean-regex/recommended: "warn"

Source file
Test file

Description

If the referenced group of a backreference is not matched because some other path leads to the backreference, the backreference will be replaced with the empty string. The same will happen if the captured text of the referenced group was reset before reaching the backreference.

This will handle backreferences which will always be replaced with the empty string for the above reason. Use no-empty-backreference for that.

Examples

Examples of valid code for this rule:

/(a+)b\1/
/(a+)b|\1/  // this will be done by no-empty-backreference

Examples of invalid code for this rule:

/(a)?b\1/
/((a)|c)+b\1/