Skip to content

Commit

Permalink
Improve support for legacy AL Language versions (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthurvdv authored Nov 1, 2024
1 parent bffc3d5 commit 01adc03
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 46 deletions.
47 changes: 22 additions & 25 deletions .github/actions/feature-flags/Get-FeatureFlags.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,30 @@ function Get-FeatureFlags {
$featureFlags = ""

$RuntimeVersion = [Ordered]@{
'Spring2018' = '1.0'
'Fall2018' = '2.0'
'Spring2019' = '3.0'
'Fall2019' = '4.0'
'Spring2020' = '5.0'
'Fall2020' = '6.0'
'Spring2021' = '7.0'
'Fall2021' = '8.0'
'Spring2022' = '9.0'
'Spring2022RV1' = '9.1'
'Spring2022RV2' = '9.2'
'Fall2022' = '10.0'
'Spring2023' = '11.0'
'Fall2023' = '12.0'
'Fall2023RV1' = '12.1'
'Fall2023RV2' = '12.2'
'Fall2023RV3' = '12.3'
'Spring2024' = '13.0'
'Fall2024' = '14.0'
'Spring2025' = '15.0'
'Fall2025' = '16.0'

'ManifestHelper' = '13.0.937154'
'PageSystemAction' = '13.0.878831'
'LessThenSpring2018' = '1.0'
'LessThenFall2018' = '2.0'
'LessThenSpring2019' = '3.0'
'LessThenFall2019' = '4.0'
'LessThenSpring2020' = '5.0'
'LessThenFall2020' = '6.0'
'LessThenSpring2021' = '7.0'
'LessThenFall2021' = '8.0'
'LessThenSpring2022' = '9.0'
'LessThenSpring2022RV1' = '9.1'
'LessThenSpring2022RV2' = '9.2'
'LessThenFall2022' = '10.0'
'LessThenSpring2023' = '11.0'
'LessThenFall2023' = '12.0'
'LessThenFall2023RV1' = '12.1'
'LessThenFall2023RV2' = '12.2'
'LessThenFall2023RV3' = '12.3'
'LessThenSpring2024' = '13.0'
'LessThenFall2024' = '14.0'
'LessThenSpring2025' = '15.0'
'LessThenFall2025' = '16.0'
}

$supportedRuntimeVersions = $RuntimeVersion.GetEnumerator() | Where-Object { $(ConvertTo-Version($_.Value)) -le $(ConvertTo-Version($version)) } | Foreach-Object { $_.Key } | ForEach-Object { "#$_" }
$supportedRuntimeVersions = $RuntimeVersion.GetEnumerator() | Where-Object { $(ConvertTo-Version($_.Value)) -gt $(ConvertTo-Version($version)) } | Foreach-Object { $_.Key } | ForEach-Object { "#$_" }
if (![string]::IsNullOrEmpty($supportedRuntimeVersions)) {
$featureFlags = [System.String]::Join("", $supportedRuntimeVersions)
}
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"${workspaceFolder}/BusinessCentral.LinterCop/BusinessCentral.LinterCop.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary",
"/p:FeatureFlags=#Spring2018#Fall2018#Spring2019#Fall2019#Spring2020#Fall2020#Spring2021#Fall2021#Spring2022#Spring2022RV1#Spring2022RV2#Fall2022#Spring2023#Fall2023#Fall2023RV1#Fall2023RV2#Fall2023RV3#Spring2024#Fall2024#ManifestHelper#PageSystemAction"
"/p:FeatureFlags="
],
"group": "build",
"problemMatcher": "$msCompile",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<DefineConstants>$(DefineConstants)$(FeatureFlags.Replace("#",";"))</DefineConstants>

</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion BusinessCentral.LinterCop.Test/Rule0043.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if Spring2024
#if !LessThenSpring2024
namespace BusinessCentral.LinterCop.Test;

public class Rule0043
Expand Down
2 changes: 1 addition & 1 deletion BusinessCentral.LinterCop.Test/Rule0068.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task HasDiagnostic(string testCase)
[TestCase("ProcedureCallsInherentPermissionsProperty")]
[TestCase("ProcedureCallsInherentPermissionsAttribute")]
[TestCase("PageSourceTable")]
#if Fall2023RV1
#if !LessThenFall2023RV1
[TestCase("ProcedureCallsPermissionsPropertyFullyQualified")]
#endif
// [TestCase("IntegerTable")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static bool TableContainsNoSeries(ITableTypeSymbol table)
return table.Fields
.Where(x => x.Id > 0 && x.Id < 2000000000)
.Where(x => x.FieldClass == FieldClassKind.Normal)
#if Fall2024
#if !LessThenFall2024
.Where(x => x.Type.GetNavTypeKindSafe() == NavTypeKind.Code)
#endif
.Any(field =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics;
using Microsoft.Dynamics.Nav.CodeAnalysis.Packaging;
using System.Collections.Immutable;
#if ManifestHelper
#if !LessThenSpring2024
using Microsoft.Dynamics.Nav.Analyzers.Common;
#else
using Microsoft.Dynamics.Nav.Analyzers.Common.AppSourceCopConfiguration;
Expand All @@ -21,7 +21,7 @@ class Rule0033AppManifestRuntimeBehind : DiagnosticAnalyzer

private void CheckAppManifestRuntime(CompilationAnalysisContext ctx)
{
#if ManifestHelper
#if !LessThenSpring2024
NavAppManifest manifest = ManifestHelper.GetManifest(ctx.Compilation);
#else
NavAppManifest manifest = AppSourceCopConfigurationProvider.GetManifest(ctx.Compilation);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if Fall2023RV1
#if !LessThenFall2023RV1
using BusinessCentral.LinterCop.AnalysisContextExtension;
using Microsoft.Dynamics.Nav.CodeAnalysis;
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void AnalyzeTableExtensionReferencePageProvider(SymbolAnalysisContext ct
private static bool AreTheSameNavObjects(ITableTypeSymbol left, ITableTypeSymbol right)
{
if (left.GetNavTypeKindSafe() != right.GetNavTypeKindSafe()) return false;
#if Fall2023RV1
#if !LessThenFall2023RV1
if (((INamespaceSymbol)left.ContainingSymbol).QualifiedName != ((INamespaceSymbol)right.ContainingSymbol).QualifiedName) return false;
#endif
if (left.Name != right.Name) return false;
Expand All @@ -146,7 +146,7 @@ private static bool AreTheSameNavObjects(ITableTypeSymbol left, ITableTypeSymbol

private static string GetFullyQualifiedObjectName(IPageTypeSymbol page)
{
#if Fall2023RV1
#if !LessThenFall2023RV1
if (page.ContainingNamespace.QualifiedName != "")
return page.ContainingNamespace.QualifiedName + "." + page.Name.QuoteIdentifierIfNeeded();
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void Initialize(AnalysisContext context)
SyntaxKind.ReportColumn,
SyntaxKind.EnumValue,
SyntaxKind.PageCustomAction,
#if PageSystemAction
#if !LessThenSpring2024
SyntaxKind.PageSystemAction,
#endif
SyntaxKind.PageView,
Expand Down
4 changes: 2 additions & 2 deletions BusinessCentral.LinterCop/Design/Rule0043SecretText.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if Fall2023RV1
#if !LessThenFall2023RV1
using System.Collections.Immutable;
using BusinessCentral.LinterCop.AnalysisContextExtension;
using Microsoft.Dynamics.Nav.CodeAnalysis;
Expand Down Expand Up @@ -29,7 +29,7 @@ public override void Initialize(AnalysisContext context)

private void AnalyzeIsolatedStorage(OperationAnalysisContext ctx)
{
#if Spring2024
#if !LessThenSpring2024
if (!VersionChecker.IsSupported(ctx.ContainingSymbol, VersionCompatibility.Spring2024OrGreater)) return;

if (ctx.IsObsoletePendingOrRemoved()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ public void PopulateFields(IApplicationObjectTypeSymbol table)
string objtype = typeprop.GetValue(field).ToString();
string fieldClass = fieldClassProp.GetValue(field).ToString();

#if Fall2023RV1
#if !LessThenFall2023RV1
// Remove the QualifiedName from the Enum for now.
// In the future refactor this to support Enums with the same object name cross different namespaces
IEnumBaseTypeSymbol? enumBaseTypeSymbol = typeprop.GetValue(field) as IEnumBaseTypeSymbol;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#nullable disable // TODO: Enable nullable and review rule
#if Fall2023RV1
#if !LessThenFall2023RV1
using BusinessCentral.LinterCop.AnalysisContextExtension;
using Microsoft.Dynamics.Nav.CodeAnalysis;
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Microsoft.Dynamics.Nav.CodeAnalysis.Packaging;
using Microsoft.Dynamics.Nav.CodeAnalysis.Utilities;
using System.Collections.Immutable;
#if ManifestHelper
#if !LessThenSpring2024
using Microsoft.Dynamics.Nav.Analyzers.Common;
#else
using Microsoft.Dynamics.Nav.Analyzers.Common.AppSourceCopConfiguration;
Expand All @@ -33,7 +33,7 @@ private class MethodSymbolAnalyzer : IDisposable

public MethodSymbolAnalyzer(CompilationAnalysisContext compilationAnalysisContext)
{
#if ManifestHelper
#if !LessThenSpring2024
NavAppManifest manifest = ManifestHelper.GetManifest(compilationAnalysisContext.Compilation);
#else
NavAppManifest manifest = AppSourceCopConfigurationProvider.GetManifest(compilationAnalysisContext.Compilation);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#nullable disable // TODO: Enable nullable and review rule
#if Spring2024
#if !LessThenSpring2024
using BusinessCentral.LinterCop.AnalysisContextExtension;
using Microsoft.Dynamics.Nav.CodeAnalysis;
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ private bool ProcedureHasInherentPermission(IEnumerable<IAttributeSymbol> inhere

var objectName = typeParts[1].Trim().Trim('"');
if (objectName.ToLowerInvariant() != variableType.Name.ToLowerInvariant())
#if Fall2023RV1
if (objectName.UnquoteIdentifier().ToLowerInvariant() != (variableType.OriginalDefinition.ContainingNamespace?.QualifiedName.ToLowerInvariant() + "." + variableType.Name.ToLowerInvariant()))
#if !LessThenFall2023RV1
if (objectName.UnquoteIdentifier().ToLowerInvariant() != (variableType.OriginalDefinition.ContainingNamespace?.QualifiedName.ToLowerInvariant() + "." + variableType.Name.ToLowerInvariant()))
#endif
continue;
continue;

if (permissionValue.Contains(requestedPermission.ToString().ToLowerInvariant()[0]))
{
Expand Down Expand Up @@ -227,7 +227,7 @@ private void CheckProcedureInvocation(IPropertySymbol? objectPermissions, ITypeS
var objectName = typeAndObjectName[typeEndIndex..].Trim().Trim('"');

bool nameSpaceNameMatch = false;
#if Fall2023RV1
#if !LessThenFall2023RV1
nameSpaceNameMatch = objectName.UnquoteIdentifier() == (variableType.OriginalDefinition.ContainingNamespace?.QualifiedName.ToLowerInvariant() + "." + variableType.Name.ToLowerInvariant());
#endif

Expand Down

0 comments on commit 01adc03

Please sign in to comment.