== Why is this an issue?
Why use named groups only to never use any of them later on in the code?
This rule raises issues every time named groups are:
* referenced while not defined;
* defined but called elsewhere in the code by their number instead.
=== Noncompliant code example
[source,python]
----
import re
def foo():
pattern = re.compile(r"(?P.)")
matches = pattern.match("abc")
g1 = matches.group("b") # Noncompliant - group "b" is not defined
g2 = matches.group(1) # Noncompliant - Directly use 'a' instead of its group number.
----
=== Compliant solution
[source,python]
----
import re
def foo():
pattern = re.compile(r"(?P.)")
matches = pattern.match("abc")
g = matches.group("a")
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
* In case there is no group with name:
** There is no group named 'S' in the regular expression.
* In case number access to named group
** Directly use 'S' instead of its group number.
=== Highlighting
* primary: the group number or group name
** secondary: named groups
endif::env-github,rspecator-view[]