Skip to content

BSL015 — Limit number of optional parameters in method

Summary

Limit number of optional parameters in method

Identifiers

Field Value
Rule code BSL015
Compatible alias NumberOfOptionalParams
Severity WARNING
Enabled by default Yes
Implemented Yes
Tags design, brain-overload

Behavior

  • The public identifier BSL015 and alias NumberOfOptionalParams are stable.
  • The rule reports the cases documented on this page.
  • Suppressions and project configuration are applied before publication.
  • The rule requires neither an external analyzer nor network access.

Configuration and suppression

BSL### is the primary stable identifier. The compatible alias is accepted in select, ignore, and compatible block suppression comments.

[tool.onec-hbk-bsl]
select = ["BSL015"]
ignore = ["NumberOfOptionalParams"]

All three suppression families support both a current line and a range. When an opening comment follows code, it affects only that line. Use any one form:

  • noqa:
Value = "example";  // noqa: BSL015
  • bsl-disable:
Value = "example";  // bsl-disable: BSL015
  • compatible BSLLS form:
Value = "example";  // BSLLS:NumberOfOptionalParams-off

When the same opening comment is on a line by itself, it starts a range. Close it with the matching marker from the same family:

// noqa: BSL015
// code without this diagnostic
// noqa-enable: BSL015

// bsl-disable: BSL015
// code without this diagnostic
// bsl-enable: BSL015

// BSLLS:NumberOfOptionalParams-off
// code without this diagnostic
// BSLLS:NumberOfOptionalParams-on

To disable the rule until the end of the file, omit the closing noqa-enable, bsl-enable, or BSLLS:…-on marker.

Opening and closing markers must belong to the same family.

Description

It is not recommended to declare many parameters in functions (best practice to use not more than seven parameters). Meanwhile there should not be many parameters with default values set (best practice to have not more than three such parameters). Otherwise code readability decreases. For example it is easy to make a mistake in number of commas passing optional parameters. If need to pass many parameters to a function, it is recommended to group same-type parameters into one or more composite parameters of type Structure.

Examples

Incorrect:

// Create an item in catalog "Goods"
Procedure CreateSKU(Name, Goods, Units, Weight, Check = True)
// ...
EndProcedure

Correct: Group parameters, having goods item properties into Structure Values.

// Create item in catalog "Goods"
Procedure CreateNewGoods(Values, Check = True)
EndProcedure

Sources