Skip to content

Latest commit

 

History

History
76 lines (56 loc) · 1.98 KB

IfConditionComplexity.md

File metadata and controls

76 lines (56 loc) · 1.98 KB

Usage of complex expressions in the "If" condition (IfConditionComplexity)

Type Scope Severity Activated
by default
Minutes
to fix
Tags
Code smell BSL
OS
Minor Yes 5 brainoverload

Parameters

Name Type Description Default value
maxIfConditionComplexity Integer Acceptable number of logical expressions in operator If condition 3

Description

Complex expressions (with more than 3 boolean constructs) must be extracted to separated method or variable.

Examples

Bad:

If Id = "Expr1"
    Or Id = "Expr2"
    Or Id = "Expr3"
    Or Id = "Expr4"
    Or Id = "Expr5"
    Or Id = "Expr6"
    Or Id = "Expr7"
    Or Id = "Expr8"
    Or Id = "Expr9" Then

   doSomeWork();

EndIf; 

Good:

If IsCorrectId(Id) Then
   doSomeWork();
КонецЕсли;

Function IsCorrectId(Id)

    Return Id = "Expr1"
            Or Id = "Expr2"
            Or Id = "Expr3"
            Or Id = "Expr4"
            Or Id = "Expr5"
            Or Id = "Expr6"
            Or Id = "Expr7"
            Or Id = "Expr8"
            Or Id = "Expr9";

EndFunction

Snippets

Diagnostic ignorance in code

// BSLLS:IfConditionComplexity-off
// BSLLS:IfConditionComplexity-on

Parameter for config

"IfConditionComplexity": {
    "maxIfConditionComplexity": 3
}