Skip to content

Initialization of method and constructor parameters by calling nested methods (NestedFunctionInParameters)

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

Parameters

Name Type Description Default value
allowOneliner Boolean Allow oneliner expression true
allowedMethodNames String Names of methods that are allowed to be used to initialize parameters НСтр,NStr,ПредопределенноеЗначение,PredefinedValue

Description

Similarly, it is not recommended to use nested calls of other functions or other parameterized constructors when initializing constructor parameters
.

At the same time, if the code with nested calls is compact (does not require the hyphenation of expressions) and is easy to read, then nested calls are acceptable.

Examples

Incorrect:

Attachments.Insert(  AttachedFile.Description,  New Picture(GetFromTempStorage(   AttachedFiles.GetFileData(AttachedFile.Ref).RefToFileBinaryData)));

It is correct to break such calls into separate operators using additional local variables:

FileImageHRef = AttachedFiles.GetFileData(AttachedFile.Ref).RefToFileBinaryData; PictureData = New Picture(GetFromTempStorage(FileImageHRef)); Attachments.Insert(AttachedFile.Description, PictureData);

Sources

Snippets

Diagnostic ignorance in code

// BSLLS:NestedFunctionInParameters-off
// BSLLS:NestedFunctionInParameters-on

Parameter for config

"NestedFunctionInParameters": {
    "allowOneliner": true,
    "allowedMethodNames": "НСтр,NStr,ПредопределенноеЗначение,PredefinedValue"
}