
## Review A dedicated reviewer checked the rule description successfully for: - [ ] logical errors and incorrect information - [ ] information gaps and missing content - [ ] text style and tone - [ ] PR summary and labels follow [the guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
76 lines
1.3 KiB
Plaintext
76 lines
1.3 KiB
Plaintext
include::../description-common.adoc[]
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,java,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
public class MyClass {
|
|
public void doThings(boolean b, boolean c) {
|
|
a = true;
|
|
if (a) { // Noncompliant
|
|
doSomething();
|
|
}
|
|
|
|
if (b && a) { // Noncompliant; "a" is always "true"
|
|
doSomething();
|
|
}
|
|
|
|
if (c || !a) { // Noncompliant; "!a" is always "false"
|
|
doSomething();
|
|
}
|
|
|
|
if (c || (!c && b)) { // Noncompliant; c || (!c && b) is equal to c || b
|
|
doSomething();
|
|
}
|
|
}
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,java,diff-id=1,diff-type=compliant]
|
|
----
|
|
public class MyClass {
|
|
public void doThings(boolean b, boolean c) {
|
|
a = true;
|
|
if (foo(a)) {
|
|
doSomething();
|
|
}
|
|
|
|
if (b) {
|
|
doSomething();
|
|
}
|
|
|
|
if (c) {
|
|
doSomething();
|
|
}
|
|
|
|
if (c || b) {
|
|
doSomething();
|
|
}
|
|
}
|
|
}
|
|
----
|
|
|
|
include::../see.adoc[]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::../message.adoc[]
|
|
|
|
include::../highlighting.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|