Enable CA1862 and fix noncompliance
"Use the 'StringComparison' method overloads to perform case-insensitive string comparisons"
This commit is contained in:
parent
96207e80ea
commit
12cd7885ec
|
@ -73,6 +73,8 @@ dotnet_diagnostic.CA1822.severity = silent
|
|||
dotnet_code_quality.CA1826.exclude_ordefault_methods = true
|
||||
# Avoid StringBuilder parameters for P/Invokes
|
||||
dotnet_diagnostic.CA1838.severity = suggestion
|
||||
# Use the 'StringComparison' method overloads to perform case-insensitive string comparisons
|
||||
dotnet_diagnostic.CA1862.severity = error
|
||||
|
||||
## Usage rules
|
||||
|
||||
|
|
|
@ -63,7 +63,9 @@ namespace BizHawk.Client.Common
|
|||
NotInDatabase = true
|
||||
};
|
||||
|
||||
#pragma warning disable CA1862 // testing whether it's all-caps
|
||||
if (!string.IsNullOrWhiteSpace(GameInfo.Name) && GameInfo.Name == GameInfo.Name.ToUpperInvariant())
|
||||
#pragma warning restore CA1862
|
||||
{
|
||||
GameInfo.Name = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(GameInfo.Name.ToLowerInvariant());
|
||||
}
|
||||
|
|
|
@ -655,7 +655,7 @@ namespace BizHawk.Client.Common
|
|||
private static bool IsDiscForXML(string system, string path)
|
||||
{
|
||||
var ext = Path.GetExtension(path);
|
||||
if (system == VSystemID.Raw.Arcade && ext.ToLowerInvariant() == ".chd")
|
||||
if (system is VSystemID.Raw.Arcade && ".chd".EqualsIgnoreCase(ext))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Drawing.Imaging;
|
|||
using BizHawk.Bizware.Graphics;
|
||||
using BizHawk.Client.Common;
|
||||
using BizHawk.Common.PathExtensions;
|
||||
using BizHawk.Common.StringExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
|
@ -49,11 +50,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
var name = Path.Combine(dir!, $"{fileNoExt}_{_frame}{ext}");
|
||||
BitmapBuffer bb = new BitmapBuffer(source.BufferWidth, source.BufferHeight, source.GetVideoBuffer());
|
||||
using var bmp = bb.ToSysdrawingBitmap();
|
||||
if (ext.ToUpperInvariant() == ".PNG")
|
||||
if (".PNG".EqualsIgnoreCase(ext))
|
||||
{
|
||||
bmp.Save(name, ImageFormat.Png);
|
||||
}
|
||||
else if (ext.ToUpperInvariant() == ".JPG")
|
||||
else if (".JPG".EqualsIgnoreCase(ext))
|
||||
{
|
||||
bmp.Save(name, ImageFormat.Jpeg);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ using System.Text;
|
|||
using System.Threading;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
using BizHawk.Common.StringExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
|
@ -600,7 +600,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
public void OpenFile(string baseName)
|
||||
{
|
||||
string ext = Path.GetExtension(baseName);
|
||||
if (ext == null || ext.ToLowerInvariant() != ".jmd")
|
||||
if (ext?.EqualsIgnoreCase(".jmd") is true or null)
|
||||
{
|
||||
baseName += ".jmd";
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Text.RegularExpressions;
|
|||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.StringExtensions;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
|
@ -33,9 +34,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
lvi.SubItems.Add(new ListViewItem.ListViewSubItem());
|
||||
lvi.Text = item.Name;
|
||||
long size = item.Size;
|
||||
var extension = Path.GetExtension(item.Name);
|
||||
if (extension != null && size % 1024 == 16 && extension.ToUpperInvariant() == ".NES")
|
||||
size -= 16;
|
||||
if (size % 1024 is 16 && Path.GetExtension(item.Name)?.EqualsIgnoreCase(".NES") is true) size -= 16;
|
||||
lvi.SubItems[1].Text = Util.FormatFileSize(size);
|
||||
_archiveItems.Add(lvi);
|
||||
}
|
||||
|
|
|
@ -1388,7 +1388,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
using (var bb = Config.ScreenshotCaptureOsd ? CaptureOSD() : MakeScreenshotImage())
|
||||
{
|
||||
using var img = bb.ToSysdrawingBitmap();
|
||||
if (Path.GetExtension(path).ToUpperInvariant() == ".JPG")
|
||||
if (".JPG".EqualsIgnoreCase(Path.GetExtension(path)))
|
||||
{
|
||||
img.Save(fi.FullName, ImageFormat.Jpeg);
|
||||
}
|
||||
|
@ -3724,7 +3724,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
InputManager.SyncControls(Emulator, MovieSession, Config);
|
||||
_multiDiskMode = false;
|
||||
|
||||
if (oaOpenrom != null && Path.GetExtension(oaOpenrom.Path.Replace("|", "")).ToLowerInvariant() == ".xml" && Emulator is not LibsnesCore)
|
||||
if (oaOpenrom is not null && ".xml".EqualsIgnoreCase(Path.GetExtension(oaOpenrom.Path.Replace("|", "")))
|
||||
&& Emulator is not LibsnesCore)
|
||||
{
|
||||
// this is a multi-disk bundler file
|
||||
// determine the xml assets and create RomStatusDetails for all of them
|
||||
|
|
|
@ -487,7 +487,9 @@ namespace BizHawk.Emulation.Common
|
|||
game.Name = Path.GetFileNameWithoutExtension(fileName)?.Replace('_', ' ');
|
||||
|
||||
// If filename is all-caps, then attempt to proper-case the title.
|
||||
#pragma warning disable CA1862 // testing whether it's all-caps
|
||||
if (!string.IsNullOrWhiteSpace(game.Name) && game.Name == game.Name.ToUpperInvariant())
|
||||
#pragma warning restore CA1862
|
||||
{
|
||||
game.Name = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(game.Name.ToLowerInvariant());
|
||||
}
|
||||
|
|
|
@ -251,7 +251,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME
|
|||
foreach (var rom in roms)
|
||||
{
|
||||
// only close non-chd files
|
||||
if (rom.Extension.ToLowerInvariant() != ".chd")
|
||||
if (!".chd".EqualsIgnoreCase(rom.Extension))
|
||||
{
|
||||
_exe.RemoveReadonlyFile(MakeFileName(rom));
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using BizHawk.Common.StringExtensions;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -57,7 +59,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
|||
int majorVer = data[8];
|
||||
int minorVer = data[9];
|
||||
|
||||
if (ident.ToUpperInvariant() != "COMPRESSED SQUARE WAVE")
|
||||
if (!"COMPRESSED SQUARE WAVE".EqualsIgnoreCase(ident))
|
||||
{
|
||||
// this is not a valid CSW format file
|
||||
return false;
|
||||
|
@ -80,7 +82,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
|||
// (first 22 bytes of the file)
|
||||
string ident = Encoding.ASCII.GetString(data, 0, 22);
|
||||
|
||||
if (ident.ToUpperInvariant() != "COMPRESSED SQUARE WAVE")
|
||||
if (!"COMPRESSED SQUARE WAVE".EqualsIgnoreCase(ident))
|
||||
{
|
||||
// this is not a valid CSW format file
|
||||
throw new Exception($"{nameof(CswConverter)}: This is not a valid CSW format file");
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using BizHawk.Common.StringExtensions;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -67,7 +69,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
|||
int majorVer = data[8];
|
||||
int minorVer = data[9];
|
||||
|
||||
if (ident.ToUpperInvariant() != "PZXT")
|
||||
if (!"PZXT".EqualsIgnoreCase(ident))
|
||||
{
|
||||
// this is not a valid PZX format file
|
||||
return false;
|
||||
|
@ -96,7 +98,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
|||
// check whether this is a valid pzx format file by looking at the identifier in the header block
|
||||
string ident = Encoding.ASCII.GetString(data, 0, 4);
|
||||
|
||||
if (ident.ToUpperInvariant() != "PZXT")
|
||||
if (!"PZXT".EqualsIgnoreCase(ident))
|
||||
{
|
||||
// this is not a valid TZX format file
|
||||
throw new Exception($"{nameof(PzxConverter)}: This is not a valid PZX format file");
|
||||
|
|
|
@ -2,6 +2,8 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
using BizHawk.Common.StringExtensions;
|
||||
|
||||
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -50,7 +52,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
|||
// check whether this is a valid wav format file by looking at the identifier in the header
|
||||
string ident = Encoding.ASCII.GetString(data, 8, 4);
|
||||
|
||||
if (ident.ToUpperInvariant() != "WAVE")
|
||||
if (!"WAVE".EqualsIgnoreCase(ident))
|
||||
{
|
||||
// this is not a valid WAV format file
|
||||
return false;
|
||||
|
@ -72,7 +74,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
|
|||
// check whether this is a valid pzx format file by looking at the identifier in the header block
|
||||
string ident = Encoding.ASCII.GetString(data, 8, 4);
|
||||
|
||||
if (ident.ToUpperInvariant() != "WAVE")
|
||||
if (!"WAVE".EqualsIgnoreCase(ident))
|
||||
{
|
||||
// this is not a valid TZX format file
|
||||
throw new Exception($"{nameof(WavConverter)}: This is not a valid WAV format file");
|
||||
|
|
|
@ -6,6 +6,7 @@ using System.Text;
|
|||
|
||||
using BizHawk.BizInvoke;
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.StringExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
#pragma warning disable BHI1007 // target-typed Exception TODO don't
|
||||
|
@ -122,7 +123,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.N3DS
|
|||
_serviceProvider.Register<IVideoProvider>(_encoreVideoProvider);
|
||||
|
||||
var romPath = lp.Roms[0].RomPath;
|
||||
if (lp.Roms[0].Extension.ToLowerInvariant() == ".cia")
|
||||
if (".cia".EqualsIgnoreCase(lp.Roms[0].Extension))
|
||||
{
|
||||
var message = new byte[1024];
|
||||
var res = _core.Encore_InstallCIA(_context, romPath, message, message.Length);
|
||||
|
@ -145,7 +146,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.N3DS
|
|||
for (var i = 1; i < lp.Roms.Count; i++)
|
||||
{
|
||||
// doesn't make sense if not a CIA
|
||||
if (lp.Roms[i].Extension.ToLowerInvariant() != ".cia")
|
||||
if (".cia".EqualsIgnoreCase(lp.Roms[i].Extension))
|
||||
{
|
||||
Dispose();
|
||||
throw new("ROMs after the index 0 should be CIAs");
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
|
|||
|
||||
public void SetCpuRegister(string register, int value)
|
||||
{
|
||||
if (register.Length == 9 && register.Substring(4, 5).ToUpperInvariant() == " BANK")
|
||||
if (register.Length is 9 && register.EndsWith(" BANK", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var type = (LibGambatte.BankType)Enum.Parse(typeof(LibGambatte.BankType), register.Substring(0, 4).ToUpperInvariant());
|
||||
LibGambatte.gambatte_setbank(GambatteState, type, value);
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
|||
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Common.PathExtensions;
|
||||
using BizHawk.Common.StringExtensions;
|
||||
using BizHawk.Emulation.Common;
|
||||
using BizHawk.Emulation.Cores.Components.W65816;
|
||||
|
||||
|
@ -279,7 +280,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES
|
|||
// every rom requests msu1.rom... why? who knows.
|
||||
// also handle msu-1 pcm files here
|
||||
bool isMsu1Rom = hint == "msu1.rom";
|
||||
bool isMsu1Pcm = Path.GetExtension(hint).ToLowerInvariant() == ".pcm";
|
||||
var isMsu1Pcm = ".pcm".EqualsIgnoreCase(Path.GetExtension(hint));
|
||||
if (isMsu1Rom || isMsu1Pcm)
|
||||
{
|
||||
// well, check if we have an msu-1 xml
|
||||
|
|
|
@ -204,7 +204,7 @@ namespace BizHawk.Emulation.DiscSystem
|
|||
var parts = line.Split('=');
|
||||
if (parts.Length != 2)
|
||||
throw new CCDParseException("Malformed or unexpected CCD format: parsing item into two parts");
|
||||
if (parts[0].ToUpperInvariant() == "FLAGS")
|
||||
if ("FLAGS".EqualsIgnoreCase(parts[0]))
|
||||
{
|
||||
// flags are a space-separated collection of symbolic constants:
|
||||
// https://www.gnu.org/software/ccd2cue/manual/html_node/FLAGS-_0028Compact-Disc-fields_0029.html#FLAGS-_0028Compact-Disc-fields_0029
|
||||
|
|
|
@ -238,7 +238,7 @@ namespace BizHawk.Emulation.DiscSystem
|
|||
return DiscType.Playdia;
|
||||
|
||||
if (sysId is "CDTV" or "AMIGA"
|
||||
|| iso.Root.Children.Keys.Any(k => k.ToLowerInvariant().Contains("cd32")))
|
||||
|| iso.Root.Children.Keys.Any(static k => k.ContainsIgnoreCase("cd32")))
|
||||
{
|
||||
return DiscType.Amiga;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,9 @@ namespace BizHawk.Tests.Emulation.Common
|
|||
public void CheckFormatOfHashes()
|
||||
{
|
||||
static void CustomAssert(string hash)
|
||||
#pragma warning disable CA1862 // testing whether it's all-caps
|
||||
=> Assert.IsTrue(hash.Length == 40 && hash == hash.ToUpperInvariant() && hash.IsHex(), $"incorrectly formatted: {hash}");
|
||||
#pragma warning restore CA1862
|
||||
foreach (var hash in FirmwareDatabase.FirmwareFilesByHash.Keys) CustomAssert(hash);
|
||||
foreach (var fo in FirmwareDatabase.FirmwareOptions) CustomAssert(fo.Hash);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue