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

Extend existing rules to support Switch Expression

    Details

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

      Description

      In Java 14, Switch expression (see JEP361) became a standard feature of the language and can be used freely. Despite the fact that the behavior is different, many existing rules targeting Switch Statements also apply to Switch Expression.

      Rules targeting Switch Statements:
      In IssuableSubscriptionVisitor:

      • RSPEC-3923 (AllBranchesAreIdenticalCheck)
      • RSPEC-1871 (IdenticalCasesInSwitchCheck)
      • RSPEC-1151 (SwitchCaseTooBigCheck)
      • RSPEC-4524 (SwitchDefaultLastCaseCheck)
      • RSPEC-1479 (SwitchWithTooManyCasesCheck)
      • RSPEC-1821 (NestedSwitchStatementCheck)
        • Was initially targeting statement, the rule description should be updated to include switch expressions aswell.
      • RSPEC-131 (SwitchLastCaseIsDefaultCheck)
        • Does not apply, compile error if is not exhaustive and can be omited if it is exhaustive.

      In BaseTreeVisitor:

      • RSPEC-1105 (LeftCurlyBraceEndLineCheck)
      • RSPEC-1106 (LeftCurlyBraceStartLineCheck)
      • RSPEC-134 (NestedIfStatementsCheck)
      • RSPEC-1301 (SwitchAtLeastThreeCasesCheck)
        • Does not apply, Switch Expressions actually return something, not cleaner to use if statements
      • RSPEC-1143 (ReturnInFinallyCheck)
        • Does not apply to Switch Expression
      • RSPEC-135 (SeveralBreakOrContinuePerLoopCheck)
        • Not needed, Switch Expression can not contain a break,

      We should extend these rules to report issues on Switch Expressions.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                quentin.jaquier Quentin Jaquier
                Reporter:
                quentin.jaquier Quentin Jaquier
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved: