-
Notifications
You must be signed in to change notification settings - Fork 31
Create rule S131: "case" statements should have "*)" clauses #5212
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
|
|
303f060
to
0990ea4
Compare
|
|
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.
I don't think the rule should include the default clause position in the case
=== Noncompliant code example | ||
|
||
[source,bash,diff-id=1,diff-type=noncompliant] | ||
---- | ||
case "$param" in # missing default clause | ||
0) | ||
do_something | ||
;; | ||
1) | ||
do_something_else | ||
;; | ||
esac | ||
|
||
case "$param" in | ||
*) # default clause should be the last one | ||
error | ||
;; | ||
0) | ||
do_something | ||
;; | ||
1) | ||
do_something_else | ||
;; | ||
esac | ||
---- | ||
|
||
=== Compliant solution |
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] | |
---- | |
case "$param" in # missing default clause | |
0) | |
do_something | |
;; | |
1) | |
do_something_else | |
;; | |
esac | |
case "$param" in | |
*) # default clause should be the last one | |
error | |
;; | |
0) | |
do_something | |
;; | |
1) | |
do_something_else | |
;; | |
esac | |
---- | |
=== Compliant solution | |
== How to fix it | |
=== Code examples | |
==== Noncompliant code example | |
[source,bash,diff-id=1,diff-type=noncompliant] | |
---- | |
case "$param" in # missing default clause | |
0) | |
do_something | |
;; | |
1) | |
do_something_else | |
;; | |
esac | |
case "$param" in | |
*) # default clause should be the last one | |
error | |
;; | |
0) | |
do_something | |
;; | |
1) | |
do_something_else | |
;; | |
esac | |
---- | |
==== Compliant solution |
case "$param" in | ||
*) # default clause should be the last one | ||
error | ||
;; | ||
0) | ||
do_something | ||
;; | ||
1) | ||
do_something_else | ||
;; | ||
esac |
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.
For the diff to be nice I would suggest to either remove this example or put into its own code block.
case "$param" in | ||
*) # default clause should be the last one | ||
error | ||
;; | ||
0) | ||
do_something | ||
;; | ||
1) | ||
do_something_else | ||
;; | ||
esac |
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.
I am not sure why this case is part of this rule.
Isn't the rule only about the missing default clause?
You can preview this rule here (updated a few minutes after each push).
Review
A dedicated reviewer checked the rule description successfully for: