A case of a switch repeats an earlier one

tx0/ts:duplicate-casedefaultwarningbug

What it finds

case 1: ... case 1:: a switch compares its value with the cases in order and runs the first that matches, so a case that repeats an earlier one never runs.

Constants are compared by value, as === compares them, so 'a' and "a" are the same case and 0 and -0 too. Other expressions are the same when they are made of the same tokens and cannot give a different value the second time, because they call, construct, await, assign or create nothing.

From the rule's source, duplicate_case.rs.

Example from the rule's tests
function describe(kind: string | number, item: { code: number }) {  switch (kind) {    case "a":      return 1;    case 'a':tx0 reports: the case 'a' repeats an earlier one      return 2;    case 1:    case 1.0:tx0 reports: the case 1.0 repeats an earlier one      return 3;    case item.code:    case item.code:tx0 reports: the case item.code repeats an earlier one      return 4;    case next():    case next():      return 5;    default:      return 0;  }} declare function next(): number;
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:duplicate-case" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:duplicate-case] reason="..."

tx0 explain tx0/ts:duplicate-case shows the same in the terminal. Found a false positive? Report it.