forked from StefanMaron/BusinessCentral.LinterCop
-
Notifications
You must be signed in to change notification settings - Fork 0
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 StefanMaron#675 from StefanMaron/TableFieldToolTips
Add Rule0064 Use table field ToolTip instead of page field ToolTip
- Loading branch information
Showing
5 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
BusinessCentral.LinterCop/Design/Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip.cs
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,65 @@ | ||
#if Spring2024OrGreater | ||
using BusinessCentral.LinterCop.AnalysisContextExtension; | ||
using Microsoft.Dynamics.Nav.CodeAnalysis; | ||
using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics; | ||
using System.Collections.Immutable; | ||
|
||
namespace BusinessCentral.LinterCop.Design | ||
{ | ||
[DiagnosticAnalyzer] | ||
public class Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip : DiagnosticAnalyzer | ||
{ | ||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip); | ||
|
||
public override void Initialize(AnalysisContext context) => context.RegisterSymbolAction(new Action<SymbolAnalysisContext>(this.AnalyzeFlowFieldEditable), SymbolKind.Page, SymbolKind.PageExtension); | ||
|
||
private void AnalyzeFlowFieldEditable(SymbolAnalysisContext ctx) | ||
{ | ||
if (!VersionChecker.IsSupported(ctx.Symbol, VersionCompatibility.Spring2024OrGreater)) return; | ||
|
||
if (ctx.IsObsoletePendingOrRemoved()) return; | ||
|
||
IEnumerable<IControlSymbol> pageFields = GetFlattenedControls(ctx.Symbol) | ||
.Where(e => e.ControlKind == ControlKind.Field) | ||
.Where(e => e.GetProperty(PropertyKind.ToolTip) != null) | ||
.Where(e => e.RelatedFieldSymbol != null); | ||
if (pageFields == null) return; | ||
|
||
foreach (IControlSymbol page in pageFields) | ||
{ | ||
ctx.CancellationToken.ThrowIfCancellationRequested(); | ||
|
||
IPropertySymbol pageToolTip = page.GetProperty(PropertyKind.ToolTip); | ||
IPropertySymbol tableToolTip = page.RelatedFieldSymbol.GetProperty(PropertyKind.ToolTip); | ||
|
||
// Page field has a value for the ToolTip property and table field does not have a value for the ToolTip property | ||
if (tableToolTip == null && page.RelatedFieldSymbol.IsSourceSymbol()) | ||
{ | ||
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip, pageToolTip.GetLocation())); | ||
continue; | ||
} | ||
|
||
// Page field has a value for the ToolTip property and table field also has a value for the ToolTip property but the value is exactly the same | ||
if (tableToolTip != null && pageToolTip.ValueText == tableToolTip.ValueText) | ||
{ | ||
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip, pageToolTip.GetLocation())); | ||
continue; | ||
} | ||
} | ||
} | ||
|
||
private static IEnumerable<IControlSymbol> GetFlattenedControls(ISymbol symbol) | ||
{ | ||
switch (symbol.Kind) | ||
{ | ||
case SymbolKind.Page: | ||
return ((IPageBaseTypeSymbol)symbol).FlattenedControls; | ||
case SymbolKind.PageExtension: | ||
return ((IPageExtensionBaseTypeSymbol)symbol).AddedControlsFlattened; | ||
default: | ||
return null; | ||
} | ||
} | ||
} | ||
} | ||
#endif |
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