rspec/rules/S5855/java/rule.adoc

42 lines
769 B
Plaintext
Raw Permalink 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[]
2021-04-28 16:49:39 +02:00
2023-08-04 16:18:23 +02:00
=== Code examples
2023-08-04 16:18:23 +02:00
==== Noncompliant code example
2021-04-28 16:49:39 +02:00
2023-08-04 16:18:23 +02:00
[source,java,diff-id=1,diff-type=noncompliant]
2021-04-28 16:49:39 +02:00
----
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
2021-04-28 16:49:39 +02:00
----
2023-08-04 16:18:23 +02:00
==== Compliant solution
2021-04-28 16:49:39 +02:00
2023-08-04 16:18:23 +02:00
[source,java,diff-id=1,diff-type=compliant]
2021-04-28 16:49:39 +02:00
----
"[ab]"
".*"
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove or rework this redundant alternative
=== Highlighting
The redundant alternative
endif::env-github,rspecator-view[]