From cce56e368ad164899302b6127830600621f5d566 Mon Sep 17 00:00:00 2001 From: Arthur van de Vondervoort Date: Mon, 27 Nov 2023 19:49:17 +0100 Subject: [PATCH 1/2] Refactor GetManifest to VersionChecker --- Design/Rule0011AccessPropertyShouldAlwaysBeSet.cs | 6 ++---- Design/Rule0031RecordInstanceIsolationLevel.cs | 7 ++----- Design/Rule0034ExtensiblePropertyShouldAlwaysBeSet.cs | 7 ++----- Design/Rule0035ExplicitSetAllowInCustomizations.cs | 7 ++----- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/Design/Rule0011AccessPropertyShouldAlwaysBeSet.cs b/Design/Rule0011AccessPropertyShouldAlwaysBeSet.cs index 7fb2ab63..f19a0736 100644 --- a/Design/Rule0011AccessPropertyShouldAlwaysBeSet.cs +++ b/Design/Rule0011AccessPropertyShouldAlwaysBeSet.cs @@ -1,5 +1,4 @@ -using Microsoft.Dynamics.Nav.Analyzers.Common.AppSourceCopConfiguration; -using Microsoft.Dynamics.Nav.CodeAnalysis; +using Microsoft.Dynamics.Nav.CodeAnalysis; using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics; using System.Collections.Immutable; using BusinessCentral.LinterCop.Helpers; @@ -16,8 +15,7 @@ public override void Initialize(AnalysisContext context) private void CheckForMissingAccessProperty(SymbolAnalysisContext context) { - var manifest = AppSourceCopConfigurationProvider.GetManifest(context.Compilation); - if (manifest.Runtime < RuntimeVersion.Spring2021 && (context.Symbol.Kind == SymbolKind.Enum || context.Symbol.Kind == SymbolKind.Interface)) + if (!VersionChecker.IsSupported(context.Symbol, VersionCompatibility.Spring2021OrGreater) && (context.Symbol.Kind == SymbolKind.Enum || context.Symbol.Kind == SymbolKind.Interface)) return; if (context.Symbol.IsObsoletePending || context.Symbol.IsObsoleteRemoved) return; diff --git a/Design/Rule0031RecordInstanceIsolationLevel.cs b/Design/Rule0031RecordInstanceIsolationLevel.cs index 9d2099e5..fa14bb89 100644 --- a/Design/Rule0031RecordInstanceIsolationLevel.cs +++ b/Design/Rule0031RecordInstanceIsolationLevel.cs @@ -1,4 +1,3 @@ -using Microsoft.Dynamics.Nav.Analyzers.Common.AppSourceCopConfiguration; using Microsoft.Dynamics.Nav.CodeAnalysis; using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics; using System.Collections.Immutable; @@ -14,6 +13,8 @@ public class Rule0031RecordInstanceIsolationLevel : DiagnosticAnalyzer private void CheckLockTable(OperationAnalysisContext ctx) { + if (!VersionChecker.IsSupported(ctx.ContainingSymbol, VersionCompatibility.Spring2023OrGreater)) return; + if (ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoletePending || ctx.ContainingSymbol.GetContainingObjectTypeSymbol().IsObsoleteRemoved) return; if (ctx.ContainingSymbol.IsObsoletePending || ctx.ContainingSymbol.IsObsoleteRemoved) return; @@ -22,10 +23,6 @@ private void CheckLockTable(OperationAnalysisContext ctx) if (!SemanticFacts.IsSameName(operation.TargetMethod.Name, "LockTable")) return; - // ReadIsolation is supported from runtime versions 11.0 or greater. - var manifest = AppSourceCopConfigurationProvider.GetManifest(ctx.Compilation); - if (manifest.Runtime < RuntimeVersion.Spring2023) return; - ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0031RecordInstanceIsolationLevel, ctx.Operation.Syntax.GetLocation())); } } diff --git a/Design/Rule0034ExtensiblePropertyShouldAlwaysBeSet.cs b/Design/Rule0034ExtensiblePropertyShouldAlwaysBeSet.cs index 81253a06..99a70041 100644 --- a/Design/Rule0034ExtensiblePropertyShouldAlwaysBeSet.cs +++ b/Design/Rule0034ExtensiblePropertyShouldAlwaysBeSet.cs @@ -1,4 +1,3 @@ -using Microsoft.Dynamics.Nav.Analyzers.Common.AppSourceCopConfiguration; using Microsoft.Dynamics.Nav.CodeAnalysis; using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics; using Microsoft.Dynamics.Nav.CodeAnalysis.Symbols; @@ -20,6 +19,8 @@ public override void Initialize(AnalysisContext context) private void CheckForMissingExtensibleProperty(SymbolAnalysisContext ctx) { + if (!VersionChecker.IsSupported(ctx.Symbol, VersionCompatibility.Fall2019OrGreater)) return; + if (ctx.Symbol.IsObsoletePending || ctx.Symbol.IsObsoleteRemoved) return; if (ctx.Symbol.GetTypeSymbol().Kind == SymbolKind.Table && ctx.Symbol.DeclaredAccessibility != Accessibility.Public) return; @@ -27,10 +28,6 @@ private void CheckForMissingExtensibleProperty(SymbolAnalysisContext ctx) if (ctx.Symbol.GetProperty(PropertyKind.Extensible) != null) return; - // The Extensible property (and DeclaredAccessibility) is supported from runtime versions 4.0 or greater. - var manifest = AppSourceCopConfigurationProvider.GetManifest(ctx.Compilation); - if (manifest.Runtime < RuntimeVersion.Fall2019) return; - ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0034ExtensiblePropertyShouldAlwaysBeSet, ctx.Symbol.GetLocation(), new object[] { Accessibility.Public.ToString().ToLower() })); } } diff --git a/Design/Rule0035ExplicitSetAllowInCustomizations.cs b/Design/Rule0035ExplicitSetAllowInCustomizations.cs index 047049a0..a08a8d8f 100644 --- a/Design/Rule0035ExplicitSetAllowInCustomizations.cs +++ b/Design/Rule0035ExplicitSetAllowInCustomizations.cs @@ -1,4 +1,3 @@ -using Microsoft.Dynamics.Nav.Analyzers.Common.AppSourceCopConfiguration; using Microsoft.Dynamics.Nav.CodeAnalysis; using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics; using Microsoft.Dynamics.Nav.CodeAnalysis.Symbols; @@ -20,13 +19,11 @@ public override void Initialize(AnalysisContext context) private void AnalyzeAllowInCustomization(SymbolAnalysisContext ctx) { + if (!VersionChecker.IsSupported(ctx.Symbol, Feature.AddPageControlInPageCustomization)) return; + if (ctx.Symbol.IsObsoletePending || ctx.Symbol.IsObsoleteRemoved) return; if (ctx.Symbol.GetContainingObjectTypeSymbol().IsObsoletePending || ctx.Symbol.GetContainingObjectTypeSymbol().IsObsoleteRemoved) return; - // The AllowInCustomizations property is supported from runtime versions 12.0 or greater. - var manifest = AppSourceCopConfigurationProvider.GetManifest(ctx.Compilation); - if (manifest.Runtime < RuntimeVersion.Fall2023) return; - ICollection tableFields = GetTableFields(ctx.Symbol).Where(x => x.Id > 0 && x.Id < 2000000000) .Where(x => x.GetBooleanPropertyValue(PropertyKind.Enabled) != false) .Where(x => x.GetProperty(PropertyKind.AllowInCustomizations) is null) From 175d7de2a9b9d71d508d783117a268a6165f8a9d Mon Sep 17 00:00:00 2001 From: Arthur van de Vondervoort Date: Tue, 28 Nov 2023 10:06:42 +0100 Subject: [PATCH 2/2] Resolve InvalidCastException on pageextension --- Design/Rule0016CheckForMissingCaptions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Design/Rule0016CheckForMissingCaptions.cs b/Design/Rule0016CheckForMissingCaptions.cs index debdcbb9..d005fb06 100644 --- a/Design/Rule0016CheckForMissingCaptions.cs +++ b/Design/Rule0016CheckForMissingCaptions.cs @@ -126,6 +126,7 @@ private bool CaptionIsMissing(ISymbol Symbol, SymbolAnalysisContext context) private static bool SuppressCaptionWarning(SymbolAnalysisContext context) { + if (context.Symbol.GetContainingObjectTypeSymbol().GetTypeSymbol().GetNavTypeKindSafe() != NavTypeKind.Page) return false; IPageTypeSymbol pageTypeSymbol = (IPageTypeSymbol)context.Symbol.GetContainingObjectTypeSymbol(); if (pageTypeSymbol.GetNavTypeKindSafe() != NavTypeKind.Page || pageTypeSymbol.PageType != PageTypeKind.API) return false; LinterSettings.Create(context.Compilation.FileSystem.GetDirectoryPath());