From f80145da41f32423d416fbe1fa0dc568703654c3 Mon Sep 17 00:00:00 2001 From: Arthur van de Vondervoort Date: Wed, 10 Jul 2024 13:38:33 +0200 Subject: [PATCH] Split Rule0064 into two reperate rules (0064+0066) --- ...Tip.cs => Rule0064UseTableFieldToolTip.cs} | 38 +++++++++++++++---- .../LinterCop.ruleset.json | 12 +++++- .../LinterCopAnalyzers.Generated.cs | 1 - .../LinterCopAnalyzers.resx | 23 +++++++---- README.md | 4 +- 5 files changed, 60 insertions(+), 18 deletions(-) rename BusinessCentral.LinterCop/Design/{Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip.cs => Rule0064UseTableFieldToolTip.cs} (50%) diff --git a/BusinessCentral.LinterCop/Design/Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip.cs b/BusinessCentral.LinterCop/Design/Rule0064UseTableFieldToolTip.cs similarity index 50% rename from BusinessCentral.LinterCop/Design/Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip.cs rename to BusinessCentral.LinterCop/Design/Rule0064UseTableFieldToolTip.cs index efacdaaa..c489e269 100644 --- a/BusinessCentral.LinterCop/Design/Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip.cs +++ b/BusinessCentral.LinterCop/Design/Rule0064UseTableFieldToolTip.cs @@ -2,14 +2,15 @@ using BusinessCentral.LinterCop.AnalysisContextExtension; using Microsoft.Dynamics.Nav.CodeAnalysis; using Microsoft.Dynamics.Nav.CodeAnalysis.Diagnostics; +using Microsoft.Dynamics.Nav.CodeAnalysis.Utilities; using System.Collections.Immutable; namespace BusinessCentral.LinterCop.Design { [DiagnosticAnalyzer] - public class Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip : DiagnosticAnalyzer + public class Rule0064UseTableFieldToolTip : DiagnosticAnalyzer { - public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(DiagnosticDescriptors.Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip); + public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(DiagnosticDescriptors.Rule0064TableFieldMissingToolTip, DiagnosticDescriptors.Rule0066DuplicateToolTipBetweenPageAndTable); public override void Initialize(AnalysisContext context) => context.RegisterSymbolAction(new Action(this.AnalyzeFlowFieldEditable), SymbolKind.Page, SymbolKind.PageExtension); @@ -25,24 +26,24 @@ private void AnalyzeFlowFieldEditable(SymbolAnalysisContext ctx) .Where(e => e.RelatedFieldSymbol != null); if (pageFields == null) return; - foreach (IControlSymbol page in pageFields) + foreach (IControlSymbol pageField in pageFields) { ctx.CancellationToken.ThrowIfCancellationRequested(); - IPropertySymbol pageToolTip = page.GetProperty(PropertyKind.ToolTip); - IPropertySymbol tableToolTip = page.RelatedFieldSymbol.GetProperty(PropertyKind.ToolTip); + IPropertySymbol pageToolTip = pageField.GetProperty(PropertyKind.ToolTip); + IPropertySymbol tableToolTip = pageField.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()) + if (tableToolTip == null && pageField.RelatedFieldSymbol.IsSourceSymbol()) { - ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip, pageToolTip.GetLocation())); + ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0064TableFieldMissingToolTip, pageToolTip.GetLocation(), new object[] { pageField.RelatedFieldSymbol.Name.QuoteIdentifierIfNeeded(), pageField.Name.QuoteIdentifierIfNeeded() })); 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())); + ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0066DuplicateToolTipBetweenPageAndTable, pageToolTip.GetLocation(), new object[] { pageField.Name.QuoteIdentifierIfNeeded(), pageField.RelatedFieldSymbol.Name.QuoteIdentifierIfNeeded() })); continue; } } @@ -60,6 +61,27 @@ private static IEnumerable GetFlattenedControls(ISymbol symbol) return null; } } + + public static class DiagnosticDescriptors + { + public static readonly DiagnosticDescriptor Rule0064TableFieldMissingToolTip = new( + id: LinterCopAnalyzers.AnalyzerPrefix + "0064", + title: LinterCopAnalyzers.GetLocalizableString("Rule0064TableFieldMissingToolTipTitle"), + messageFormat: LinterCopAnalyzers.GetLocalizableString("Rule0064TableFieldMissingToolTipFormat"), + category: "Design", + defaultSeverity: DiagnosticSeverity.Info, isEnabledByDefault: true, + description: LinterCopAnalyzers.GetLocalizableString("Rule0064TableFieldMissingToolTipDescription"), + helpLinkUri: "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0064"); + + public static readonly DiagnosticDescriptor Rule0066DuplicateToolTipBetweenPageAndTable = new( + id: LinterCopAnalyzers.AnalyzerPrefix + "0066", + title: LinterCopAnalyzers.GetLocalizableString("Rule0066DuplicateToolTipBetweenPageAndTableTitle"), + messageFormat: LinterCopAnalyzers.GetLocalizableString("Rule0066DuplicateToolTipBetweenPageAndTableFormat"), + category: "Design", + defaultSeverity: DiagnosticSeverity.Info, isEnabledByDefault: true, + description: LinterCopAnalyzers.GetLocalizableString("Rule0066DuplicateToolTipBetweenPageAndTableDescription"), + helpLinkUri: "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0066"); + } } } #endif \ No newline at end of file diff --git a/BusinessCentral.LinterCop/LinterCop.ruleset.json b/BusinessCentral.LinterCop/LinterCop.ruleset.json index f9d95ae2..ea030785 100644 --- a/BusinessCentral.LinterCop/LinterCop.ruleset.json +++ b/BusinessCentral.LinterCop/LinterCop.ruleset.json @@ -320,7 +320,17 @@ { "id": "LC0064", "action": "Info", - "justification": "Use table field ToolTip instead of page field ToolTip." + "justification": "Missing ToolTip property on table field." + }, + { + "id": "LC0065", + "action": "Info", + "justification": "Event subscriber var keyword mismatch." + }, + { + "id": "LC0066", + "action": "Info", + "justification": "Duplicate ToolTip between page and table field." } ] } \ No newline at end of file diff --git a/BusinessCentral.LinterCop/LinterCopAnalyzers.Generated.cs b/BusinessCentral.LinterCop/LinterCopAnalyzers.Generated.cs index 04826993..36c54f43 100644 --- a/BusinessCentral.LinterCop/LinterCopAnalyzers.Generated.cs +++ b/BusinessCentral.LinterCop/LinterCopAnalyzers.Generated.cs @@ -69,6 +69,5 @@ public static class DiagnosticDescriptors public static readonly DiagnosticDescriptor Rule0060PropertyApplicationAreaOnApiPage = new DiagnosticDescriptor(LinterCopAnalyzers.AnalyzerPrefix + "0060", (LocalizableString)new LocalizableResourceString("Rule0060PropertyApplicationAreaOnApiPageTitle", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), (LocalizableString)new LocalizableResourceString("Rule0060PropertyApplicationAreaOnApiPageFormat", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "Design", DiagnosticSeverity.Info, true, (LocalizableString)new LocalizableResourceString("Rule0060PropertyApplicationAreaOnApiPageDescription", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0060"); public static readonly DiagnosticDescriptor Rule0061SetODataKeyFieldsWithSystemIdField = new DiagnosticDescriptor(LinterCopAnalyzers.AnalyzerPrefix + "0061", (LocalizableString)new LocalizableResourceString("Rule0061SetODataKeyFieldsWithSystemIdFieldTitle", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), (LocalizableString)new LocalizableResourceString("Rule0061SetODataKeyFieldsWithSystemIdFieldFormat", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "Design", DiagnosticSeverity.Info, true, (LocalizableString)new LocalizableResourceString("Rule0061SetODataKeyFieldsWithSystemIdFieldDescription", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0061"); public static readonly DiagnosticDescriptor Rule0062MandatoryFieldMissingOnApiPage = new DiagnosticDescriptor(LinterCopAnalyzers.AnalyzerPrefix + "0062", (LocalizableString)new LocalizableResourceString("Rule0062MandatoryFieldMissingOnApiPageTitle", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), (LocalizableString)new LocalizableResourceString("Rule0062MandatoryFieldMissingOnApiPageFormat", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "Design", DiagnosticSeverity.Info, true, (LocalizableString)new LocalizableResourceString("Rule0062MandatoryFieldMissingOnApiPageDescription", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0062"); - public static readonly DiagnosticDescriptor Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip = new DiagnosticDescriptor(LinterCopAnalyzers.AnalyzerPrefix + "0064", (LocalizableString)new LocalizableResourceString("Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTipTitle", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), (LocalizableString)new LocalizableResourceString("Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTipFormat", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "Design", DiagnosticSeverity.Info, true, (LocalizableString)new LocalizableResourceString("Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTipDescription", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0064"); } } \ No newline at end of file diff --git a/BusinessCentral.LinterCop/LinterCopAnalyzers.resx b/BusinessCentral.LinterCop/LinterCopAnalyzers.resx index 808d1d8a..e48c5db3 100644 --- a/BusinessCentral.LinterCop/LinterCopAnalyzers.resx +++ b/BusinessCentral.LinterCop/LinterCopAnalyzers.resx @@ -681,17 +681,17 @@ It is common for API pages to give certain fields a more describing name. - - Use table field ToolTip instead of page field ToolTip. + + Missing ToolTip property on table field. - - Use table field ToolTip instead of page field ToolTip. + + A value for the ToolTip property is missing for the table field {0} of page field {1}. Consider adding a ToolTip for table field {0} and/or removing the ToolTip from page field {1}. - - Use table field ToolTip instead of page field ToolTip. + + Informs the user that it is better to apply the ToolTip property on the table field instead of the page field. - Event subscriber var keyword mismatch + Event subscriber var keyword mismatch. Parameter '{0}' must use the 'var' keyword if the publisher parameter is 'var'. @@ -699,4 +699,13 @@ Ensures that event subscriber methods use 'var' keyword for parameters as defined by event publisher. + + Duplicate ToolTip between page and table field. + + + The ToolTip property of page field {0} and it's table field {1} have the same value and therefore the page field's ToolTip can be removed. + + + Informs the user that it is better to only apply the ToolTip property on the table field when the page fields ToolTip is the same. + \ No newline at end of file diff --git a/README.md b/README.md index 55cf4387..7ca8548f 100644 --- a/README.md +++ b/README.md @@ -217,4 +217,6 @@ For an example and the default values see: [LinterCop.ruleset.json](LinterCop.ru |[LC0061](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0061)|Pages of type API must have the `ODataKeyFields` property set to the SystemId field.|Info| |[LC0062](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0062)|Mandatory field is missing on API page.|Info| |[LC0063](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0063)|Consider naming field with a more descriptive name.|Info| -|[LC0064](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0064)|Use table field ToolTip instead of page field ToolTip.|Info| +|[LC0064](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0064)|Missing ToolTip property on table field.|Info| +|[LC0065](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0065)|Event subscriber var keyword mismatch.|Info| +|[LC0066](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0066)|Duplicate ToolTip between page and table field.|Info|