sindresorhus/eslint-plugin-unicorn

Rule proposal: `arguments-length`

Chiusa

#1998 aperta il 28 nov 2022

 (5 commenti) (4 reazioni) (0 assegnatari)JavaScript (468 fork)user submission
help wantednew rule

Metriche repository

Star
 (5022 stelle)
Metriche merge PR
 (Merge medio 1g 16h) (399 PR mergiate in 30 g)

Descrizione

Description

A common source of bugs during refactoring is when functions are called with less or more arguments than they expect. Prior art includes sonarjs/no-extra-arguments, but I would like to see a more strict version that also triggers on too few arguments.

Fail

const fn = (a, b) => a + b;
fn(1); // Expected 2 function arguments, but got 1
const fn = (a, b) => a + b;
fn(1, 2, 3); // Expected 2 function arguments, but got 3

Pass

const fn = (a, b) => a + b;
fn(1, 2);

Additional Info

Unlike sonarjs/no-extra-arguments, I'd not make a exception for arguments because such usage should be replaced with spread syntax.

Guida contributor