Fix IDE0055

This rule no longer appears to be buggy, so enforce it. Some of the automated fixes are adjusted in order to improve the result. #pragma directives have no option to control indentation, so remove them where possible.
This commit is contained in:
RoosterDragon
2023-11-09 19:56:52 +00:00
committed by Pavel Penev
parent 60cbf79c9b
commit 360f24f609
58 changed files with 719 additions and 714 deletions

View File

@@ -427,10 +427,7 @@ dotnet_diagnostic.IDE0077.severity = warning
### Formatting Rules (IDE0055)
### https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0055
# We may eventually wish to enforce this rule, however some existing formatting conflicts with the rule despite being reasonable.
# Additionally, the rule is buggy and likes to report spuriously after invoking Format Document in the IDE.
dotnet_diagnostic.IDE0055.severity = none
dotnet_diagnostic.IDE0055.severity = warning
#dotnet_sort_system_directives_first = true
#dotnet_separate_import_directive_groups = false
@@ -448,7 +445,7 @@ dotnet_diagnostic.IDE0055.severity = none
#csharp_indent_labels = one_less_than_current
#csharp_indent_block_contents = true
#csharp_indent_braces = false
#csharp_indent_case_contents_when_block = true
csharp_indent_case_contents_when_block = false
#csharp_space_after_cast = false
#csharp_space_after_keywords_in_control_flow_statements = true

View File

@@ -50,7 +50,7 @@ namespace OpenRA.FileFormats
var length = IPAddress.NetworkToHostOrder(s.ReadInt32());
var type = s.ReadASCII(4);
var content = s.ReadBytes(length);
/*var crc = */s.ReadInt32();
s.ReadInt32(); // crc
if (!headerParsed && type != "IHDR")
throw new InvalidDataException("Invalid PNG file - header does not appear first.");
@@ -76,7 +76,7 @@ namespace OpenRA.FileFormats
Data = new byte[Width * Height * PixelStride];
var compression = ms.ReadUInt8();
/*var filter = */ms.ReadUInt8();
ms.ReadUInt8(); // filter
var interlace = ms.ReadUInt8();
if (compression != 0)

View File

@@ -152,7 +152,8 @@ namespace OpenRA
// If a more specific init is not available, fall back to an unnamed init.
// If duplicate inits are defined, take the last to match standard yaml override expectations
if (info != null && !string.IsNullOrEmpty(info.InstanceName))
return inits.LastOrDefault(i => i.InstanceName == info.InstanceName) ??
return
inits.LastOrDefault(i => i.InstanceName == info.InstanceName) ??
inits.LastOrDefault(i => string.IsNullOrEmpty(i.InstanceName));
// Untagged traits will only use untagged inits

View File

@@ -280,7 +280,8 @@ namespace OpenRA.Server
}
}
}
}) { Name = $"Connection listener ({listener.LocalEndpoint})", IsBackground = true }.Start();
})
{ Name = $"Connection listener ({listener.LocalEndpoint})", IsBackground = true }.Start();
}
catch (SocketException ex)
{
@@ -1504,9 +1505,9 @@ namespace OpenRA.Server
readonly int[] pingHistory;
// TODO: future net code changes
#pragma warning disable IDE0052
#pragma warning disable IDE0052
readonly byte queueLength;
#pragma warning restore IDE0052
#pragma warning restore IDE0052
public ConnectionPingEvent(Connection connection, int[] pingHistory, byte queueLength)
{

View File

@@ -157,28 +157,26 @@ namespace OpenRA
var lsq = x * x + y * y + z * z + w * w;
// Quaternion components use 10 bits, so there's no risk of overflow
#pragma warning disable SA1115 // Allow blank lines to visually separate matrix rows
mtx = new Int32Matrix4x4(
lsq - 2 * (y * y + z * z),
2 * (x * y + z * w),
2 * (x * z - y * w),
0,
/* row */
2 * (x * y - z * w),
lsq - 2 * (x * x + z * z),
2 * (y * z + x * w),
0,
/* row */
2 * (x * z + y * w),
2 * (y * z - x * w),
lsq - 2 * (x * x + y * y),
0,
/* row */
0,
0,
0,
lsq);
#pragma warning restore SA1115
}
public Int32Matrix4x4 AsMatrix()

View File

@@ -251,9 +251,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
*op++ = *ip++;
if (t > 2)
{
#pragma warning disable IDE0047
(*op++) = *ip++;
#pragma warning restore IDE0047
*op++ = *ip++;
}
}

View File

@@ -68,13 +68,13 @@ namespace OpenRA.Mods.Cnc.FileFormats
// Decode FORM chunk
if (stream.ReadASCII(4) != "FORM")
throw new InvalidDataException("Invalid vqa (invalid FORM section)");
/*var length = */stream.ReadUInt32();
stream.ReadUInt32(); // length
if (stream.ReadASCII(8) != "WVQAVQHD")
throw new InvalidDataException("Invalid vqa (not WVQAVQHD)");
/*var length2 = */stream.ReadUInt32();
stream.ReadUInt32(); // length2
/*var version = */stream.ReadUInt16();
stream.ReadUInt16(); // version
videoFlags = stream.ReadUInt16();
FrameCount = stream.ReadUInt16();
Width = stream.ReadUInt16();
@@ -87,20 +87,20 @@ namespace OpenRA.Mods.Cnc.FileFormats
blocks = new int2(Width / blockWidth, Height / blockHeight);
numColors = stream.ReadUInt16();
/*var maxBlocks = */stream.ReadUInt16();
/*var unknown1 = */stream.ReadUInt16();
/*var unknown2 = */stream.ReadUInt32();
stream.ReadUInt16(); // maxBlocks
stream.ReadUInt16(); // unknown1
stream.ReadUInt32(); // unknown2
// Audio
SampleRate = stream.ReadUInt16();
AudioChannels = stream.ReadUInt8();
SampleBits = stream.ReadUInt8();
/*var unknown3 =*/stream.ReadUInt32();
/*var unknown4 =*/stream.ReadUInt16();
/*maxCbfzSize =*/stream.ReadUInt32(); // Unreliable
stream.ReadUInt32(); // unknown3
stream.ReadUInt16(); // unknown4
stream.ReadUInt32(); // maxCbfzSize, unreliable
/*var unknown5 =*/stream.ReadUInt32();
stream.ReadUInt32(); // unknown5
if (IsHqVqa)
{
@@ -131,8 +131,8 @@ namespace OpenRA.Mods.Cnc.FileFormats
throw new NotSupportedException($"Vqa uses unknown Subtype: {type}");
}
/*var length = */stream.ReadUInt16();
/*var unknown4 = */stream.ReadUInt16();
stream.ReadUInt16(); // length
stream.ReadUInt16(); // unknown4
// Frame offsets
offsets = new uint[FrameCount];

View File

@@ -45,13 +45,13 @@ namespace OpenRA.Mods.Cnc.FileFormats
FrameCount = stream.ReadUInt16();
/*var x = */stream.ReadUInt16();
/*var y = */stream.ReadUInt16();
stream.ReadUInt16(); // x
stream.ReadUInt16(); // y
Width = stream.ReadUInt16();
Height = stream.ReadUInt16();
/*var delta = */stream.ReadUInt16(); /* + 37*/
stream.ReadUInt16(); // delta (+37)
var flags = stream.ReadUInt16();
frameOffsets = new uint[FrameCount + 2];

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
try
{
/* var signature = */ s.ReadASCII(4);
s.ReadASCII(4); // signature
// Total archive size.
s.ReadUInt32();

View File

@@ -113,7 +113,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
{
s.Seek(offset, SeekOrigin.Begin);
var numFiles = s.ReadUInt16();
/*uint dataSize = */s.ReadUInt32();
s.ReadUInt32(); // dataSize
var items = new List<PackageEntry>();
for (var i = 0; i < numFiles; i++)

View File

@@ -37,7 +37,8 @@ namespace OpenRA.Mods.Cnc.Graphics
: this(renderer, models, pos, zOffset, camera, scale,
lightSource, lightAmbientColor, lightDiffuseColor,
color, normals, shadow, 1f,
float3.Ones, TintModifiers.None) { }
float3.Ones, TintModifiers.None)
{ }
public ModelRenderable(
ModelRenderer renderer, IEnumerable<ModelAnimation> models, WPos pos, int zOffset, in WRot camera, float scale,

View File

@@ -196,18 +196,24 @@ namespace OpenRA.Mods.Cnc.Traits
}
public Activity MoveTo(CPos cell, int nearEnough = 0, Actor ignoreActor = null,
bool evaluateNearestMovableCell = false, Color? targetLineColor = null) { return null; }
bool evaluateNearestMovableCell = false, Color? targetLineColor = null)
{ return null; }
public Activity MoveWithinRange(in Target target, WDist range,
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{ return null; }
public Activity MoveWithinRange(in Target target, WDist minRange, WDist maxRange,
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{ return null; }
public Activity MoveFollow(Actor self, in Target target, WDist minRange, WDist maxRange,
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{ return null; }
public Activity ReturnToCell(Actor self) { return null; }
public Activity MoveToTarget(Actor self, in Target target,
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{ return null; }
public Activity MoveOntoTarget(Actor self, in Target target, in WVec offset,
WAngle? facing, Color? targetLineColor = null) { return null; }
WAngle? facing, Color? targetLineColor = null)
{ return null; }
public Activity MoveIntoTarget(Actor self, in Target target) { return null; }
public Activity LocalMove(Actor self, WPos fromPos, WPos toPos) { return null; }

View File

@@ -194,7 +194,7 @@ namespace OpenRA.Mods.Cnc.Traits
var correctionTransform = Util.MatrixMultiply(translateMtx, FlipMtx);
var shadowCorrectionTransform = Util.MatrixMultiply(shadowTranslateMtx, ShadowScaleFlipMtx);
doRender.Add((sprite.Sheet, () =>
void RenderFunc()
{
foreach (var m in models)
{
@@ -235,7 +235,9 @@ namespace OpenRA.Mods.Cnc.Traits
ShadowAmbient, ShadowDiffuse, shadowPalette.TextureIndex, normals.TextureIndex);
}
}
}));
}
doRender.Add((sprite.Sheet, RenderFunc));
var screenLightVector = Util.MatrixVectorMultiply(invShadowTransform, ZVector);
screenLightVector = Util.MatrixVectorMultiply(cameraTransform, screenLightVector);

View File

@@ -119,10 +119,10 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
var rx = mf.ReadUInt16();
var ry = mf.ReadUInt16();
var tilenum = mf.ReadUInt16();
/*var zero1 = */mf.ReadInt16();
mf.ReadInt16(); // zero1
var subtile = mf.ReadUInt8();
var z = mf.ReadUInt8();
/*var zero2 = */mf.ReadUInt8();
mf.ReadUInt8(); // zero2
var uv = ToMPos(rx, ry, fullSize.X);

View File

@@ -115,8 +115,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
var templateWidth = s.ReadUInt32();
var templateHeight = s.ReadUInt32();
/* var tileWidth = */s.ReadInt32();
/* var tileHeight = */s.ReadInt32();
s.ReadInt32(); // tileWidth
s.ReadInt32(); // tileHeight
var offsets = new uint[templateWidth * templateHeight];
for (var j = 0; j < offsets.Length; j++)
offsets[j] = s.ReadUInt32();

View File

@@ -40,15 +40,15 @@ namespace OpenRA.Mods.Cnc.VideoLoaders
if (frames <= 1) // TODO: find a better way to differentiate .shp icons
return false;
/* var x = */ s.ReadUInt16();
/* var y = */ s.ReadUInt16();
s.ReadUInt16(); // x
s.ReadUInt16(); // y
var width = s.ReadUInt16();
var height = s.ReadUInt16();
if (width <= 0 || height <= 0)
return false;
/*var delta = */ s.ReadUInt16(); /* + 37;*/
s.ReadUInt16(); // delta (+37)
var flags = s.ReadUInt16();
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Cnc.VideoLoaders
if (flags == 1)
{
/* var palette = */ s.ReadBytes(768);
s.ReadBytes(768); // palette
for (var i = 0; i < offsets.Length; i++)
offsets[i] += 768;
}

View File

@@ -49,11 +49,11 @@ namespace OpenRA.Mods.Common.FileSystem
try
{
// Parse package header
/*var signature = */s.ReadUInt32();
s.ReadUInt32(); // signature
s.Position += 8;
/*var FileCount = */s.ReadUInt16();
s.ReadUInt16(); // FileCount
s.Position += 4;
/*var ArchiveSize = */s.ReadUInt32();
s.ReadUInt32(); // ArchiveSize
s.Position += 19;
var tocAddress = s.ReadInt32();
s.Position += 4;

View File

@@ -38,7 +38,8 @@ namespace OpenRA.Mods.Common.Graphics
: this(font, pos, zOffset, color,
ChromeMetrics.Get<Color>("TextContrastColorDark"),
ChromeMetrics.Get<Color>("TextContrastColorLight"),
text) { }
text)
{ }
public WPos Pos { get; }
public int ZOffset { get; }

View File

@@ -40,7 +40,8 @@ namespace OpenRA.Mods.Common.Graphics
: this(font, effectiveWorldPos, screenPos, zOffset, color,
ChromeMetrics.Get<Color>("TextContrastColorDark"),
ChromeMetrics.Get<Color>("TextContrastColorLight"),
text) { }
text)
{ }
public WPos Pos { get; }
public int ZOffset { get; }

View File

@@ -1262,8 +1262,7 @@ namespace OpenRA.Mods.Common.Traits
foreach (var cell in rallyPoint)
self.QueueActivity(new AttackMoveActivity(self, () => aircraft.MoveTo(cell, 1, evaluateNearestMovableCell: true, targetLineColor: Color.OrangeRed)));
}
else
if (self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length <= aircraft.LandAltitude.Length)
else if (self.World.Map.DistanceAboveTerrain(aircraft.CenterPosition).Length <= aircraft.LandAltitude.Length)
QueueChild(new TakeOff(self));
aircraft.UnReserve();

View File

@@ -217,10 +217,12 @@ namespace OpenRA.Mods.Common.Traits
chargedToken = self.RevokeCondition(chargedToken);
}
else
{
if (chargedToken == Actor.InvalidConditionToken)
chargedToken = self.GrantCondition(Info.ChargedCondition);
}
}
}
float ISelectionBar.GetValue()
{

View File

@@ -27,7 +27,8 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
public override IEnumerable<string> AfterUpdate(ModData modData)
{
if (locations.Count > 0)
yield return "The *Palette fields have been removed from the *PlaceBuildingPreview traits.\n" +
yield return
"The *Palette fields have been removed from the *PlaceBuildingPreview traits.\n" +
"You may wish to inspect the following definitions and define new Alpha or\n" +
"LineBuildSegmentAlpha properties as appropriate to recreate transparency effects:\n" +
UpdateUtils.FormatMessageList(locations);

View File

@@ -24,7 +24,8 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
public override IEnumerable<string> AfterUpdate(ModData modData)
{
if (locations.Count > 0)
yield return "You must define new Color fields on the following traits:\n" +
yield return
"You must define new Color fields on the following traits:\n" +
UpdateUtils.FormatMessageList(locations);
locations.Clear();

View File

@@ -56,7 +56,8 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
if (requiredMetadata.Count != 0)
{
yield return $"The ExplicitSequenceFilenames rule requires {requiredMetadata.JoinWith(", ")}\n" +
yield return
$"The ExplicitSequenceFilenames rule requires {requiredMetadata.JoinWith(", ")}\n" +
"to be defined under the SpriteSequenceFormat definition in mod.yaml.\n" +
"Add these definitions back and run the update rule again.";
disabled = true;
@@ -457,8 +458,7 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
var overrideFilename = filename;
if (useTilesetCode)
overrideFilename = filename[..1] + tilesetCodes[sequenceTileset] +
filename[2..];
overrideFilename = filename[..1] + tilesetCodes[sequenceTileset] + filename[2..];
if (addExtension)
overrideFilename += useTilesetExtension ? tilesetExtensions[sequenceTileset] : defaultSpriteExtension;

View File

@@ -26,7 +26,8 @@ namespace OpenRA.Mods.Common.UpdateRules.Rules
public override IEnumerable<string> AfterUpdate(ModData modData)
{
if (locations.Count > 0)
yield return "The PaletteFromEmbeddedSpritePalette trait no longer references a sequence.\n" +
yield return
"The PaletteFromEmbeddedSpritePalette trait no longer references a sequence.\n" +
"You must manually define Filename (and Frame if needed) on the following actors:\n" +
UpdateUtils.FormatMessageList(locations);

View File

@@ -79,9 +79,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
}
var png = new Png(pngData, SpriteFrameType.Indexed8, frameSize.Width, frameSize.Height, palColors);
#pragma warning disable SA1003
png.Save($"{prefix}-{count++:D4}.png");
#pragma warning restore SA1003
}
Console.WriteLine("Saved {0}-[0..{1}].png", prefix, count - 1);

View File

@@ -73,9 +73,7 @@ namespace OpenRA.Mods.Common.Widgets
{
for (var s = 0; s < 256; s++)
{
#pragma warning disable IDE0047
(*(c + s * 256 + v)) = Color.FromAhsv(newHue.Value, 1 - s / 255f, v / 255f).ToArgb();
#pragma warning restore IDE0047
*(c + s * 256 + v) = Color.FromAhsv(newHue.Value, 1 - s / 255f, v / 255f).ToArgb();
}
}
}

View File

@@ -39,9 +39,7 @@ namespace OpenRA.Mods.Common.Widgets
var c = (int*)cc;
for (var h = 0; h < 256; h++)
{
#pragma warning disable IDE0047
(*(c + 0 * 256 + h)) = Color.FromAhsv(h / 255f, 1, 1).ToArgb();
#pragma warning restore IDE0047
*(c + 0 * 256 + h) = Color.FromAhsv(h / 255f, 1, 1).ToArgb();
}
}
}

View File

@@ -749,7 +749,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var players = item.GetOrNull<LabelWithTooltipWidget>("PLAYERS");
if (players != null)
{
var label = $"{game.Players + game.Bots} / {game.MaxPlayers + game.Bots}"
var label =
$"{game.Players + game.Bots} / {game.MaxPlayers + game.Bots}"
+ (game.Spectators > 0 ? $" + {game.Spectators}" : "");
var color = canJoin ? players.TextColor : incompatibleGameColor;