Skip to content

Commit

Permalink
Merge pull request StefanMaron#693 from StefanMaron/Rule0064ReworkUse…
Browse files Browse the repository at this point in the history
…TableFieldToolTip

Split Rule0064 into two reperate rules (0064+0066)
  • Loading branch information
Arthurvdv authored Jul 10, 2024
2 parents d2aa153 + f80145d commit 4d18b1f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTip);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0064TableFieldMissingToolTip, DiagnosticDescriptors.Rule0066DuplicateToolTipBetweenPageAndTable);

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

Expand All @@ -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;
}
}
Expand All @@ -60,6 +61,27 @@ private static IEnumerable<IControlSymbol> 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
12 changes: 11 additions & 1 deletion BusinessCentral.LinterCop/LinterCop.ruleset.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
]
}
1 change: 0 additions & 1 deletion BusinessCentral.LinterCop/LinterCopAnalyzers.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
23 changes: 16 additions & 7 deletions BusinessCentral.LinterCop/LinterCopAnalyzers.resx
Original file line number Diff line number Diff line change
Expand Up @@ -681,22 +681,31 @@
<data name="Rule0063GiveFieldMoreDescriptiveNameDescription" xml:space="preserve">
<value>It is common for API pages to give certain fields a more describing name.</value>
</data>
<data name="Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTipTitle" xml:space="preserve">
<value>Use table field ToolTip instead of page field ToolTip.</value>
<data name="Rule0064TableFieldMissingToolTipTitle" xml:space="preserve">
<value>Missing ToolTip property on table field.</value>
</data>
<data name="Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTipFormat" xml:space="preserve">
<value>Use table field ToolTip instead of page field ToolTip.</value>
<data name="Rule0064TableFieldMissingToolTipFormat" xml:space="preserve">
<value>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}.</value>
</data>
<data name="Rule0064UseTableFieldToolTipInsteadOfPageFieldToolTipDescription" xml:space="preserve">
<value>Use table field ToolTip instead of page field ToolTip.</value>
<data name="Rule0064TableFieldMissingToolTipDescription" xml:space="preserve">
<value>Informs the user that it is better to apply the ToolTip property on the table field instead of the page field.</value>
</data>
<data name="Rule0065EventSubscriberVarCheckTitle" xml:space="preserve">
<value>Event subscriber var keyword mismatch</value>
<value>Event subscriber var keyword mismatch.</value>
</data>
<data name="Rule0065EventSubscriberVarCheckFormat" xml:space="preserve">
<value>Parameter '{0}' must use the 'var' keyword if the publisher parameter is 'var'.</value>
</data>
<data name="Rule0065EventSubscriberVarCheckDescription" xml:space="preserve">
<value>Ensures that event subscriber methods use 'var' keyword for parameters as defined by event publisher.</value>
</data>
<data name="Rule0066DuplicateToolTipBetweenPageAndTableTitle" xml:space="preserve">
<value>Duplicate ToolTip between page and table field.</value>
</data>
<data name="Rule0066DuplicateToolTipBetweenPageAndTableFormat" xml:space="preserve">
<value>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.</value>
</data>
<data name="Rule0066DuplicateToolTipBetweenPageAndTableDescription" xml:space="preserve">
<value>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.</value>
</data>
</root>
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|

0 comments on commit 4d18b1f

Please sign in to comment.