Skip to content

Latest commit

 

History

History
70 lines (51 loc) · 1.4 KB

no-array-push-push.md

File metadata and controls

70 lines (51 loc) · 1.4 KB

Enforce combining multiple Array#push() 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() accepts multiple arguments. Multiple calls should be combined into one.

Fail

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

Pass

foo.push(1, 2, 3);
const length = foo.push(1);
foo.push(2);
foo.push(1);
bar();
foo.push(2);

Options

Type: object

ignore

Type: string[]

Ignore objects, stream, this, this.stream are ignored by default.

Example:

{
	'unicorn/no-array-push-push': [
		'error',
		{
			ignore: [
				'readable',
				'foo.stream'
			]
		}
	]
}
// eslint unicorn/no-array-push-push: ["error", {"ignore": ["readable"]}]
const {Readable} = require('stream');

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