rspec/rules/S5855/python/rule.adoc

25 lines
534 B
Plaintext
Raw Normal View History

2023-08-04 16:18:23 +02:00
This rule raises an issue when multiple branches of a regex alternative match the same input.
== Why is this an issue?
include::../description.adoc[]
2023-08-04 16:18:23 +02:00
=== Code examples
2023-08-04 16:18:23 +02:00
==== Noncompliant code example
2023-08-04 16:18:23 +02:00
[source,python,diff-id=1,diff-type=noncompliant]
----
2023-08-04 16:18:23 +02:00
r"[ab]|a" # Noncompliant: the "|a" is redundant because "[ab]" already matches "a"
r".*|a" # Noncompliant: .* matches everything, so any other alternative is redundant
----
2023-08-04 16:18:23 +02:00
==== Compliant solution
2023-08-04 16:18:23 +02:00
[source,python,diff-id=1,diff-type=compliant]
----
r"[ab]"
r".*"
----