Skip to content

Commit

Permalink
Enforce use of 'var' instead of explicit type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Dec 26, 2022
1 parent 9437515 commit 92ce83d
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Graphics/Palette.cs
Expand Up @@ -108,7 +108,7 @@ public ImmutablePalette(IPalette p, IPaletteRemap r)

public ImmutablePalette(IPalette p)
{
for (int i = 0; i < Palette.Size; i++)
for (var i = 0; i < Palette.Size; i++)
colors[i] = p[i];
}

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Map/MapPreview.cs
Expand Up @@ -344,7 +344,7 @@ public void UpdateFromMap(IReadOnlyPackage p, IReadOnlyPackage parent, MapClassi
if (yaml.TryGetValue("Visibility", out temp))
newData.Visibility = FieldLoader.GetValue<MapVisibility>("Visibility", temp.Value);

string requiresMod = string.Empty;
var requiresMod = string.Empty;
if (yaml.TryGetValue("RequiresMod", out temp))
requiresMod = temp.Value;

Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Game/Network/SyncReport.cs
Expand Up @@ -131,7 +131,7 @@ internal void DumpSyncReport(int frame)
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]}");
}
Expand All @@ -142,7 +142,7 @@ internal void DumpSyncReport(int frame)
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]}");
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Scripting/ScriptTypes.cs
Expand Up @@ -26,7 +26,7 @@ public static Type WrappedClrType(this LuaValue value)

public static bool TryGetClrValue<T>(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;
}
Expand Down
6 changes: 3 additions & 3 deletions OpenRA.Mods.Cnc/FileFormats/LZOCompression.cs
Expand Up @@ -77,12 +77,12 @@ static unsafe int LZO1xDecompress(byte* @in, uint inLen, byte* @out, ref uint ou
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);
Expand Down
8 changes: 4 additions & 4 deletions OpenRA.Mods.Cnc/UtilityCommands/ImportTSMapCommand.cs
Expand Up @@ -338,8 +338,8 @@ static void ReadTiles(Map map, IniFile file, int2 fullSize)
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);

Expand All @@ -354,8 +354,8 @@ static void ReadTiles(Map map, IniFile file, int2 fullSize)
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);

Expand Down
8 changes: 4 additions & 4 deletions OpenRA.Mods.Common/Projectiles/Missile.cs
Expand Up @@ -760,10 +760,10 @@ int IncreaseAltitude(int predClfDist, int diffClfMslHgt, int relTarHorDist, int

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);
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs
Expand Up @@ -175,8 +175,8 @@ public bool PlayMovieInRadar(string movie, LuaFunction playComplete = null)
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();
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/TargetExtensions.cs
Expand Up @@ -21,7 +21,7 @@ public static class TargetExtensions
/// /// </summary>
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;
}

Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/AutoTarget.cs
Expand Up @@ -342,7 +342,7 @@ Target ChooseTarget(Actor self, AttackBase ab, PlayerRelationship attackStances,
{
var chosenTarget = Target.Invalid;
var chosenTargetPriority = int.MinValue;
int chosenTargetRange = 0;
var chosenTargetRange = 0;

var activePriorities = activeTargetPriorities.ToList();
if (activePriorities.Count == 0)
Expand Down
Expand Up @@ -136,7 +136,7 @@ bool TickQueue(IBot bot, ProductionQueue queue)
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];
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Mobile.cs
Expand Up @@ -376,7 +376,7 @@ public void Nudge(Actor nudger)
{
var availCells = new List<CPos>();
var notStupidCells = new List<CPos>();
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)))
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/UtilityCommands/Extensions.cs
Expand Up @@ -19,7 +19,7 @@ public static class Extensions
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
var knownKeys = new HashSet<TKey>();
foreach (TSource element in source)
foreach (var element in source)
{
if (knownKeys.Add(keySelector(element)))
yield return element;
Expand Down
8 changes: 4 additions & 4 deletions OpenRA.Mods.Common/UtilityCommands/Rgba2Hex.cs
Expand Up @@ -25,7 +25,7 @@ bool IUtilityCommand.ValidateArguments(string[] args)
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)
Expand Down Expand Up @@ -75,7 +75,7 @@ bool PrintUsage()
[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)
Expand Down Expand Up @@ -113,7 +113,7 @@ bool IUtilityCommand.ValidateArguments(string[] args)
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)
Expand Down Expand Up @@ -180,7 +180,7 @@ bool PrintUsage()
[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)
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Widgets/ModelWidget.cs
Expand Up @@ -188,7 +188,7 @@ public override void PrepareRenderables()

var animations = new ModelAnimation[] { animation };

ModelPreview preview = new ModelPreview(
var preview = new ModelPreview(
new ModelAnimation[] { animation }, WVec.Zero, 0,
cachedScale,
new WAngle(cachedLightPitch),
Expand Down

0 comments on commit 92ce83d

Please sign in to comment.