rspec/rules/S1107/rule.adoc

58 lines
982 B
Plaintext
Raw Normal View History

== Why is this an issue?
2020-06-30 12:47:33 +02:00
Shared coding conventions make it possible for a team to collaborate efficiently.
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
This rule makes it mandatory to place closing curly braces on the same line as the next ``++else++``, ``++catch++`` or ``++finally++`` keywords.
2020-06-30 12:47:33 +02:00
=== Noncompliant code example
2020-06-30 12:47:33 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:47:33 +02:00
----
public void myMethod() {
if(something) {
executeTask();
} else if (somethingElse) {
doSomethingElse();
}
else { // Noncompliant
generateError();
}
try {
generateOrder();
} catch (Exception e) {
log(e);
}
finally { // Noncompliant
closeConnection();
}
}
----
=== Compliant solution
2020-06-30 12:47:33 +02:00
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:47:33 +02:00
----
public void myMethod() {
if(something) {
executeTask();
} else if (somethingElse) {
doSomethingElse();
} else {
generateError();
}
try {
generateOrder();
} catch (Exception e) {
log(e);
} finally {
closeConnection();
}
}
----