Skip to content

Commit

Permalink
Shared message and title when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
credfeto committed Nov 27, 2023
1 parent 5ca3b2e commit 7a13ea5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/FunFair.CodeAnalysis/Helpers/RuleHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Microsoft.CodeAnalysis;

namespace FunFair.CodeAnalysis.Helpers;
Expand All @@ -7,7 +8,7 @@ internal static class RuleHelpers
public static DiagnosticDescriptor CreateRule(string code, string category, string title, string message)
{
LiteralString translatableTitle = new(title);
LiteralString translatableMessage = new(message);
LiteralString translatableMessage = UseTitleForMessage(title: title, message: message, translatableTitle: translatableTitle);

return new(id: code,
title: translatableTitle,
Expand All @@ -17,4 +18,11 @@ public static DiagnosticDescriptor CreateRule(string code, string category, stri
isEnabledByDefault: true,
description: translatableMessage);
}

private static LiteralString UseTitleForMessage(string title, string message, LiteralString translatableTitle)
{
return StringComparer.Ordinal.Equals(x: message, y: title)
? translatableTitle
: new(message);
}
}

0 comments on commit 7a13ea5

Please sign in to comment.