Skip to content

Commit

Permalink
Fix message in MA0159
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou committed Jun 13, 2024
1 parent 11bbcbf commit 053e1e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Meziantou.Analyzer/Rules/OptimizeLinqUsageAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public sealed class OptimizeLinqUsageAnalyzer : DiagnosticAnalyzer
private static readonly DiagnosticDescriptor UseOrderRule = new(
RuleIdentifiers.OptimizeEnumerable_UseOrder,
title: "Use 'Order' instead of 'OrderBy'",
messageFormat: "Use '{0}' instead of '{0}By'",
messageFormat: "Use '{0}' instead of '{1}'",
RuleCategories.Performance,
DiagnosticSeverity.Info,
isEnabledByDefault: true,
Expand Down Expand Up @@ -514,7 +514,9 @@ private void UseOrder(OperationAnalysisContext context, IInvocationOperation ope
.Add("FirstOperationStart", operation.Syntax.Span.Start.ToString(CultureInfo.InvariantCulture))
.Add("FirstOperationLength", operation.Syntax.Span.Length.ToString(CultureInfo.InvariantCulture));

context.ReportDiagnostic(UseOrderRule, properties, operation, DiagnosticInvocationReportOptions.ReportOnMember, operation.TargetMethod.Name);
var newMethodName = operation.TargetMethod.Name is "OrderBy" ? "Order" : "OrderDescending";

context.ReportDiagnostic(UseOrderRule, properties, operation, DiagnosticInvocationReportOptions.ReportOnMember, newMethodName, operation.TargetMethod.Name);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public Test()
}
}
""")
.ShouldReportDiagnosticWithMessage("Use 'Order' instead of 'OrderBy'")
.ShouldFixCodeWith("""
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -122,6 +123,7 @@ public Test()
}
}
""")
.ShouldReportDiagnosticWithMessage("Use 'OrderDescending' instead of 'OrderByDescending'")
.ShouldFixCodeWith("""
using System.Collections.Generic;
using System.Linq;
Expand Down

0 comments on commit 053e1e4

Please sign in to comment.