Skip to content

Commit ffc657c

Browse files
authored
fix code inspections (#2249)
* Remove unused local variables * Remove unused using directives * Use explicit public modifier in interfaces * Correctly prepend single char to stringbuilder instead of using it as capacity and allocating a new sb * Use 'this' qualifier * Remove unneeded parenthesis * Qualifier 'this.' is redundant * Redundant control flow jump statement * Discard unused parameter * Remove possible multiple enumerations * Remove possible multiple enumerations * Fix broken RequirePermissionsAttribute check * Revert "Redundant control flow jump statement" This reverts commit b86b0a5.
1 parent 570f527 commit ffc657c

72 files changed

Lines changed: 157 additions & 180 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.

DSharpPlus.Commands/Converters/DiscordAttachmentConverter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Globalization;
43
using System.Linq;

DSharpPlus.Commands/Processors/SlashCommands/EnumAutoCompleteProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static EnumAutoCompleteProvider()
3333
: fieldInfo.Name;
3434

3535
object? obj = fieldInfo.GetValue(null);
36-
if (obj is not T enumValue)
36+
if (obj is not T)
3737
{
3838
// Hey what the fuck
3939
continue;

DSharpPlus.Commands/Processors/SlashCommands/InteractionNamingPolicies/IInteractionNamingPolicy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public interface IInteractionNamingPolicy
2121
/// The value will be -1 if this parameter is not part of an <see cref="IEnumerable" />.
2222
/// </param>
2323
/// <returns>The name that should be used for the interaction data.</returns>
24-
string GetParameterName(CommandParameter parameter, CultureInfo culture, int arrayIndex);
24+
public string GetParameterName(CommandParameter parameter, CultureInfo culture, int arrayIndex);
2525

2626
/// <summary>
2727
/// Transforms the text into it's new case.
2828
/// </summary>
2929
/// <param name="text">The text to transform.</param>
3030
/// <param name="culture">The culture to use for the transformation.</param>
3131
/// <returns>The transformed text.</returns>
32-
string TransformText(ReadOnlySpan<char> text, CultureInfo culture);
32+
public string TransformText(ReadOnlySpan<char> text, CultureInfo culture);
3333
}

DSharpPlus.Commands/Processors/TextCommands/Parsing/DefaultTextArgumentSplicer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private enum TextState
101101
if (state == TextState.InQuote)
102102
{
103103
// Prepend the quoted character
104-
result = new StringBuilder(quotedCharacter).Append(result);
104+
result.Insert(0, quotedCharacter);
105105
}
106106

107107
if (result.Length == 0)

DSharpPlus.Commands/Trees/CommandBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public CommandBuilder WithSubcommands(IEnumerable<CommandBuilder> subcommands)
7373
public CommandBuilder WithParameters(IEnumerable<CommandParameterBuilder> parameters)
7474
{
7575
this.Parameters = new(parameters);
76-
foreach (CommandParameterBuilder parameter in parameters)
76+
foreach (CommandParameterBuilder parameter in this.Parameters)
7777
{
7878
parameter.Parent ??= this;
7979
}
@@ -85,7 +85,7 @@ public CommandBuilder WithAttributes(IEnumerable<Attribute> attributes)
8585
{
8686
this.Attributes = new(attributes);
8787

88-
foreach (Attribute attribute in attributes)
88+
foreach (Attribute attribute in this.Attributes)
8989
{
9090
if (attribute is CommandAttribute commandAttribute)
9191
{

DSharpPlus.CommandsNext/Attributes/CooldownAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public CommandCooldownBucket GetBucket(CommandContext ctx)
6565
public TimeSpan GetRemainingCooldown(CommandContext ctx)
6666
{
6767
CommandCooldownBucket? bucket = GetBucket(ctx);
68-
return (bucket is null || bucket.RemainingUses > 0) ? TimeSpan.Zero : bucket.ResetsAt - DateTimeOffset.UtcNow;
68+
return bucket is null || bucket.RemainingUses > 0 ? TimeSpan.Zero : bucket.ResetsAt - DateTimeOffset.UtcNow;
6969
}
7070

7171
/// <summary>
@@ -118,7 +118,7 @@ public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help
118118
if (!buckets.TryGetValue(bucketId, out CommandCooldownBucket? bucket))
119119
{
120120
bucket = new CommandCooldownBucket(ctx.Command!.QualifiedName, ctx.Client.CurrentUser.Id, this.MaxUses, this.Reset, userId, channelId, guildId);
121-
buckets.AddOrUpdate(bucketId, bucket, (key, value) => bucket);
121+
buckets.AddOrUpdate(bucketId, bucket, (_, _) => bucket);
122122
}
123123

124124
return await bucket.DecrementUseAsync();

DSharpPlus.CommandsNext/Attributes/RequireBotPermissionsAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help
3838
return this.IgnoreDms;
3939
}
4040

41-
DSharpPlus.Entities.DiscordMember bot = await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id);
41+
DiscordMember bot = await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id);
4242
if (bot == null)
4343
{
4444
return false;

DSharpPlus.CommandsNext/Attributes/RequirePermissionsAttribute.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,40 @@ public RequirePermissionsAttribute(bool ignoreDms = true, params DiscordPermissi
3333

3434
public override async Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
3535
{
36-
if (ctx.Guild == null)
36+
if (ctx.Guild is null)
3737
{
3838
return this.IgnoreDms;
3939
}
4040

41-
DSharpPlus.Entities.DiscordMember? usr = ctx.Member;
42-
if (usr == null)
41+
DiscordMember? user = ctx.Member;
42+
if (user is null)
4343
{
4444
return false;
4545
}
4646

47-
DiscordPermissions pusr = ctx.Channel.PermissionsFor(usr);
47+
DiscordPermissions userPermissions = ctx.Channel.PermissionsFor(user);
4848

49-
DSharpPlus.Entities.DiscordMember bot = await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id);
50-
if (bot == null)
49+
DiscordMember bot = await ctx.Guild.GetMemberAsync(ctx.Client.CurrentUser.Id);
50+
if (bot is null)
5151
{
5252
return false;
5353
}
5454

55-
DiscordPermissions pbot = ctx.Channel.PermissionsFor(bot);
55+
DiscordPermissions botPermissions = ctx.Channel.PermissionsFor(bot);
5656

57-
bool usrok = ctx.Guild.OwnerId == usr.Id;
58-
bool botok = ctx.Guild.OwnerId == bot.Id;
57+
bool userIsOwner = ctx.Guild.OwnerId == user.Id;
58+
bool botIsOwner = ctx.Guild.OwnerId == bot.Id;
5959

60-
if (!usrok)
60+
if (!userIsOwner)
6161
{
62-
usrok = pusr.HasAllPermissions(this.Permissions);
62+
userIsOwner = userPermissions.HasAllPermissions(this.Permissions);
6363
}
6464

65-
if (!botok)
65+
if (!botIsOwner)
6666
{
67-
botok = pusr.HasAllPermissions(this.Permissions);
67+
botIsOwner = botPermissions.HasAllPermissions(this.Permissions);
6868
}
6969

70-
return usrok && botok;
70+
return userIsOwner && botIsOwner;
7171
}
7272
}

DSharpPlus.CommandsNext/Attributes/RequireUserPermissionsAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public override Task<bool> ExecuteCheckAsync(CommandContext ctx, bool help)
3838
return Task.FromResult(this.IgnoreDms);
3939
}
4040

41-
DSharpPlus.Entities.DiscordMember? usr = ctx.Member;
41+
DiscordMember? usr = ctx.Member;
4242
if (usr == null)
4343
{
4444
return Task.FromResult(false);

DSharpPlus.CommandsNext/CommandsNextConfiguration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using DSharpPlus.CommandsNext.Converters;
88
using DSharpPlus.CommandsNext.Executors;
99
using DSharpPlus.Entities;
10-
using Microsoft.Extensions.DependencyInjection;
1110

1211
namespace DSharpPlus.CommandsNext;
1312

0 commit comments

Comments
 (0)