-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #320 from StefanMaron/Rule0029CompareDateTimeThrou…
…ghCodeunit Rule0029 Use CompareDateTime method in Type Helper codeunit for DateTime variable comparisons.
- Loading branch information
Showing
5 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Microsoft.Dynamics.Nav.Analyzers.Common.AppSourceCopConfiguration; | ||
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 | ||
{ | ||
[DiagnosticAnalyzer] | ||
public class Rule0029CompareDateTimeThroughCodeunit : DiagnosticAnalyzer | ||
{ | ||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0029CompareDateTimeThroughCodeunit); | ||
|
||
public override void Initialize(AnalysisContext context) => context.RegisterOperationAction(new Action<OperationAnalysisContext>(this.CompareDateTimeWithTypeHelper), OperationKind.BinaryOperatorExpression); | ||
|
||
private void CompareDateTimeWithTypeHelper(OperationAnalysisContext context) | ||
{ | ||
if (context.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoletePending || context.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoleteRemoved) return; | ||
if (context.ContainingSymbol.IsObsoletePending || context.ContainingSymbol.IsObsoleteRemoved) return; | ||
|
||
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))) | ||
context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0029CompareDateTimeThroughCodeunit, context.Operation.Syntax.GetLocation())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters