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

Add support for ternary operator #933

Merged
merged 5 commits into from
Feb 11, 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
3 changes: 3 additions & 0 deletions BusinessCentral.LinterCop.Test/Rule0089.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public void Setup()
}

[Test]
#if !LessThenFall2024
[TestCase("ConditionalExpressionNested")]
#endif
[TestCase("IfStatement")]
[TestCase("IfStatementNested")]
public async Task HasDiagnostic(string testCase)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
codeunit 50100 MyCodeunit
{
procedure [|MyProcedure|](Day: Integer) // Cognitive Complexity: 15 (threshold >=15)
var
DayName: Text;
begin
DayName := (Day = 1) ? 'Monday' : // +1 (nested = 0)
(Day = 2) ? 'Tuesday' : // +2 (nested = 1)
(Day = 3) ? 'Wednesday' : // +3 (nested = 2)
(Day = 4) ? 'Thursday' : // +4 (nested = 3)
(Day = 5) ? 'Friday' : // +5 (nested = 4)
'Invalid Day';
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
using Microsoft.Dynamics.Nav.CodeAnalysis.Syntax;
using System.Collections.Immutable;
using BusinessCentral.LinterCop.Helpers;
using System.Collections.Concurrent;

namespace BusinessCentral.LinterCop.Design;

[DiagnosticAnalyzer]
public class Rule0089CognitiveComplexity : DiagnosticAnalyzer
{
private static readonly Dictionary<Compilation, int> thresholdCache = new();
private static readonly ConcurrentDictionary<Compilation, int> thresholdCache = new();

private static readonly HashSet<SyntaxKind> flowBreakingKinds = new()
{
Expand All @@ -29,7 +30,10 @@ public class Rule0089CognitiveComplexity : DiagnosticAnalyzer
SyntaxKind.ForStatement,
SyntaxKind.WhileStatement,
SyntaxKind.CaseStatement,
SyntaxKind.RepeatStatement
SyntaxKind.RepeatStatement,
#if !LessThenFall2024
SyntaxKind.ConditionalExpression
#endif
};

public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } =
Expand Down
1 change: 1 addition & 0 deletions BusinessCentral.LinterCop/LinterCop.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cyclomaticComplexityThreshold": 8,
"maintainabilityIndexThreshold": 20,
"cognitiveComplexityThreshold": 15,
"enableRule0011ForTableFields": false,
"enableRule0016ForApiObjects": false
}