Using parameter "Cancel" (UsingCancelParameter)¶
Type | Scope | Severity | Activated by default |
Minutes to fix |
Tags |
---|---|---|---|---|---|
Code smell |
BSL OS |
Major |
Yes |
10 |
standard badpractice |
Description¶
In event handlers of object's modules, record sets, forms and etc. using parameter "Cancel" (for example BeforeWrite and etc.) it should not be assigned value "false".
This is due to the fact, that in code of event handlers the parameter "Cancel" can be set in several consecutive checks (or in several subscriptions on the same event). In this case, by the time the next check is performed, the Cancel parameter may already contain the True value, and you can erroneously reset it back to False.
In addition, with configuration improvements, the number of these checks may increase.
Examples¶
Incorrect¶
Procedure BeforeWrite(Cancel)
...
Cancel = CheckName();
...
EndProcedure
Correct¶
Procedure BeforeWrite(Cancel)
...
If CheckName() Then
Cancel = True;
EndIf;
...
EndProcedure
or
Cancel = Cancel or CheckName();
Sources¶
Snippets¶
Diagnostic ignorance in code¶
// BSLLS:UsingCancelParameter-off
// BSLLS:UsingCancelParameter-on
Parameter for config¶
"UsingCancelParameter": false