A method that returns a new string, number or array is called as a statement and its result is lost

tx0/ts:discarded-new-valuedefaultwarningbug

What it finds

name.trim();, list.toSorted();, price.toFixed(2);: these methods leave the value they are called on alone and return a new one. Called as a statement, the new value is lost and nothing changes. name = name.trim() was meant.

The methods are those of strings, numbers and arrays whose names no common library reuses for methods with effects: trimStart, trimEnd, toUpperCase, toLowerCase, toLocaleUpperCase, toLocaleLowerCase, padStart, padEnd, toFixed, toPrecision, toExponential, toSorted, toReversed and toSpliced. On a string, template or array literal, trim, concat, slice, replace, replaceAll and split count as well. trim and normalize on other values are left alone: caches and DOM nodes have methods of those names that change them.

From the rule's source, discarded_new_value.rs.

Example from the rule's tests
function clean(name: string, list: number[], price: number) {  name.toUpperCase();tx0 reports: toUpperCase returns a new value, which is thrown away here  name.trim();  price.toFixed(2);tx0 reports: toFixed returns a new value  list.toSorted();tx0 reports: toSorted returns a new value  "a,b".split(",");tx0 reports: split returns a new value  list.sort();  name = name.trim();  return name;}
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:discarded-new-value" = "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:discarded-new-value] reason="..."

tx0 explain tx0/ts:discarded-new-value shows the same in the terminal. Found a false positive? Report it.