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

Comments for LC0069 instead of special cases #771

Merged
merged 1 commit into from
Sep 21, 2024
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
codeunit 50100 MyCodeunit
// testcase for a normal assignment with semicolon (not an empty statement)
codeunit 50100 MyCodeunit
{
procedure MyProcedure(Param: Boolean)
var
LocalVar: Boolean;
begin
LocalVar := Param[|;|] // just a normal assignment with semicolon (not an empty statement)
LocalVar := Param[|;|]
end;
}
10 changes: 8 additions & 2 deletions BusinessCentral.LinterCop/Design/Rule0069EmptyStatements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using BusinessCentral.LinterCop.AnalysisContextExtension;
using Microsoft.Dynamics.Nav.CodeAnalysis;
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics;
using Microsoft.Dynamics.Nav.CodeAnalysis.Syntax;
using System.Collections.Immutable;

namespace BusinessCentral.LinterCop.Design
Expand All @@ -17,8 +18,13 @@ private void AnalyzeEmptyStatement(OperationAnalysisContext ctx)
{
if (ctx.IsObsoletePendingOrRemoved()) return;

// exclude empty ifs (runtime error guard) and empty case lines
if (ctx.Operation.Syntax.Parent.IsKind(SyntaxKind.IfStatement) || ctx.Operation.Syntax.Parent.IsKind(SyntaxKind.CaseLine)) return;
foreach (SyntaxTrivia trivia in ctx.Operation.Syntax.Parent.GetLeadingTrivia())
if (trivia.IsKind(SyntaxKind.LineCommentTrivia))
return;

foreach (SyntaxTrivia trivia in ctx.Operation.Syntax.Parent.GetTrailingTrivia())
if (trivia.IsKind(SyntaxKind.LineCommentTrivia))
return;

ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0069EmptyStatements, ctx.Operation.Syntax.GetLocation()));
}
Expand Down
2 changes: 1 addition & 1 deletion BusinessCentral.LinterCop/LinterCop.ruleset.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@
{
"id": "LC0069",
"action": "Info",
"justification": "Avoid empty statements."
"justification": "Empty statements should be avoided or should have a leading or trailing comment explaining their use."
},
{
"id": "LC0070",
Expand Down
6 changes: 3 additions & 3 deletions BusinessCentral.LinterCop/LinterCopAnalyzers.resx
Original file line number Diff line number Diff line change
Expand Up @@ -733,13 +733,13 @@
<value>Informs the user that there are missing permission to access tabledata.</value>
</data>
<data name="Rule0069EmptyStatementsTitle" xml:space="preserve">
<value>Avoid empty statements.</value>
<value>Empty statements should be avoided or should have a leading or trailing comment explaining their use.</value>
</data>
<data name="Rule0069EmptyStatementsFormat" xml:space="preserve">
<value>Empty statements should be avoided.</value>
<value>Empty statements should be avoided or should have a leading or trailing comment explaining their use.</value>
</data>
<data name="Rule0069EmptyStatementsDescription" xml:space="preserve">
<value>Empty statements should be avoided.</value>
<value>Empty statements should be avoided or should have a leading or trailing comment explaining their use.</value>
</data>
<data name="Rule0070ListObjectsAreOneBasedTitle" xml:space="preserve">
<value>Zero index access on 1-based List objects.</value>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,5 @@ For an example and the default values see: [LinterCop.ruleset.json](LinterCop.ru
|[LC0066](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0066)|Duplicate ToolTip between page and table field.|Info|
|[LC0067](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0067)|Set `NotBlank` property to `false` when 'No. Series' TableRelation exists.|Warning|
|[LC0068](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0068)|Informs the user that there are missing permission to access tabledata.|Info|
|[LC0069](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0069)|Avoid empty statements.|Info|
|[LC0069](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0069)|Empty statements should be avoided or should have a leading or trailing comment explaining their use.|Info|
|[LC0070](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0070)|Zero index access on 1-based List objects.|Warning|