StefanMaron / BusinessCentral.LinterCop

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

LC0063 - false positive for global variable #688

Open pri-kise opened 2 months ago

pri-kise commented 2 months ago

If we add a global variable to a page then the rule shouldn't trigger. What i don't like is that the rule suggest DisplayName.

page 50000 "PTE API Dimension Values"
{
    APIGroup = 'projectapi';
    APIPublisher = 'defaultpublisher';
    APIVersion = 'v1.0';
    Caption = 'Dimension Values';
    ChangeTrackingAllowed = true;
    DelayedInsert = true;
    Editable = false;
    EntityCaption = 'Dimension Value';
    EntityName = 'dimensionValue';
    EntitySetCaption = 'Dimension Values';
    EntitySetName = 'dimensionValues';
    Extensible = false;
    ODataKeyFields = SystemId;
    PageType = API;
    SourceTable = "Dimension Value";

    layout
    {
        area(Content)
        {
            repeater(Lines)
            {
                Caption = 'Lines';
                ShowCaption = false;
                field(id; Rec.SystemId)
                {
                }
                field(dimensionCode; Rec."Dimension Code")
                {
                }
                field(dimensionName; DimensionGlobal.Name) // Wrong warning -> Or is this warnig really intended here?
                {
                }
                field("code"; Rec.Code)
                {
                }
                field(name; Rec.Name) // The warning here is correct for me.
                {
                }
                field(dimensionValueType; Rec."Dimension Value Type")
                {
                }
                field(blocked; Rec.Blocked)
                {
                }
            }
        }
    }
    var

        DimensionGlobal: Record Dimension;

    trigger OnAfterGetRecord()    begin
        if not DimensionGlobal.Get(Rec."Dimension Code") then
            DimensionGlobal.Init();
    end;
}
Arthurvdv commented 2 months ago

This is indeed a false positive, where the rule shouldn't be raised.

In the update pre-release version of the LinterCop v0.30.28 this should now been resolved.

Arthurvdv commented 1 month ago

The version v0.30.28 of the LinterCop is now the latest release. Could you verify if this is now working as expected? If this is the case, you may close this issue.