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

Perform verification on label length #5736

Closed nicolassaleron closed 2 years ago

nicolassaleron commented 4 years ago

Rules are currently checking if Text or Code variable/fields matches in length. We have warning when we assign a Text[250] to Code[20] for instance. This is not the case for Labels.

Title Rules are currently checking if Text or Code variable/fields matches in length. We have warning when we assign a Text[250] to Code[20] for instance. This is not the case for Labels..

Description Rules are currently checking if Text or Code variable/fields matches in length. We have warning when we assign a Text[250] to Code[20] for instance. This is not the case for Labels.

Reason for the rule When we translate a label, we do not have the full context. If the English version of the label might respect the length of all usages of the label, it happens that the translation can be longer. In that case, an runtime error occurs due to the translation. A new rule could warn us if the label is used in a context where the length should be limited. In that case, a warning should be raised if the MaxLength is not set or if the MaxLength is greater than the length of the assignment.

Bad code sample Example of what bad code the rule should catch:

procedure A()
var
  MsgLbl: Label 'Hello World'; // Hello World = 11 chars. If we translate it by 'Bonjour tout le monde !!!', a runtime error will occur.
begin
  LogMessage(MsgLbl);
end;

procedure LogMessage(Msg: Text[20])
begin
  //Do something with Msg
end;

Good code sample Example of what code should look like:

procedure A()
var
  MsgLbl: Label 'Hello World', MaxLength = 250;
begin
  LogMessage(MsgLbl);
end;

procedure LogMessage(Msg: Text[250])
begin
  //Do something with Msg
end;

Good and bad practices for fixing the rule ./.

Remarks ./.

dzzzb commented 3 years ago

Do you mean that, in the "Bad code sample", the translator should get an error about exceeding the length at the point of creating the XLIFF file? I don't see how AL itself can know that the translation will exceed the length.

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.