StefanMaron / BusinessCentral.LinterCop

Community driven code linter for AL (MS Dynamics 365 Business Central)
https://stefanmaron.com
MIT License
72 stars 29 forks source link

AD0001 in specific app.json #682

Closed Arthurvdv closed 1 month ago

Arthurvdv commented 1 month ago

Discussed in https://github.com/StefanMaron/BusinessCentral.LinterCop/discussions/680

Originally posted by **SorenBogelund-ECIT** July 8, 2024 I have an issue with a specific app.json in a specific repository. The issue does not appear in other app.json files. For some reason 10 warnings are generated for no reason? ![image](https://github.com/StefanMaron/BusinessCentral.LinterCop/assets/169046245/8c486e3f-66fb-4c3a-b3e7-37464f42557e)
Arthurvdv commented 1 month ago

@SorenBogelund-ECIT, thank you for reporting this error. Not sure what's causing this at the moment, but I've added an check in the pre-release version of the LinterCop to identify the line of code responsible for this exception.

Could you switch to the pre-release version of the LinterCop look for a LC0000 diagnostic? Would be great if you could share a small code example so I could investigate this.

image

Arthurvdv commented 1 month ago

@SorenBogelund-ECIT, did you by any chance had the time to look into this?

SorenBogelund-ECIT commented 1 month ago

Hi Arthur

Do you mean like this?:

image

Arthurvdv commented 1 month ago

I believe this needs to be a User Setting I've never try'ed as a workspace-setting, so not sure if this works.

image

After setting this, you need to close all(!) VS Code windows and after that opening the AL project it will download the pre-release version of the LinterCop, where you should no longer have the error on the app.json, but on the specific line in the AL file.

You could also manually grab the BusinessCentral.LinterCop.dll file from the releases and override this in the %userprofile%\.vscode\extensions\ms-dynamics-smb.al-13.1.1065068\bin\Analyzers folder. It should be the pre-release version v0.30.28 of the LinterCop.

image

SorenBogelund-ECIT commented 1 month ago

I have done both of your suggestions:

image image

And now I get new errors: image

Arthurvdv commented 1 month ago

@SorenBogelund-ECIT , thank you for providing these, this was exactly the information what I was looking for.

This should now be resolved in the (pre)release version of v0.30.28 of the LinterCop, where the error shouldn't occur anymore.

For now the LC0027 diagnostic will not be raised for this example, where I believe it should. If these are the pages are the same as the 'LookupPageId' of the entity (Table) itself, you can replace the case statement with one single line. I'll create a separate issue to look if we can the LC0027 rule to also show an diagnostic on this scenario.

EDIT: This example below isn't right I release now, sorry. This will show the ListPage of the entity with probably one single record with your example. I didn't pay attention that you're referring to the CardPage, where the Page Management codeunit defaults to the LookupPageId, which mostly returns the ListPage.

    local procedure HandleError(MyErrorInfo: ErrorInfo)
    var
        PageManagement: Codeunit "Page Management";
        RecRelatedVariant: Variant;
    begin
        RecRelatedVariant := MyErrorInfo.RecordId.GetRecord();

        // case MyErrorInfo.TableId of
        //     Database::Resource:
        //         Page.Run(Page::"Resource Card", RecRelatedVariant);
        //     Database::"Allocation Account":
        //         Page.Run(Page::"Allocation Account", RecRelatedVariant);
        //     Database::"Item Charge":
        //         Page.Run(Page::"Item Charges", RecRelatedVariant);
        //     Database::"G/L Account":
        //         Page.Run(Page::"G/L Account Card", RecRelatedVariant);
        // end;
        PageManagement.PageRun(RecRelatedVariant);
    end;
SorenBogelund-ECIT commented 1 month ago

Hi Arthur

It looks like, you are right, no errors:

image

Thank for the tip about the Page Management codeunit. :)

Arthurvdv commented 1 month ago

The version v0.30.28 of the LinterCop is now the latest release.