sindresorhus/eslint-plugin-unicorn

Rule proposal: `arguments-length`

クローズ

#1,998 opened on 2022/11/28

 (5 件のコメント) (4 件のリアクション) (0 人の担当者)JavaScript (468 件のフォーク)user submission
help wantednew rule

Repository metrics

Stars
 (5,022 個のスター)
PR merge metrics
 (平均マージ 1d 16h) (30d で 399 merged PRs)

説明

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.

コントリビューターガイド