sindresorhus/eslint-plugin-unicorn

Rule proposal: `call-arguments-length`

Closed

#1,356 opened on Jun 15, 2021

 (5 comments) (2 reactions) (0 assignees)JavaScript (468 forks)user submission
help wantednew rule

Repository metrics

Stars
 (5,022 stars)
PR merge metrics
 (Avg merge 1d 16h) (399 merged PRs in 30d)

Description

A generic rule to enforce correct call arguments length.

For example CanvasRenderingContext2D.drawImage() can config as {'*.drawImage': [3, 5, 9]}, so it must be called with 3 or 5 or 9 arguments.

// Fail
context.drawImage(image, dx);
context.drawImage(image, dx, dy, dWidth, );

// Pass
context.drawImage(image, dx, dy);

This rule accepts a configurable list, for each method of function, value can be a number or a range, or allowed lengths.

{
	rules: {
		'unicorn/call-arguments-length':[
			'error',
			{
				'parseInt': 2,
				'*.drawImage': [3, 5, 9],
				'*.addEventListener': {min: 2}
			}
		]
	}
}

Ref: https://github.com/sindresorhus/eslint-plugin-unicorn/issues/974#issuecomment-768746222

Contributor guide