Skip to content
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
8 changes: 7 additions & 1 deletion src/ALCops.Common/Reflection/EnumProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1370,8 +1370,12 @@ public static class SyntaxKind
new(() => ParseEnum<NavCodeAnalysis.SyntaxKind>(nameof(NavCodeAnalysis.SyntaxKind.EmptyProperty)));
private static readonly Lazy<NavCodeAnalysis.SyntaxKind> _equalsToken =
new(() => ParseEnum<NavCodeAnalysis.SyntaxKind>(nameof(NavCodeAnalysis.SyntaxKind.EqualsToken)));
private static readonly Lazy<NavCodeAnalysis.SyntaxKind> _greaterThanToken =
new(() => ParseEnum<NavCodeAnalysis.SyntaxKind>(nameof(NavCodeAnalysis.SyntaxKind.GreaterThanToken)));
private static readonly Lazy<NavCodeAnalysis.SyntaxKind> _lessThanToken =
new(() => ParseEnum<NavCodeAnalysis.SyntaxKind>(nameof(NavCodeAnalysis.SyntaxKind.LessThanToken)));
private static readonly Lazy<NavCodeAnalysis.SyntaxKind> _endOfLineTrivia =
new(() => ParseEnum<NavCodeAnalysis.SyntaxKind>(nameof(NavCodeAnalysis.SyntaxKind.EndOfLineTrivia)));
new(() => ParseEnum<NavCodeAnalysis.SyntaxKind>(nameof(NavCodeAnalysis.SyntaxKind.EndOfLineTrivia)));
private static readonly Lazy<NavCodeAnalysis.SyntaxKind> _enumExtensionType =
new(() => ParseEnum<NavCodeAnalysis.SyntaxKind>(nameof(NavCodeAnalysis.SyntaxKind.EnumExtensionType)));
private static readonly Lazy<NavCodeAnalysis.SyntaxKind> _enumDataType =
Expand Down Expand Up @@ -1627,6 +1631,8 @@ public static class SyntaxKind
public static NavCodeAnalysis.SyntaxKind ElifKeyword => _elifKeyword.Value;
public static NavCodeAnalysis.SyntaxKind EmptyProperty => _emptyProperty.Value;
public static NavCodeAnalysis.SyntaxKind EqualsToken => _equalsToken.Value;
public static NavCodeAnalysis.SyntaxKind GreaterThanToken => _greaterThanToken.Value;
public static NavCodeAnalysis.SyntaxKind LessThanToken => _lessThanToken.Value;
public static NavCodeAnalysis.SyntaxKind EndOfLineTrivia => _endOfLineTrivia.Value;
public static NavCodeAnalysis.SyntaxKind EnumExtensionType => _enumExtensionType.Value;
public static NavCodeAnalysis.SyntaxKind EnumDataType => _enumDataType.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|1 > MyTable.Count()|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; MyField; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() = 0|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; MyField; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() >= 0|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; MyField; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() > 0|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; MyField; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() < 1|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; MyField; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() <= 0|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; MyField; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() < 0|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; MyField; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() <> 0|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; MyField; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() = 1|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; MyField; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
TempMyTable: Record MyTable temporary;
begin
if [|TempMyTable.Count() = 0|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; MyField; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using RoslynTestKit;

namespace ALCops.LinterCop.Test
{
public class UseIsEmptyMethodInsteadOfCount : NavCodeAnalysisBase
{
private AnalyzerTestFixture _fixture;
private string _testCasePath;

[SetUp]
public void Setup()
{
_fixture = RoslynFixtureFactory.Create<Analyzers.AnalyzeCountMethod>();

_testCasePath = Path.Combine(
Directory.GetParent(
Environment.CurrentDirectory)!.Parent!.Parent!.FullName,
Path.Combine("Rules", nameof(UseIsEmptyMethodInsteadOfCount)));
}

[Test]
[TestCase("OneGreaterThanRecordCount")]
[TestCase("RecordCountEqualsZero")]
[TestCase("RecordCountGreaterThanOrEqualZero")]
[TestCase("RecordCountGreaterThanZero")]
[TestCase("RecordCountLessThanOne")]
[TestCase("RecordCountLessThanOrEqualZero")]
[TestCase("RecordCountLessThanZero")]
[TestCase("RecordCountNotEqualsZero")]
public async Task HasDiagnostic(string testCase)
{
var code = await File.ReadAllTextAsync(Path.Combine(_testCasePath, nameof(HasDiagnostic), $"{testCase}.al"))
.ConfigureAwait(false);

_fixture.HasDiagnosticAtAllMarkers(code, DiagnosticIds.UseIsEmptyMethodInsteadOfCount);
}

[Test]
[TestCase("RecordCountEqualsOne")]
[TestCase("RecordTemporaryCountEqualsZero")]
public async Task NoDiagnostic(string testCase)
{
var code = await File.ReadAllTextAsync(Path.Combine(_testCasePath, nameof(NoDiagnostic), $"{testCase}.al"))
.ConfigureAwait(false);

_fixture.NoDiagnosticAtAllMarkers(code, DiagnosticIds.UseIsEmptyMethodInsteadOfCount);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() = 1|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; "Entry No."; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() > 1|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; "Entry No."; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() >= 1|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; "Entry No."; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() <= 1|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; "Entry No."; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() < 2|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; "Entry No."; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|MyTable.Count() <> 1|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; "Entry No."; Integer) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
MyTable: Record MyTable;
begin
if [|2 > MyTable.Count()|] then;
end;
}

table 50100 MyTable
{
fields
{
field(1; "Entry No."; Integer) { }
}
}
Loading
Loading