rspec/rules/S5855/php/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,php,diff-id=1,diff-type=noncompliant]
----
2023-08-04 16:18:23 +02:00
"/[ab]|a/" // Noncompliant: the "|a" is redundant because "[ab]" already matches "a"
"/.*|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,php,diff-id=1,diff-type=compliant]
----
"/[ab]/"
"/.*/"
2022-02-04 17:28:24 +01:00
----