Skip to content

Commit

Permalink
Merge pull request #318 from StefanMaron/bugfixOnRule0016
Browse files Browse the repository at this point in the history
Improve enableRule0016ForApiObjects on LC0016
  • Loading branch information
Arthurvdv authored Nov 4, 2023
2 parents d0146fb + 80d3f6a commit 0b5d0f6
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Design/Rule0016CheckForMissingCaptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BusinessCentral.LinterCop.Helpers;
using Microsoft.Dynamics.Nav.CodeAnalysis;
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics;
using Microsoft.Dynamics.Nav.CodeAnalysis.Symbols;
using System.Collections.Immutable;

namespace BusinessCentral.LinterCop.Design
Expand All @@ -26,16 +27,6 @@ private void CheckForMissingCaptions(SymbolAnalysisContext context)
if (context.Symbol.IsObsoletePending || context.Symbol.IsObsoleteRemoved) return;
if (context.Symbol.GetContainingObjectTypeSymbol().IsObsoletePending || context.Symbol.GetContainingObjectTypeSymbol().IsObsoleteRemoved) return;

LinterSettings.Create(context.Compilation.FileSystem.GetDirectoryPath());
if (!(LinterSettings.instance.enableRule0016ForApiObjects) && context.Symbol.GetContainingObjectTypeSymbol().GetProperty(PropertyKind.PageType) != null)
{
if (context.Symbol.Kind == SymbolKind.Page)
{
IPageTypeSymbol pageTypeSymbol = (IPageTypeSymbol)context.Symbol;
if (pageTypeSymbol.PageType == PageTypeKind.API) return;
}
}

if (context.Symbol.Kind == SymbolKind.Control)
{
var Control = ((IControlSymbol)context.Symbol);
Expand All @@ -50,7 +41,8 @@ private void CheckForMissingCaptions(SymbolAnalysisContext context)
}
else
{
RaiseCaptionWarning(context);
if (!SuppressCaptionWarning(context))
RaiseCaptionWarning(context);
}
break;

Expand All @@ -64,7 +56,8 @@ private void CheckForMissingCaptions(SymbolAnalysisContext context)
if (CaptionIsMissing(context.Symbol, context))
if (Control.RelatedPartSymbol != null)
if (CaptionIsMissing(Control.RelatedPartSymbol, context))
RaiseCaptionWarning(context);
if (!SuppressCaptionWarning(context))
RaiseCaptionWarning(context);
break;

case ControlKind.UserControl:
Expand Down Expand Up @@ -129,8 +122,16 @@ private bool CaptionIsMissing(ISymbol Symbol, SymbolAnalysisContext context)
if (Symbol.GetProperty(PropertyKind.Caption) == null && Symbol.GetProperty(PropertyKind.CaptionClass) == null)
return true;
return false;
}

private static bool SuppressCaptionWarning(SymbolAnalysisContext context)
{
IPageTypeSymbol pageTypeSymbol = (IPageTypeSymbol)context.Symbol.GetContainingObjectTypeSymbol();
if (pageTypeSymbol.GetNavTypeKindSafe() != NavTypeKind.Page || pageTypeSymbol.PageType != PageTypeKind.API) return false;
LinterSettings.Create(context.Compilation.FileSystem.GetDirectoryPath());
return !LinterSettings.instance.enableRule0016ForApiObjects;
}

private void RaiseCaptionWarning(SymbolAnalysisContext context)
{
context.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0016CheckForMissingCaptions, context.Symbol.GetLocation()));
Expand Down

0 comments on commit 0b5d0f6

Please sign in to comment.