diff --git a/LocalisationAnalyser.Tests/Analysers/LocalisationKeyUsedMultipleTimesInClassAnalyserTests.cs b/LocalisationAnalyser.Tests/Analysers/LocalisationKeyUsedMultipleTimesInClassAnalyserTests.cs new file mode 100644 index 0000000..ee10324 --- /dev/null +++ b/LocalisationAnalyser.Tests/Analysers/LocalisationKeyUsedMultipleTimesInClassAnalyserTests.cs @@ -0,0 +1,13 @@ +using System.Threading.Tasks; +using LocalisationAnalyser.Analysers; +using Xunit; + +namespace LocalisationAnalyser.Tests.Analysers +{ + public class LocalisationKeyUsedMultipleTimesInClassAnalyserTests : AbstractAnalyserTests + { + [Theory] + [InlineData("DuplicatedLocalisationKeys")] + public Task RunTest(string name) => Check(name); + } +} \ No newline at end of file diff --git a/LocalisationAnalyser.Tests/Resources/Analysers/DuplicatedLocalisationKeys/Localisation/CommonStrings.txt b/LocalisationAnalyser.Tests/Resources/Analysers/DuplicatedLocalisationKeys/Localisation/CommonStrings.txt new file mode 100644 index 0000000..251f76a --- /dev/null +++ b/LocalisationAnalyser.Tests/Resources/Analysers/DuplicatedLocalisationKeys/Localisation/CommonStrings.txt @@ -0,0 +1,36 @@ +using osu.Framework.Localisation; + +namespace TestProject.Localisation +{ + public static class CommonStrings + { + private const string prefix = @"TestProject.Localisation.Common"; + + /// + /// "first string" + /// + public static LocalisableString FirstString => new TranslatableString(getKey([|@"first_string"|]), @"first string"); + + /// + /// "second string" + /// + public static LocalisableString SecondString => new TranslatableString(getKey([|@"first_string"|]), @"second string"); + + /// + /// "third string" + /// + public static LocalisableString ThirdString => new TranslatableString(getKey(@"third_string"), @"third string"); + + /// + /// "first string with arguments (like {0})" + /// + public static LocalisableString FirstStringWithArguments(string test) => new TranslatableString(getKey([|@"first_string"|]), @"first string with arguments (like {0})"); + + /// + /// "second string with arguments (like {0})" + /// + public static LocalisableString SecondStringWithArguments(string test) => new TranslatableString(getKey(@"second_string_with_args"), @"second string with arguments (like {0})"); + + private static string getKey(string key) => $@"{prefix}:{key}"; + } +} diff --git a/LocalisationAnalyser/Analysers/LocalisationKeyUsedMultipleTimesInClassAnalyser.cs b/LocalisationAnalyser/Analysers/LocalisationKeyUsedMultipleTimesInClassAnalyser.cs new file mode 100644 index 0000000..560bcd6 --- /dev/null +++ b/LocalisationAnalyser/Analysers/LocalisationKeyUsedMultipleTimesInClassAnalyser.cs @@ -0,0 +1,13 @@ +using System.Collections.Immutable; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Diagnostics; + +namespace LocalisationAnalyser.Analysers +{ + [DiagnosticAnalyzer(LanguageNames.CSharp)] + public class LocalisationKeyUsedMultipleTimesInClassAnalyser : AbstractMemberAnalyser + { + public override ImmutableArray SupportedDiagnostics => + ImmutableArray.Create(DiagnosticRules.LOCALISATION_KEY_USED_MULTIPLE_TIMES_IN_CLASS); + } +} \ No newline at end of file