Rule suggestions from recent and future additions to Companial Cop #776
Replies: 4 comments 2 replies
-
These all look very good! |
Beta Was this translation helpful? Give feedback.
-
It feels like it's almost Christmas, because these would be great gifts! 🫡
Option data type is not allowed (2) procedure ExampleA()
var
ReservationMgt: Codeunit "Reservation Management";
Mode: Option "None","Allow deletion",Match;
begin
ReservationMgt.SetReservSource(Rec);
ReservationMgt.SetItemTrackingHandling(Mode::"Allow deletion");
ReservationMgt.DeleteReservEntries(true, 0);
end; procedure ExampleB()
var
ReservationMgt: Codeunit "Reservation Management";
begin
ReservationMgt.SetReservSource(Rec);
ReservationMgt.SetItemTrackingHandling(1);
ReservationMgt.DeleteReservEntries(true, 0);
end; |
Beta Was this translation helpful? Give feedback.
-
Please don't forget that one can get a record using it's recordid as well. |
Beta Was this translation helpful? Give feedback.
-
Test cases: local procedure TestRecordGetLocalVariable()
var
ItemVariant: Record "Item Variant";
begin
// Warning
ItemVariant.Get('10000');
end;
local procedure TestRecordGetLocalVariableNoWarning()
var
ItemVariant: Record "Item Variant";
begin
// NO warning
ItemVariant.Get('10000', 'VARIANTCODE');
end;
local procedure TestRecordGetParameter(var ItemVariant: Record "Item Variant")
begin
// Warning
ItemVariant.Get('10000');
end;
local procedure TestRecordGetReturnValue() ItemVariant: Record "Item Variant"
begin
// Warning
ItemVariant.Get('10000');
end;
local procedure TestRecordGetMethod()
begin
// Warning
TestRecordGetReturnValue().Get('10000');
end;
local procedure TestRecordGetReportDataItem()
begin
// Warning
InvLineDataItem.Get('10000');
end;
local procedure TestRecordGetXmlPortTableElement()
begin
// Warning
InvLineXmlPortTableElement.Get('10000');
end;
local procedure TestRecordGetSetupTableNoArgumentsProvided()
var
CompanyInformation: Record "Company Information";
begin
// NO warning
CompanyInformation.Get();
end;
local procedure TestRecordGetSetupTableCorrectArgumentsProvided()
var
CompanyInformation: Record "Company Information";
begin
// NO warning
CompanyInformation.Get('');
end;
local procedure TestRecordGetSetupTableIncorrectArgumentsProvided()
var
CompanyInformation: Record "Company Information";
begin
// Warning
CompanyInformation.Get('', 12345);
end;
local procedure TestRecordGetLocalVariableRecordID()
var
ItemVariant: Record "Item Variant";
MyRecordId: RecordId;
begin
// NO warning
ItemVariant.Get(MyRecordId);
end;
local procedure TestRecordGetParameterRecordID(MyRecordId: RecordId)
var
ItemVariant: Record "Item Variant";
begin
// NO warning
ItemVariant.Get(MyRecordId);
end;
local procedure TestRecordGetReturnValueRecordID() MyRecordId: RecordId
var
ItemVariant: Record "Item Variant";
begin
// NO warning
ItemVariant.Get(MyRecordId);
end;
local procedure TestRecordGetMethodRecordID()
var
ItemVariant: Record "Item Variant";
begin
// NO warning
ItemVariant.Get(TestRecordGetReturnValueRecordID());
end;
local procedure TestRecordGetBuiltInMethodRecordID()
var
ItemVariant: Record "Item Variant";
begin
// NO warning
ItemVariant.Get(ItemVariant.RecordId());
end;
local procedure TestRecordGetFieldRecordID()
var
ApprovalEntry: Record "Approval Entry";
begin
// NO warning
ApprovalEntry.Get(ApprovalEntry."Record ID to Approve");
end; |
Beta Was this translation helpful? Give feedback.
-
Hey,
about a year ago I did a similar post where I described a couple of rules that we have implemented internally that I think could be interesting for the wider community. I think it's time for another batch :D
I'll list them down, and for the interesting ones I can later create a pull request
When using Get, the values provided must match the values required by the table key
A rule to catch.Get() with too few, or wrong parameters. It ignores Get with 0 parameters which are usually used for setups.
Option data type is not allowed
Self-explanatory. Everything should be an enum.
DataClassification and ApplicationArea Property already exists on the object level
Checks for properties on the object and field level, if a duplicate property is found, a warning is thrown.
Redundant Editable property
Checks for Editable property defined on a field, when Editable property has been defined on the object or the base object in case of Extension objects. If the base object is not editable, the properties on fields are redundant.
The field assigned in the TableRelation is longer than the field being assigned to
This one is to prevent runtime issues where a field of length 10, has a table relation to a field of length 20 for example.
Event publishers must be local
Keeping publishers local gives you the benefit of freely extending the parameters with additional fields without causing a breaking change.
IsEmpty and Count should have parenthesis specified
For some reason, these two functions are not covered by the default warning and we wanted to have consistency
Temporary records should not trigger the table triggers
In most cases, running the triggers on the Temp table will cause issues, as the code might read/insert/modify/delete data that's no longer temporary.
(Future) Throw a warning for redundant using directives
Not yet implemented. Check for "using" directives that are not needed in the object.
(Future) Check for "This"
Not yet implemented. The default rule AA0248 checks that both global variables and local procedures are prefixed with "this". We find it useful on global variables, but not on local procedures, so we want to implement the same rule, but split the rule IDs, so we can silence one, but keep the other.
(Future) Enums with 0 value need to have InitValue on fields
Not yet implemented. If Enum does not have a 0 value, is used on a field, and doesn't have InitValue, then when Initializing a record, you don't have valid data in the field, unless later specify it.
Beta Was this translation helpful? Give feedback.
All reactions