A function with several parameters is memoized by Lodash or Underscore without a resolver, so only the first argument is the cache key

tx0/ts:memoize-ignores-extra-argumentsdefaultwarningreliability/api-misusedepth fastbug

What it finds

_.memoize(fn) caches results by the first argument alone. A function of several parameters then returns the result of an earlier call that had the same first argument and different others. A resolver as second argument builds a key from all of them.

Reported are memoize calls through _, lodash or underscore, or imported from them, with a single argument that is a function of two or more parameters.

From the rule's source, memoize_ignores_extra_arguments.rs.

Example from the rule's tests
import _ from "lodash";export const price = _.memoize((item: string, currency: string) => lookup(item, currency));tx0 reports: this caches by the first of 2 arguments onlyexport const name = _.memoize((id: string) => lookup(id, ""));declare function lookup(a: string, b: string): 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:memoize-ignores-extra-arguments" = "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:memoize-ignores-extra-arguments] reason="..."

tx0 explain tx0/ts:memoize-ignores-extra-arguments shows the same in the terminal. Found a false positive? Report it.