identical_case_bodies
Finds two cases of a switch with the same body, which could list their values together.
Category pedantic, allow by default.
Off by default; the example is shown with the rule enabled.
#import "Basic";
Kind :: enum {
PNG;
JPEG;
WAV;
}
describe :: (kind: Kind) -> string {
if kind == {
case .PNG;
return "image";
case .JPEG;
return "image";
case .WAV;
return "audio";
}
return "";
}
main :: () {
print("%\n", describe(.PNG));
}warning[identical_case_bodies]: `case .JPEG` does the same as `case .PNG`
--> example.jai:13:9
|
13 | case .JPEG;
| ^^^^^^^^^^
|
help: list the values together: `case .PNG, .JPEG;`
|
11 - case .PNG;
12 - return "image";
13 - case .JPEG;
11 + case .PNG, .JPEG;
|#import "Basic";
Kind :: enum {
PNG;
JPEG;
WAV;
}
describe :: (kind: Kind) -> string {
if kind == {
case .PNG; #through;
case .JPEG;
return "image";
case .WAV;
return "audio";
}
return "";
}
main :: () {
print("%\n", describe(.PNG));
}Off by default, since one case per row is sometimes the clearer table.