The function always returns the same primitive value (FunctionReturnsSamePrimitive)¶
Type | Scope | Severity | Activated by default |
Minutes to fix |
Tags |
---|---|---|---|---|---|
Error |
BSL OS |
Major |
Yes |
5 |
design badpractice |
Parameters¶
Name | Type | Description | Default value |
---|---|---|---|
skipAttachable |
Boolean |
Ignore attachable methods |
true |
caseSensitiveForString |
Boolean |
Case sensitive for strings |
false |
Description¶
A function should not return the same primitive value. If the result of the function isn't use into code, then you need the function rewrite to the procedure.
Examples¶
Bad:
Function CheckString(Val RowTable)
If ItsGoodString(RowTable) Then
ActionGood();
Return True;
ElsIf ItsNodBadString(RowTable) Then
ActionNoBad();
Return True;
Else
Return True;
EndIf;
EndFunction
Good:
Function CheckString(Val RowTable)
If ItsGoodString(RowTable) Then
ActionGood();
ElsIf ItsNodBadString(RowTable) Then
ActionNoBad();
Else
ActionElse();
EndIf;
EndFunction
Nuances¶
Attachable functions excluded from the scan. Example:
Function Attachable_RandomAction(Command)
If ValueIsFilled(CurrentDate) Then
Return Undefined;
EndIf;
Return Undefined;
EndFunction
Sources¶
Snippets¶
Diagnostic ignorance in code¶
// BSLLS:FunctionReturnsSamePrimitive-off
// BSLLS:FunctionReturnsSamePrimitive-on
Parameter for config¶
"FunctionReturnsSamePrimitive": {
"skipAttachable": true,
"caseSensitiveForString": false
}