-
What language is this for?
TypeScript -
Which rule?
typescript:S3801 - Functions should use “return” consistently -
Why do you believe it’s a false-positive/false-negative?
False positive, see the code below.
Tested with TypeScript 5.0.4. -
Are you using
SonarQube - Enterprise Edition Version 9.9.1 (build 69595) -
How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
export type Variant = "A" | "B" | "C";
// SQ: Refactor this function to use "return" consistently.
// But the default case is not needed here, since TS compiler already ensures that the switch returns something for every input variant.
export function getVariantNumber(variant: Variant): number {
switch (variant) {
case "A":
return 1;
case "B":
return 2;
case "C":
return 3;
}
}