Enforce a maximum number of parameters in a function

이 페이지는 아직 영어로 제공되지 않습니다. 번역 작업 중입니다.
현재 번역 프로젝트에 대한 질문이나 피드백이 있으신 경우 언제든지 연락주시기 바랍니다.

Metadata

ID: javascript-code-style/max-params

Language: JavaScript

Severity: Notice

Category: Code Style

Description

Having too many parameters can make your code hard to read. The parameters must be used in appropriate order. Forgetting the order of parameters can cause mistakes.

Too many parameters is a code smell. You should refactor your code in smaller reusable bits. While it may be valid to require more than four parameters, you should use object destructuring.

Arguments

  • max-params: Maximum number of parameters. Default: 4.

Non-Compliant Code Examples

function test(a, b, c, d, e) {}
var test = function(a, b, c, d, e, f) {};
var test = (a, b, c, d, e) => {};
(function(a, b, c, d, e) {});

// object property options
function test(a, b, c, d, e) {}

Compliant Code Examples

function test(d, e, f) {}
var test = function(a, b, c) {};
var test = (a, b, c) => {};
var test = function test(a, b, c) {};

// object property options
var test = function(a, b, c) {};
PREVIEWING: aliciascott/DOCS-9725-Cloudcraft