Skip to content

Commit

Permalink
Update suppressions
Browse files Browse the repository at this point in the history
Move to a global suppression mechanism for code clarity and clean all messages.
  • Loading branch information
JeremyKuhne committed Jan 26, 2024
1 parent ca0b5ad commit 21b2ac4
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 63 deletions.
16 changes: 15 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true

# Test .cs files
[**/*Tests.cs]

# This doesn't work well with TheoryData
# CA1861: Avoid constant arrays as arguments
dotnet_diagnostic.CA1861.severity = none

# Native .cs files
[**/Win32/**/*.cs]

Expand All @@ -22,9 +29,13 @@ dotnet_diagnostic.SA1313.severity = none
# IDE1006: Naming Styles
dotnet_diagnostic.IDE1006.severity = none

# CS0649:
# CS0649:
dotnet_diagnostic.CS0649.severity = none

[**/Interop.**.cs]
# SA1313: Parameter names should begin with lower-case letter
dotnet_diagnostic.SA1313.severity = none

# C# files
[*.cs]

Expand Down Expand Up @@ -388,6 +399,9 @@ csharp_style_prefer_pattern_matching = true:silent
csharp_style_prefer_extended_property_pattern = true:suggestion
csharp_style_prefer_not_pattern = true:suggestion

# SYSLIB1096: Convert to 'GeneratedComInterface'
dotnet_diagnostic.SYSLIB1096.severity = none

[*.{cs,vb}]
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:silent
Expand Down
2 changes: 1 addition & 1 deletion src/samples/KeyWatch/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected override LRESULT WindowProcedure(HWND window, MessageType message, WPA
switch (message)
{
case MessageType.KeyUp:
Message.KeyUpDown key = new(wParam, lParam);
Message.KeyUpDown key = new(wParam);
Debug.WriteLine($"KeyUp: {key.Key}");
break;
case MessageType.KeyDown:
Expand Down
3 changes: 1 addition & 2 deletions src/thirtytwo/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public static void Run(
string? windowTitle = null,
WindowStyles style = WindowStyles.OverlappedWindow,
ExtendedWindowStyles extendedStyle = ExtendedWindowStyles.Default,
HMENU menuHandle = default)
=> Run(
HMENU menuHandle = default) => Run(
windowClass,
Window.DefaultBounds,
windowTitle,
Expand Down
1 change: 0 additions & 1 deletion src/thirtytwo/CharacterSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public enum CharacterSet : byte
Symbol = FONT_CHARSET.SYMBOL_CHARSET,
Mac = FONT_CHARSET.MAC_CHARSET,
ShiftJis = FONT_CHARSET.SHIFTJIS_CHARSET,
Hangeul = FONT_CHARSET.HANGEUL_CHARSET,
Hangul = FONT_CHARSET.HANGUL_CHARSET,
GB2312 = FONT_CHARSET.GB2312_CHARSET,
ChineseBig5 = FONT_CHARSET.CHINESEBIG5_CHARSET,
Expand Down
4 changes: 2 additions & 2 deletions src/thirtytwo/Clipboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static unsafe uint[] GetAvailableClipboardFormats()
uint count = (uint)Interop.CountClipboardFormats();
if (count == 0)
{
return Array.Empty<uint>();
return [];
}

using BufferScope<uint> buffer = new(stackalloc uint[(int)count]);
Expand All @@ -42,7 +42,7 @@ public static unsafe uint[] GetAvailableClipboardFormats()
buffer.EnsureCapacity((int)count);
} while (true);

return count == 0 ? Array.Empty<uint>() : buffer[..(int)count].ToArray();
return count == 0 ? [] : buffer[..(int)count].ToArray();
}

/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions src/thirtytwo/Controls/ButtonControl.Styles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,18 @@ public enum Styles : uint

/// <summary>
/// Draw text to the left of radio buttons and checkboxes.
/// Same as RightButton.
/// </summary>
/// <remarks>
/// <para>Same as <see cref="RightButton"/>.</para>
/// </remarks>
LeftText = Interop.BS_LEFTTEXT,

/// <summary>
/// Draw text to the left of radio buttons and checkboxes.
/// Same as LeftText
/// </summary>
/// <remarks>
/// <para>Same as <see cref="LeftText"/>.</para>
/// </remarks>
RightButton = Interop.BS_RIGHTBUTTON,

// This is the default state- buttons have text
Expand Down
6 changes: 1 addition & 5 deletions src/thirtytwo/DrawTextFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace Windows;

#pragma warning disable CA1069 // Enums values should not be duplicated

[Flags]
public enum DrawTextFormat : uint
{
Expand Down Expand Up @@ -32,6 +30,4 @@ public enum DrawTextFormat : uint
NoFullWidthCharacterBreak = DRAW_TEXT_FORMAT.DT_NOFULLWIDTHCHARBREAK,
HidePrefix = DRAW_TEXT_FORMAT.DT_HIDEPREFIX,
PrefixOnly = DRAW_TEXT_FORMAT.DT_PREFIXONLY
}

#pragma warning restore CA1069 // Enums values should not be duplicated
}
5 changes: 1 addition & 4 deletions src/thirtytwo/ExtendedWindowStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace Windows;
#pragma warning disable CA1069 // Enums values should not be duplicated

[Flags]
public enum ExtendedWindowStyles : uint
Expand Down Expand Up @@ -136,6 +135,4 @@ public enum ExtendedWindowStyles : uint
/// user clicks it.
/// </summary>
NoActivate = WINDOW_EX_STYLE.WS_EX_NOACTIVATE
}

#pragma warning restore CA1069 // Enums values should not be duplicated
}
14 changes: 14 additions & 0 deletions src/thirtytwo/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Jeremy W. Kuhne. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.ButtonControl.Styles")]
[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "member", Target = "~F:Windows.FontWeight.Black")]
[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.FontWeight")]
[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.SystemColor")]
[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.StockBrush")]
[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.ExtendedWindowStyles")]
[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.DrawTextFormat")]
[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.IconId")]
[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.MessageBoxStyles")]
[assembly: SuppressMessage("Design", "CA1069:Enums values should not be duplicated", Justification = "Matches Windows", Scope = "type", Target = "~T:Windows.WindowStyles")]
[assembly: SuppressMessage("Usage", "CA2231:Overload operator equals on overriding value type Equals", Justification = "CsWin32", Scope = "type", Target = "~T:Windows.Win32.Foundation.PCWSTR")]
4 changes: 1 addition & 3 deletions src/thirtytwo/Messages/Message.KeyUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ namespace Windows;

public static partial class Message
{
#pragma warning disable CS9113 // LPARAM is needed for other details, just haven't implemented yet.
public readonly ref struct KeyUpDown(WPARAM wParam, LPARAM lParam)
#pragma warning restore CS9113
public readonly ref struct KeyUpDown(WPARAM wParam)
{
public VIRTUAL_KEY Key { get; } = (VIRTUAL_KEY)(nuint)wParam;
}
Expand Down
6 changes: 2 additions & 4 deletions src/thirtytwo/Messages/Message.Timer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ public static partial class Message
{
public readonly ref struct Timer(WPARAM wParam, LPARAM lParam)
{
private readonly WPARAM _wParam = wParam;
private readonly LPARAM _lParam = lParam;

public uint Id => (uint)_wParam;
public uint Id => (uint)wParam;

public nint Procedure => lParam;
// public TimerProcedure? Procedure
// => _lParam.IsNull ? null : Marshal.GetDelegateForFunctionPointer<TimerProcedure>(_lParam);
}
Expand Down
2 changes: 0 additions & 2 deletions src/thirtytwo/StockBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ public enum StockBrush : uint
DarkGray = GET_STOCK_OBJECT_FLAGS.DKGRAY_BRUSH,
Black = GET_STOCK_OBJECT_FLAGS.BLACK_BRUSH,
Hollow = GET_STOCK_OBJECT_FLAGS.HOLLOW_BRUSH,
#pragma warning disable CA1069 // Enums values should not be duplicated
Null = GET_STOCK_OBJECT_FLAGS.NULL_BRUSH,
#pragma warning restore CA1069

/// <summary>
/// Device context brush. Color is changed via Get/SetDeviceContextBrushColor.
Expand Down
2 changes: 2 additions & 0 deletions src/thirtytwo/Support/SpanWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,14 @@ private void UnsafeAdvance(int count)
UncheckedSlice(ref _unwritten, count, _unwritten.Length - count);
}

/*
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void UncheckedSliceTo(ref Span<T> span, int length)
{
Debug.Assert((uint)length <= (uint)span.Length);
span = MemoryMarshal.CreateSpan(ref MemoryMarshal.GetReference(span), length);
}
*/

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void UncheckedSlice(ref Span<T> span, int start, int length)
Expand Down
2 changes: 1 addition & 1 deletion src/thirtytwo/Support/TempFolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Windows.Support;

public class TempFolder : IDisposable
public sealed class TempFolder : IDisposable
{
public string Path { get; } = IO.Path.Join(IO.Path.GetTempPath(), IO.Path.GetRandomFileName());

Expand Down
2 changes: 0 additions & 2 deletions src/thirtytwo/SystemColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,11 @@ public enum SystemColor : int

MenuBar = SYS_COLOR_INDEX.COLOR_MENUBAR,

#pragma warning disable CA1069 // Enums values should not be duplicated
Desktop = SYS_COLOR_INDEX.COLOR_DESKTOP,

Face3d = SYS_COLOR_INDEX.COLOR_3DFACE,

Shadow3d = SYS_COLOR_INDEX.COLOR_3DSHADOW,

Highlight3d = SYS_COLOR_INDEX.COLOR_3DHIGHLIGHT
#pragma warning restore CA1069 // Enums values should not be duplicated
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

namespace Windows.Wdk;

#pragma warning disable SA1313 // Parameter names should begin with lower-case letter

public static partial class Interop
{
/// <summary>
Expand All @@ -34,6 +32,4 @@ public static extern unsafe NTSTATUS NtQueryKey(
void* KeyInformation,
uint Length,
uint* ResultLength);
}

#pragma warning restore SA1313 // Parameter names should begin with lower-case letter
}
2 changes: 0 additions & 2 deletions src/thirtytwo/Win32/Foundation/PCWSTR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

namespace Windows.Win32.Foundation;

#pragma warning disable CA2231 // Overload operator equals on overriding value type Equals
public unsafe partial struct PCWSTR
#pragma warning restore CA2231
{
public bool IsNull => Value is null;

Expand Down
2 changes: 1 addition & 1 deletion src/thirtytwo/Win32/System/Com/ComTypeDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public ComTypeDescriptor(IComPointer comObject)
PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
{
InitializePropertyDescriptors();
return new(_properties.ToArray());
return new([.. _properties]);
}

PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[]? attributes) => throw new NotImplementedException();
Expand Down
11 changes: 2 additions & 9 deletions src/thirtytwo/Win32/System/Com/EnumUnknown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@ public unsafe abstract class EnumUnknown : IEnumUnknown.Interface, IManagedWrapp

public EnumUnknown(int count, int index = 0)
{
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count));
}

if (index < 0)
{
throw new ArgumentOutOfRangeException(nameof(index));
}
ArgumentOutOfRangeException.ThrowIfNegative(count);
ArgumentOutOfRangeException.ThrowIfNegative(index);

_count = count;
_index = index;
Expand Down
2 changes: 1 addition & 1 deletion src/thirtytwo/Win32/System/Com/IDispatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public int[] GetIdsOfNames(params string[] names)

if (names.Length == 0)
{
return Array.Empty<int>();
return [];
}

using StringParameterArray namesArg = new(names);
Expand Down
11 changes: 2 additions & 9 deletions src/thirtytwo/Win32/System/Ole/EnumVARIANT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@ public unsafe abstract class EnumVARIANT : IEnumVARIANT.Interface, IManagedWrapp

public EnumVARIANT(int count, int index = 0)
{
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count));
}

if (index < 0)
{
throw new ArgumentOutOfRangeException(nameof(index));
}
ArgumentOutOfRangeException.ThrowIfNegative(count);
ArgumentOutOfRangeException.ThrowIfNegative(index);

_count = count;
_index = index;
Expand Down
2 changes: 1 addition & 1 deletion src/thirtytwo/Win32/System/Variant/VARIANT_ToObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public unsafe partial struct VARIANT
}
}

private static object? ToArray(SAFEARRAY* psa, VARENUM vt)
private static Array? ToArray(SAFEARRAY* psa, VARENUM vt)
{
if (psa is null)
{
Expand Down
4 changes: 1 addition & 3 deletions src/thirtytwo/WindowStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,4 @@ public enum WindowStyles : uint
/// Same as <see cref="Child"/>.
/// </summary>
ChildWindow = WINDOW_STYLE.WS_CHILDWINDOW
}

#pragma warning restore CA1069 // Enums values should not be duplicated
}
2 changes: 1 addition & 1 deletion src/thirtytwo/thirtytwo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.83-beta">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 3 additions & 1 deletion src/thirtytwo_tests/ProcessAndThreads/ProcessInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ public void BasicFunctionality()
}
}

/*
private void CannotModify()
{
ProcessInfo info = new();
// This doesn't compile as it returns a ref readonly
// info[0].UniqueProcessId = default;
info[0].UniqueProcessId = default;
}
*/
}

0 comments on commit 21b2ac4

Please sign in to comment.