Enable CA1065 and fix noncompliance

"Do not raise exceptions in unexpected locations" (e.g. static ctors and
`IDisposable.Dispose`, but also prop getters which is a bit annoying)
This commit is contained in:
YoshiRulz 2025-07-13 15:47:07 +10:00
parent 2ccddbd99e
commit fcb5d0d273
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
22 changed files with 53 additions and 0 deletions

View File

@ -59,6 +59,8 @@ dotnet_diagnostic.BHI3300.severity = error
# Do not declare static members on generic types # Do not declare static members on generic types
dotnet_diagnostic.CA1000.severity = error dotnet_diagnostic.CA1000.severity = error
# Do not raise exceptions in unexpected locations
dotnet_diagnostic.CA1065.severity = warning
## Globalization rules ## Globalization rules

View File

@ -20,6 +20,7 @@ namespace BizHawk.Bizware.Graphics
/// </summary> /// </summary>
public class SDL2OpenGLContext : IDisposable public class SDL2OpenGLContext : IDisposable
{ {
#pragma warning disable CA1065 // not sure how else to handle failure other than throwing with a good message
static SDL2OpenGLContext() static SDL2OpenGLContext()
{ {
if (OSTailoredCode.IsUnixHost) if (OSTailoredCode.IsUnixHost)
@ -101,6 +102,7 @@ namespace BizHawk.Bizware.Graphics
// it's not needed and can be dangerous in some rare cases // it's not needed and can be dangerous in some rare cases
SDL_SetHintWithPriority(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, "0", SDL_HintPriority.SDL_HINT_OVERRIDE); SDL_SetHintWithPriority(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, "0", SDL_HintPriority.SDL_HINT_OVERRIDE);
} }
#pragma warning restore CA1065
#if DEBUG_OPENGL #if DEBUG_OPENGL
private static readonly DebugProc _debugProc = DebugCallback; private static readonly DebugProc _debugProc = DebugCallback;

View File

@ -48,7 +48,9 @@ namespace BizHawk.Client.Common
{ {
var error = $"Error: {Emulator.Attributes().CoreName} does not implement memory domains"; var error = $"Error: {Emulator.Attributes().CoreName} does not implement memory domains";
LogCallback(error); LogCallback(error);
#pragma warning disable CA1065 // yes, really throw
throw new NotImplementedException(error); throw new NotImplementedException(error);
#pragma warning restore CA1065
} }
return MemoryDomainCore; return MemoryDomainCore;
} }
@ -62,7 +64,9 @@ namespace BizHawk.Client.Common
{ {
var error = $"Error: {Emulator.Attributes().CoreName} does not implement memory domains"; var error = $"Error: {Emulator.Attributes().CoreName} does not implement memory domains";
LogCallback(error); LogCallback(error);
#pragma warning disable CA1065 // yes, really throw
throw new NotImplementedException(error); throw new NotImplementedException(error);
#pragma warning restore CA1065
} }
return MemoryDomainCore.MainMemory.Name; return MemoryDomainCore.MainMemory.Name;
} }

View File

@ -67,7 +67,9 @@ namespace BizHawk.Client.EmuHawk
get get
{ {
if (DesignMode) return PLACEHOLDER_TITLE; if (DesignMode) return PLACEHOLDER_TITLE;
#pragma warning disable CA1065 // yes, really throw
throw new NotImplementedException("you have to implement this; the Designer prevents this from being an abstract method"); throw new NotImplementedException("you have to implement this; the Designer prevents this from being an abstract method");
#pragma warning restore CA1065
} }
} }

View File

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

View File

@ -52,7 +52,9 @@ namespace BizHawk.Common
if (PageSize != Environment.SystemPageSize) if (PageSize != Environment.SystemPageSize)
{ {
// We can do it, but we'll have to change up some waterbox stuff // We can do it, but we'll have to change up some waterbox stuff
#pragma warning disable CA1065 // yes, really throw
throw new InvalidOperationException("Wrong page size"); throw new InvalidOperationException("Wrong page size");
#pragma warning restore CA1065
} }
} }

View File

@ -53,6 +53,8 @@ namespace BizHawk.Emulation.Common
public void Step(StepType type) => throw new NotImplementedException(); public void Step(StepType type) => throw new NotImplementedException();
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
public long TotalExecutedCycles => throw new NotImplementedException(); public long TotalExecutedCycles => throw new NotImplementedException();
#pragma warning restore CA1065
} }
} }

View File

@ -146,6 +146,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
private const byte Rts = 0x60; private const byte Rts = 0x60;
private const byte JsrSize = 3; private const byte JsrSize = 3;
[FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
public IMemoryCallbackSystem MemoryCallbacks => throw new NotImplementedException(); public IMemoryCallbackSystem MemoryCallbacks => throw new NotImplementedException();
#pragma warning restore CA1065
} }
} }

View File

@ -88,7 +88,9 @@ namespace BizHawk.Emulation.Cores.Atari.Jaguar
[FeatureNotImplemented] [FeatureNotImplemented]
public long TotalExecutedCycles public long TotalExecutedCycles
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
=> throw new NotImplementedException(); => throw new NotImplementedException();
#pragma warning restore CA1065
public IMemoryCallbackSystem MemoryCallbacks => _memoryCallbacks; public IMemoryCallbackSystem MemoryCallbacks => _memoryCallbacks;

View File

@ -12,7 +12,9 @@ namespace BizHawk.Emulation.Cores.Atari.Lynx
public IInputCallbackSystem InputCallbacks public IInputCallbackSystem InputCallbacks
{ {
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
get => throw new NotImplementedException(); get => throw new NotImplementedException();
#pragma warning restore CA1065
} }
} }
} }

View File

@ -19,7 +19,9 @@ namespace BizHawk.Emulation.Cores.ColecoVision
public IInputCallbackSystem InputCallbacks public IInputCallbackSystem InputCallbacks
{ {
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
get => throw new NotImplementedException(); get => throw new NotImplementedException();
#pragma warning restore CA1065
} }
private int _lagCount = 0; private int _lagCount = 0;

View File

@ -46,12 +46,16 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.Ares64
public void SetCpuRegister(string register, int value) => throw new NotImplementedException(); public void SetCpuRegister(string register, int value) => throw new NotImplementedException();
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
public IMemoryCallbackSystem MemoryCallbacks => throw new NotImplementedException(); public IMemoryCallbackSystem MemoryCallbacks => throw new NotImplementedException();
#pragma warning restore CA1065
public bool CanStep(StepType type) => false; public bool CanStep(StepType type) => false;
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
public long TotalExecutedCycles => throw new NotImplementedException(); public long TotalExecutedCycles => throw new NotImplementedException();
#pragma warning restore CA1065
[FeatureNotImplemented] [FeatureNotImplemented]
public void Step(StepType type) => throw new NotImplementedException(); public void Step(StepType type) => throw new NotImplementedException();

View File

@ -96,7 +96,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.N64
} }
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
public long TotalExecutedCycles => throw new NotImplementedException(); public long TotalExecutedCycles => throw new NotImplementedException();
#pragma warning restore CA1065
public void Step(StepType type) public void Step(StepType type)
{ {

View File

@ -34,10 +34,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
public IMemoryCallbackSystem MemoryCallbacks public IMemoryCallbackSystem MemoryCallbacks
{ {
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
get => throw new NotImplementedException(); get => throw new NotImplementedException();
#pragma warning restore CA1065
} }
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
public long TotalExecutedCycles => throw new NotImplementedException(); public long TotalExecutedCycles => throw new NotImplementedException();
#pragma warning restore CA1065
} }
} }

View File

@ -10,7 +10,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
public IInputCallbackSystem InputCallbacks public IInputCallbackSystem InputCallbacks
{ {
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
get => throw new NotImplementedException(); get => throw new NotImplementedException();
#pragma warning restore CA1065
} }
} }
} }

View File

@ -29,7 +29,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
{ {
if (sizeof(CommStruct) != 368) if (sizeof(CommStruct) != 368)
{ {
#pragma warning disable CA1065 // yes, really throw
throw new InvalidOperationException("sizeof(comm)"); throw new InvalidOperationException("sizeof(comm)");
#pragma warning restore CA1065
} }
} }

View File

@ -62,6 +62,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
} }
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
public long TotalExecutedCycles => throw new NotImplementedException(); public long TotalExecutedCycles => throw new NotImplementedException();
#pragma warning restore CA1065
} }
} }

View File

@ -51,7 +51,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
return _memoryCallbacks; return _memoryCallbacks;
} }
#pragma warning disable CA1065 // I guess this is like a conditional [FeatureNotImplemented], for which the convention is to throw NIE
throw new NotImplementedException(); throw new NotImplementedException();
#pragma warning restore CA1065
} }
} }
@ -61,7 +63,9 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
public void Step(StepType type) => throw new NotImplementedException(); public void Step(StepType type) => throw new NotImplementedException();
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
public long TotalExecutedCycles => throw new NotImplementedException(); public long TotalExecutedCycles => throw new NotImplementedException();
#pragma warning restore CA1065
private readonly MemoryCallbackSystem _memoryCallbacks = new([ "M68K BUS" ]); private readonly MemoryCallbackSystem _memoryCallbacks = new([ "M68K BUS" ]);

View File

@ -85,7 +85,9 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
public void Step(StepType type) => throw new NotImplementedException(); public void Step(StepType type) => throw new NotImplementedException();
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
public long TotalExecutedCycles => throw new NotImplementedException(); public long TotalExecutedCycles => throw new NotImplementedException();
#pragma warning restore CA1065
private OctoshockDll.ShockCallback_Mem mem_cb; private OctoshockDll.ShockCallback_Mem mem_cb;

View File

@ -874,7 +874,9 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
public IInputCallbackSystem InputCallbacks public IInputCallbackSystem InputCallbacks
{ {
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
get => throw new NotImplementedException(); get => throw new NotImplementedException();
#pragma warning restore CA1065
} }
public bool DeterministicEmulation => true; public bool DeterministicEmulation => true;

View File

@ -129,7 +129,9 @@ namespace BizHawk.Emulation.Cores.WonderSwan
public void Step(StepType type) => throw new NotImplementedException(); public void Step(StepType type) => throw new NotImplementedException();
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
public long TotalExecutedCycles => throw new NotImplementedException(); public long TotalExecutedCycles => throw new NotImplementedException();
#pragma warning restore CA1065
private BizSwan.MemoryCallback ReadCallbackD; private BizSwan.MemoryCallback ReadCallbackD;
private BizSwan.MemoryCallback WriteCallbackD; private BizSwan.MemoryCallback WriteCallbackD;

View File

@ -14,7 +14,9 @@ namespace BizHawk.Emulation.Cores.Libretro
public bool IsLagFrame { get; set; } public bool IsLagFrame { get; set; }
[FeatureNotImplemented] [FeatureNotImplemented]
#pragma warning disable CA1065 // convention for [FeatureNotImplemented] is to throw NIE
public IInputCallbackSystem InputCallbacks => throw new NotImplementedException(); public IInputCallbackSystem InputCallbacks => throw new NotImplementedException();
#pragma warning restore CA1065
private readonly short[] _joypad0States = new short[(int)RETRO_DEVICE_ID_JOYPAD.LAST]; private readonly short[] _joypad0States = new short[(int)RETRO_DEVICE_ID_JOYPAD.LAST];
private readonly short[] _joypad1States = new short[(int)RETRO_DEVICE_ID_JOYPAD.LAST]; private readonly short[] _joypad1States = new short[(int)RETRO_DEVICE_ID_JOYPAD.LAST];