From 2b587f206165bd6b56116d23a34d3a0a4a78ef6c Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 21 Mar 2025 05:30:07 +1000 Subject: [PATCH] Enable CA1820 and fix noncompliance "Test for empty strings using string length" --- .global.editorconfig.ini | 2 ++ src/BizHawk.Client.Common/movie/import/LsmvImport.cs | 8 ++++---- src/BizHawk.Client.EmuHawk/config/FirmwareConfig.cs | 2 +- .../tools/Debugger/RegisterBoxControl.cs | 2 +- .../tools/TAStudio/TAStudio.ListView.cs | 2 +- src/BizHawk.Emulation.Common/DSKIdentifier.cs | 2 +- .../Arcades/MAME/MAME.ISettable.cs | 4 ++-- src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs | 2 +- 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.global.editorconfig.ini b/.global.editorconfig.ini index 0762cf21e5..11759dd1e8 100644 --- a/.global.editorconfig.ini +++ b/.global.editorconfig.ini @@ -76,6 +76,8 @@ dotnet_diagnostic.CA1310.severity = silent # SpecifyStringComparisonAnalyzer ver # Do not initialize unnecessarily dotnet_diagnostic.CA1805.severity = silent +# Test for empty strings using string length +dotnet_diagnostic.CA1820.severity = warning # Mark members as static dotnet_diagnostic.CA1822.severity = silent # Use property instead of Linq Enumerable method diff --git a/src/BizHawk.Client.Common/movie/import/LsmvImport.cs b/src/BizHawk.Client.Common/movie/import/LsmvImport.cs index 29ed4fcbb1..ffb3caae3d 100644 --- a/src/BizHawk.Client.Common/movie/import/LsmvImport.cs +++ b/src/BizHawk.Client.Common/movie/import/LsmvImport.cs @@ -105,9 +105,9 @@ namespace BizHawk.Client.Common.movie.import while (reader.ReadLine() is string line) { string author = line.Trim(); - if (author != "") + if (author.Length is not 0) { - if (authorLast != "") + if (authorLast.Length is not 0) { authorList += $"{authorLast}, "; } @@ -117,12 +117,12 @@ namespace BizHawk.Client.Common.movie.import } } - if (authorList != "") + if (authorList.Length is not 0) { authorList += "and "; } - if (authorLast != "") + if (authorLast.Length is not 0) { authorList += authorLast; } diff --git a/src/BizHawk.Client.EmuHawk/config/FirmwareConfig.cs b/src/BizHawk.Client.EmuHawk/config/FirmwareConfig.cs index 994642cf52..ae41094b78 100644 --- a/src/BizHawk.Client.EmuHawk/config/FirmwareConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/FirmwareConfig.cs @@ -631,7 +631,7 @@ namespace BizHawk.Client.EmuHawk } catch { - if (errors != "") + if (errors.Length is not 0) { errors += "\n"; } diff --git a/src/BizHawk.Client.EmuHawk/tools/Debugger/RegisterBoxControl.cs b/src/BizHawk.Client.EmuHawk/tools/Debugger/RegisterBoxControl.cs index 58a51878b2..20807aae61 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Debugger/RegisterBoxControl.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Debugger/RegisterBoxControl.cs @@ -159,7 +159,7 @@ namespace BizHawk.Client.EmuHawk { try { - if (t.Text != "") + if (t.Text.Length is not 0) { Core.SetCpuRegister(t.Name, int.Parse(t.Text, System.Globalization.NumberStyles.HexNumber)); } diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs index 12785bf0e6..a0f6e5feea 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.ListView.cs @@ -1373,7 +1373,7 @@ namespace BizHawk.Client.EmuHawk { if (_axisTypedValue.Length is 0) { - if (prevTyped != "") + if (prevTyped.Length is not 0) { value = ControllerType.Axes[_axisEditColumn].Neutral; CurrentTasMovie.SetAxisState(_axisEditRow, _axisEditColumn, value); diff --git a/src/BizHawk.Emulation.Common/DSKIdentifier.cs b/src/BizHawk.Emulation.Common/DSKIdentifier.cs index 0bdab02468..514ba55bd0 100644 --- a/src/BizHawk.Emulation.Common/DSKIdentifier.cs +++ b/src/BizHawk.Emulation.Common/DSKIdentifier.cs @@ -217,7 +217,7 @@ namespace BizHawk.Emulation.Common } // last chance. use the possible value - if (IdentifiedSystem == VSystemID.Raw.AppleII && _possibleIdent != "") + if (IdentifiedSystem == VSystemID.Raw.AppleII && _possibleIdent.Length is not 0) // wait but it's not being used for the assignment? { IdentifiedSystem = VSystemID.Raw.ZXSpectrum; } diff --git a/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.ISettable.cs b/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.ISettable.cs index 34ae2c37bf..50295873a0 100644 --- a/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.ISettable.cs +++ b/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.ISettable.cs @@ -134,7 +134,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME foreach (var ROM in ROMs) { - if (ROM != string.Empty) + if (ROM.Length is not 0) { var substrings = ROM.Split('~'); var name = substrings[0]; @@ -200,7 +200,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME foreach (var View in Views) { - if (View != string.Empty) + if (View.Length is not 0) { var substrings = View.Split('@'); setting.Options.Add(substrings[0], substrings[1]); diff --git a/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs b/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs index fcea9dafa9..24c93aeee0 100644 --- a/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs +++ b/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs @@ -72,7 +72,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME StartMAME(lp.Roms); } - if (_loadFailure != string.Empty) + if (_loadFailure.Length is not 0) { Dispose(); throw new Exception("\n\n" + _loadFailure);