Skip to content

Commit d4eeaac

Browse files
Rule0092: Extend naming pattern validation (Captions, Fields, Groups, Actions, API Page Fields) (#1170)
* extend rule 0092 * fix test
1 parent deb0283 commit d4eeaac

13 files changed

Lines changed: 626 additions & 1 deletion

BusinessCentral.LinterCop.Test/Rule0092.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,23 @@ public void Setup()
3535
"variable.name" : {
3636
"allow.pattern": "^[A-Z][A-Za-z0-9]*$", // No special characters allowed & must start with upper case letter
3737
"disallow.pattern": "^A42.*", // variable and parameter names must not start with A42
38-
}
38+
},
39+
"caption.name" : {
40+
"allow.pattern": "^[A-Z][A-Za-z0-9]*$", // No special characters allowed & must start with upper case letter
41+
"disallow.pattern": "^A42.*", // caption must not start with A42
42+
},
43+
"field.name" : {
44+
"allow.pattern": "^[A-Z][A-Za-z0-9]*$", // No special characters allowed & must start with upper case letter
45+
"disallow.pattern": "^A42.*", // field name must not start with A42
46+
},
47+
"group.name" : {
48+
"allow.pattern": "^[A-Z][A-Za-z0-9]*$", // No special characters allowed & must start with upper case letter
49+
"disallow.pattern": "^A42.*", // group name must not start with A42
50+
},
51+
"action.name" : {
52+
"allow.pattern": "^[A-Z][A-Za-z0-9]*$", // No special characters allowed & must start with upper case letter
53+
"disallow.pattern": "^A42.*", // action name must not start with A42
54+
},
3955
}
4056
""");
4157

@@ -59,6 +75,11 @@ public void Cleanup()
5975
[TestCase("ReturnParameterWithSpecialCharacter")]
6076
[TestCase("VariableWithSpecialCharacter")]
6177
[TestCase("VariableWithDisallowPattern")]
78+
[TestCase("CaptionWithDisallowedChars")]
79+
[TestCase("FieldNamesWithSpecialCharacters")]
80+
[TestCase("ApiFieldWithSpecialCharacters")]
81+
[TestCase("InvalidGroupNames")]
82+
[TestCase("InvalidActionNames")]
6283
public async Task HasDiagnostic(string testCase)
6384
{
6485
var code = await File.ReadAllTextAsync(Path.Combine(_testCaseDir, "HasDiagnostic", $"{testCase}.al"))
@@ -73,6 +94,11 @@ public async Task HasDiagnostic(string testCase)
7394
[TestCase("GlobalProcedureWithoutLocalAllowPattern")]
7495
[TestCase("ObsoleteLowerCaseStart")]
7596
[TestCase("VariableNameWithoutSpecialCharacters")]
97+
[TestCase("CaptionWithoutSpecialCharacters")]
98+
[TestCase("FieldNamesWithoutSpecialCharacters")]
99+
[TestCase("ValidAPIFieldNames")]
100+
[TestCase("ValidGroupNames")]
101+
[TestCase("ValidActionNames")]
76102
public async Task NoDiagnostic(string testCase)
77103
{
78104
var code = await File.ReadAllTextAsync(Path.Combine(_testCaseDir, "NoDiagnostic", $"{testCase}.al"))
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
table 50100 "My Table"
2+
{
3+
Caption = 'MyTable';
4+
DataClassification = CustomerContent;
5+
6+
fields
7+
{
8+
field(1; "No."; Code[20]) { }
9+
field(2; Name; Text[100]) { }
10+
}
11+
12+
keys
13+
{
14+
key(PK; "No.") { Clustered = true; }
15+
}
16+
}
17+
18+
page 60101 "My Api Page Invalid"
19+
{
20+
PageType = API;
21+
SourceTable = "My Table";
22+
APIPublisher = 'contoso';
23+
APIGroup = 'test';
24+
APIVersion = 'v1.0';
25+
EntityName = 'myEntity2';
26+
EntitySetName = 'myEntities2';
27+
ODataKeyFields = SystemId;
28+
DelayedInsert = true;
29+
30+
layout
31+
{
32+
area(content)
33+
{
34+
repeater(Group)
35+
{
36+
field([|MyField|]; Name) { } // starts uppercase (invalid)
37+
field([|my_field|]; Name) { } // underscore (invalid)
38+
field([|MyField2|]; "No.") { } // starts uppercase (invalid)
39+
field([|my_field2|]; "No.") { } // underscore (invalid)
40+
}
41+
}
42+
}
43+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
table 50100 "My Table"
2+
{
3+
Caption = [|'My Table!!'|];
4+
DataClassification = CustomerContent;
5+
6+
fields
7+
{
8+
field(1; Test; Code[10])
9+
{
10+
Caption = [|'Test%'|];
11+
}
12+
field(2; Test2; Code[10])
13+
{
14+
Caption = [|'A42Test'|];
15+
}
16+
}
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
table 50102 "My Table"
2+
{
3+
Caption = 'MyTable';
4+
DataClassification = CustomerContent;
5+
6+
fields
7+
{
8+
field(1; [|testfield|]; Code[10]) // starts with lowercase, violates allow pattern
9+
{
10+
Caption = 'testfield';
11+
}
12+
field(2; [|A42Field|]; Code[10]) // starts with A42, violates disallow pattern
13+
{
14+
Caption = 'A42Field';
15+
}
16+
field(3; [|Field_With_Special|]; Code[10]) // contains underscore, violates allow pattern
17+
{
18+
Caption = 'Field_With_Special';
19+
}
20+
}
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
page 50101 MyPageInvalid
2+
{
3+
layout { }
4+
5+
actions
6+
{
7+
area(Processing)
8+
{
9+
action([|post|]) { } // violates allow (must start uppercase)
10+
action([|A42Run|]) { } // violates disallow (^A42)
11+
action([|Run_Action|]) { } // underscore not allowed
12+
}
13+
}
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
page 51001 GroupInvalid
2+
{
3+
layout
4+
{
5+
area(content)
6+
{
7+
group([|general|]) { } // lowercase start
8+
group([|A42Stuff|]) { } // disallow ^A42
9+
group([|Group_Test|]) { } // underscore
10+
}
11+
}
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
table 50100 "My Table"
2+
{
3+
Caption = [|'MyTable'|];
4+
DataClassification = CustomerContent;
5+
6+
fields
7+
{
8+
field(1; Test; Code[10])
9+
{
10+
Caption = [|'Test'|];
11+
}
12+
}
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
table 50101 "My Table"
2+
{
3+
Caption = 'MyTable';
4+
DataClassification = CustomerContent;
5+
6+
fields
7+
{
8+
field(1; [|TestField|]; Code[10])
9+
{
10+
Caption = 'TestField';
11+
}
12+
field(2; [|AnotherField2|]; Code[10])
13+
{
14+
Caption = 'AnotherField2';
15+
}
16+
}
17+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
table 50100 "My Table"
2+
{
3+
Caption = 'MyTable';
4+
DataClassification = CustomerContent;
5+
6+
fields
7+
{
8+
field(1; "No."; Code[20]) { }
9+
field(2; Name; Text[100]) { }
10+
}
11+
12+
keys
13+
{
14+
key(PK; "No.") { Clustered = true; }
15+
}
16+
}
17+
18+
page 60100 "My Api Page Valid"
19+
{
20+
PageType = API;
21+
SourceTable = "My Table";
22+
APIPublisher = 'contoso';
23+
APIGroup = 'test';
24+
APIVersion = 'v1.0';
25+
EntityName = 'myEntity';
26+
EntitySetName = 'myEntities';
27+
ODataKeyFields = SystemId;
28+
DelayedInsert = true;
29+
30+
layout
31+
{
32+
area(content)
33+
{
34+
repeater(Group)
35+
{
36+
field([|myfield|]; Name) { }
37+
field([|myField1|]; "No.") { }
38+
}
39+
}
40+
}
41+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
page 50100 MyPage
2+
{
3+
layout { }
4+
5+
actions
6+
{
7+
area(Processing)
8+
{
9+
action([|Post|]) { }
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)