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

LC0067 - false positve for Journal Template Tables #710

Open pri-kise opened 1 month ago

pri-kise commented 1 month ago

I receive the warning The NotBlank property should be set to false (or removed) if a TableRelation of 'No. Series' is present on the table.for a Journal Template table.

The table has a similiar structure like the Job Journal Template.

a primary key

        field(1; Name; Code[10])
        {
            Caption = 'Name';
            NotBlank = true;
        }

and a "No. Series" field.

        field(16; "No. Series"; Code[20])
        {
            Caption = 'No. Series';
            TableRelation = "No. Series";

            trigger OnValidate()
            begin
                if "No. Series" <> '' then begin
                    if Recurring then
                        Error(
                          Text000,
                          FieldCaption("Posting No. Series"));
                    if "No. Series" = "Posting No. Series" then
                        "Posting No. Series" := '';
                end;
            end;
        }

I can use a pragma for this table but I wanted to track this false positive issue

Arthurvdv commented 1 month ago

You're right, in this scenario the rule shouldn't be raised.

Some thoughts here

@janvtBE Do you maybe have some idea's on howto prevent these false positives?

janvtBE commented 1 month ago

@Arthurvdv instead of "only raise rule when FieldName equals No.", maybe turn it around: don't raise the rule when FieldName equals "Name". Because you can also have "Code" as PK field, or maybe another value and in those cases the rule must raise.

Arthurvdv commented 1 month ago

Good idea @janvtBE, hopefully this will be enough to prevent other false positives.

@pri-kise the updated pre-release should now no longer raise this false positive.