AL icon indicating copy to clipboard operation
AL copied to clipboard

Forbid numeric object numbers

Open rdebath opened this issue 5 years ago • 3 comments

Title Forbid explicit numeric object numbers

Description Explicit object numbers can be used when calling RUN and RUNMODAL. Please generate a Codecop warning when this value is a literal numeric value like 80 and instead suggest something like Codeunit:"Sales Post". The autofix should provide the correct substitution for the number in the Codeunit.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:

page.run(130, SalesShptHdr);

Good code sample Example of what code should look like:

Page.Run(Page::"Posted Sales Shipment", SalesShptHdr);

rdebath avatar Oct 28 '20 10:10 rdebath

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.

bjarkihall avatar Oct 28 '20 15:10 bjarkihall

Yes, but then that would be a variable Integer, not a constant/literal, which is the subject of the OP.

dzzzb avatar Oct 28 '20 15:10 dzzzb

Ah, didn't notice that, then it makes total sense. :)

bjarkihall avatar Oct 28 '20 15:10 bjarkihall