BSL225 — Limit on the number of property values passed to the structure constructor¶
Summary¶
Limit on the number of property values passed to the structure constructor
Identifiers¶
| Field | Value |
|---|---|
| Rule code | BSL225 |
| Compatible alias | NumberOfValuesInStructureConstructor |
| Severity | INFORMATION |
| Enabled by default | Yes |
| Implemented | Yes |
| Tags | design, readability |
Behavior¶
- The public identifier
BSL225and aliasNumberOfValuesInStructureConstructorare 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.
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:
bsl-disable:
- compatible
BSLLSform:
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: BSL225
// code without this diagnostic
// noqa-enable: BSL225
// bsl-disable: BSL225
// code without this diagnostic
// bsl-enable: BSL225
// BSLLS:NumberOfValuesInStructureConstructor-off
// code without this diagnostic
// BSLLS:NumberOfValuesInStructureConstructor-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¶
When creating an object of type Structure it is not recommended to pass more than 3 property values to the constructor. Instead, it is recommended to use the Insert method or assign values to properties explicitly
Examples¶
Incorrect:
Parameters = New Structure(
"UseParam1,
|UseParam2,
|UseParam3,
|UseParam4,
|UseParam5,
|DataAddress,
|SettingsAddress,
|UUID,
|Description",
True,
True,
True,
True,
True,
Current.DataAddress,
?(Current.DataAddress <> Undefined,
Current.DataAddress,
EmptyAddress()),
UUID,
Description));
Correct:
Parameters = New Structure;
Parameters.Insert("UseParam1", True);
Parameters.Insert("UseParam2", True);
Parameters.Insert("UseParam3", True);
Parameters.Insert("UseParam4", True);
Parameters.Insert("UseParam5", True);
Parameters.Insert("DataAddress", Current.DataAddress);
Parameters.Insert("SettingsAddress", ?(Current.DataAddress <> Undefined,
Current.DataAddress,
EmptyAddress));
Parameters.Insert("UUID ", UUID);
Parameters.Insert("Description", Description);