BSL019 - Cyclomatic complexity¶
Summary¶
Cyclomatic complexity
Identifiers¶
| Field | Value |
|---|---|
| Rule code | BSL019 |
| Compatible alias | CyclomaticComplexity |
| Severity | WARNING |
| Without configuration | Yes |
BSLLS JSON, ON mode without overrides |
Yes |
Registry flag implemented |
Yes |
| Tags | brain-overload, complexity |
The implemented flag describes the registry; it does not certify verified BSLLS parity.
Behavior¶
- The public identifier
BSL019and aliasCyclomaticComplexityare 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: BSL019
// code without this diagnostic
// noqa-enable: BSL019
// bsl-disable: BSL019
// code without this diagnostic
// bsl-enable: BSL019
// BSLLS:CyclomaticComplexity-off
// code without this diagnostic
// BSLLS:CyclomaticComplexity-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¶
Module-body complexity is summed across all executable blocks outside methods.
When the threshold is exceeded, one body diagnostic points to the first
executable token, skipping variable declarations and region directives.
Method complexity is calculated separately.
The initial method complexity is 1; the initial module-body complexity is 0.
Cyclomatic complexity of the program code is one of the oldest metrics, it was first mentioned by Thomas McCab in 1976. Cyclomatic complexity shows the minimum number of required tests. The most effective way to reduce cyclomatic complexity is to decompose the code, split the methods into simpler ones, and also optimize logical expressions.
Cyclomatic complexity increases by 1 for each of following constructions
For ... To .. DoFor each ... Of ... DoIf ... ThenElsIf ... ThenElseTry ... Except ... EndTryGoTo ~Label- Binary operations
AND ... OR - Ternary operator
ProcedureFunction
Examples¶
Function ServerModuleManager(Name) // 1
ObjectFounded = False; // 0
// 0
NameParts = StrSplit(Name, "."); // 0
If NameParts.Count() = 2 Then // 1
// 0
TypeName = Upper(NameParts[0]); // 0
ObjectName = NameParts[1]; // 0
// 0
If TypeName = Upper("Constants") Then // 1
If Metadata.Constants.Find(ObjectName) <> Undefined Then // 1
ObjectFounded = True; // 0
EndIf; // 0
ElsIf TypeName = Upper("InformationRegisters") Then // 1
If Metadata.InformationRegisters.Find(ObjectName) <> Undefined Then // 1
ObjectFounded = True; // 0
EndIf; // 0
Else // 1
ObjectFounded = False; // 0
EndIf; // 0
EndIf; // 0
// 0
If Not ObjectFounded Then // 1
Raise СтроковыеФункцииКлиентСервер.ПодставитьПараметрыВСтроку( // 0
НСтр("ru = 'Объект метаданных ""%1"" не найден, // 0
|либо для него не поддерживается получение модуля менеджера.'"), // 0
Name); // 0
EndIf; // 0
SetSafeMode(True); // 0
Module = Eval(Name); // 0
F = ?(SomeCondition1, True, Undefined); // 1
А = ?(SomeCondition1, True, ?(SomeCondition2, False, Undefined)); // 2
M = True Or 7; // 1
Return Module; // 0
EndFunction // Total 12