microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
744 stars 245 forks source link

Forbid numeric object numbers #6257

Open rdebath opened 3 years ago

rdebath commented 3 years ago

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);
bjarkihall commented 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.

dzzzb commented 3 years ago

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

bjarkihall commented 3 years ago

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