-
Notifications
You must be signed in to change notification settings - Fork 31
Create rule S126: "if ... elif" constructs should end with "else" clauses #5210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the LaYC format
rules/S126/shell/rule.adoc
Outdated
=== Noncompliant code example | ||
|
||
[source,bash,diff-id=1,diff-type=noncompliant] | ||
---- | ||
if [[ $x -eq 0 ]]; then | ||
do_something | ||
elif [[ $x -eq 1 ]]; then | ||
do_something_else | ||
fi | ||
---- | ||
|
||
=== Compliant solution | ||
|
||
[source,bash,diff-id=1,diff-type=compliant] | ||
---- | ||
if [[ $x -eq 0 ]]; then | ||
do_something | ||
elif [[ $x -eq 1 ]]; then | ||
do_something_else | ||
else | ||
echo "Unexpected value: $x" | ||
exit 1 | ||
fi | ||
---- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=== Noncompliant code example | |
[source,bash,diff-id=1,diff-type=noncompliant] | |
---- | |
if [[ $x -eq 0 ]]; then | |
do_something | |
elif [[ $x -eq 1 ]]; then | |
do_something_else | |
fi | |
---- | |
=== Compliant solution | |
[source,bash,diff-id=1,diff-type=compliant] | |
---- | |
if [[ $x -eq 0 ]]; then | |
do_something | |
elif [[ $x -eq 1 ]]; then | |
do_something_else | |
else | |
echo "Unexpected value: $x" | |
exit 1 | |
fi | |
---- | |
== How to fix it | |
=== Code examples | |
==== Noncompliant code example | |
[source,bash,diff-id=1,diff-type=noncompliant] | |
---- | |
if [[ $x -eq 0 ]]; then | |
do_something | |
elif [[ $x -eq 1 ]]; then | |
do_something_else | |
fi | |
---- | |
==== Compliant solution | |
[source,bash,diff-id=1,diff-type=compliant] | |
---- | |
if [[ $x -eq 0 ]]; then | |
do_something | |
elif [[ $x -eq 1 ]]; then | |
do_something_else | |
else | |
echo "Unexpected value: $x" | |
exit 1 | |
fi | |
---- |
|
|
You can preview this rule here (updated a few minutes after each push).
Review
A dedicated reviewer checked the rule description successfully for: