From 19ecddcd86c242b65e2e0351537ffc8ca19d8501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Mon, 26 Dec 2022 15:28:53 +0100 Subject: [PATCH] Enforce use of 'var' instead of explicit type. --- .editorconfig | 3 +++ OpenRA.Game/Graphics/Palette.cs | 2 +- OpenRA.Game/Map/MapPreview.cs | 2 +- OpenRA.Game/Network/SyncReport.cs | 4 ++-- OpenRA.Game/Scripting/ScriptTypes.cs | 2 +- OpenRA.Mods.Cnc/FileFormats/LZOCompression.cs | 6 +++--- OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs | 8 ++++---- OpenRA.Mods.Common/Projectiles/Missile.cs | 8 ++++---- OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs | 4 ++-- OpenRA.Mods.Common/TargetExtensions.cs | 2 +- OpenRA.Mods.Common/Traits/AutoTarget.cs | 2 +- .../BotModules/BotModuleLogic/BaseBuilderQueueManager.cs | 2 +- OpenRA.Mods.Common/Traits/Mobile.cs | 2 +- OpenRA.Mods.Common/UtilityCommands/Extensions.cs | 2 +- OpenRA.Mods.Common/UtilityCommands/Rgba2Hex.cs | 8 ++++---- OpenRA.Mods.Common/Widgets/ModelWidget.cs | 2 +- 16 files changed, 31 insertions(+), 28 deletions(-) diff --git a/.editorconfig b/.editorconfig index 9902b623b4..90d8b1132e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -126,6 +126,9 @@ dotnet_style_predefined_type_for_locals_parameters_members = true # Show an IDE warning when default access modifiers are explicitly specified. dotnet_style_require_accessibility_modifiers = omit_if_default:warning +# use 'var' instead of explicit type +dotnet_diagnostic.IDE0007.severity = warning + # Don't prefer braces (for one liners). dotnet_diagnostic.IDE0011.severity = silent diff --git a/OpenRA.Game/Graphics/Palette.cs b/OpenRA.Game/Graphics/Palette.cs index c41bc2f278..c71a371544 100644 --- a/OpenRA.Game/Graphics/Palette.cs +++ b/OpenRA.Game/Graphics/Palette.cs @@ -108,7 +108,7 @@ namespace OpenRA.Graphics public ImmutablePalette(IPalette p) { - for (int i = 0; i < Palette.Size; i++) + for (var i = 0; i < Palette.Size; i++) colors[i] = p[i]; } diff --git a/OpenRA.Game/Map/MapPreview.cs b/OpenRA.Game/Map/MapPreview.cs index bae14db614..264314ed7f 100644 --- a/OpenRA.Game/Map/MapPreview.cs +++ b/OpenRA.Game/Map/MapPreview.cs @@ -344,7 +344,7 @@ namespace OpenRA if (yaml.TryGetValue("Visibility", out temp)) newData.Visibility = FieldLoader.GetValue("Visibility", temp.Value); - string requiresMod = string.Empty; + var requiresMod = string.Empty; if (yaml.TryGetValue("RequiresMod", out temp)) requiresMod = temp.Value; diff --git a/OpenRA.Game/Network/SyncReport.cs b/OpenRA.Game/Network/SyncReport.cs index 7e33f3585c..5d4557ba6c 100644 --- a/OpenRA.Game/Network/SyncReport.cs +++ b/OpenRA.Game/Network/SyncReport.cs @@ -131,7 +131,7 @@ namespace OpenRA.Network Log.Write("sync", $"\t {a.ActorID} {a.Type} {a.Owner} {a.Trait} ({a.Hash})"); var nvp = a.NamesValues; - for (int i = 0; i < nvp.Names.Length; i++) + for (var i = 0; i < nvp.Names.Length; i++) if (nvp.Values[i] != null) Log.Write("sync", $"\t\t {nvp.Names[i]}: {nvp.Values[i]}"); } @@ -142,7 +142,7 @@ namespace OpenRA.Network Log.Write("sync", "\t {0} ({1})", e.Name, e.Hash); var nvp = e.NamesValues; - for (int i = 0; i < nvp.Names.Length; i++) + for (var i = 0; i < nvp.Names.Length; i++) if (nvp.Values[i] != null) Log.Write("sync", $"\t\t {nvp.Names[i]}: {nvp.Values[i]}"); } diff --git a/OpenRA.Game/Scripting/ScriptTypes.cs b/OpenRA.Game/Scripting/ScriptTypes.cs index 50602a802b..8c04be6918 100644 --- a/OpenRA.Game/Scripting/ScriptTypes.cs +++ b/OpenRA.Game/Scripting/ScriptTypes.cs @@ -26,7 +26,7 @@ namespace OpenRA.Scripting public static bool TryGetClrValue(this LuaValue value, out T clrObject) { - var ret = value.TryGetClrValue(typeof(T), out object temp); + var ret = value.TryGetClrValue(typeof(T), out var temp); clrObject = ret ? (T)temp : default; return ret; } diff --git a/OpenRA.Mods.Cnc/FileFormats/LZOCompression.cs b/OpenRA.Mods.Cnc/FileFormats/LZOCompression.cs index d394381e4d..0c6d606af1 100644 --- a/OpenRA.Mods.Cnc/FileFormats/LZOCompression.cs +++ b/OpenRA.Mods.Cnc/FileFormats/LZOCompression.cs @@ -77,12 +77,12 @@ namespace OpenRA.Mods.Cnc.FileFormats byte* ip; uint t; byte* mPos; - byte* ipEnd = @in + inLen; + var ipEnd = @in + inLen; outLen = 0; op = @out; ip = @in; - bool gtFirstLiteralRun = false; - bool gtMatchDone = false; + var gtFirstLiteralRun = false; + var gtMatchDone = false; if (*ip > 17) { t = (uint)(*ip++ - 17); diff --git a/OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs index c037feb83f..8fa227e658 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs @@ -338,8 +338,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands var mapSection = file.GetSection("IsoMapPack5"); var data = Convert.FromBase64String(string.Concat(mapSection.Select(kvp => kvp.Value))); - int cells = (fullSize.X * 2 - 1) * fullSize.Y; - int lzoPackSize = cells * 11 + 4; // last 4 bytes contains a lzo pack header saying no more data is left + var cells = (fullSize.X * 2 - 1) * fullSize.Y; + var lzoPackSize = cells * 11 + 4; // last 4 bytes contains a lzo pack header saying no more data is left var isoMapPack = new byte[lzoPackSize]; UnpackLZO(data, isoMapPack); @@ -354,8 +354,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands var z = mf.ReadUInt8(); /*var zero2 = */mf.ReadUInt8(); - int dx = rx - ry + fullSize.X - 1; - int dy = rx + ry - fullSize.X - 1; + var dx = rx - ry + fullSize.X - 1; + var dy = rx + ry - fullSize.X - 1; var mapCell = new MPos(dx / 2, dy); var cell = mapCell.ToCPos(map); diff --git a/OpenRA.Mods.Common/Projectiles/Missile.cs b/OpenRA.Mods.Common/Projectiles/Missile.cs index 0a9c4abfe4..1b71277f51 100644 --- a/OpenRA.Mods.Common/Projectiles/Missile.cs +++ b/OpenRA.Mods.Common/Projectiles/Missile.cs @@ -760,10 +760,10 @@ namespace OpenRA.Mods.Common.Projectiles WVec HomingTick(World world, in WVec tarDistVec, int relTarHorDist) { - int predClfHgt = 0; - int predClfDist = 0; - int lastHtChg = 0; - int lastHt = 0; + var predClfHgt = 0; + var predClfDist = 0; + var lastHtChg = 0; + var lastHt = 0; if (info.TerrainHeightAware) InclineLookahead(world, relTarHorDist, out predClfHgt, out predClfDist, out lastHtChg, out lastHt); diff --git a/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs index b63cfa36d6..d0202ec736 100644 --- a/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs @@ -175,8 +175,8 @@ namespace OpenRA.Mods.Common.Scripting return false; } - AsyncLoader l = new AsyncLoader(Media.LoadVideo); - IAsyncResult ar = l.BeginInvoke(s, null, null); + var l = new AsyncLoader(Media.LoadVideo); + var ar = l.BeginInvoke(s, null, null); Action onLoadComplete = () => { Media.StopFMVInRadar(); diff --git a/OpenRA.Mods.Common/TargetExtensions.cs b/OpenRA.Mods.Common/TargetExtensions.cs index bd3ecaf227..5d2d35758e 100644 --- a/OpenRA.Mods.Common/TargetExtensions.cs +++ b/OpenRA.Mods.Common/TargetExtensions.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common /// /// public static Target RecalculateInvalidatingHiddenTargets(this Target t, Player viewer) { - var updated = t.Recalculate(viewer, out bool targetIsHiddenActor); + var updated = t.Recalculate(viewer, out var targetIsHiddenActor); return targetIsHiddenActor ? Target.Invalid : updated; } diff --git a/OpenRA.Mods.Common/Traits/AutoTarget.cs b/OpenRA.Mods.Common/Traits/AutoTarget.cs index 161881aa1b..b8747d2547 100644 --- a/OpenRA.Mods.Common/Traits/AutoTarget.cs +++ b/OpenRA.Mods.Common/Traits/AutoTarget.cs @@ -342,7 +342,7 @@ namespace OpenRA.Mods.Common.Traits { var chosenTarget = Target.Invalid; var chosenTargetPriority = int.MinValue; - int chosenTargetRange = 0; + var chosenTargetRange = 0; var activePriorities = activeTargetPriorities.ToList(); if (activePriorities.Count == 0) diff --git a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs index e5022821a1..32bfa8118f 100644 --- a/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs +++ b/OpenRA.Mods.Common/Traits/BotModules/BotModuleLogic/BaseBuilderQueueManager.cs @@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.Traits var type = BuildingType.Building; CPos? location = null; var actorVariant = 0; - string orderString = "PlaceBuilding"; + var orderString = "PlaceBuilding"; // Check if Building is a plug for other Building var actorInfo = world.Map.Rules.Actors[currentBuilding.Item]; diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 228ff39004..c1c048fb46 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -376,7 +376,7 @@ namespace OpenRA.Mods.Common.Traits { var availCells = new List(); var notStupidCells = new List(); - foreach (CVec direction in CVec.Directions) + foreach (var direction in CVec.Directions) { var p = ToCell + direction; if (CanEnterCell(p) && CanStayInCell(p) && (preferToAvoid == null || !preferToAvoid(p))) diff --git a/OpenRA.Mods.Common/UtilityCommands/Extensions.cs b/OpenRA.Mods.Common/UtilityCommands/Extensions.cs index a3217221d1..de1d128941 100644 --- a/OpenRA.Mods.Common/UtilityCommands/Extensions.cs +++ b/OpenRA.Mods.Common/UtilityCommands/Extensions.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.Common.UtilityCommands public static IEnumerable DistinctBy(this IEnumerable source, Func keySelector) { var knownKeys = new HashSet(); - foreach (TSource element in source) + foreach (var element in source) { if (knownKeys.Add(keySelector(element))) yield return element; diff --git a/OpenRA.Mods.Common/UtilityCommands/Rgba2Hex.cs b/OpenRA.Mods.Common/UtilityCommands/Rgba2Hex.cs index c2d6575994..7e73d7d497 100644 --- a/OpenRA.Mods.Common/UtilityCommands/Rgba2Hex.cs +++ b/OpenRA.Mods.Common/UtilityCommands/Rgba2Hex.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.UtilityCommands return PrintUsage(); var invalid = false; - for (int i = 1; i < args.Length; i++) + for (var i = 1; i < args.Length; i++) { var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 3 && parts.Length != 4) @@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.UtilityCommands [Desc("Convert r,g,b[,a] triples/quads into hex colors")] void IUtilityCommand.Run(Utility utility, string[] args) { - for (int i = 1; i < args.Length;) + for (var i = 1; i < args.Length;) { var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 3) @@ -113,7 +113,7 @@ namespace OpenRA.Mods.Common.UtilityCommands return PrintUsage(); var invalid = false; - for (int i = 1; i < args.Length; i++) + for (var i = 1; i < args.Length; i++) { var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 3 && parts.Length != 4) @@ -180,7 +180,7 @@ namespace OpenRA.Mods.Common.UtilityCommands [Desc("Convert a,r,g,b legacy colors into hex colors")] void IUtilityCommand.Run(Utility utility, string[] args) { - for (int i = 1; i < args.Length;) + for (var i = 1; i < args.Length;) { var parts = args[i].Split(Comma, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 3) diff --git a/OpenRA.Mods.Common/Widgets/ModelWidget.cs b/OpenRA.Mods.Common/Widgets/ModelWidget.cs index ca72ffda87..1500e4543d 100644 --- a/OpenRA.Mods.Common/Widgets/ModelWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ModelWidget.cs @@ -188,7 +188,7 @@ namespace OpenRA.Mods.Common.Widgets var animations = new ModelAnimation[] { animation }; - ModelPreview preview = new ModelPreview( + var preview = new ModelPreview( new ModelAnimation[] { animation }, WVec.Zero, 0, cachedScale, new WAngle(cachedLightPitch),