Skip to content

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

github-actions[bot]
Copy link
Contributor

You can preview this rule here (updated a few minutes after each push).

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

Copy link

Quality Gate passed Quality Gate passed for 'rspec-tools'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@denis-troller denis-troller changed the title Create rule S131 Create rule S131: "CASE" statements should have "WHEN OTHERS" clauses Jul 16, 2025
Copy link

Quality Gate passed Quality Gate passed for 'rspec-frontend'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link

Quality Gate passed Quality Gate passed for 'rspec-tools'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link

Quality Gate passed Quality Gate passed for 'rspec-frontend'

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
No data about Duplication

See analysis details on SonarQube

Copy link
Contributor

@sebastien-marichal sebastien-marichal left a 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

Comment on lines +5 to +31
=== 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
=== 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

Comment on lines +18 to +28
case "$param" in
*) # default clause should be the last one
error
;;
0)
do_something
;;
1)
do_something_else
;;
esac
Copy link
Contributor

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.

Comment on lines +18 to +28
case "$param" in
*) # default clause should be the last one
error
;;
0)
do_something
;;
1)
do_something_else
;;
esac
Copy link
Contributor

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?

@sebastien-marichal sebastien-marichal changed the title Create rule S131: "CASE" statements should have "WHEN OTHERS" clauses Create rule S131: "case" statements should have "*)" clauses Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants