Enable RCS1156 and fix noncompliance

"Use string.Length instead of comparison with empty string"
inb4 this introduces an NRE somewhere
This commit is contained in:
YoshiRulz 2025-01-31 14:46:54 +10:00
parent af32948756
commit 6ec2f0c49f
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
17 changed files with 23 additions and 50 deletions

View File

@ -411,6 +411,8 @@ dotnet_diagnostic.RCS1102.severity = silent
dotnet_diagnostic.RCS1138.severity = silent
# Add summary element to documentation comment
dotnet_diagnostic.RCS1139.severity = silent
# Use string.Length instead of comparison with empty string
dotnet_diagnostic.RCS1156.severity = error
# Implement exception constructors
dotnet_diagnostic.RCS1194.severity = silent
# Do not pass non-read-only struct by read-only reference

View File

@ -176,7 +176,7 @@ namespace BizHawk.Client.Common
return Successful ? "Screenshot was sent" : "Screenshot could not be sent";
}
var resp = ReceiveString();
return resp == "" ? "Failed to get a response" : resp;
return resp.Length is 0 ? "Failed to get a response" : resp;
}
public int SendString(string sendString, Encoding encoding = null)

View File

@ -26,11 +26,7 @@ namespace BizHawk.Client.Common.Filters
while (true)
{
var match = RxInclude.Match(content);
if (match.Value == string.Empty)
{
return content;
}
if (match.Value.Length is 0) return content;
var fname = match.Groups[4].Value;
fname = Path.Combine(baseDirectory,fname);
var includedContent = ResolveIncludes(File.ReadAllText(fname),Path.GetDirectoryName(fname));

View File

@ -244,13 +244,8 @@ namespace BizHawk.Client.Common
{
var name = game.FilesystemSafeName();
name = Path.GetDirectoryName(name);
if (name == "")
{
name = game.FilesystemSafeName();
}
name ??= "";
if (name is null) name = string.Empty;
else if (name.Length is 0) name = game.FilesystemSafeName();
var pathEntry = collection[game.System, "Save RAM"]
?? collection[game.System, "Base"];

View File

@ -33,10 +33,7 @@ namespace BizHawk.Client.Common
string line;
while ((line = sr.ReadLine()) != null)
{
if (line == "")
{
continue;
}
if (line.Length is 0) continue;
if (line[0] == '|')
{

View File

@ -178,9 +178,7 @@ namespace BizHawk.Client.Common.movie.import
{
while(reader.ReadLine() is string line)
{
if (line == "") continue;
ImportTextFrame(line);
if (line.Length is not 0) ImportTextFrame(line);
}
}
Result.Movie.AppendFrame(_controller);

View File

@ -57,13 +57,8 @@ namespace BizHawk.Client.Common
while ((line = sr.ReadLine()) != null)
{
if (line == "")
{
}
else if (Header.ParseLineFromFile(line))
{
}
else if (line.StartsWith('|'))
if (line.Length is 0 || Header.ParseLineFromFile(line)) continue;
if (line.StartsWith('|'))
{
_log.Add(line);
}

View File

@ -85,11 +85,7 @@ namespace BizHawk.Client.Common
{
int index = IndexOf(old);
newBranch.Uuid = old.Uuid;
if (newBranch.UserText == "")
{
newBranch.UserText = old.UserText;
}
if (newBranch.UserText.Length is 0) newBranch.UserText = old.UserText;
this[index] = newBranch;
_movie.FlagChanges();
}

View File

@ -274,12 +274,7 @@ namespace BizHawk.Client.Common
{
TruncateLog(UndoIndex + 1);
}
if (name == "")
{
name = $"Undo step {_totalSteps}";
}
if (name.Length is 0) name = $"Undo step {_totalSteps}";
bool ret = false;
if (!_recordingBatch)
{
@ -510,7 +505,7 @@ namespace BizHawk.Client.Common
else
{
LastFrame = marker.Frame;
_oldMessage = oldMessage == "" ? marker.Message : oldMessage;
_oldMessage = oldMessage.Length is 0 ? marker.Message : oldMessage;
_newMessage = marker.Message;
}
}

View File

@ -19,7 +19,7 @@ namespace BizHawk.Client.EmuHawk
public MovieZone(IEmulator emulator, ToolManager tools, IMovieSession movieSession, int start, int length, string key = "")
: this(emulator, tools, movieSession)
{
if (key == "")
if (key.Length is 0)
{
key = Bk2LogEntryGenerator.GenerateLogKey(movieSession.MovieController.Definition);
}

View File

@ -1314,7 +1314,7 @@ namespace BizHawk.Client.EmuHawk
}
else if (e.KeyCode == Keys.Back)
{
if (_axisTypedValue == "") // Very first key press is backspace?
if (_axisTypedValue.Length is 0) // Very first key press is backspace?
{
_axisTypedValue = value.ToString(NumberFormatInfo.InvariantInfo);
}
@ -1372,7 +1372,7 @@ namespace BizHawk.Client.EmuHawk
}
else
{
if (_axisTypedValue == "")
if (_axisTypedValue.Length is 0)
{
if (prevTyped != "")
{

View File

@ -212,7 +212,7 @@ namespace BizHawk.Common.PathExtensions
{
var dirPath = ReadPathFromEnvVar("BIZHAWK_HOME") ?? AppContext.BaseDirectory;
ExeDirectoryPath = string.IsNullOrEmpty(dirPath) || dirPath == "/" ? string.Empty : dirPath;
DllDirectoryPath = Path.Combine(ExeDirectoryPath == string.Empty ? "/" : ExeDirectoryPath, "dll");
DllDirectoryPath = Path.Combine(ExeDirectoryPath.Length is 0 ? "/" : ExeDirectoryPath, "dll");
// yes, this is a lot of extra code to make sure BizHawk can run in `/` on Unix, but I've made up for it by caching these for the program lifecycle --yoshi
DataDirectoryPath = ReadPathFromEnvVar("BIZHAWK_DATA_HOME") ?? ExeDirectoryPath;
}

View File

@ -45,7 +45,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME
$"Framerate: { (float)VsyncNumerator / VsyncDenominator } " +
$"({ VsyncNumerator } / { VsyncDenominator })\r\n" +
$"Driver Source File: { _driverSourceFile.RemovePrefix("src")}\r\n\r\n" +
text + (text == "" ? "" : "\r\n") +
text + (text.Length is 0 ? string.Empty : "\r\n") +
string.Join("\r\n", _romHashes.Select(static r => $"{r.Value} - {r.Key}"));
if (text.ContainsIgnoreCase("doesn't work")) lp.Game.Status = RomStatus.NotWorking;
@ -243,7 +243,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME
_core.mame_coswitch();
_core.mame_lua_execute(MAMELuaCommand.Unpause);
}
else if (_loadFailure == string.Empty)
else if (_loadFailure.Length is 0)
{
_loadFailure = "Unknown load error occurred???";
}

View File

@ -221,7 +221,7 @@ namespace BizHawk.Emulation.Cores.Components.M68000
while (true)
{
string[] args = reader.ReadLine().Split(' ');
if (args[0].Trim() == "") continue;
if (args[0].Trim().Length is 0) continue;
if (args[0] == "[/" + id + "]") break;
else if (args[0] == "D0") D[0].s32 = int.Parse(args[1], NumberStyles.HexNumber);
else if (args[0] == "D1") D[1].s32 = int.Parse(args[1], NumberStyles.HexNumber);

View File

@ -41,8 +41,7 @@ namespace BizHawk.Emulation.Cores.Sony.PSX
var tagstring = br.ReadStringFixedUtf8((int)(fs.Length - fs.Position)).Replace("\r\n", "\n");
foreach (var tag in tagstring.Split('\n', '\x0'))
{
if (tag.Trim() == "")
continue;
if (tag.Trim().Length is 0) continue;
int eq = tag.IndexOf('=');
if (eq != -1)
TagsDictionary[tag.Substring(0, eq)] = tag.Substring(eq + 1);

View File

@ -188,7 +188,7 @@ namespace BizHawk.Emulation.DiscSystem
{
var line = sr.ReadLine();
if (line is null) break;
if (line == string.Empty) continue;
if (line.Length is 0) continue;
if (line.StartsWith('['))
{
currSection = new()

View File

@ -140,7 +140,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE
CurrentLine++;
var line = tr.ReadLine()?.Trim();
if (line is null) break;
if (line == string.Empty) continue;
if (line.Length is 0) continue;
var clp = new CueLineParser(line);
var key = clp.ReadToken().ToUpperInvariant();