Skip to content

Commit ccc10f3

Browse files
committed
Refactor diagnostics to use centralized constants
Refactored `AnalyzerDiagnostics` and `SourceGeneratorDiagnostics` to use constants from the `Constants` class for diagnostic IDs and titles, reducing duplication and improving maintainability. Added new constants to the `Constants` class for diagnostic IDs and titles, including: - `OldLocalizationApiUsedId` and `OldLocalizationApiUsedTitle` - `CouldNotFindResourceDictionariesId` - `LocalizationKeyUnusedId` - `EnumFieldLocalizationKeyValueInvalidId` Updated the `SuppressWarning` constant to dynamically reference `OldLocalizationApiUsedId` and `OldLocalizationApiUsedTitle`. Replaced hardcoded diagnostic strings with centralized constants, ensuring consistency and simplifying future updates.
1 parent 99c47d3 commit ccc10f3

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

Localization/Editor.Localization.Analyzers/AnalyzerDiagnostics.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ namespace Editor.Localization.Analyzers
66
public static class AnalyzerDiagnostics
77
{
88
public static readonly DiagnosticDescriptor OldLocalizationApiUsed = new DiagnosticDescriptor(
9-
"FLAN0001",
10-
"Old localization API used",
9+
Constants.OldLocalizationApiUsedId,
10+
Constants.OldLocalizationApiUsedTitle,
1111
$"Use `{Constants.ClassName}.{{0}}({{1}})` instead",
1212
"Localization",
1313
DiagnosticSeverity.Warning,

Localization/Editor.Localization.Shared/Constants.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ namespace Editor.Localization.Shared
44
{
55
public static class Constants
66
{
7+
public const string OldLocalizationApiUsedId = "FLAN0001";
8+
public const string OldLocalizationApiUsedTitle = "Old localization API used";
9+
public const string CouldNotFindResourceDictionariesId = "FLSG0001";
10+
public const string LocalizationKeyUnusedId = "FLSG0002";
11+
public const string EnumFieldLocalizationKeyValueInvalidId = "FLSG0003";
12+
713
public const string DefaultNamespace = "Editor";
814
public const string ClassName = "Localize";
915
public const string SystemPrefixUri = "http://schemas.microsoft.com/winfx/2006/xaml";
@@ -23,7 +29,7 @@ public static class Constants
2329
public const string EnumLocalizeKeyAttributeName = "EnumLocalizeKeyAttribute";
2430
public const string EnumLocalizeValueAttributeName = "EnumLocalizeValueAttribute";
2531
public const string Internationalization = "Internationalization";
26-
public const string SuppressWarning = "#pragma warning disable FLAN0001 // Old localization API used";
32+
public static readonly string SuppressWarning = $"#pragma warning disable {OldLocalizationApiUsedId} // {OldLocalizationApiUsedTitle}";
2733
// Regex to match file paths ending with /Languages/en.axaml on Linux & MacOS or \Languages\en.axaml on Windows
2834
public static readonly Regex LanguagesAxamlRegex = new Regex(@"[\\/]+Languages[\\/]en\.axaml$", RegexOptions.IgnoreCase);
2935
public static readonly string[] OldLocalizationClasses = { "Internationalization" };

Localization/Editor.Localization.SourceGenerators/SourceGeneratorDiagnostics.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Editor.Localization.SourceGenerators
66
public static class SourceGeneratorDiagnostics
77
{
88
public static readonly DiagnosticDescriptor CouldNotFindResourceDictionaries = new DiagnosticDescriptor(
9-
"FLSG0001",
9+
Constants.CouldNotFindResourceDictionariesId,
1010
"Could not find resource dictionaries",
1111
"Could not find resource dictionaries. There must be a `en.axaml` file under `Language` folder.",
1212
"Localization",
@@ -15,7 +15,7 @@ public static class SourceGeneratorDiagnostics
1515
);
1616

1717
public static readonly DiagnosticDescriptor LocalizationKeyUnused = new DiagnosticDescriptor(
18-
"FLSG0002",
18+
Constants.LocalizationKeyUnusedId,
1919
"Localization key is unused",
2020
$"Method `{Constants.ClassName}.{{0}}` is never used",
2121
"Localization",
@@ -24,7 +24,7 @@ public static class SourceGeneratorDiagnostics
2424
);
2525

2626
public static readonly DiagnosticDescriptor EnumFieldLocalizationKeyValueInvalid = new DiagnosticDescriptor(
27-
"FLSG0003",
27+
Constants.EnumFieldLocalizationKeyValueInvalidId,
2828
"Enum field localization key and value invalid",
2929
$"Enum field `{{0}}` does not have a valid localization key or value",
3030
"Localization",

0 commit comments

Comments
 (0)