Skip to content

Commit

Permalink
Merge pull request #327 from StefanMaron/AccessInternalForInstallOrUp…
Browse files Browse the repository at this point in the history
…gradeCodeunits

Rule0030AccessInternalForInstallAndUpgradeCodeunit
  • Loading branch information
Arthurvdv authored Nov 13, 2023
2 parents 79c6141 + 60d4878 commit b4f0836
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Design/Rule0030AccessInternalForInstallOrUpgradeCodeunits.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Dynamics.Nav.CodeAnalysis;
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics;
using System.Collections.Immutable;
using Microsoft.Dynamics.Nav.CodeAnalysis.Symbols;

namespace BusinessCentral.LinterCop.Design
{
[DiagnosticAnalyzer]
class Rule0030AccessInternalForInstallAndUpgradeCodeunits : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0030AccessInternalForInstallAndUpgradeCodeunits);

public override void Initialize(AnalysisContext context) => context.RegisterSymbolAction(new Action<SymbolAnalysisContext>(this.CheckAccessOnInstallAndUpgradeCodeunits), SymbolKind.Codeunit);

private void CheckAccessOnInstallAndUpgradeCodeunits(SymbolAnalysisContext context)
{
if (context.Symbol.IsObsoletePending || context.Symbol.IsObsoleteRemoved) return;

ICodeunitTypeSymbol symbol = (ICodeunitTypeSymbol)context.Symbol;
if (symbol.Subtype != CodeunitSubtypeKind.Install && symbol.Subtype != CodeunitSubtypeKind.Upgrade)
return;

if (symbol.DeclaredAccessibility == Accessibility.Public)
context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0030AccessInternalForInstallAndUpgradeCodeunits, symbol.GetLocation()));
}
}
}
1 change: 1 addition & 0 deletions LinterCopAnalyzers.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ public static class DiagnosticDescriptors
public static readonly DiagnosticDescriptor Rule0027RunPageImplementPageManagement = new DiagnosticDescriptor(LinterCopAnalyzers.AnalyzerPrefix + "0027", (LocalizableString)new LocalizableResourceString("Rule0027RunPageImplementPageManagement", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), (LocalizableString)new LocalizableResourceString("Rule0027RunPageImplementPageManagement", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "Design", DiagnosticSeverity.Info, true, (LocalizableString)new LocalizableResourceString("Rule0027RunPageImplementPageManagement", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0027");
public static readonly DiagnosticDescriptor Rule0028CodeNavigabilityOnEventSubscribers = new DiagnosticDescriptor(LinterCopAnalyzers.AnalyzerPrefix + "0028", (LocalizableString)new LocalizableResourceString("Rule0028CodeNavigabilityOnEventSubscribersTitle", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), (LocalizableString)new LocalizableResourceString("Rule0028CodeNavigabilityOnEventSubscribersFormat", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "Design", DiagnosticSeverity.Info, true, (LocalizableString)new LocalizableResourceString("Rule0028CodeNavigabilityOnEventSubscribersDescription", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0028");
public static readonly DiagnosticDescriptor Rule0029CompareDateTimeThroughCodeunit = new DiagnosticDescriptor(LinterCopAnalyzers.AnalyzerPrefix + "0029", (LocalizableString)new LocalizableResourceString("Rule0029CompareDateTimeThroughCodeunitTitle", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), (LocalizableString)new LocalizableResourceString("Rule0029CompareDateTimeThroughCodeunitFormat", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "Design", DiagnosticSeverity.Info, true, (LocalizableString)new LocalizableResourceString("Rule0029CompareDateTimeThroughCodeunitDescription", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0029");
public static readonly DiagnosticDescriptor Rule0030AccessInternalForInstallAndUpgradeCodeunits = new DiagnosticDescriptor(LinterCopAnalyzers.AnalyzerPrefix + "0030", (LocalizableString)new LocalizableResourceString("Rule0030AccessInternalForInstallAndUpgradeCodeunitsTitle", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), (LocalizableString)new LocalizableResourceString("Rule0030AccessInternalForInstallAndUpgradeCodeunitsFormat", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "Design", DiagnosticSeverity.Info, true, (LocalizableString)new LocalizableResourceString("Rule0030AccessInternalForInstallAndUpgradeCodeunitsDescription", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0030");
}
}
9 changes: 9 additions & 0 deletions LinterCopAnalyzers.resx
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,13 @@
<data name="Rule0027RunPageImplementPageManagement" xml:space="preserve">
<value>Page.Run(Modal) must be implemented through the "Page Management" codeunit from the Base Application.</value>
</data>
<data name="Rule0030AccessInternalForInstallAndUpgradeCodeunitsTitle" xml:space="preserve">
<value>Set Access property to Internal for Install/Upgrade codeunits.</value>
</data>
<data name="Rule0030AccessInternalForInstallAndUpgradeCodeunitsFormat" xml:space="preserve">
<value>Set Access property to Internal for Install/Upgrade codeunits.</value>
</data>
<data name="Rule0030AccessInternalForInstallAndUpgradeCodeunitsDescription" xml:space="preserve">
<value>Set Access property to Internal for Install/Upgrade codeunits.</value>
</data>
</root>

0 comments on commit b4f0836

Please sign in to comment.