Promote BHI1007 to a build error, fixing some cases and muting others

"Don't use target-typed new for throw expressions"
where there was a type name checked-in before being removed,
I've restored it (they were all `Exception`)
This commit is contained in:
YoshiRulz 2024-09-10 04:31:25 +10:00
parent a72b0f7e8c
commit 29c15adbbf
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
20 changed files with 38 additions and 13 deletions

View File

@ -18,7 +18,7 @@ dotnet_diagnostic.BHI1005.severity = error
# Do not discard local variables
dotnet_diagnostic.BHI1006.severity = error
# Don't use target-typed new for throw expressions
dotnet_diagnostic.BHI1007.severity = suggestion
dotnet_diagnostic.BHI1007.severity = error
# Don't call this.GetType() in sealed type, use typeof operator
dotnet_diagnostic.BHI1100.severity = error
# Don't call this.GetType(), use typeof operator (or replace subtype check with better encapsulation)

View File

@ -7,6 +7,8 @@ using BizHawk.Common.NumberExtensions;
using static SDL2.SDL;
#pragma warning disable BHI1007 // target-typed Exception TODO don't
namespace BizHawk.Bizware.Audio
{
internal sealed class SDL2WavStream : Stream, ISpanStream

View File

@ -3,6 +3,8 @@ using System.Numerics;
using Silk.NET.OpenGL;
#pragma warning disable BHI1007 // target-typed Exception TODO don't
namespace BizHawk.Bizware.Graphics
{
/// <summary>

View File

@ -9,6 +9,8 @@ using BizHawk.Common;
using static SDL2.SDL;
#pragma warning disable BHI1007 // target-typed Exception TODO don't
namespace BizHawk.Bizware.Graphics
{
/// <summary>

View File

@ -7,6 +7,8 @@ using BizHawk.Common.CollectionExtensions;
using static SDL2.SDL;
#pragma warning disable BHI1007 // target-typed Exception TODO don't
namespace BizHawk.Bizware.Graphics
{
/// <summary>

View File

@ -31,7 +31,10 @@ namespace BizHawk.Bizware.Input
if (Display == IntPtr.Zero)
{
throw new("Could not open XDisplay");
// There doesn't seem to be a convention for what exception type to throw in these situations. Can't use NRE. Well...
// _ = Unsafe.AsRef<X11.Display>()!; // hmm
// InvalidOperationException doesn't match. Exception it is. --yoshi
throw new Exception("Could not open XDisplay");
}
using (new XLock(Display))

View File

@ -9,6 +9,8 @@ using BizHawk.Common.CollectionExtensions;
using static SDL2.SDL;
#pragma warning disable BHI1007 // target-typed Exception TODO don't
namespace BizHawk.Bizware.Input
{
public sealed class SDL2InputAdapter : OSTailoredKeyInputAdapter

View File

@ -66,7 +66,7 @@ namespace BizHawk.Client.Common
}
else
{
throw new($"Couldn't load XMLGame Asset \"{filename}\"");
throw new Exception($"Couldn't load XMLGame Asset \"{filename}\"");
}
}
else
@ -96,7 +96,7 @@ namespace BizHawk.Client.Common
}
catch (Exception e)
{
throw new($"Couldn't load XMLGame LoadAsset \"{filename}\"", e);
throw new Exception($"Couldn't load XMLGame LoadAsset \"{filename}\"", e);
}
}

View File

@ -168,7 +168,7 @@ namespace BizHawk.Client.EmuHawk
{
if (!_workerT.IsAlive)
{
throw new("AVI Worker thread died!");
throw new Exception("AVI Worker thread died!");
}
}
}
@ -194,7 +194,7 @@ namespace BizHawk.Client.EmuHawk
{
if (!_workerT.IsAlive)
{
throw new("AVI Worker thread died!");
throw new Exception("AVI Worker thread died!");
}
}
}
@ -977,7 +977,7 @@ namespace BizHawk.Client.EmuHawk
public void SetDefaultVideoCodecToken(Config config)
{
var ct = CodecToken.DeSerialize(config.AviCodecToken);
_currVideoCodecToken = ct ?? throw new($"No default {nameof(config.AviCodecToken)} in config!");
_currVideoCodecToken = ct ?? throw new Exception($"No default {nameof(config.AviCodecToken)} in config!");
}
public string DesiredExtension()

View File

@ -11,6 +11,8 @@ using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Arcades.MAME;
using BizHawk.Emulation.DiscSystem;
#pragma warning disable BHI1007 // target-typed Exception TODO don't
namespace BizHawk.Client.EmuHawk
{
public partial class RCheevos

View File

@ -10,6 +10,8 @@ using BizHawk.Common.IOExtensions;
using BizHawk.Client.Common;
using BizHawk.Emulation.Common;
#pragma warning disable BHI1007 // target-typed Exception TODO don't
namespace BizHawk.Client.EmuHawk
{
public partial class RCheevos : RetroAchievements

View File

@ -13,6 +13,8 @@ using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.DiscSystem;
#pragma warning disable BHI1007 // target-typed Exception TODO don't
namespace BizHawk.Client.EmuHawk
{
public abstract partial class RetroAchievements

View File

@ -191,7 +191,7 @@ namespace BizHawk.Client.EmuHawk
lib.APIs = _apiContainer;
if (!ServiceInjector.UpdateServices(newServiceProvider, lib, mayCache: true))
{
throw new("Lua lib has required service(s) that can't be fulfilled");
throw new Exception("Lua lib has required service(s) that can't be fulfilled");
}
lib.Restarted();

View File

@ -219,7 +219,9 @@ namespace BizHawk.Common.PathExtensions
else
{
var dirPath = AppContext.BaseDirectory;
DataDirectoryPath = ExeDirectoryPath = string.IsNullOrEmpty(dirPath) ? throw new("failed to get location of executable, very bad things must have happened") : dirPath.RemoveSuffix('\\');
DataDirectoryPath = ExeDirectoryPath = string.IsNullOrEmpty(dirPath)
? throw new Exception("failed to get location of executable, very bad things must have happened")
: dirPath.RemoveSuffix('\\');
DllDirectoryPath = Path.Combine(ExeDirectoryPath, "dll");
}
}

View File

@ -279,7 +279,7 @@ namespace BizHawk.Common
using var proc = ConstructSubshell(cmd, args);
proc.Start();
var stdout = proc.StandardOutput;
if (stdout.EndOfStream) throw new($"{noOutputMsg} ({cmd} wrote nothing to stdout)");
if (stdout.EndOfStream) throw new Exception($"{noOutputMsg} ({cmd} wrote nothing to stdout)");
return stdout.ReadLine()!;
}
}

View File

@ -4,6 +4,8 @@ using System.Runtime.InteropServices;
using static SDL2.SDL;
#pragma warning disable BHI1007 // target-typed Exception TODO don't
namespace BizHawk.Emulation.Common
{
/// <summary>

View File

@ -88,7 +88,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME
if (_loadFailure != string.Empty)
{
Dispose();
throw new("\n\n" + _loadFailure);
throw new Exception("\n\n" + _loadFailure);
}
// concat all SHA1 hashes together (unprefixed), then hash that

View File

@ -8,6 +8,8 @@ using BizHawk.BizInvoke;
using BizHawk.Common;
using BizHawk.Emulation.Common;
#pragma warning disable BHI1007 // target-typed Exception TODO don't
namespace BizHawk.Emulation.Cores.Consoles.Nintendo.N3DS
{
[PortedCore(CoreNames.Encore, "", "nightly-2104", "https://github.com/CasualPokePlayer/encore", singleInstance: true)]

View File

@ -385,7 +385,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS
private static byte[] GetTMDData(ulong titleId)
{
using var zip = new ZipArchive(Zstd.DecompressZstdStream(new MemoryStream(Resources.TMDS.Value)), ZipArchiveMode.Read, false);
using var tmd = zip.GetEntry($"{titleId:x16}.tmd")?.Open() ?? throw new($"Cannot find TMD for title ID {titleId:x16}, please report");
using var tmd = zip.GetEntry($"{titleId:x16}.tmd")?.Open() ?? throw new Exception($"Cannot find TMD for title ID {titleId:x16}, please report");
return tmd.ReadAllBytes();
}

View File

@ -91,7 +91,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
{
if (lp.Discs.Count > 128)
{
throw new("Too many discs loaded at once!");
throw new ArgumentException(paramName: nameof(lp), message: "Too many discs loaded at once!");
}
_cds = lp.Discs.Select(d => d.DiscData).ToArray();