rspec/rules/S6001/rule.adoc
2023-03-23 14:57:03 +01:00

23 lines
567 B
Plaintext

include::description.adoc[]
== Noncompliant Code Example
[source,text]
----
Pattern.compile("\\1(.)"); // Noncompliant, group 1 is defined after the back reference
Pattern.compile("(.)\\2"); // Noncompliant, group 2 isn't defined at all
Pattern.compile("(.)|\\1"); // Noncompliant, group 1 and the back reference are in different branches
Pattern.compile("(?<x>.)|\\k<x>"); // Noncompliant, group x and the back reference are in different branches
----
== Compliant Solution
[source,text]
----
Pattern.compile("(.)\\1");
Pattern.compile("(?<x>.)\\k<x>");
----