Skip to content

Commit

Permalink
New Rule0075: Record Get Procedure Arguments (#826)
Browse files Browse the repository at this point in the history
* New Rule0075: Record Get Procedure Arguments
* Exclude AL version below 13.0
* Move GetTypeSymbol() to ArgumentExtension
* Remove conversion Integer to Enum
* Fix test
  • Loading branch information
Arthurvdv authored Dec 12, 2024
1 parent 591de91 commit 0528ed9
Show file tree
Hide file tree
Showing 33 changed files with 869 additions and 1 deletion.
62 changes: 62 additions & 0 deletions BusinessCentral.LinterCop.Test/Rule0075.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#if !LessThenSpring2024
namespace BusinessCentral.LinterCop.Test;

public class Rule0075
{
private string _testCaseDir = "";

[SetUp]
public void Setup()
{
_testCaseDir = Path.Combine(Directory.GetParent(Environment.CurrentDirectory)!.Parent!.Parent!.FullName,
"TestCases", "Rule0075");
}

[Test]
[TestCase("ImplicitConversiontCodeToEnum")]
[TestCase("ImplicitConversiontEnumToAnotherEnum")]
[TestCase("RecordGetGlobalVariable")]
[TestCase("RecordGetLocalVariable")]
[TestCase("RecordGetMethod")]
[TestCase("RecordGetParameter")]
[TestCase("RecordGetReportDataItem")]
[TestCase("RecordGetReturnValue")]
[TestCase("RecordGetSetupTableIncorrectArgumentsProvided")]
[TestCase("RecordGetSetupTableNoArgumentsProvided")]
[TestCase("RecordGetXmlPortTableElement")]
public async Task HasDiagnostic(string testCase)
{
var code = await File.ReadAllTextAsync(Path.Combine(_testCaseDir, "HasDiagnostic", $"{testCase}.al"))
.ConfigureAwait(false);

var fixture = RoslynFixtureFactory.Create<Rule0075RecordGetProcedureArguments>();
fixture.HasDiagnostic(code, Rule0075RecordGetProcedureArguments.DiagnosticDescriptors.Rule0075RecordGetProcedureArguments.Id);
}

[Test]
[TestCase("ImplicitConversiontIntegerToEnum")]
[TestCase("RecordGetBuiltInMethodRecordId")]
[TestCase("RecordGetFieldRecordId")]
[TestCase("RecordGetGlobalVariable")]
[TestCase("RecordGetLocalVariable")]
[TestCase("RecordGetLocalVariableRecordId")]
[TestCase("RecordGetMethod")]
[TestCase("RecordGetMethodRecordId")]
[TestCase("RecordGetParameter")]
[TestCase("RecordGetParameterRecordId")]
[TestCase("RecordGetReportDataItem")]
[TestCase("RecordGetReturnValue")]
[TestCase("RecordGetReturnValueRecordId")]
[TestCase("RecordGetSetupTableCorrectArgumentsProvided")]
[TestCase("RecordGetSetupTableNoArgumentsProvided")]
[TestCase("RecordGetXmlPortTableElement")]
public async Task NoDiagnostic(string testCase)
{
var code = await File.ReadAllTextAsync(Path.Combine(_testCaseDir, "NoDiagnostic", $"{testCase}.al"))
.ConfigureAwait(false);

var fixture = RoslynFixtureFactory.Create<Rule0075RecordGetProcedureArguments>();
fixture.NoDiagnosticAtMarker(code, Rule0075RecordGetProcedureArguments.DiagnosticDescriptors.Rule0075RecordGetProcedureArguments.Id);
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
SalesHeader: Record "Sales Header";
DocumentNo: Code[20];
begin
[|SalesHeader.Get(DocumentNo, DocumentNo)|];
end;
}

table 50100 "Sales Header"
{
fields
{
field(1; "Document Type"; Enum "Sales Document Type") { }
field(2; "No."; Code[20]) { }
}
keys
{
key(Key1; "Document Type", "No.") { }
}
}

enum 50100 "Sales Document Type" { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
SalesHeader: Record "Sales Header";
PurchaseDocumentType: Enum "Purchase Document Type";
DocumentNo: Code[20];
begin
[|SalesHeader.Get(PurchaseDocumentType, DocumentNo)|];
end;
}

table 50100 "Sales Header"
{
fields
{
field(1; "Document Type"; Enum "Sales Document Type") { }
field(2; "No."; Code[20]) { }
}
keys
{
key(Key1; "Document Type", "No.") { }
}
}

enum 50100 "Sales Document Type" { }
enum 50101 "Purchase Document Type" { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
codeunit 50100 MyCodeunit
{
var
ItemVariant: Record "Item Variant";

procedure MyProcedure()
begin
[|ItemVariant.Get('10000')|];
end;
}

table 50100 "Item Variant"
{
fields
{
field(1; "Code"; Code[10]) { }
field(2; "Item No."; Code[20]) { }
}
keys
{
key(Key1; "Item No.", "Code") { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
ItemVariant: Record "Item Variant";
begin
[|ItemVariant.Get('10000')|];
end;
}

table 50100 "Item Variant"
{
fields
{
field(1; "Code"; Code[10]) { }
field(2; "Item No."; Code[20]) { }
}
keys
{
key(Key1; "Item No.", "Code") { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
begin
[|RecordReturnValue().Get('10000')|];
end;

procedure RecordReturnValue() ItemVariant: Record "Item Variant"
begin
end;
}

table 50100 "Item Variant"
{
fields
{
field(1; "Code"; Code[10]) { }
field(2; "Item No."; Code[20]) { }
}
keys
{
key(Key1; "Item No.", "Code") { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure(var ItemVariant: Record "Item Variant")
begin
[|ItemVariant.Get('10000')|];
end;
}

table 50100 "Item Variant"
{
fields
{
field(1; "Code"; Code[10]) { }
field(2; "Item No."; Code[20]) { }
}
keys
{
key(Key1; "Item No.", "Code") { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
report 50100 MyReport
{
dataset
{
dataitem(ItemVariant; "Item Variant") { }
}

trigger OnPreReport()
begin
[|ItemVariant.Get('10000')|];
end;
}

table 50100 "Item Variant"
{
fields
{
field(1; "Code"; Code[10]) { }
field(2; "Item No."; Code[20]) { }
}
keys
{
key(Key1; "Item No.", "Code") { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure() ItemVariant: Record "Item Variant"
begin
[|ItemVariant.Get('10000')|];
end;
}

table 50100 "Item Variant"
{
fields
{
field(1; "Code"; Code[10]) { }
field(2; "Item No."; Code[20]) { }
}
keys
{
key(Key1; "Item No.", "Code") { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
CompanyInformation: Record "Company Information";
begin
[|CompanyInformation.Get('', 12345)|];
end;
}

table 79 "Company Information"
{
fields
{
field(1; "Primary Key"; Code[10]) { }
}

keys
{
key(Key1; "Primary Key") { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
ItemVariant: Record "Item Variant";
begin
[|ItemVariant.Get()|];
end;
}

table 50100 "Item Variant"
{
fields
{
field(1; "Code"; Code[10]) { }
field(2; "Item No."; Code[20]) { }
}
keys
{
key(Key1; "Item No.", "Code") { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
xmlport 50100 MyXmlport
{
schema
{
tableelement(ItemVariant; "Item Variant") { }
}

trigger OnPreXmlPort()
begin
[|ItemVariant.Get('10000')|];
end;
}

table 50100 "Item Variant"
{
fields
{
field(1; "Code"; Code[10]) { }
field(2; "Item No."; Code[20]) { }
}
keys
{
key(Key1; "Item No.", "Code") { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
SalesHeader: Record "Sales Header";
myInteger: Integer;
DocumentNo: Code[20];
begin
[|SalesHeader.Get("Sales Document Type".FromInteger(myInteger), DocumentNo)|];
end;
}

table 50100 "Sales Header"
{
fields
{
field(1; "Document Type"; Enum "Sales Document Type") { }
field(2; "No."; Code[20]) { }
}
keys
{
key(Key1; "Document Type", "No.") { }
}
}

enum 50100 "Sales Document Type" { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
ItemVariant: Record "Item Variant";
begin
[|ItemVariant.Get(ItemVariant.RecordId())|];
end;
}

table 50100 "Item Variant"
{
fields
{
field(1; "Code"; Code[10]) { }
field(2; "Item No."; Code[20]) { }
}
keys
{
key(Key1; "Item No.", "Code") { }
}
}
Loading

0 comments on commit 0528ed9

Please sign in to comment.