From a50e72f68d18c68d96b87646a979f8e0186c18b5 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sun, 12 Mar 2023 15:46:31 +0000 Subject: [PATCH] Fix CA1802 --- .editorconfig | 4 ++++ OpenRA.Game/Actor.cs | 6 +++--- OpenRA.Game/FileSystem/ZipFile.cs | 2 +- OpenRA.Game/TextNotificationsManager.cs | 2 +- OpenRA.Mods.Common/Effects/Beacon.cs | 2 +- OpenRA.Mods.Common/FileFormats/Blast.cs | 4 ++-- OpenRA.Mods.Common/ServerTraits/PlayerPinger.cs | 6 +++--- OpenRA.Platforms.Default/FreeTypeFont.cs | 4 ++-- 8 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.editorconfig b/.editorconfig index 8d57dda4ac..e57b39688c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -692,6 +692,10 @@ dotnet_diagnostic.CA1717.severity = warning ### Performance Rules ### https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/performance-warnings +# Use Literals Where Appropriate. +#dotnet_code_quality.CA1802.required_modifiers = static +dotnet_diagnostic.CA1802.severity = warning + # Remove empty finalizers. dotnet_diagnostic.CA1821.severity = warning diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 03b5139901..0b55fc30a9 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -35,6 +35,9 @@ namespace OpenRA public sealed class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable, IDisposable { + /// Value used to represent an invalid token. + public const int InvalidConditionToken = -1; + internal readonly struct SyncHash { public readonly ISync Trait; @@ -78,9 +81,6 @@ namespace OpenRA public WRot Orientation => facing?.Orientation ?? WRot.None; - /// Value used to represent an invalid token. - public static readonly int InvalidConditionToken = -1; - sealed class ConditionState { /// Delegates that have registered to be notified when this condition changes. diff --git a/OpenRA.Game/FileSystem/ZipFile.cs b/OpenRA.Game/FileSystem/ZipFile.cs index c335b083ae..bc43a634c3 100644 --- a/OpenRA.Game/FileSystem/ZipFile.cs +++ b/OpenRA.Game/FileSystem/ZipFile.cs @@ -19,7 +19,7 @@ namespace OpenRA.FileSystem { public class ZipFileLoader : IPackageLoader { - static readonly uint ZipSignature = 0x04034b50; + const uint ZipSignature = 0x04034b50; class ReadOnlyZipFile : IReadOnlyPackage { diff --git a/OpenRA.Game/TextNotificationsManager.cs b/OpenRA.Game/TextNotificationsManager.cs index 3eac9d2fd0..bb1582a359 100644 --- a/OpenRA.Game/TextNotificationsManager.cs +++ b/OpenRA.Game/TextNotificationsManager.cs @@ -17,7 +17,7 @@ namespace OpenRA { public static class TextNotificationsManager { - public static readonly int SystemClientId = -1; + public const int SystemClientId = -1; static readonly string SystemMessageLabel; public static long ChatDisabledUntil { get; internal set; } diff --git a/OpenRA.Mods.Common/Effects/Beacon.cs b/OpenRA.Mods.Common/Effects/Beacon.cs index 41b8168c3e..2d754b90a2 100644 --- a/OpenRA.Mods.Common/Effects/Beacon.cs +++ b/OpenRA.Mods.Common/Effects/Beacon.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.Effects { public class Beacon : IEffect, IScriptBindable, IEffectAboveShroud { - static readonly int MaxArrowHeight = 512; + const int MaxArrowHeight = 512; readonly Player owner; readonly WPos position; diff --git a/OpenRA.Mods.Common/FileFormats/Blast.cs b/OpenRA.Mods.Common/FileFormats/Blast.cs index a636dd6dad..8c5f8a4766 100644 --- a/OpenRA.Mods.Common/FileFormats/Blast.cs +++ b/OpenRA.Mods.Common/FileFormats/Blast.cs @@ -22,8 +22,8 @@ namespace OpenRA.Mods.Common.FileFormats { public static class Blast { - public static readonly int MAXBITS = 13; // maximum code length - public static readonly int MAXWIN = 4096; // maximum window size + public const int MAXBITS = 13; // maximum code length + public const int MAXWIN = 4096; // maximum window size static readonly byte[] LitLen = { diff --git a/OpenRA.Mods.Common/ServerTraits/PlayerPinger.cs b/OpenRA.Mods.Common/ServerTraits/PlayerPinger.cs index fe09dd6320..53b2e6740f 100644 --- a/OpenRA.Mods.Common/ServerTraits/PlayerPinger.cs +++ b/OpenRA.Mods.Common/ServerTraits/PlayerPinger.cs @@ -30,9 +30,9 @@ namespace OpenRA.Mods.Common.Server [TranslationReference("player", "timeout")] const string TimeoutIn = "notification-timeout-dropped-in"; - static readonly int PingInterval = 5000; // Ping every 5 seconds - static readonly int ConnReportInterval = 20000; // Report every 20 seconds - static readonly int ConnTimeout = 60000; // Drop unresponsive clients after 60 seconds + const int PingInterval = 5000; // Ping every 5 seconds + const int ConnReportInterval = 20000; // Report every 20 seconds + const int ConnTimeout = 60000; // Drop unresponsive clients after 60 seconds long lastPing = 0; long lastConnReport = 0; diff --git a/OpenRA.Platforms.Default/FreeTypeFont.cs b/OpenRA.Platforms.Default/FreeTypeFont.cs index 6dd0476bf4..72b218d3e7 100644 --- a/OpenRA.Platforms.Default/FreeTypeFont.cs +++ b/OpenRA.Platforms.Default/FreeTypeFont.cs @@ -24,15 +24,15 @@ namespace OpenRA.Platforms.Default internal const uint OK = 0x00; internal const int FT_LOAD_RENDER = 0x04; + internal const int MetricsWidthOffset = 0; // offsetof(FT_Glyph_Metrics, width) + internal const int BitmapPitchOffset = 8; // offsetof(FT_Bitmap, pitch) internal static readonly int FaceRecGlyphOffset = IntPtr.Size == 8 ? 152 : 84; // offsetof(FT_FaceRec, glyph) internal static readonly int GlyphSlotMetricsOffset = IntPtr.Size == 8 ? 48 : 24; // offsetof(FT_GlyphSlotRec, metrics) internal static readonly int GlyphSlotBitmapOffset = IntPtr.Size == 8 ? 152 : 76; // offsetof(FT_GlyphSlotRec, bitmap) internal static readonly int GlyphSlotBitmapLeftOffset = IntPtr.Size == 8 ? 192 : 100; // offsetof(FT_GlyphSlotRec, bitmap_left) internal static readonly int GlyphSlotBitmapTopOffset = IntPtr.Size == 8 ? 196 : 104; // offsetof(FT_GlyphSlotRec, bitmap_top) - internal static readonly int MetricsWidthOffset = 0; // offsetof(FT_Glyph_Metrics, width) internal static readonly int MetricsHeightOffset = IntPtr.Size == 8 ? 8 : 4; // offsetof(FT_Glyph_Metrics, height) internal static readonly int MetricsAdvanceOffset = IntPtr.Size == 8 ? 32 : 16; // offsetof(FT_Glyph_Metrics, horiAdvance) - internal static readonly int BitmapPitchOffset = 8; // offsetof(FT_Bitmap, pitch) internal static readonly int BitmapBufferOffset = IntPtr.Size == 8 ? 16 : 12; // offsetof(FT_Bitmap, buffer) [DllImport("freetype6", CallingConvention = CallingConvention.Cdecl)]