Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle trailing comments on LC0017 #857

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
Loading