Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve diagnostic message format on Rule0083 #891

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading