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:
- 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.
- Does not apply, compile error if is not exhaustive and can be omited if it is exhaustive.
- RSPEC-1105 (LeftCurlyBraceEndLineCheck)
- RSPEC-1106 (LeftCurlyBraceStartLineCheck)
- RSPEC-134 (NestedIfStatementsCheck)
- Does not apply, Switch Expressions actually return something, not cleaner to use if statements
- Does not apply to Switch Expression
- Not needed, Switch Expression can not contain a break,
We should extend these rules to report issues on Switch Expressions.