Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump AnalysisLevel to 8 #4131

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .global.editorconfig.ini
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ dotnet_code_quality.CA1305.excluded_symbol_names = T:System.Byte|T:System.SByte|
# Specify marshalling for P/Invoke string arguments
dotnet_diagnostic.CA2101.severity = suggestion

## Reliability rules

# ThreadStatic fields should not use inline initialization
dotnet_diagnostic.CA2019.severity = error

## Performance rules

# Do not initialize unnecessarily
Expand All @@ -73,6 +78,10 @@ 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 concrete types when possible for improved performance
dotnet_diagnostic.CA1859.severity = suggestion
# Avoid constant arrays as arguments
dotnet_diagnostic.CA1861.severity = none

## Usage rules

Expand Down
2 changes: 1 addition & 1 deletion Common.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<AnalysisLevel>6</AnalysisLevel>
<AnalysisLevel>8</AnalysisLevel>
<AnalysisModeGlobalization>Recommended</AnalysisModeGlobalization>
<AnalysisModeMaintainability>Recommended</AnalysisModeMaintainability>
<AnalysisModeReliability>Recommended</AnalysisModeReliability>
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.BizInvoke/BizInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static class BizInvoker
/// <summary>
/// holds information about a proxy implementation, including type and setup hooks
/// </summary>
private class InvokerImpl
private sealed class InvokerImpl
{
private readonly Action<object, ICallingConventionAdapter> _connectCallingConventionAdapter;

Expand Down
8 changes: 4 additions & 4 deletions src/BizHawk.BizInvoke/BizInvokerUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace BizHawk.BizInvoke
public static unsafe class BizInvokerUtilities
{
[StructLayout(LayoutKind.Explicit)]
private class U
private sealed class U
{
[FieldOffset(0)]
public readonly U1? First;
Expand All @@ -32,22 +32,22 @@ public U(U2 second)
}

[StructLayout(LayoutKind.Explicit)]
private class U1
private sealed class U1
{
[FieldOffset(0)]
public UIntPtr P;
}

[StructLayout(LayoutKind.Explicit)]
private class U2
private sealed class U2
{
[FieldOffset(0)]
public object Target;

public U2(object target) => Target = target;
}

private class CF
private sealed class CF
{
public int FirstField = 0;
}
Expand Down
15 changes: 5 additions & 10 deletions src/BizHawk.BizInvoke/CallingConventionAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public interface ICallbackAdjuster

public static class CallingConventionAdapters
{
private class NativeConvention : ICallingConventionAdapter
private sealed class NativeConvention : ICallingConventionAdapter
{
public IntPtr GetArrivalFunctionPointer(IntPtr p, InvokerParameterInfo pp, object lifetime)
=> p;
Expand Down Expand Up @@ -132,9 +132,9 @@ public static ICallingConventionAdapter MakeWaterboxDepartureOnly(ICallbackAdjus
public static ICallingConventionAdapter GetWaterboxUnsafeUnwrapped()
=> WaterboxAdapter.WaterboxWrapper;

private class WaterboxAdapter : ICallingConventionAdapter
private sealed class WaterboxAdapter : ICallingConventionAdapter
{
private class ReferenceEqualityComparer : IEqualityComparer<Delegate>
private sealed class ReferenceEqualityComparer : IEqualityComparer<Delegate>
{
public bool Equals(Delegate x, Delegate y)
=> x == y;
Expand Down Expand Up @@ -218,19 +218,14 @@ public IntPtr GetFunctionPointerForDelegate(Delegate d)
/// Calling Convention Adapter for where host code expects msabi and guest code is sysv.
/// Does not handle anything Waterbox specific.
/// </summary>
private class MsHostSysVGuest : ICallingConventionAdapter
private sealed class MsHostSysVGuest : ICallingConventionAdapter
{
// This is implemented by using thunks defined in a small dll, and putting stubs on top of them that close over the
// function pointer parameter. A dll is used here to easily set unwind information (allowing SEH exceptions to work).
// TODO: Another dll might be required for ARM64? Investigate

private const int BlockSize = 32;
private static readonly IImportResolver ThunkDll;

static MsHostSysVGuest()
{
ThunkDll = new DynamicLibraryImportResolver("libbizabiadapter_msabi_sysv.dll", hasLimitedLifetime: false);
}
private static readonly DynamicLibraryImportResolver ThunkDll = new("libbizabiadapter_msabi_sysv.dll", hasLimitedLifetime: false);

private readonly MemoryBlock _memory;
private readonly object _sync = new();
Expand Down
4 changes: 2 additions & 2 deletions src/BizHawk.Bizware.Audio/OpenALSoundOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private void AllocateTempSampleBuffer(int sampleCount)
}
}

private class BufferPool : IDisposable
private sealed class BufferPool : IDisposable
{
private readonly Stack<BufferPoolItem> _availableItems = new();
private readonly Queue<BufferPoolItem> _obtainedItems = new();
Expand Down Expand Up @@ -285,7 +285,7 @@ public BufferPoolItem ReleaseOne()
return item;
}

public class BufferPoolItem
public sealed class BufferPoolItem
{
public uint BufferID { get; } = _al.GenBuffer();
public int Length { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Bizware.Audio/SDL2WavStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void Write(ReadOnlySpan<byte> buffer)
public override void Write(byte[] buffer, int offset, int count)
=> throw new NotSupportedException();

private unsafe class SDLRwOpsStreamWrapper : IDisposable
private sealed unsafe class SDLRwOpsStreamWrapper : IDisposable
{
public IntPtr Rw { get; private set; }
private readonly Stream _s;
Expand Down
4 changes: 2 additions & 2 deletions src/BizHawk.Bizware.Audio/XAudio2SoundOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void PlayWavFile(Stream wavFile, double volume)
_wavVoice.Start();
}

private class BufferPool : IDisposable
private sealed class BufferPool : IDisposable
{
private readonly List<BufferPoolItem> _availableItems = new();
private readonly Queue<BufferPoolItem> _obtainedItems = new();
Expand Down Expand Up @@ -235,7 +235,7 @@ public void Release(int buffersQueued)
_availableItems.Add(_obtainedItems.Dequeue());
}

public class BufferPoolItem
public sealed class BufferPoolItem
{
public int MaxLength { get; }
public AudioBuffer AudioBuffer { get; }
Expand Down
4 changes: 2 additions & 2 deletions src/BizHawk.Bizware.Graphics/D3D11/D3D11Pipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace BizHawk.Bizware.Graphics
{
internal class D3D11Pipeline : IPipeline
internal sealed class D3D11Pipeline : IPipeline
{
private readonly D3D11Resources _resources;
private ID3D11Device Device => _resources.Device;
Expand Down Expand Up @@ -43,7 +43,7 @@ internal class D3D11Pipeline : IPipeline
private readonly Dictionary<string, int> _vsSamplers = new();
private readonly Dictionary<string, int> _psSamplers = new();

public class D3D11PendingBuffer
public sealed class D3D11PendingBuffer
{
public IntPtr VSPendingBuffer, PSPendingBuffer;
public int VSBufferSize, PSBufferSize;
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Bizware.Graphics/D3D11/D3D11SwapChain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ControlParameters(IntPtr handle, int width, int height, bool vsync, bool
}
}

internal class SwapChainResources : IDisposable
internal sealed class SwapChainResources : IDisposable
{
public ID3D11Device Device;
public ID3D11DeviceContext Context;
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Bizware.Graphics/OpenGL/OpenGLPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace BizHawk.Bizware.Graphics
{
internal class OpenGLPipeline : IPipeline
internal sealed class OpenGLPipeline : IPipeline
{
private readonly GL GL;

Expand Down
4 changes: 2 additions & 2 deletions src/BizHawk.Bizware.Graphics/Renderers/ImGui2DRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ private void ResetDrawList()
EnableBlending = _pendingBlendEnable;
}

protected class ImGuiUserTexture
protected sealed class ImGuiUserTexture
{
public Bitmap Bitmap;
public bool WantCache;
}

protected class DrawStringArgs
protected sealed class DrawStringArgs
{
public string Str;
public Font Font;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace BizHawk.Bizware.Graphics
/// Wraps SDL2's software rendering with an ImGui 2D renderer
/// Used for the GDI+ IGL, which doesn't understand vertexes and such
/// </summary>
internal class SDLImGui2DRenderer : ImGui2DRenderer
internal sealed class SDLImGui2DRenderer : ImGui2DRenderer
{
// SDL's software renderer sometimes doesn't fill in shapes all the way with a thickness of 1
// a thickness of 2 seems to suffice however
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Bizware.Input/SDL2/SDL2Gamepad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BizHawk.Bizware.Input
/// <summary>
/// SDL2 Gamepad Handler
/// </summary>
internal class SDL2Gamepad : IDisposable
internal sealed class SDL2Gamepad : IDisposable
{
// indexed by instance id
private static readonly Dictionary<int, SDL2Gamepad> Gamepads = new();
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/Api/ExternalToolAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override bool NotApplicableTo(string romHash, string? sysID)
[AttributeUsage(AttributeTargets.Class)]
public sealed class RomList : ExternalToolApplicabilityAttributeBase
{
private readonly IList<string> _romHashes;
private readonly List<string> _romHashes;

private readonly string _sysID;

Expand Down
8 changes: 4 additions & 4 deletions src/BizHawk.Client.Common/DisplayManager/Filters/Retro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,22 +229,22 @@ public class ShaderPass
public Vector2 Scale;
}

private static string FetchString(IDictionary<string, string> dict, string key, string @default)
private static string FetchString(Dictionary<string, string> dict, string key, string @default)
{
return dict.TryGetValue(key, out var str) ? str : @default;
}

private static int FetchInt(IDictionary<string, string> dict, string key, int @default)
private static int FetchInt(Dictionary<string, string> dict, string key, int @default)
{
return dict.TryGetValue(key, out var str) ? int.Parse(str) : @default;
}

private static float FetchFloat(IDictionary<string, string> dict, string key, float @default)
private static float FetchFloat(Dictionary<string, string> dict, string key, float @default)
{
return dict.TryGetValue(key, out var str) ? float.Parse(str, NumberFormatInfo.InvariantInfo) : @default;
}

private static bool FetchBool(IDictionary<string, string> dict, string key, bool @default)
private static bool FetchBool(Dictionary<string, string> dict, string key, bool @default)
{
return dict.TryGetValue(key, out var str) ? ParseBool(str) : @default;
}
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/DisplayManager/OSDManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void DrawMessages(IBlitter g)

_messages.RemoveAll(m => DateTime.Now > m.ExpireAt);

if (_messages.Any())
if (_messages.Count != 0)
{
if (_config.StackOSDMessages)
{
Expand Down
7 changes: 3 additions & 4 deletions src/BizHawk.Client.Common/RecentFiles.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;

namespace BizHawk.Client.Common
Expand Down Expand Up @@ -29,15 +28,15 @@ public RecentFiles(int max)
public bool Frozen { get; set; }

[JsonIgnore]
public bool Empty => !recentlist.Any();
public bool Empty => recentlist.Count == 0;

[JsonIgnore]
public int Count => recentlist.Count;

[JsonIgnore]
public string MostRecent => recentlist.Any() ? recentlist[0] : "";
public string MostRecent => recentlist.Count != 0 ? recentlist[0] : "";

public string this[int index] => recentlist.Any() ? recentlist[index] : "";
public string this[int index] => recentlist.Count != 0 ? recentlist[index] : "";

public IEnumerator<string> GetEnumerator() => recentlist.GetEnumerator();

Expand Down
2 changes: 2 additions & 0 deletions src/BizHawk.Client.Common/RomGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public RomGame(HawkFile file, string patch)
NotInDatabase = true
};

#pragma warning disable CA1862 // incorrect detection, see https://github.com/dotnet/roslyn-analyzers/issues/7074
if (!string.IsNullOrWhiteSpace(GameInfo.Name) && GameInfo.Name == GameInfo.Name.ToUpperInvariant())
#pragma warning restore CA1862
{
GameInfo.Name = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(GameInfo.Name.ToLowerInvariant());
}
Expand Down
4 changes: 2 additions & 2 deletions src/BizHawk.Client.Common/RomLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private IEmulator MakeCoreFromCoreInventory(CoreInventoryParameters cip, string
return (int)CorePriority.UserPreference;
}

if (string.Equals(c.Name, dbForcedCoreName, StringComparison.OrdinalIgnoreCase))
if (c.Name.Equals(dbForcedCoreName, StringComparison.OrdinalIgnoreCase))
{
return (int)CorePriority.GameDbPreference;
}
Expand Down Expand Up @@ -532,7 +532,7 @@ static byte[] CbDeflater(Stream instream, int size)
private static bool IsDiscForXML(string system, string path)
{
var ext = Path.GetExtension(path);
if (system == VSystemID.Raw.Arcade && ext.ToLowerInvariant() == ".chd")
if (system == VSystemID.Raw.Arcade && ext.Equals(".chd", StringComparison.OrdinalIgnoreCase))
{
return false;
}
Expand Down
6 changes: 1 addition & 5 deletions src/BizHawk.Client.Common/controllers/StickyControllers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,10 @@ public void MassToggleStickyState(List<string> buttons)
{
foreach (var button in buttons.Where(button => !_justPressed.Contains(button)))
{
if (_buttonHolds.Contains(button))
if (!_buttonHolds.Add(button))
{
_buttonHolds.Remove(button);
}
else
{
_buttonHolds.Add(button);
}
}

_justPressed = buttons;
Expand Down
8 changes: 4 additions & 4 deletions src/BizHawk.Client.Common/inputAdapters/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public void ToggleAutoStickies()

private static Controller BindToDefinition(
ControllerDefinition def,
IDictionary<string, Dictionary<string, string>> allBinds,
IDictionary<string, Dictionary<string, AnalogBind>> analogBinds,
IDictionary<string, Dictionary<string, FeedbackBind>> feedbackBinds)
Dictionary<string, Dictionary<string, string>> allBinds,
Dictionary<string, Dictionary<string, AnalogBind>> analogBinds,
Dictionary<string, Dictionary<string, FeedbackBind>> feedbackBinds)
{
var ret = new Controller(def);
if (allBinds.TryGetValue(def.Name, out var binds))
Expand Down Expand Up @@ -129,7 +129,7 @@ private static Controller BindToDefinition(

private static AutofireController BindToDefinitionAF(
IEmulator emulator,
IDictionary<string, Dictionary<string, string>> allBinds,
Dictionary<string, Dictionary<string, string>> allBinds,
int on,
int off)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/lua/LuaDocumentation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public string ToSublime2CompletionList()

var sb = new StringBuilder();

if (f.ParameterList.Any())
if (f.ParameterList.Length != 0)
{
sb
.Append($"{f.Library}.{f.Name}(");
Expand Down
6 changes: 2 additions & 4 deletions src/BizHawk.Client.Common/movie/bk2/Bk2Movie.ModeApi.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Linq;

namespace BizHawk.Client.Common
namespace BizHawk.Client.Common
{
public partial class Bk2Movie
{
Expand All @@ -9,7 +7,7 @@ public partial class Bk2Movie
public virtual void StartNewRecording()
{
Mode = MovieMode.Record;
if (Session.Settings.EnableBackupMovies && MakeBackup && Log.Any())
if (Session.Settings.EnableBackupMovies && MakeBackup && Log.Count != 0)
{
SaveBackup();
MakeBackup = false;
Expand Down
Loading
Loading