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

Disable ALxxx warnings with pragma not working #6702

Closed DavidFeldhoff closed 3 years ago

DavidFeldhoff commented 3 years ago

1. Describe the bug In reference to https://github.com/microsoft/AL/issues/6700

  1. Warning ALxxxx is set to error (default: warning)
    • I'll name these ALxxx cop in the following "Compiler" Cop
  2. Warning AAxxxx is set to error (default warning)
    • =CodeCop warning. But it's the same for UI Cop/PTE Cop/AppSource Cop

At the beginning of a file we disable all warnings with "pragma warning disable" If there are AA-Cop-Issues inside the file, the "pragma warning disable" disable all the warnings AND errors If there are AL-Cop-Issues inside the file, the "pragma warning disable" does NOT disable the errors. It only disables warnings. Esben said in the linked issue that it's by design, but I want to ask you to think about it a second time as it's

  1. inconsistent and
  2. in our scenario quite annoying: We do have a clone object of the base app temporarily as we are waiting for some "request for externals". But we don't want to fix all the warnings in the cloned objects. Instead, we simply want to add a "pragma warning disable" at the top of the file, so that if it's take more time for Microsoft to implement our requests for external, we can still update easily our cloned objects, as the files are not diverged due to fixed warnings. But currently we cannot do that. That means we are not able to set a cop rule from warning to error if ANY cloned file contains this warning. The only way we would have then, is that we have to fix the warnings and clutter the merge which makes it harder to get back to Msft Standard.

I don't see any reason why the "compiler cops" (ALxxxx) behave differently than the other cops (CodeCop etc.) and I even do not see a reason why the "pragma warning disable" should not disable warnings which were "updated" to errors.

2. To Reproduce Steps to reproduce the behavior:

  1. Add an al file
#pragma warning disable
codeunit 50100 "Test"
{
    Access = Internal;
    TableNo = Item;
    trigger OnRun()
    var
        Item: Record Item;
    begin
        Copy(Item);        //warning AL0604
        with Item do begin //warning AL0606 and AA0005
            Description := Format(CurrentDateTime());
        end;
    end;

}
  1. Add a ruleset
{
    "name": "Our ruleset",
    "description": "Some specific rules",
    "rules": [
        {
            "id": "AL0604",
            "action": "Error",
            "justification": "Use of implicit 'with' will be removed in the future. Qualify with 'Rec.'."
        },
        {
            "id": "AL0606",
            "action": "Error",
            "justification": "The 'with' statement is deprecated and will be removed for cloud development in a future release."
        },
        {
            "id": "AA0005",
            "action": "Error",
            "justification": "Only use BEGIN..END to enclose compound statements."
        }
    ]
}
  1. Set the settings
{
    "al.codeAnalyzers": [
        "${CodeCop}"
    ],
    "al.enableCodeAnalysis": true,
    "al.ruleSetPath": "ruleset.json"
}

3. Expected behavior The pragma warning disable disables the warnings and compiles the file successfully.

4. Actual behavior The file errors due to the AL warnings. If I fix the ALxxx cop issues, so that only the AA-Cop is left which is upgraded to an error as well, then the app compiles successfully as the AA-Error is suppressed.

5. Versions:

esbenk commented 3 years ago

Hi David,

I will take another look. They should behave the same.

DavidFeldhoff commented 3 years ago

Thanks Esben. Appreciate you're looking into it.

JesperSchulz commented 3 years ago

The fix for this issue has been checked in to the master branch. It will be available in the bcinsider.azurecr.io/bcsandbox-master Docker image starting from platform build number 27937 and VS Code Extension Version .

If you don’t have access to these images you need to become part of the Ready2Go program: aka.ms/readytogo

For more details on code branches and docker images please read: https://blogs.msdn.microsoft.com/nav/2018/05/03/al-developer-previews-multiple-releases-and-github/ https://freddysblog.com/2020/06/25/working-with-artifacts/