rspec/rules/S1199/rule.adoc

47 lines
731 B
Plaintext
Raw Normal View History

== Why is this an issue?
2020-06-30 12:47:33 +02:00
include::description.adoc[]
=== Noncompliant code example
[source,text]
----
public void evaluate(int operator) {
switch (operator) {
/* ... */
case ADD: { // Noncompliant - nested code block '{' ... '}'
int a = stack.pop();
int b = stack.pop();
int result = a + b;
stack.push(result);
break;
}
/* ... */
}
}
----
=== Compliant solution
[source,text]
----
public void evaluate(int operator) {
switch (operator) {
/* ... */
case ADD: // Compliant
evaluateAdd();
break;
/* ... */
}
}
private void evaluateAdd() {
int a = stack.pop();
int b = stack.pop();
int result = a + b;
stack.push(result);
}
----
2020-06-30 12:47:33 +02:00