unicorn/prefer-single-call
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-single-call": "error",
},
},
];Enforce combining multiple Array#{push,unshift}(), Element#classList.{add,remove}(), and importScripts() into one call.
foo.push(1);
foo.push(2, 3);foo.unshift(1);
foo.unshift(2, 3);element.classList.add('foo');
element.classList.add('bar', 'baz');foo.push(1, 2, 3);foo.unshift(2, 3, 1);element.classList.add('foo', 'bar', 'baz');Examples from the ESLint documentation.
unicorn/prefer-single-call
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-single-call": "error",
},
},
];unicorn/prefer-single-call
unicorn plugin · pedantic
{
"rules": {
"unicorn/prefer-single-call": "error"
}
}Biome does not have this rule.
Prefer Set#has() over Array#includes() when checking for existence or non-existence.
Prefer String#replaceAll() over regex searches with the global flag and String#split().join().
Prefer Response.json() over new Response(JSON.stringify()).
Prefer using structuredClone to create a deep clone.
Prefer Reflect.apply() over Function#apply().
Prefer ternary expressions over simple if statements.