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

Naming of Dotnet variables Business Central AL Language Source Control #6457

Closed PortHH closed 2 years ago

PortHH commented 3 years ago

The naming of DotNet Variables on prem is very strange

example:

MyDateTime: DotNet MyDateTime; //AL(AA0072) Warning "System.DateTime": DotNet MyDateTime; //Not warning

As it seems wrong to me to declare the variable in this way ("System.DateTime"), I would give it the same name as the alias (MyDateTime).

dzzzb commented 3 years ago

This might explain what https://github.com/microsoft/AL/issues/6422 was trying to determine, i.e. what the AA0072 CodeCop currently considers a "valid" name for .Net objects.

GuillemPM commented 3 years ago

The only way to bypass the warning at the moment is by using the name of the assembly, it seems that the code analyzers don't use the alias as the expected name.

There is an extended example:

dotnet
{
    assembly(mscorlib)
    {
        type(System.DateTime; MyDateTime){}
    }
}

codeunit XXX MyCodeunit
{
    trigger OnRun()
    var
        MyDateTime: DotNet MyDateTime; //This is showing the AL(AA0072) Warning
        "System.DateTime": DotNet MyDateTime; //This is not showing any warning
    begin
    end;

}

I understand this is a bug, it is not critical but it should be corrected

dzzzb commented 3 years ago

Thanks for that info. I'd propose that #6422 be closed as a dupe of this, since this thread got the answer on what the current preferred naming rule is and what it should be instead.

JSebastianN commented 2 years ago

Agreed. This sucks image

Naming should follow the regular rules and not be special for DotNet

dzzzb commented 2 years ago

In that case I would just #pragma out the warning for sections of code using .Net variables, rather than follow the (accidental?) convention with protest ;-)

S-Keim commented 2 years ago

Hello dnpb,

can you please write a code sample, how to use #pragma to suppress the warning in a special region?

Thanks S-Keim

dzzzb commented 2 years ago
#pragma warning disable AA0072
// code for which you don't want / care about warnings here
#pragma warning restore AA0072
mazhelez commented 2 years ago

Thanks for reporting this issue. Sorry we haven’t completed it yet, but we’ve had to prioritize elsewhere. We’re planning to give the CodeCop engine and its rules an overhaul in a future major release. Thanks for your patience.

For this case consider using Pragma Warning Directive.