From 332ab244a78255de0e3105eb6fcd5ecef9e3c72d Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Wed, 13 Nov 2024 19:02:20 +0000 Subject: [PATCH] Fix CA1862 --- .editorconfig | 3 +++ OpenRA.Mods.Cnc/UtilityCommands/LegacyRulesImporter.cs | 3 ++- OpenRA.Mods.Cnc/UtilityCommands/LegacySequenceImporter.cs | 3 ++- OpenRA.Mods.Common/Activities/LayMines.cs | 4 +++- OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs | 2 ++ 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.editorconfig b/.editorconfig index 928edc5ca6..c09da4d9cd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -913,6 +913,9 @@ dotnet_diagnostic.CA1858.severity = warning # Avoid using 'Enumerable.Any()' extension method. dotnet_diagnostic.CA1860.severity = warning +# Use the 'StringComparison' method overloads to perform case-insensitive string comparisons. +dotnet_diagnostic.CA1862.severity = warning + # Use 'CompositeFormat'. dotnet_diagnostic.CA1863.severity = suggestion # TODO: Change to warning once using .NET 7 or later. diff --git a/OpenRA.Mods.Cnc/UtilityCommands/LegacyRulesImporter.cs b/OpenRA.Mods.Cnc/UtilityCommands/LegacyRulesImporter.cs index 5991d246fc..ba6bfae45f 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/LegacyRulesImporter.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/LegacyRulesImporter.cs @@ -130,7 +130,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands Console.WriteLine("\t\tIntoActor: " + undeploysInto); } - if (artIni.Sections.Any(s => s.Name == building.ToLowerInvariant())) + var buildingLower = building.ToLowerInvariant(); + if (artIni.Sections.Any(s => s.Name == buildingLower)) { var artSection = artIni.GetSection(building); diff --git a/OpenRA.Mods.Cnc/UtilityCommands/LegacySequenceImporter.cs b/OpenRA.Mods.Cnc/UtilityCommands/LegacySequenceImporter.cs index b9b810f847..b509f0ebcd 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/LegacySequenceImporter.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/LegacySequenceImporter.cs @@ -138,7 +138,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands Console.WriteLine("\t\tUseTilesetCode: false"); } - if (file.Sections.Any(s => s.Name == sequence.ToLowerInvariant())) + var sequenceLower = sequence.ToLowerInvariant(); + if (file.Sections.Any(s => s.Name == sequenceLower)) { var sequenceSection = file.GetSection(sequence); var guard = sequenceSection.GetValue("Guard", string.Empty); diff --git a/OpenRA.Mods.Common/Activities/LayMines.cs b/OpenRA.Mods.Common/Activities/LayMines.cs index 1f8f838c30..a5d93bcb70 100644 --- a/OpenRA.Mods.Common/Activities/LayMines.cs +++ b/OpenRA.Mods.Common/Activities/LayMines.cs @@ -150,7 +150,9 @@ namespace OpenRA.Mods.Common.Activities var positionable = (IPositionable)movement; var mobile = positionable as Mobile; minefield.RemoveAll(c => self.World.ActorMap.GetActorsAt(c) - .Any(a => a.Info.Name == minelayer.Info.Mine.ToLowerInvariant() && a.CanBeViewedByPlayer(self.Owner)) || + .Any(a => + string.Equals(a.Info.Name, minelayer.Info.Mine, System.StringComparison.OrdinalIgnoreCase) + && a.CanBeViewedByPlayer(self.Owner)) || ((!positionable.CanEnterCell(c, null, BlockedByActor.Immovable) || (mobile != null && !mobile.CanStayInCell(c))) && self.Owner.Shroud.IsVisible(c))); } diff --git a/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs b/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs index 4aa5b20204..7916956688 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdateUtils.cs @@ -336,7 +336,9 @@ namespace OpenRA.Mods.Common.UpdateRules public static bool IsAlreadyExtracted(string key) { +#pragma warning disable CA1862 // Use the 'StringComparison' method overloads to perform case-insensitive string comparisons if (key == key.ToLowerInvariant() && key.Any(c => c == '-') && key.All(c => c != ' ')) +#pragma warning restore CA1862 { Console.WriteLine($"Skipping {key} because it is already extracted."); return true;