Skip to content

Commit

Permalink
Improve Diagnostic message format
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthurvdv committed Jan 25, 2025
1 parent 6820990 commit d623487
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions BusinessCentral.LinterCop/Design/Rule0083BuiltInDateTimeMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ private void AnalyzeInvocation(OperationAnalysisContext ctx)
{
"Date2DMY" => GetDate2DMYReplacement(operation),
"Date2DWY" => GetDate2DWYReplacement(operation),
"DT2Date" => "Date",
"DT2Time" => "Time",
"DT2Date" => "Date()",
"DT2Time" => "Time()",
"Format" => GetFormatReplacement(operation),
_ => null
};
Expand All @@ -43,7 +43,7 @@ private void AnalyzeInvocation(OperationAnalysisContext ctx)
ctx.ReportDiagnostic(Diagnostic.Create(
DiagnosticDescriptors.Rule0083BuiltInDateTimeMethod,
ctx.Operation.Syntax.GetLocation(),
operation.Arguments[0].Value.Syntax.ToString().QuoteIdentifierIfNeeded(),
operation.Arguments[0].Value.Syntax.ToString(),
recommendedMethod));
}

Expand All @@ -54,9 +54,9 @@ private void AnalyzeInvocation(OperationAnalysisContext ctx)

return operation.Arguments[1].Value.ConstantValue.Value switch
{
1 => "Day",
2 => "Month",
3 => "Year",
1 => "Day()",
2 => "Month()",
3 => "Year()",
_ => "<Day/Month/Year>"
};
}
Expand All @@ -70,8 +70,8 @@ private void AnalyzeInvocation(OperationAnalysisContext ctx)

return formatSpecifier switch
{
1 => "DayOfWeek",
2 => "Year",
1 => "DayOfWeek()",
2 => "Year()",
_ => "<DayOfWeek/Year>"
};
}
Expand All @@ -81,12 +81,12 @@ private void AnalyzeInvocation(OperationAnalysisContext ctx)
if (operation.Arguments.Length < 3)
return string.Empty;

return operation.Arguments[2].Value.ConstantValue.Value?.ToString() switch
return operation.Arguments[2].Value.ConstantValue.Value?.ToString() switch
{
"<HOURS24>" => "Hour",
"<MINUTES>" => "Minute",
"<SECONDS>" => "Second",
"<THOUSANDS>" => "Millisecond",
"<HOURS24>" => "Hour()",
"<MINUTES>" => "Minute()",
"<SECONDS>" => "Second()",
"<THOUSANDS>" => "Millisecond()",
_ => string.Empty
};
}
Expand Down
2 changes: 1 addition & 1 deletion BusinessCentral.LinterCop/LinterCopAnalyzers.resx
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@
<value>Use new Date/Time/DateTime methods for extracting parts.</value>
</data>
<data name="Rule0083BuiltInDateTimeMethodFormat" xml:space="preserve">
<value>Use the new method '{0}.{1}' to extract specific parts of date/time values.</value>
<value>Use the new method {0}.{1} to extract specific parts of date/time values.</value>
</data>
<data name="Rule0083BuiltInDateTimeMethodDescription" xml:space="preserve">
<value>Replace outdated functions for extracting specific parts of Date, Time, and DateTime types (such as day, month, hour, or second) with the new, modernized methods.</value>
Expand Down

0 comments on commit d623487

Please sign in to comment.