From 4f98733c2968804e80048449be8d7aa383a704bc Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Thu, 14 Jul 2022 22:49:04 +1000 Subject: [PATCH] Add Analyzer to enforce exception type for default switch branches --- Common.ruleset | 3 ++ .../BizHawk.Analyzer/HawkSourceAnalyzer.cs | 44 +++++++++++++++++- References/BizHawk.Analyzer.dll | Bin 9728 -> 12288 bytes src/BizHawk.Bizware.DirectX/IGL_SlimDX9.cs | 4 +- ...izHawkSystemIdToCoreSystemEnumConverter.cs | 4 +- .../Api/DisplaySurfaceID.cs | 4 +- .../DisplayManager/DisplayManagerBase.cs | 2 +- .../DialogControllerWinFormsExtensions.cs | 2 +- src/BizHawk.Client.EmuHawk/Input/Input.cs | 2 +- .../tools/Watch/RamWatch.cs | 2 +- src/BizHawk.Common/OSTailoredCode.cs | 2 +- .../Nintendo/BSNES/BsnesCore.IDebuggable.cs | 2 +- .../Consoles/Nintendo/Gameboy/GBColors.cs | 2 +- .../Consoles/Nintendo/NDS/NDSDisassembler.cs | 2 +- .../Nintendo/SNES/SNESGraphicsDecoder.cs | 2 +- .../vpads_schemata/PSXSchema.cs | 2 +- 16 files changed, 62 insertions(+), 17 deletions(-) diff --git a/Common.ruleset b/Common.ruleset index eda23b84dc..1c81730929 100644 --- a/Common.ruleset +++ b/Common.ruleset @@ -12,6 +12,9 @@ + + + diff --git a/ExternalProjects/BizHawk.Analyzer/HawkSourceAnalyzer.cs b/ExternalProjects/BizHawk.Analyzer/HawkSourceAnalyzer.cs index 29e7a5080f..33eeda8dff 100644 --- a/ExternalProjects/BizHawk.Analyzer/HawkSourceAnalyzer.cs +++ b/ExternalProjects/BizHawk.Analyzer/HawkSourceAnalyzer.cs @@ -1,5 +1,6 @@ namespace BizHawk.Analyzers; +using System; using System.Collections.Immutable; using Microsoft.CodeAnalysis; @@ -10,6 +11,10 @@ using Microsoft.CodeAnalysis.Diagnostics; [DiagnosticAnalyzer(LanguageNames.CSharp)] public class HawkSourceAnalyzer : DiagnosticAnalyzer { + private const string ERR_MSG_SWITCH_THROWS_UNKNOWN = "Indeterminable exception type in default switch branch, should be InvalidOperationException/SwitchExpressionException"; + + private const string ERR_MSG_SWITCH_THROWS_WRONG_TYPE = "Incorrect exception type in default switch branch, should be InvalidOperationException/SwitchExpressionException"; + private static readonly DiagnosticDescriptor DiagInterpStringIsDollarAt = new( id: "BHI1004", title: "Verbatim interpolated strings should begin $@, not @$", @@ -42,11 +47,20 @@ public class HawkSourceAnalyzer : DiagnosticAnalyzer defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true); + private static readonly DiagnosticDescriptor DiagSwitchShouldThrowIOE = new( + id: "BHI1005", + title: "Default branch of switch expression should throw InvalidOperationException/SwitchExpressionException or not throw", + messageFormat: "{0}", + category: "Usage", + defaultSeverity: DiagnosticSeverity.Error, + isEnabledByDefault: true); + public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create( DiagInterpStringIsDollarAt, DiagNoAnonClasses, DiagNoAnonDelegates, - DiagNoQueryExpression); + DiagNoQueryExpression, + DiagSwitchShouldThrowIOE); public override void Initialize(AnalysisContext context) { @@ -69,11 +83,37 @@ public class HawkSourceAnalyzer : DiagnosticAnalyzer case QueryExpressionSyntax: snac.ReportDiagnostic(Diagnostic.Create(DiagNoQueryExpression, snac.Node.GetLocation())); break; + case SwitchExpressionArmSyntax { WhenClause: null, Pattern: DiscardPatternSyntax, Expression: ThrowExpressionSyntax tes }: + if (tes.Expression is ObjectCreationExpressionSyntax oces) + { + // to resolve edge-cases involving aliases, you're supposed to use `snac.SemanticModel.GetTypeInfo(oces.Type).ConvertedType?.Name`, but I couldn't get it to work + if (((oces.Type as IdentifierNameSyntax)?.Identifier)?.ToString() is "SwitchExpressionException" or nameof(InvalidOperationException)) + { + // correct usage, do not flag + } + else + { + snac.ReportDiagnostic(Diagnostic.Create(DiagSwitchShouldThrowIOE, tes.GetLocation(), ERR_MSG_SWITCH_THROWS_WRONG_TYPE)); + } + } + else + { + // code reads `throw ` + snac.ReportDiagnostic(Diagnostic.Create( + DiagSwitchShouldThrowIOE, + tes.GetLocation(), + DiagnosticSeverity.Warning, + additionalLocations: null, + properties: null, + ERR_MSG_SWITCH_THROWS_UNKNOWN)); + } + break; } }, SyntaxKind.AnonymousObjectCreationExpression, SyntaxKind.AnonymousMethodExpression, SyntaxKind.InterpolatedStringExpression, - SyntaxKind.QueryExpression); + SyntaxKind.QueryExpression, + SyntaxKind.SwitchExpressionArm); } } diff --git a/References/BizHawk.Analyzer.dll b/References/BizHawk.Analyzer.dll index f2f42456ff2338c932a8fefae56c1d2cac43a0ec..1d654f89a2ed075fbbb0846ffe0c401262b668c4 100644 GIT binary patch literal 12288 zcmeHN4RBP~bw2OC{nLVkw1^+`yFv!bU{(@B7!l$~+Fc>pAV4dDowOFK)k9kIcHjEF zT|iLqGGM2k0skZu$4;HphB{MEnv65;)J{E)%Mf=$rZn|ToQ&I~V;8p>Cr#@#(>8S- zyWctQ?H>Zy?zEjunkT*U?)karo_o%@_uYHn?)dmaq!Ez^_j~UVJ%=Y>y#n7K6v1v- z`6mtZM|GE4o>R78Y8jnQ+u@vLPFcxJIF-z1&3t%54_k$7IGqj0b|%6Zb5f7g*9Wh6 zRqu)uZC5l(KDy+QQfsf#s_-18gQyJ@pF@3Q0M9V)eYlAlrK~!3GlA`w>j^;6`O;|L zy)4TAm8Xj`30FV#?&QKgB7+@qgq+fB9?BL5M*1ah?{jqa93Tu=x!A%#e?iu zTx^?4Uivu#(;FsInE2ngR;X=FM8UOpI!|@cnN}!Uy-<7n7*u-JZgJ__l_>1>tS!}^ z{XB};RM!@?B6bvRsb&khLOtqba>W*Oj%_)6Oz0I`1ckWIG2*D7pGV53G8sK_YJ1Ke z6ZW23w#T7XnS}6Hn(;WqURR&G^b8nqz;R@W=j`f5$Lr;} z_;`anuRA_Zo=c8nzlQUPw;?d= z>?IH{awFEu%zT}}I_2tOY=iY_W}aj4`ZdJZL~ExCiE#!`F}O;j+yiT+24*{hX3y2d zxPx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Q?X+Gu{+**@U7i8O7i-( zsKx0F6)7bx&h}8mbuKs+d?mQD48J^n?Rdh=Mcd?>@M+Z@nfr;;)-vg<{XmRI%>M$N C*A3?Y diff --git a/src/BizHawk.Bizware.DirectX/IGL_SlimDX9.cs b/src/BizHawk.Bizware.DirectX/IGL_SlimDX9.cs index e19864843c..3049536252 100644 --- a/src/BizHawk.Bizware.DirectX/IGL_SlimDX9.cs +++ b/src/BizHawk.Bizware.DirectX/IGL_SlimDX9.cs @@ -257,7 +257,7 @@ namespace BizHawk.Bizware.DirectX BlendEquationMode.Max => BlendOperation.Maximum, BlendEquationMode.Min => BlendOperation.Minimum, BlendEquationMode.FuncReverseSubtract => BlendOperation.ReverseSubtract, - _ => throw new ArgumentOutOfRangeException() + _ => throw new InvalidOperationException() }; } @@ -284,7 +284,7 @@ namespace BizHawk.Bizware.DirectX BlendingFactorSrc.Src1Color => throw new NotSupportedException(), BlendingFactorSrc.OneMinusSrc1Color => throw new NotSupportedException(), BlendingFactorSrc.OneMinusSrc1Alpha => throw new NotSupportedException(), - _ => throw new ArgumentOutOfRangeException() + _ => throw new InvalidOperationException() }; public void SetBlendState(IBlendState rsBlend) diff --git a/src/BizHawk.Client.Common/Api/BizHawkSystemIdToCoreSystemEnumConverter.cs b/src/BizHawk.Client.Common/Api/BizHawkSystemIdToCoreSystemEnumConverter.cs index dab511b773..27ccf09c6c 100644 --- a/src/BizHawk.Client.Common/Api/BizHawkSystemIdToCoreSystemEnumConverter.cs +++ b/src/BizHawk.Client.Common/Api/BizHawkSystemIdToCoreSystemEnumConverter.cs @@ -65,7 +65,7 @@ namespace BizHawk.Client.Common VSystemID.Raw.SGB => CoreSystem.SuperGameBoy, VSystemID.Raw.UZE => CoreSystem.UzeBox, VSystemID.Raw.PCFX => CoreSystem.PcFx, - _ => throw new IndexOutOfRangeException($"{value} is missing in convert list") + _ => throw new InvalidOperationException($"{value} is missing in convert list") }; } @@ -131,7 +131,7 @@ namespace BizHawk.Client.Common CoreSystem.ZXSpectrum => VSystemID.Raw.ZXSpectrum, CoreSystem.AmstradCPC => VSystemID.Raw.AmstradCPC, CoreSystem.Odyssey2 => VSystemID.Raw.O2, - _ => throw new IndexOutOfRangeException($"{value} is missing in convert list") + _ => throw new InvalidOperationException($"{value} is missing in convert list") }; } diff --git a/src/BizHawk.Client.Common/Api/DisplaySurfaceID.cs b/src/BizHawk.Client.Common/Api/DisplaySurfaceID.cs index 9d78283229..4358fc3f5f 100644 --- a/src/BizHawk.Client.Common/Api/DisplaySurfaceID.cs +++ b/src/BizHawk.Client.Common/Api/DisplaySurfaceID.cs @@ -14,6 +14,7 @@ namespace BizHawk.Client.Common /// should probably centralise these enum extensions and not-extensions somewhere... --yoshi public static class DisplaySurfaceIDParser { +#pragma warning disable BHI1005 // switching on string, possibly from user input, ArgumentException is correct here [return: NotNullIfNotNull("str")] public static DisplaySurfaceID? Parse(string? str) => str?.ToLowerInvariant() switch { @@ -24,12 +25,13 @@ namespace BizHawk.Client.Common "native" => DisplaySurfaceID.Client, _ => throw new ArgumentException(message: $"{str} is not the name of a display surface", paramName: nameof(str)) }; +#pragma warning restore BHI1005 public static string GetName(this DisplaySurfaceID surfaceID) => surfaceID switch { DisplaySurfaceID.EmuCore => "emucore", DisplaySurfaceID.Client => "client", - _ => throw new ArgumentException(message: "not a valid enum member", paramName: nameof(surfaceID)) + _ => throw new InvalidOperationException() }; } } diff --git a/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs b/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs index c84a58cc76..4c4baf9ae0 100644 --- a/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs +++ b/src/BizHawk.Client.Common/DisplayManager/DisplayManagerBase.cs @@ -1023,7 +1023,7 @@ namespace BizHawk.Client.Common { DisplaySurfaceID.EmuCore => (GameExtraPadding.Left + _currEmuWidth + GameExtraPadding.Right, GameExtraPadding.Top + _currEmuHeight + GameExtraPadding.Bottom), DisplaySurfaceID.Client => (currNativeWidth, currNativeHeight), - _ => throw new ArgumentException(message: "not a valid enum member", paramName: nameof(surfaceID)) + _ => throw new InvalidOperationException() }; IDisplaySurface ret = sdss.AllocateSurface(width, height, clear); diff --git a/src/BizHawk.Client.EmuHawk/DialogControllerWinFormsExtensions.cs b/src/BizHawk.Client.EmuHawk/DialogControllerWinFormsExtensions.cs index 77d29cd2d9..2c34c0587a 100644 --- a/src/BizHawk.Client.EmuHawk/DialogControllerWinFormsExtensions.cs +++ b/src/BizHawk.Client.EmuHawk/DialogControllerWinFormsExtensions.cs @@ -43,7 +43,7 @@ namespace BizHawk.Client.EmuHawk EMsgBoxIcon.Question => MessageBoxIcon.Question, EMsgBoxIcon.Warning => MessageBoxIcon.Warning, EMsgBoxIcon.Info => MessageBoxIcon.Information, - _ => throw new ArgumentException(message: "not a valid enum member", paramName: nameof(icon)) + _ => throw new InvalidOperationException() }); } } diff --git a/src/BizHawk.Client.EmuHawk/Input/Input.cs b/src/BizHawk.Client.EmuHawk/Input/Input.cs index f59a62e47a..7573586eac 100644 --- a/src/BizHawk.Client.EmuHawk/Input/Input.cs +++ b/src/BizHawk.Client.EmuHawk/Input/Input.cs @@ -51,7 +51,7 @@ namespace BizHawk.Client.EmuHawk EHostInputMethod.OpenTK => new OpenTKInputAdapter(), _ when OSTailoredCode.IsUnixHost => new OpenTKInputAdapter(), EHostInputMethod.DirectInput => new DirectInputAdapter(), - _ => throw new Exception() + _ => throw new InvalidOperationException() }; Console.WriteLine($"Using {Adapter.Desc} for host input (keyboard + gamepads)"); Adapter.UpdateConfig(_currentConfig); diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 7b4dfda2c5..eb73129d92 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -774,7 +774,7 @@ namespace BizHawk.Client.EmuHawk { WatchSize.DWord => WatchSize.Word, WatchSize.Word => WatchSize.Byte, - _ => throw new Exception() + _ => throw new InvalidOperationException() }; var a = Watch.GenerateWatch(ab.Domain, ab.Address, newSize, ab.Type, ab.BigEndian, ab.Notes); var b = Watch.GenerateWatch(ab.Domain, ab.Address + (int) newSize, newSize, ab.Type, ab.BigEndian, ab.Notes); diff --git a/src/BizHawk.Common/OSTailoredCode.cs b/src/BizHawk.Common/OSTailoredCode.cs index dcde789507..9044784df2 100644 --- a/src/BizHawk.Common/OSTailoredCode.cs +++ b/src/BizHawk.Common/OSTailoredCode.cs @@ -72,7 +72,7 @@ namespace BizHawk.Common DistinctOS.Linux => new UnixMonoLLManager(), DistinctOS.macOS => new UnixMonoLLManager(), DistinctOS.Windows => new WindowsLLManager(), - _ => throw new ArgumentOutOfRangeException() + _ => throw new InvalidOperationException() }); public static ILinkedLibManager LinkedLibManager => _LinkedLibManager.Value; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.IDebuggable.cs index 41eaa6ac8d..e027da64a7 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesCore.IDebuggable.cs @@ -152,7 +152,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES { 0x20 or 0xfc => 3, 0x22 => 4, - _ => throw new ArgumentOutOfRangeException() + _ => throw new InvalidOperationException() }; } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GBColors.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GBColors.cs index d74d1f43fd..8abeb88248 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GBColors.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/Gameboy/GBColors.cs @@ -214,7 +214,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy ColorType.vbabgbold => OldVBAColor, ColorType.gba => GBAColor, ColorType.libretrogbc => LibretroGBCColor, - _ => throw new ArgumentOutOfRangeException(nameof(c)), + _ => throw new InvalidOperationException() }; int i = 0; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/NDSDisassembler.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/NDSDisassembler.cs index d65b7d72cd..285d236b19 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/NDSDisassembler.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/NDSDisassembler.cs @@ -37,7 +37,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.NDS "ARM v5 (Thumb)" => LibMelonDS.TraceMask.ARM9_THUMB, "ARM v4" => LibMelonDS.TraceMask.ARM7_ARM, "ARM v4 (Thumb)" => LibMelonDS.TraceMask.ARM7_THUMB, - _ => throw new Exception("Invalid CPU mode?"), + _ => throw new InvalidOperationException("Invalid CPU mode?") }; if (Cpu.Length == 14) diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/SNESGraphicsDecoder.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/SNESGraphicsDecoder.cs index 7cc8b74a42..238fddf312 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/SNESGraphicsDecoder.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/SNESGraphicsDecoder.cs @@ -68,7 +68,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES ScreenSize.ABAB_64x32 => new Dimensions(2, 1), ScreenSize.AABB_32x64 => new Dimensions(1, 2), ScreenSize.ABCD_64x64 => new Dimensions(2, 2), - _ => throw new Exception() + _ => throw new InvalidOperationException() }; } diff --git a/src/BizHawk.Emulation.Cores/vpads_schemata/PSXSchema.cs b/src/BizHawk.Emulation.Cores/vpads_schemata/PSXSchema.cs index d601dbff8c..7238fe6c4e 100644 --- a/src/BizHawk.Emulation.Cores/vpads_schemata/PSXSchema.cs +++ b/src/BizHawk.Emulation.Cores/vpads_schemata/PSXSchema.cs @@ -63,7 +63,7 @@ namespace BizHawk.Emulation.Cores "guncon" => NymaGunCon(num), "justifier" => NymaKonamiJustifier(num), "dancepad" => NymaDancePad(num), - _ => throw new NotSupportedException($"device {device} is not supported"), + _ => throw new InvalidOperationException($"device {device} is not supported") }; }