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) {};
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis

PREVIEWING: rtrieu/product-analytics-ui-changes