# unicorn/prefer-single-call

> Require one call instead of several in a row to `push()`, `unshift()`, `classList.add()` and the like

`push()`, `unshift()`, `classList.add()`, `classList.remove()` and `importScripts()` take any number of arguments. Two calls in a row on the same object do the same thing as one call, with more lines.

`--fix` merges the two calls. It leaves them alone when there's a comment between them, or when one of the second call's arguments reads the object, as in `items.push(items.length)`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"unicorn/prefer-single-call" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"unicorn/prefer-single-call" = ["error", {
  ignore = [], # list of strings
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 4} */}
```js
errors.push("name is required");
errors.push("email is not valid");

queue.unshift(second);
queue.unshift(first);

button.classList.add("active");
button.classList.add("large");

importScripts("parser.js");
importScripts("worker-utils.js");
```

Not reported:

{/* good */}
```js
errors.push("name is required", "email is not valid");

queue.unshift(first, second);

button.classList.add("active", "large");

importScripts("parser.js", "worker-utils.js");
```

`push()` on a stream is a different method that takes one chunk. `push()` and `unshift()` are never reported on `stream`, `this`, `this.stream`, `process.stdin`, `process.stdout` and `process.stderr`:

{/* good */}
```js
stream.push(header);
stream.push(body);
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `ignore` | `[]` | More `push()` and `unshift()` calls to allow, written the way they appear in the code, like `"readable.push"`. |

{/* bad */}
```js
readable.push(header);
readable.push(body);
```

{/* good {"options": [{"ignore": ["readable.push"]}]} */}
```js
readable.push(header);
readable.push(body);
```
