Skip to content

Commit

Permalink
Merge pull request #667 from StefanMaron/SingleQuoteEscapingIssueDete…
Browse files Browse the repository at this point in the history
…cted

Add Rule 0059: Single quote escaping issue detected
  • Loading branch information
Arthurvdv authored Jul 2, 2024
2 parents 652fe2f + b561348 commit aa8c791
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace BusinessCentral.LinterCop.Design
[DiagnosticAnalyzer]
public class Rule0050OperatorAndPlaceholderInFilterExpression : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0050OperatorAndPlaceholderInFilterExpression);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create<DiagnosticDescriptor>(DiagnosticDescriptors.Rule0050OperatorAndPlaceholderInFilterExpression, DiagnosticDescriptors.Rule0059SingleQuoteEscapingIssueDetected);

public override void Initialize(AnalysisContext context) => context.RegisterOperationAction(new Action<OperationAnalysisContext>(this.AnalyzeInvocation), OperationKind.InvocationExpression);

Expand All @@ -36,6 +36,11 @@ private void CheckParameter(IOperation operand, ref IInvocationExpression operat
return;

string parameterString = operand.Syntax.ToFullString();
if (parameterString.Equals("'<>'''"))
{
ctx.ReportDiagnostic(Diagnostic.Create(DiagnosticDescriptors.Rule0059SingleQuoteEscapingIssueDetected, operand.Syntax.GetLocation()));
return;
}

string pattern = @"%\d+"; // Only when a placeholders (%1) is used in the filter expression we need to raise the rule that the placeholders won't work as expected
Regex regex = new Regex(pattern);
Expand Down
5 changes: 5 additions & 0 deletions BusinessCentral.LinterCop/LinterCop.ruleset.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@
"id": "LC0058",
"action": "Warning",
"justification": "PageVariable.SetRecord(): You cannot use a temporary record for the Record parameter."
},
{
"id": "LC0059",
"action": "Warning",
"justification": "Single quote escaping issue detected."
}
]
}
1 change: 1 addition & 0 deletions BusinessCentral.LinterCop/LinterCopAnalyzers.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ public static class DiagnosticDescriptors
public static readonly DiagnosticDescriptor Rule0056EmptyEnumValueWithCaption = new DiagnosticDescriptor(LinterCopAnalyzers.AnalyzerPrefix + "0056", (LocalizableString)new LocalizableResourceString("Rule0056EmptyEnumValueWithCaptionTitle", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), (LocalizableString)new LocalizableResourceString("Rule0056EmptyEnumValueWithCaptionFormat", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "Design", DiagnosticSeverity.Info, true, (LocalizableString)new LocalizableResourceString("Rule0056EmptyEnumValueWithCaptionDescription", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0056");
public static readonly DiagnosticDescriptor Rule0057EnumValueWithEmptyCaption = new DiagnosticDescriptor(LinterCopAnalyzers.AnalyzerPrefix + "0057", (LocalizableString)new LocalizableResourceString("Rule0057EnumValueWithEmptyCaptionTitle", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), (LocalizableString)new LocalizableResourceString("Rule0057EnumValueWithEmptyCaptionFormat", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "Design", DiagnosticSeverity.Info, true, (LocalizableString)new LocalizableResourceString("Rule0057EnumValueWithEmptyCaptionDescription", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0057");
public static readonly DiagnosticDescriptor Rule0058PageVariableMethodOnTemporaryTable = new DiagnosticDescriptor(LinterCopAnalyzers.AnalyzerPrefix + "0058", (LocalizableString)new LocalizableResourceString("Rule0058PageVariableMethodOnTemporaryTableTitle", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), (LocalizableString)new LocalizableResourceString("Rule0058PageVariableMethodOnTemporaryTableFormat", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "Design", DiagnosticSeverity.Warning, true, (LocalizableString)new LocalizableResourceString("Rule0058PageVariableMethodOnTemporaryTableDescription", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0058");
public static readonly DiagnosticDescriptor Rule0059SingleQuoteEscapingIssueDetected = new DiagnosticDescriptor(LinterCopAnalyzers.AnalyzerPrefix + "0059", (LocalizableString)new LocalizableResourceString("Rule0059SingleQuoteEscapingIssueDetectedTitle", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), (LocalizableString)new LocalizableResourceString("Rule0059SingleQuoteEscapingIssueDetectedFormat", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "Design", DiagnosticSeverity.Warning, true, (LocalizableString)new LocalizableResourceString("Rule0059SingleQuoteEscapingIssueDetectedDescription", LinterCopAnalyzers.ResourceManager, typeof(LinterCopAnalyzers)), "https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0059");
}
}
9 changes: 9 additions & 0 deletions BusinessCentral.LinterCop/LinterCopAnalyzers.resx
Original file line number Diff line number Diff line change
Expand Up @@ -636,4 +636,13 @@
<data name="Rule0058PageVariableMethodOnTemporaryTableDescription" xml:space="preserve">
<value>{0}.{1}(): You cannot use a temporary record for the Record parameter.</value>
</data>
<data name="Rule0059SingleQuoteEscapingIssueDetectedTitle" xml:space="preserve">
<value>Single quote escaping issue detected: Use %1 or '''' for correct text escaping.</value>
</data>
<data name="Rule0059SingleQuoteEscapingIssueDetectedFormat" xml:space="preserve">
<value>Single quote escaping issue detected: Use %1 or '''' for correct text escaping.</value>
</data>
<data name="Rule0059SingleQuoteEscapingIssueDetectedDescription" xml:space="preserve">
<value>Single quote escaping issue detected: Use %1 or '''' for correct text escaping.</value>
</data>
</root>
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,5 @@ For an example and the default values see: [LinterCop.ruleset.json](LinterCop.ru
|[LC0055](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0055)|The suffix `Tok` is meant to be used when the value of the label matches the name.|Info|
|[LC0056](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0056)|Empty Enum values should not have a specified `Caption` property.|Info|
|[LC0057](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0057)|Enum values must have non-empty a `Caption` to be selectable in the client|Info|
|[LC0058](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0058)|PageVariable.SetRecord(): You cannot use a temporary record for the Record parameter.|Warning|
|[LC0058](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0058)|PageVariable.SetRecord(): You cannot use a temporary record for the Record parameter.|Warning|
|[LC0059](https://github.com/StefanMaron/BusinessCentral.LinterCop/wiki/LC0058)|Single quote escaping issue detected.|Warning|

0 comments on commit aa8c791

Please sign in to comment.