-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add barebones analyser definition and failing tests
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
LocalisationAnalyser.Tests/Analysers/LocalisationKeyUsedMultipleTimesInClassAnalyserTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Threading.Tasks; | ||
using LocalisationAnalyser.Analysers; | ||
using Xunit; | ||
|
||
namespace LocalisationAnalyser.Tests.Analysers | ||
{ | ||
public class LocalisationKeyUsedMultipleTimesInClassAnalyserTests : AbstractAnalyserTests<LocalisationKeyUsedMultipleTimesInClassAnalyser> | ||
{ | ||
[Theory] | ||
[InlineData("DuplicatedLocalisationKeys")] | ||
public Task RunTest(string name) => Check(name); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...lyser.Tests/Resources/Analysers/DuplicatedLocalisationKeys/Localisation/CommonStrings.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using osu.Framework.Localisation; | ||
|
||
namespace TestProject.Localisation | ||
{ | ||
public static class CommonStrings | ||
{ | ||
private const string prefix = @"TestProject.Localisation.Common"; | ||
|
||
/// <summary> | ||
/// "first string" | ||
/// </summary> | ||
public static LocalisableString FirstString => new TranslatableString(getKey([|@"first_string"|]), @"first string"); | ||
|
||
/// <summary> | ||
/// "second string" | ||
/// </summary> | ||
public static LocalisableString SecondString => new TranslatableString(getKey([|@"first_string"|]), @"second string"); | ||
|
||
/// <summary> | ||
/// "third string" | ||
/// </summary> | ||
public static LocalisableString ThirdString => new TranslatableString(getKey(@"third_string"), @"third string"); | ||
|
||
/// <summary> | ||
/// "first string with arguments (like {0})" | ||
/// </summary> | ||
public static LocalisableString FirstStringWithArguments(string test) => new TranslatableString(getKey([|@"first_string"|]), @"first string with arguments (like {0})"); | ||
|
||
/// <summary> | ||
/// "second string with arguments (like {0})" | ||
/// </summary> | ||
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}"; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
LocalisationAnalyser/Analysers/LocalisationKeyUsedMultipleTimesInClassAnalyser.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DiagnosticDescriptor> SupportedDiagnostics => | ||
ImmutableArray.Create(DiagnosticRules.LOCALISATION_KEY_USED_MULTIPLE_TIMES_IN_CLASS); | ||
} | ||
} |