rspec/rules/S5860/python/rule.adoc
2023-03-29 10:41:03 +02:00

40 lines
704 B
Plaintext

include::description.adoc[]
== Noncompliant Code Example
[source,python]
----
import re
def foo():
pattern = re.compile(r"(?P<a>.)")
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<a>.)")
matches = pattern.match("abc")
g = matches.group("a")
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]