rspec/rules/S5860/python/rule.adoc

42 lines
732 B
Plaintext

== Why is this an issue?
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[]