Skip to content

Latest commit

 

History

History
80 lines (59 loc) · 2.01 KB

prefer-single-call.md

File metadata and controls

80 lines (59 loc) · 2.01 KB

Enforce combining multiple Array#push(), Element#classList.{add,remove}(), and importScripts() into one call

💼 This rule is enabled in the ✅ recommended config.

🔧💡 This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.

Array#push(), Element#classList.add(), Element#classList.remove(), and importScripts accepts multiple arguments. Multiple calls should be combined into one.

Examples

// ❌
foo.push(1);
foo.push(2, 3);

// ✅
foo.push(1, 2, 3);
// ❌
element.classList.add('foo');
element.classList.add('bar', 'baz');

// ✅
element.classList.add('foo', 'bar', 'baz');
// ❌
importScripts("https://example.com/foo.js");
importScripts("https://example.com/bar.js");

// ✅
importScripts(
	"https://example.com/foo.js",
	"https://example.com/bar.js",
);

Options

Type: object

ignore

Type: string[]

Functions to ignore.

stream.push, this.push, and this.stream.push are ignored by default.

Example:

{
	'unicorn/prefer-single-call': [
		'error',
		{
			ignore: [
				'readable.push',
				'foo.stream.push'
			]
		}
	]
}
// eslint unicorn/prefer-single-call: ["error", {"ignore": ["readable"]}]
import {Readable} from 'node:stream';

const readable = new Readable();
readable.push('one');
readable.push('another');
readable.push(null);