Skip to content

Commit

Permalink
Handle trailing comments (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthurvdv authored Jan 7, 2025
1 parent bd3e29e commit 655949a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
7 changes: 5 additions & 2 deletions BusinessCentral.LinterCop.Test/Rule0017.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public async Task HasDiagnostic(string testCase)
}

[Test]
[TestCase("Assignment")]
[TestCase("Validate")]
[TestCase("AssignmentWithLeadingComment")]
[TestCase("AssignmentWithTrailingComment")]
[TestCase("ValidateWithLeadingComment")]
//TODO: The HasExplainingComment method in the Rule0017WriteToFlowField class doesn't support this scenario currently
// [TestCase("ValidateWithTrailingComment")]
public async Task NoDiagnostic(string testCase)
{
var code = await File.ReadAllTextAsync(Path.Combine(_testCaseDir, "NoDiagnostic", $"{testCase}.al"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
table 50100 MyTable
{
fields
{
field(1; MyField; Integer) { }
field(2; MyField2; Boolean)
{
FieldClass = FlowField;
}
}

procedure MyProcedure();
begin
[|Rec.MyField2|] := false; // Comment
end;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

table 50100 MyTable
{
fields
{
field(1; MyField; Integer) { }
field(2; MyField2; Boolean)
{
FieldClass = FlowField;
}
}

procedure MyProcedure();
begin
Rec.Validate([|MyField2|], false); // Comment
end;
}
3 changes: 2 additions & 1 deletion BusinessCentral.LinterCop/Design/Rule0017WriteToFlowField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ operation.Target is ITextIndexAccess textIndexAccess &&
}

private bool HasExplainingComment(IOperation operation) =>
operation.Syntax.GetLeadingTrivia().Any(trivia => trivia.IsKind(SyntaxKind.LineCommentTrivia));
operation.Syntax.GetLeadingTrivia().Any(trivia => trivia.IsKind(SyntaxKind.LineCommentTrivia)) ||
operation.Syntax.GetTrailingTrivia().Any(trivia => trivia.IsKind(SyntaxKind.LineCommentTrivia));
}

0 comments on commit 655949a

Please sign in to comment.