Skip to content

Commit

Permalink
Merge pull request #332 from StefanMaron/ImproveRule0029WithUseOffZer…
Browse files Browse the repository at this point in the history
…oDateTimeComparison

Improve LC0029 with use of 0DT comparison
  • Loading branch information
Arthurvdv authored Nov 13, 2023
2 parents a10d244 + ecdb858 commit 2502245
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Design/Rule0029CompareDateTimeThroughCodeunit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ private void CompareDateTimeWithTypeHelper(OperationAnalysisContext context)

IBinaryOperatorExpression operation = (IBinaryOperatorExpression)context.Operation;

if (operation.LeftOperand.Type.NavTypeKind == NavTypeKind.DateTime && operation.RightOperand.Type.NavTypeKind == NavTypeKind.DateTime &&
(operation.Syntax.IsKind(SyntaxKind.EqualsExpression) ||
operation.Syntax.IsKind(SyntaxKind.NotEqualsExpression) ||
operation.Syntax.IsKind(SyntaxKind.GreaterThanExpression) ||
operation.Syntax.IsKind(SyntaxKind.GreaterThanOrEqualExpression) ||
operation.Syntax.IsKind(SyntaxKind.LessThanExpression) ||
operation.Syntax.IsKind(SyntaxKind.LessThanOrEqualExpression)))
if (!(operation.LeftOperand.Type.NavTypeKind == NavTypeKind.DateTime && operation.RightOperand.Type.NavTypeKind == NavTypeKind.DateTime)) return;
if (operation.LeftOperand.Syntax.IsKind(SyntaxKind.LiteralExpression) && operation.LeftOperand.Syntax.GetIdentifierOrLiteralValue() == "0DT") return;
if (operation.RightOperand.Syntax.IsKind(SyntaxKind.LiteralExpression) && operation.RightOperand.Syntax.GetIdentifierOrLiteralValue() == "0DT") return;

if (operation.Syntax.IsKind(SyntaxKind.EqualsExpression) ||
operation.Syntax.IsKind(SyntaxKind.NotEqualsExpression) ||
operation.Syntax.IsKind(SyntaxKind.GreaterThanExpression) ||
operation.Syntax.IsKind(SyntaxKind.GreaterThanOrEqualExpression) ||
operation.Syntax.IsKind(SyntaxKind.LessThanExpression) ||
operation.Syntax.IsKind(SyntaxKind.LessThanOrEqualExpression)
)
context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0029CompareDateTimeThroughCodeunit, context.Operation.Syntax.GetLocation()));
}
}
Expand Down

0 comments on commit 2502245

Please sign in to comment.