unicorn/prefer-single-call Pedantic
What it does
Enforces combining multiple Array#{push,unshift}(), Element#classList.{add,remove}(), and importScripts() into a single call.
Supersedes the deprecated unicorn/no-array-push-push rule.
Why is this bad?
Calling the same variadic method on the same receiver multiple times consecutively can be merged into a single call, which is more concise and can be marginally more performant.
Examples
Examples of incorrect code for this rule:
javascript
foo.push(1);
foo.push(2);
foo.unshift(1);
foo.unshift(2);
element.classList.add("foo");
element.classList.add("bar");
importScripts("foo.js");
importScripts("bar.js");Examples of correct code for this rule:
javascript
foo.push(1, 2);
foo.unshift(2, 1);
element.classList.add("foo", "bar");
importScripts("foo.js", "bar.js");Configuration
This rule accepts a configuration object with the following properties:
ignore
type: string[]
default: []
Methods to ignore.
How to use
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"unicorn/prefer-single-call": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"unicorn/prefer-single-call": "error",
},
});bash
oxlint --deny unicorn/prefer-single-callVersion
This rule was added in vnext.
