sindresorhus/eslint-plugin-unicorn
Rule proposal: `arguments-length`
Closed
#1,998 opened on Nov 28, 2022
help wantednew rule
Repository metrics
- Stars
- (5,022 stars)
- PR merge metrics
- (Avg merge 1d 16h) (399 merged PRs in 30d)
Description
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.