Fix RCS1257, RCS1258, RCS1261, RCS1262, RCS1265, RCS1266, RCS1267
This commit is contained in:
committed by
Gustas Kažukauskas
parent
a324af1afd
commit
1b2c119b58
@@ -1263,3 +1263,24 @@ dotnet_diagnostic.RCS1239.severity = warning
|
||||
|
||||
# Use element access.
|
||||
dotnet_diagnostic.RCS1246.severity = warning
|
||||
|
||||
# Use enum field explicitly.
|
||||
dotnet_diagnostic.RCS1257.severity = warning
|
||||
|
||||
# Unnecessary enum flag.
|
||||
dotnet_diagnostic.RCS1258.severity = warning
|
||||
|
||||
# Resource can be disposed asynchronously.
|
||||
dotnet_diagnostic.RCS1261.severity = warning
|
||||
|
||||
# Unnecessary raw string literal.
|
||||
dotnet_diagnostic.RCS1262.severity = warning
|
||||
|
||||
# Remove redundant catch block.
|
||||
dotnet_diagnostic.RCS1265.severity = warning
|
||||
|
||||
# Use raw string literal.
|
||||
dotnet_diagnostic.RCS1266.severity = warning
|
||||
|
||||
# Use string interpolation instead of 'string.Concat'.
|
||||
dotnet_diagnostic.RCS1267.severity = warning
|
||||
|
||||
@@ -53,7 +53,7 @@
|
||||
<!-- StyleCop/Roslynator -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" PrivateAssets="All" />
|
||||
<PackageReference Include="Roslynator.Analyzers" Version="4.2.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Roslynator.Formatting.Analyzers" Version="4.2.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Roslynator.Analyzers" Version="4.13.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Roslynator.Formatting.Analyzers" Version="4.13.0" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.FileSystem
|
||||
return Directory.GetFiles(Name, "*", SearchOption.TopDirectoryOnly)
|
||||
.Concat(Directory.GetDirectories(Name))
|
||||
.Select(Path.GetFileName)
|
||||
.OrderBy(f => f);
|
||||
.Order();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -408,7 +408,7 @@ namespace OpenRA
|
||||
|
||||
// Sanitize input from platform-specific launchers
|
||||
// Process.Start requires paths to not be quoted, even if they contain spaces
|
||||
if (launchPath != null && launchPath[0] == '"' && launchPath.Last() == '"')
|
||||
if (launchPath != null && launchPath[0] == '"' && launchPath[^1] == '"')
|
||||
launchPath = launchPath[1..^1];
|
||||
|
||||
// Metadata registration requires an explicit launch path
|
||||
@@ -584,7 +584,7 @@ namespace OpenRA
|
||||
Directory.CreateDirectory(directory);
|
||||
|
||||
var filename = TimestampedFilename(true);
|
||||
var path = Path.Combine(directory, string.Concat(filename, ".png"));
|
||||
var path = Path.Combine(directory, $"{filename}.png");
|
||||
Log.Write("debug", "Taking screenshot " + path);
|
||||
|
||||
Renderer.SaveScreenshot(path);
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA
|
||||
var total = response.Content.Headers.ContentLength ?? -1;
|
||||
var canReportProgress = total > 0;
|
||||
|
||||
using (var contentStream = await response.Content.ReadAsStreamAsync(token))
|
||||
await using (var contentStream = await response.Content.ReadAsStreamAsync(token))
|
||||
{
|
||||
var totalRead = 0L;
|
||||
var buffer = new byte[8192];
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Mods.Cnc.AudioLoaders
|
||||
@@ -186,7 +185,7 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
|
||||
// See if last block contained additional information
|
||||
if (blockList.Count > 0)
|
||||
{
|
||||
var b = blockList.Last();
|
||||
var b = blockList[^1];
|
||||
if (b.Code == 8)
|
||||
{
|
||||
block.SampleBlock.Rate = b.SampleBlock.Rate;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
|
||||
if (pos != 0)
|
||||
name = name[..pos];
|
||||
|
||||
Filename = string.Concat(name, ".wav");
|
||||
Filename = $"{name}.wav";
|
||||
Offset = s.ReadUInt32();
|
||||
Length = s.ReadUInt32();
|
||||
SampleRate = s.ReadUInt32();
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
||||
[Desc("PNGFILE [PNGFILE ...]", "Combine a list of PNG images into a SHP")]
|
||||
void IUtilityCommand.Run(Utility utility, string[] args)
|
||||
{
|
||||
var inputFiles = GlobArgs(args).OrderBy(a => a).ToList();
|
||||
var inputFiles = GlobArgs(args).Order().ToList();
|
||||
var dest = inputFiles[0].Split('-').First() + ".shp";
|
||||
|
||||
var frames = inputFiles.ConvertAll(a => new Png(File.OpenRead(a)));
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
||||
if (!string.IsNullOrEmpty(foundation))
|
||||
{
|
||||
var dimensions = foundation.Split('x');
|
||||
if (dimensions[0] == "0" || dimensions.Last() == "0")
|
||||
if (dimensions[0] == "0" || dimensions[^1] == "0")
|
||||
Console.WriteLine("\tImmobile:\n \t\tOccupiesSpace: False");
|
||||
else
|
||||
{
|
||||
@@ -149,11 +149,11 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
||||
if (!string.IsNullOrEmpty(adjacent))
|
||||
Console.WriteLine("\t\tAdjacent: " + adjacent);
|
||||
|
||||
Console.WriteLine("\t\tDimensions: " + dimensions[0] + "," + dimensions.Last());
|
||||
Console.WriteLine("\t\tDimensions: " + dimensions[0] + "," + dimensions[^1]);
|
||||
|
||||
Console.Write("\t\tFootprint:");
|
||||
int.TryParse(dimensions[0], out var width);
|
||||
int.TryParse(dimensions.Last(), out var height);
|
||||
int.TryParse(dimensions[^1], out var height);
|
||||
for (var y = 0; y < height; y++)
|
||||
{
|
||||
Console.Write(" ");
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#endregion
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Cnc.FileFormats;
|
||||
using OpenRA.Video;
|
||||
|
||||
@@ -65,7 +64,7 @@ namespace OpenRA.Mods.Cnc.VideoLoaders
|
||||
|
||||
s.Position = start;
|
||||
|
||||
return s.Length == offsets.Last();
|
||||
return s.Length == offsets[^1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Commands
|
||||
{
|
||||
TextNotificationsManager.Debug(FluentProvider.GetMessage(AvailableCommands));
|
||||
|
||||
foreach (var key in console.Commands.Keys.OrderBy(k => k))
|
||||
foreach (var key in console.Commands.Keys.Order())
|
||||
{
|
||||
if (!helpDescriptions.TryGetValue(key, out var description))
|
||||
description = FluentProvider.GetMessage(NoDescription);
|
||||
|
||||
@@ -96,10 +96,10 @@ namespace OpenRA.Mods.Common.Effects
|
||||
{
|
||||
var palette = wr.Palette(rp.PaletteName);
|
||||
if (circles != null)
|
||||
renderables = renderables.Concat(circles.Render(targetLineNodes.Last(), palette));
|
||||
renderables = renderables.Concat(circles.Render(targetLineNodes[^1], palette));
|
||||
|
||||
if (flag != null)
|
||||
renderables = renderables.Concat(flag.Render(targetLineNodes.Last(), palette));
|
||||
renderables = renderables.Concat(flag.Render(targetLineNodes[^1], palette));
|
||||
}
|
||||
|
||||
return renderables;
|
||||
|
||||
@@ -163,7 +163,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
// Scripted cargo aircraft must turn to default position before unloading.
|
||||
// TODO: pass facing through UnloadCargo instead.
|
||||
if (aircraft != null)
|
||||
transport.QueueActivity(new Land(transport, Target.FromCell(transport.World, entryPath.Last()), WDist.FromCells(dropRange)));
|
||||
transport.QueueActivity(new Land(transport, Target.FromCell(transport.World, entryPath[^1]), WDist.FromCells(dropRange)));
|
||||
|
||||
if (cargo != null)
|
||||
transport.QueueActivity(new UnloadCargo(transport, WDist.FromCells(dropRange)));
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
get
|
||||
{
|
||||
if (rp.Path.Count > 0)
|
||||
return rp.Path.Last();
|
||||
return rp.Path[^1];
|
||||
|
||||
var exit = Self.NearestExitOrDefault(Self.CenterPosition);
|
||||
if (exit != null)
|
||||
|
||||
@@ -331,11 +331,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public bool HasSpace(int weight) { return totalWeight + reservedWeight + weight <= Info.MaxWeight; }
|
||||
public bool IsEmpty() { return cargo.Count == 0; }
|
||||
|
||||
public Actor Peek() { return cargo.Last(); }
|
||||
public Actor Peek() { return cargo[^1]; }
|
||||
|
||||
public Actor Unload(Actor self, Actor passenger = null)
|
||||
{
|
||||
passenger ??= cargo.Last();
|
||||
passenger ??= cargo[^1];
|
||||
if (!cargo.Remove(passenger))
|
||||
throw new ArgumentException("Attempted to unload an actor that is not a passenger.");
|
||||
|
||||
|
||||
@@ -373,7 +373,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
});
|
||||
|
||||
if (path.Count > 0)
|
||||
return lookup[path.Last()];
|
||||
return lookup[path[^1]];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
static string MakeKey(string[] prerequisites)
|
||||
{
|
||||
return "condition_" + string.Join("_", prerequisites.OrderBy(a => a));
|
||||
return "condition_" + string.Join("_", prerequisites.Order());
|
||||
}
|
||||
|
||||
public void Register(Actor actor, GrantConditionOnPrerequisite u, string[] prerequisites)
|
||||
|
||||
@@ -477,7 +477,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var types = typeWeights
|
||||
.Select(kv => kv.Key)
|
||||
.OrderBy(k => k)
|
||||
.Order()
|
||||
.ToArray();
|
||||
var weights = types
|
||||
.Select(type => typeWeights[type])
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
allCategories = allActors.SelectMany(ac => ac.Categories)
|
||||
.Distinct()
|
||||
.OrderBy(x => x)
|
||||
.Order()
|
||||
.ToArray();
|
||||
|
||||
foreach (var c in allCategories)
|
||||
@@ -149,7 +149,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
s => s.Contains(searchFilter, StringComparison.CurrentCultureIgnoreCase)))
|
||||
.SelectMany(t => t.Categories)
|
||||
.Distinct()
|
||||
.OrderBy(x => x));
|
||||
.Order());
|
||||
else
|
||||
FilteredCategories.AddRange(allCategories);
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
return;
|
||||
}
|
||||
|
||||
using (var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.ReadWrite, 8192, true))
|
||||
await using (var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.ReadWrite, 8192, true))
|
||||
{
|
||||
await response.ReadAsStreamWithProgress(fileStream, OnDownloadProgress, token);
|
||||
}
|
||||
@@ -205,7 +205,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var archiveValid = false;
|
||||
try
|
||||
{
|
||||
using (var stream = File.OpenRead(file))
|
||||
await using (var stream = File.OpenRead(file))
|
||||
{
|
||||
var archiveSHA1 = CryptoUtil.SHA1Hash(stream);
|
||||
Log.Write("install", "Downloaded SHA1: " + archiveSHA1);
|
||||
@@ -233,7 +233,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var extracted = new List<string>();
|
||||
try
|
||||
{
|
||||
using (var stream = File.OpenRead(file))
|
||||
await using (var stream = File.OpenRead(file))
|
||||
{
|
||||
var packageLoader = modData.ObjectCreator.CreateObject<IPackageLoader>($"{download.Type}Loader");
|
||||
|
||||
@@ -253,8 +253,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
|
||||
extracted.Add(targetPath);
|
||||
|
||||
using (var zz = package.GetStream(kv.Value))
|
||||
using (var f = File.Create(targetPath))
|
||||
await using (var zz = package.GetStream(kv.Value))
|
||||
await using (var f = File.Create(targetPath))
|
||||
await zz.CopyToAsync(f);
|
||||
}
|
||||
|
||||
|
||||
@@ -887,7 +887,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (orderManager.LobbyInfo.GlobalSettings.Dedicated)
|
||||
{
|
||||
var endpoint = CurrentServerSettings.Target.GetConnectEndPoints().First();
|
||||
secret = string.Concat(endpoint.Address, "|", endpoint.Port);
|
||||
secret = $"{endpoint.Address}|{endpoint.Port}";
|
||||
}
|
||||
|
||||
var state = skirmishMode ? DiscordState.InSkirmishLobby : DiscordState.InMultiplayerLobby;
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace OpenRA.Test
|
||||
Assert.That(queue.Empty, Is.False, "Queue should not be empty - items have been added.");
|
||||
}
|
||||
|
||||
foreach (var value in shuffledValues.Take(10).OrderBy(x => x).Take(5))
|
||||
foreach (var value in shuffledValues.Take(10).Order().Take(5))
|
||||
{
|
||||
Assert.That(value, Is.EqualTo(queue.Peek()), "Peek returned the wrong item - should be in order.");
|
||||
Assert.That(queue.Empty, Is.False, "Queue should not be empty yet.");
|
||||
@@ -125,8 +125,8 @@ namespace OpenRA.Test
|
||||
Assert.That(queue.Empty, Is.False, "Queue should not be empty - items have been added.");
|
||||
}
|
||||
|
||||
foreach (var value in shuffledValues.Take(10).OrderBy(x => x).Skip(5)
|
||||
.Concat(shuffledValues.Skip(10).Take(5)).OrderBy(x => x).Take(5))
|
||||
foreach (var value in shuffledValues.Take(10).Order().Skip(5)
|
||||
.Concat(shuffledValues.Skip(10).Take(5)).Order().Take(5))
|
||||
{
|
||||
Assert.That(value, Is.EqualTo(queue.Peek()), "Peek returned the wrong item - should be in order.");
|
||||
Assert.That(queue.Empty, Is.False, "Queue should not be empty yet.");
|
||||
@@ -139,9 +139,9 @@ namespace OpenRA.Test
|
||||
Assert.That(queue.Empty, Is.False, "Queue should not be empty - items have been added.");
|
||||
}
|
||||
|
||||
foreach (var value in shuffledValues.Take(10).OrderBy(x => x).Skip(5)
|
||||
.Concat(shuffledValues.Skip(10).Take(5)).OrderBy(x => x).Skip(5)
|
||||
.Concat(shuffledValues.Skip(15)).OrderBy(x => x))
|
||||
foreach (var value in shuffledValues.Take(10).Order().Skip(5)
|
||||
.Concat(shuffledValues.Skip(10).Take(5)).Order().Skip(5)
|
||||
.Concat(shuffledValues.Skip(15)).Order())
|
||||
{
|
||||
Assert.That(value, Is.EqualTo(queue.Peek()), "Peek returned the wrong item - should be in order.");
|
||||
Assert.That(queue.Empty, Is.False, "Queue should not be empty yet.");
|
||||
|
||||
@@ -152,7 +152,7 @@ namespace OpenRA
|
||||
if (actions == null)
|
||||
return;
|
||||
|
||||
var keys = actions.Keys.OrderBy(x => x);
|
||||
var keys = actions.Keys.Order();
|
||||
|
||||
foreach (var key in keys)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user