Skip to content

Commit 28294b9

Browse files
Resolve Most Compiler Warnings (#1870)
* Temporarily disable nullability and XML warnings * How many times does `dotnet format` need to be ran... * Collection Expressions - int[] numbers = [] * CA1836: Prefer IsEmpty over Count when available * IDE0004: Cast is redundant * IDE0074: Use compound assignment * CA1510: Use ArgumentNullException throw helper * CA1829: Use Length/Count property instead of Enumerable.Count method * IDE0063: Using statement can be simplified * CA1826: Use property instead of Linq Enumerable method * CA1512: Use ArgumentOutOfRangeException throw helper * IDE0070: 'GetHashCode' implementation can be simplified * IDE0057: Substring can be simplified * IDE0056: Indexing can be simplified * IDE0251: Member can be made 'readonly' * CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method * IDE1006: Naming rule violation: Missing suffix: 'Async' * Split different namespaces/class into separate files * IDE0090: 'new' expression can be simplified * CA1866: Use 'string.StartsWith(char)' instead of 'string.StartsWith(string)' when you have a string with a single char * CS9191: The 'ref' modifier for argument 2 corresponding to 'in' parameter is equivalent to 'in'. Consider using 'in' instead. * CS0108: 'ThreadChannelEditModel.Flags' hides inherited member 'ChannelEditModel.Flags'. Use the new keyword if hiding was intended. * CA1860: Prefer comparing 'Length' to 0 rather than using 'Any()', both for clarity and for performance * CA2208: Instantiate argument exceptions correctly * CA2017: Number of parameters supplied in the logging message template do not match the number of named placeholders * CA2253: Named placeholders in the logging message template should not be comprised of only numeric characters * IDE0059: Unnecessary assignment of a value to '{0}' * CS0168: The variable 'guild' is declared but never used * CA1827: Do not use Count()/LongCount() when Any() can be used * CA2021: Type 'Newtonsoft.Json.Linq.JToken' is incompatible with type 'string' and cast attempts will throw InvalidCastException at runtime * CA1853: Do not guard 'Dictionary.Remove(key)' with 'Dictionary.ContainsKey(key)' * CA1822: Mark members as static * SYSLIB1045: Use 'GeneratedRegexAttribute' to generate the regular expression implementation at compile-time. * IDE0250: Struct can be made 'readonly' * CA1834: Use 'StringBuilder.Append(char)' instead of 'StringBuilder.Append(string)' when the input is a constant unit string * CA1806: '{0}' calls '{1}' but does not use the value the method returns. Linq methods are known to not have side effects. Use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method. * CA1068: Method '{0}' should take CancellationToken as the last parameter * IDE0051: Private member '{0}' is unused * Namespaces below the usings * Except for OrDefault methods, CA1826: Use property instead of Linq Enumerable method * `dotnet format` * IDE0052: Private member '{0}' can be removed as the value assigned to it is never read * CA2254: The logging message template should not vary between calls to 'LoggerExtensions.LogCritical(ILogger, Exception?, string?, params object?[])' * SYSLIB1054: Mark the method '{0}' with 'LibraryImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time * CA1835: Change the 'ReadAsync' method call to use the 'Stream.ReadAsync(Memory<byte>, CancellationToken)' overload * CA1859: Change type of property '{0}' from '{1}' to '{2}' for improved performance * CA1825: Avoid unnecessary zero-length array allocations. Use Array.Empty<byte>() instead. * IDE0051: Remove unread private members * Minor optimization * Resolve CA1067 and CS0659 * Resolve CA1816 * refactor: Formatting go boom * IDE0220: 'foreach' statement implicitly converts 'object' to 'System.Text.RegularExpressions.Match'. Add an explicit cast to make intent clearer, as it may fail at runtime * CA2012: ValueTask instances should not have their result directly accessed unless the instance has already completed. Unlike Tasks, calling Result or GetAwaiter().GetResult() on a ValueTask is not guaranteed to block until the operation completes. If you can't simply await the instance, consider first checking its IsCompleted property (or asserting it's true if you know that to be the case). * Resolve IDE0060 * Re-enable XML doc warnings * CS1572: XML comment has a param tag for '{0}', but there is no parameter by that name * Resolve CS1574 * CS1573 * No compiler warnings! * Reenable nullability * Sort WarningsNotAsErrors * Fix triple newlines * IDE0078: Use pattern matching --------- Co-authored-by: Velvet <42438262+VelvetToroyashi@users.noreply.github.com>
1 parent 6382c0c commit 28294b9

731 files changed

Lines changed: 2819 additions & 2911 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ indent_size = 2
2222
###############################
2323
[*.{cs,vb}]
2424

25+
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1826#exclude-firstordefault-and-lastordefault-methods
26+
dotnet_code_quality.CA1826.exclude_ordefault_methods = true
27+
28+
# Collection Expressions - int[] numbers = []
29+
dotnet_style_collection_initializer = true:error
30+
dotnet_style_prefer_collection_expression = true:error
31+
32+
# Nullable reference types
33+
dotnet_diagnostic.CS8632.severity = none
34+
2535
# Suppress CS1591: Missing XML comment for publicly visible type or member
2636
dotnet_diagnostic.CS1591.severity = none
2737

@@ -147,7 +157,7 @@ csharp_style_inlined_variable_declaration = true:error
147157

148158
# https://stackoverflow.com/q/63369382/10942966
149159
csharp_qualified_using_at_nested_scope = true:error
150-
csharp_using_directive_placement = inside_namespace:error
160+
csharp_using_directive_placement = outside_namespace:error
151161

152162
# New line preferences
153163
csharp_new_line_before_open_brace = all

DSharpPlus.Commands/AbstractContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
namespace DSharpPlus.Commands;
2-
31
using System;
42
using DSharpPlus.Commands.Trees;
53
using DSharpPlus.Entities;
64
using Microsoft.Extensions.DependencyInjection;
75

6+
namespace DSharpPlus.Commands;
7+
88
public abstract record AbstractContext
99
{
1010
public required DiscordUser User { get; init; }

DSharpPlus.Commands/ArgumentModifiers/FromCode/CodeType.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
namespace DSharpPlus.Commands.ArgumentModifiers;
2-
31
using System;
42

3+
namespace DSharpPlus.Commands.ArgumentModifiers;
4+
55
/// <summary>
66
/// The types of code-formatted text to accept.
77
/// </summary>

DSharpPlus.Commands/ArgumentModifiers/FromCode/FromCodeAttribute.LanguageList.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// <auto-generated/>
22
// Last modified on Tuesday, 12 March 2024 22:52:02
3-
43
using System;
54
using System.Collections.Frozen;
65
using System.Collections.Generic;

DSharpPlus.Commands/ArgumentModifiers/FromCode/FromCodeAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
namespace DSharpPlus.Commands.ArgumentModifiers;
2-
31
using System;
42

3+
namespace DSharpPlus.Commands.ArgumentModifiers;
4+
55
/// <summary>
66
/// Removes the need to manually parse code blocks from a string.
77
/// </summary>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
namespace DSharpPlus.Commands.ArgumentModifiers;
2-
31
using System;
42

3+
namespace DSharpPlus.Commands.ArgumentModifiers;
4+
55
[AttributeUsage(AttributeTargets.Parameter)]
66
public sealed class RemainingTextAttribute : Attribute;

DSharpPlus.Commands/CommandAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
namespace DSharpPlus.Commands;
2-
31
using System;
42

3+
namespace DSharpPlus.Commands;
4+
55
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method | AttributeTargets.Delegate)]
66
public sealed class CommandAttribute : Attribute
77
{

DSharpPlus.Commands/CommandContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
namespace DSharpPlus.Commands;
2-
31
using System.Collections.Generic;
42
using System.Threading.Tasks;
53
using DSharpPlus.Commands.Trees;
64
using DSharpPlus.Entities;
75

6+
namespace DSharpPlus.Commands;
7+
88
/// <summary>
99
/// Represents a base context for application command contexts.
1010
/// </summary>

DSharpPlus.Commands/CommandsConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
namespace DSharpPlus.Commands;
2-
31
using System;
42

3+
namespace DSharpPlus.Commands;
4+
55
/// <summary>
66
/// The configuration copied to an instance of <see cref="CommandsExtension"/>.
77
/// </summary>

DSharpPlus.Commands/CommandsExtension.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
namespace DSharpPlus.Commands;
2-
31
using System;
42
using System.Collections.Frozen;
53
using System.Collections.Generic;
@@ -10,7 +8,6 @@ namespace DSharpPlus.Commands;
108
using System.Runtime.CompilerServices;
119
using System.Text;
1210
using System.Threading.Tasks;
13-
1411
using DSharpPlus.AsyncEvents;
1512
using DSharpPlus.Commands.ContextChecks;
1613
using DSharpPlus.Commands.ContextChecks.ParameterChecks;
@@ -25,28 +22,27 @@ namespace DSharpPlus.Commands;
2522
using DSharpPlus.Commands.Trees;
2623
using DSharpPlus.Entities;
2724
using DSharpPlus.Exceptions;
28-
2925
using Microsoft.Extensions.DependencyInjection;
3026
using Microsoft.Extensions.Logging;
3127
using Microsoft.Extensions.Logging.Abstractions;
32-
3328
using CheckFunc = System.Func
3429
<
3530
object,
3631
DSharpPlus.Commands.ContextChecks.ContextCheckAttribute,
37-
CommandContext,
32+
DSharpPlus.Commands.CommandContext,
3833
System.Threading.Tasks.ValueTask<string?>
3934
>;
40-
4135
using ParameterCheckFunc = System.Func
4236
<
4337
object,
4438
DSharpPlus.Commands.ContextChecks.ParameterChecks.ParameterCheckAttribute,
4539
DSharpPlus.Commands.ContextChecks.ParameterChecks.ParameterCheckInfo,
46-
CommandContext,
40+
DSharpPlus.Commands.CommandContext,
4741
System.Threading.Tasks.ValueTask<string?>
4842
>;
4943

44+
namespace DSharpPlus.Commands;
45+
5046
/// <summary>
5147
/// An all in one extension for managing commands.
5248
/// </summary>

0 commit comments

Comments
 (0)