A local variable, function or class is declared but never read

tx0/ts:unused-localrecommendedwarningsmell

What it finds

const total = sum(items); with total never read: a local variable, function or class that nothing uses is dead code. Either it is left over, or the code that was meant to use it is missing, as when a result is computed and then the wrong variable is returned.

Reported are let, const, var, function and class declarations inside functions and blocks whose name is never read, only declared or assigned. Declarations at the top level of a file are left alone, since scripts share them with other files, and so are names starting with _, names with declare or export, and names bound next to a rest element in an object pattern, as const { id, ...rest } = user, which leave id out of rest on purpose. The names of function and class expressions, which only the expression itself can see, are left alone too. Files with syntax errors or a with statement are skipped.

From the rule's source, unused_local.rs.

Example from the rule's tests
export function total(items: number[]) {  const sum = items.reduce((a, b) => a + b, 0);tx0 reports: sum is never read  let count = 0;tx0 reports: count is never read  count = items.length;  const { id, ...rest } = { id: 1, name: "x" };  const _ignored = 1;  function helper() {tx0 reports: helper is never read    return 1;  }  const used = items.length;  return [used, rest];}
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 from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:unused-local" = "warning"

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:unused-local] reason="..."

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