Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3753

Rule S6208: Comma-separated labels should be used in Switch with colon case

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.15
    • Component/s: Rules

      Description

      Implements RSPEC-6208.
      Note: make sure this rule does not overlap with RSPEC-3923 or RSPEC-1871, reporting similar cases.

          switch (mode) {
            case "a":
              doSomething();
              break;
            case "b": // Compliant for S1871
              doSomething();
              break;
            default:
              doSomethingElse();
          }
      
          switch (mode) {
            case "a":
              doSomething();
              break;
            case "b": // Noncompliant for S1871
              doSomething();
              break;
          }
      
          switch (mode) {
            case "a" -> doSomething();
            case "b" -> doSomething(); // Compliant for S1871
            default -> doSomethingElse();
          }
      
          switch (mode) {
            case "a" -> {
              doSomething();
              doSomething();
            }
            case "b" -> { // Compliant for S1871
              doSomething();
              doSomething();
            }
            default -> doSomethingElse();
          }
          switch (mode) {
            case "a" -> {
              doSomething();
              doSomething();
            }
            case "b" -> { // Noncompliant for S1871
              doSomething();
              doSomething();
            }
          }
      
      
      int i = switch (mode) {
        case "a":
        case "b": // Noncompliant
          yield 1;
        default:
          yield 3;
      };
      
      int i = switch (mode) {
        case "a":
          yield 1;
        case "b": // Compliant for S1871, should be reported by S6208??
          yield 1;
        default:
          yield 3;
      };
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dorian.burihabwa Dorian Burihabwa
                Reporter:
                quentin.jaquier Quentin Jaquier
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: