Open rdebath opened 3 years ago
Yes, that would be great, as long as it's a CodeCop and not required, since these should also be able to accept an integer since some patterns depend on that feature for dynamic Codeunit running.
Yes, but then that would be a variable Integer
, not a constant/literal, which is the subject of the OP.
Ah, didn't notice that, then it makes total sense. :)
Title Forbid explicit numeric object numbers
Description Explicit object numbers can be used when calling
RUN
andRUNMODAL
. Please generate a Codecop warning when this value is a literal numeric value like80
and instead suggest something likeCodeunit:"Sales Post"
. The autofix should provide the correct substitution for the number in theCodeunit.Run(80, SalesHeader)
statement.This should apply to all
ObjectType.RUN
methods,ObjectType.RUNMODAL
methods and Event subscriptions.Reason for the rule When object numbers are used unless, like me :grin:, you have perfect recall of these numbers from years of practice it's very unclear which objects they actually are.
In addition, renumbering objects in an extension can be almost trivial (three regular expressions), use of literal object numbers can defeat that.
Bad code sample Example of what bad code the rule should catch:
Good code sample Example of what code should look like: