[].slice.call(list) creates an array only to reach slice, and then throws it away. Array.prototype.slice.call(list) names where the method comes from and creates nothing.
The rule reports a method of an empty [] or {} that's used with .call(), .apply() or .bind(), or passed as the first argument of Reflect.apply().
--fix replaces [] with Array.prototype and {} with Object.prototype.
Configure
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"unicorn/prefer-prototype-methods" = "error" # or "warn"
Examples
Reported:
const links = [].slice.call(document.links);
const isOwn = {}.hasOwnProperty.call(user, "name");
const first = Reflect.apply([].at, items, [0]);
Not reported:
const links = Array.prototype.slice.call(document.links);
const isOwn = Object.prototype.hasOwnProperty.call(user, "name");
const first = Reflect.apply(Array.prototype.at, items, [0]);
A method of any other object isn't reported:
const log = console.log.bind(console);
const all = [1, 2].concat.call(items, more);