Skip to content

Commit

Permalink
Merge pull request #3335 from andreas-henning/dev/ah/code-style
Browse files Browse the repository at this point in the history
Code formatting, comment and nuget package metadata updates
  • Loading branch information
not-ilinked authored Oct 17, 2022
2 parents c0e5e88 + 0ac9311 commit c6d398e
Show file tree
Hide file tree
Showing 248 changed files with 165 additions and 1,237 deletions.
53 changes: 37 additions & 16 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ csharp_style_var_for_built_in_types = false
csharp_style_var_when_type_is_apparent = true

# Expression-bodied members
csharp_style_expression_bodied_accessors = true
csharp_style_expression_bodied_constructors = false
csharp_style_expression_bodied_indexers = true
csharp_style_expression_bodied_lambdas = true
csharp_style_expression_bodied_local_functions = false
csharp_style_expression_bodied_methods = false
csharp_style_expression_bodied_operators = false
csharp_style_expression_bodied_properties = true
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent

# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true
Expand All @@ -106,27 +106,27 @@ csharp_prefer_static_local_function = true
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async

# Code-block preferences
csharp_prefer_braces = when_multiline
csharp_prefer_simple_using_statement = true
csharp_style_namespace_declarations = block_scoped
csharp_style_prefer_method_group_conversion = true
csharp_prefer_braces = when_multiline:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent

# Expression-level preferences
csharp_prefer_simple_default_expression = true
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_deconstructed_variable_declaration = true
csharp_style_implicit_object_creation_when_type_is_apparent = true
csharp_style_inlined_variable_declaration = true
csharp_style_prefer_index_operator = true
csharp_style_prefer_local_over_anonymous_function = true
csharp_style_prefer_null_check_over_type_check = true
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_style_prefer_range_operator = true
csharp_style_prefer_tuple_swap = true
csharp_style_throw_expression = true
csharp_style_throw_expression = true:suggestion
csharp_style_unused_value_assignment_preference = discard_variable
csharp_style_unused_value_expression_statement_preference = discard_variable

# 'using' directive preferences
csharp_using_directive_placement = outside_namespace
csharp_using_directive_placement = outside_namespace:silent

# New line preferences
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
Expand Down Expand Up @@ -221,3 +221,24 @@ dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

[*.{cs,vb}]
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
4 changes: 4 additions & 0 deletions Anarchy.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{DF
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{48CAFB24-2F02-4E07-9E8E-CE64AA5A3C49}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitignore = .gitignore
Changelog.md = Changelog.md
EndProjectSection
Expand Down Expand Up @@ -97,4 +98,7 @@ Global
{A34F8993-D2B3-4F92-9CB3-DA7AACEA6186} = {DF7071F8-A2B3-419A-951F-94946CFF12FC}
{7EBF4ED8-CC72-41CB-ACE6-BFE6E5BB3FA8} = {DF7071F8-A2B3-419A-951F-94946CFF12FC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A4CAD5AB-8223-4E10-8E41-A16FFED6C015}
EndGlobalSection
EndGlobal
11 changes: 9 additions & 2 deletions Anarchy/Anarchy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<NoWarn>IDE1006, CS0649, CS0414, IDE0051</NoWarn>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
Expand All @@ -17,10 +18,16 @@
<VersionSuffix></VersionSuffix>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Title>Anarchy</Title>
<PackageId>Anarchy-Wrapper</PackageId>
<PackageIcon>nuget-logo.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageReleaseNotes>See the changelog on github (https://github.com/not-ilinked/Anarchy/blob/master/Changelog.md)</PackageReleaseNotes>
<PackageReleaseNotes>See the changelog on github:
https://github.com/not-ilinked/Anarchy/blob/master/Changelog.md</PackageReleaseNotes>
<Authors>iLinked</Authors>
<PackageProjectUrl></PackageProjectUrl>
<RepositoryUrl>https://github.com/not-ilinked/Anarchy</RepositoryUrl>
<PackageTags>discord;anarchy</PackageTags>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 2 additions & 3 deletions Anarchy/Commands/Command/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ internal CommandHandler(string prefix, DiscordSocketClient client)
}
}


private void Client_OnMessageReceived(DiscordSocketClient client, MessageEventArgs args)
{
if (args.Message.Content.StartsWith(Prefix))
Expand All @@ -41,7 +40,7 @@ private void Client_OnMessageReceived(DiscordSocketClient client, MessageEventAr
{
parts.RemoveAt(0);

CommandBase inst = (CommandBase)Activator.CreateInstance(command.Type);
CommandBase inst = (CommandBase) Activator.CreateInstance(command.Type);
inst.Prepare(_client, args.Message);

for (int i = 0; i < command.Parameters.Count; i++)
Expand Down Expand Up @@ -171,7 +170,7 @@ internal static bool TryGetAttribute<TAttr>(IEnumerable<object> attributes, out
{
if (attribute.GetType() == typeof(TAttr))
{
attr = (TAttr)attribute;
attr = (TAttr) attribute;
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Anarchy/Commands/SlashCommands/SlashCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class SlashCommand

internal void Prepare(DiscordInteraction interaction)
{
Client = (DiscordSocketClient)interaction.Client;
Client = (DiscordSocketClient) interaction.Client;

Caller = interaction.User;
CallerMember = interaction.Member;
Expand Down
6 changes: 3 additions & 3 deletions Anarchy/Commands/SlashCommands/SlashCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public SlashCommandHandler(DiscordSocketClient client, ulong appId, ulong? guild
{
if (choices == null) choices = new List<CommandOptionChoice>();

var choiceAttr = (SlashParameterChoiceAttribute)ok;
var choiceAttr = (SlashParameterChoiceAttribute) ok;

if (choiceAttr.Value.GetType() != typeof(string) && !IsInteger(choiceAttr.Value.GetType()))
throw new InvalidOperationException("All choice values must either be strings or integers");
Expand Down Expand Up @@ -177,7 +177,7 @@ private void Handle(string cmdName, DiscordInteraction interaction, List<SlashCo
{
var localCommand = _handlerDict[cmdName];

var handler = (SlashCommand)Activator.CreateInstance(localCommand.HandlerType);
var handler = (SlashCommand) Activator.CreateInstance(localCommand.HandlerType);
handler.Prepare(interaction);

if (arguments != null)
Expand Down Expand Up @@ -239,7 +239,7 @@ private static bool TryGetAttribute<TAttr>(IEnumerable<object> attributes, out T
{
if (attribute.GetType() == typeof(TAttr))
{
attr = (TAttr)attribute;
attr = (TAttr) attribute;
return true;
}
}
Expand Down
1 change: 0 additions & 1 deletion Anarchy/Local/Controllable/Controllable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public DiscordClient Client
}
}


public void Dispose()
{
_client = null;
Expand Down
1 change: 0 additions & 1 deletion Anarchy/Local/Controllable/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public static T SetClient<T>(this T @class, DiscordClient client) where T : Cont
return @class;
}


internal static IReadOnlyList<T> SetClientsInList<T>(this IReadOnlyList<T> classes, DiscordClient client) where T : Controllable
{
if (classes != null)
Expand Down
2 changes: 1 addition & 1 deletion Anarchy/Local/Controllable/JsonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static T ParseDeterministic<T>(this JObject obj)
if (TryFindTypes(typeof(T), out Dictionary<int, Type> types))
{
int type = obj.Value<int>("type");
return (T)obj.ToObject(types.TryGetValue(type, out var t) ? t : typeof(T));
return (T) obj.ToObject(types.TryGetValue(type, out var t) ? t : typeof(T));
}
else
throw new InvalidCastException("Unable to find any implementations for T");
Expand Down
2 changes: 1 addition & 1 deletion Anarchy/Local/DiscordImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Discord
{
class ImageJsonConverter : JsonConverter<DiscordImage>
internal class ImageJsonConverter : JsonConverter<DiscordImage>
{
public override bool CanRead => false;

Expand Down
2 changes: 0 additions & 2 deletions Anarchy/Local/DiscordParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ public T Value
}
}


public static implicit operator T(DiscordParameter<T> instance)
{
return instance.Value;
}


public override string ToString()
{
return Value.ToString();
Expand Down
6 changes: 0 additions & 6 deletions Anarchy/REST/Billing/BillingAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,21 @@ public class BillingAddress
[JsonProperty("name")]
public string Name { get; private set; }


[JsonProperty("line_1")]
public string Address1 { get; private set; }


[JsonProperty("line_2")]
public string Address2 { get; private set; }


[JsonProperty("city")]
public string City { get; private set; }


[JsonProperty("state")]
public string State { get; private set; }


[JsonProperty("country")]
public string Country { get; private set; }


[JsonProperty("postal_code")]
public dynamic PostalCode { get; private set; }
}
Expand Down
4 changes: 0 additions & 4 deletions Anarchy/REST/Billing/CardPaymentMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ public class CardPaymentMethod : PaymentMethod
[JsonProperty("brand")]
public string Brand { get; private set; }


[JsonProperty("country")]
public string Country { get; private set; }


[JsonProperty("last_4")]
public int Last4 { get; private set; }


[JsonProperty("expires_month")]
public int ExpirationMonth { get; private set; }


[JsonProperty("expires_year")]
public int ExpirationYear { get; private set; }
}
Expand Down
7 changes: 0 additions & 7 deletions Anarchy/REST/Billing/DiscordPayment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,24 @@ public DiscordPayment()
[JsonProperty("id")]
public ulong Id { get; private set; }


[JsonProperty("created_at")]
public DateTime Timestamp { get; private set; }


[JsonProperty("currency")]
public string Currency { get; private set; }


[JsonProperty("amount")]
public string Amount { get; private set; }


[JsonProperty("status")]
public DiscordPaymentStatus Status { get; private set; }


[JsonProperty("description")]
public string Description { get; private set; }


[JsonProperty("flags")]
public DiscordPaymentFlags Flags { get; private set; }


[JsonProperty("payment_source")]
[JsonConverter(typeof(DeepJsonConverter<PaymentMethod>))]
public PaymentMethod PaymentMethod { get; private set; }
Expand Down
1 change: 0 additions & 1 deletion Anarchy/REST/Billing/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public static IReadOnlyList<DiscordPayment> GetPayments(this DiscordClient clien
return client.GetPaymentsAsync(limit).GetAwaiter().GetResult();
}


public static async Task<IReadOnlyList<PaymentMethod>> GetPaymentMethodsAsync(this DiscordClient client)
{
return (await client.HttpClient.GetAsync("/users/@me/billing/payment-sources"))
Expand Down
7 changes: 0 additions & 7 deletions Anarchy/REST/Billing/PaymentMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,21 @@ public class PaymentMethod : Controllable
[JsonProperty("id")]
public ulong Id { get; private set; }


[JsonProperty("type")]
public PaymentMethodType Type { get; private set; }


[JsonProperty("invalid")]
public bool Invalid { get; private set; }


[JsonProperty("billing_address")]
public BillingAddress BillingAddress { get; private set; }


[JsonProperty("country")]
public string County { get; private set; }


[JsonProperty("default")]
public bool Default { get; private set; }


public async Task<string> PurchaseGiftAsync(ulong skuId, ulong subPlanId, int expectedAmount)
{
return await Client.PurchaseGiftAsync(Id, skuId, subPlanId, expectedAmount);
Expand All @@ -39,7 +33,6 @@ public string PurchaseGift(ulong skuId, ulong subPlanId, int expectedAmount)
return PurchaseGiftAsync(skuId, subPlanId, expectedAmount).GetAwaiter().GetResult();
}


public async Task<string> PurchaseNitroGiftAsync(DiscordNitroSubType nitroType)
{
return await Client.PurchaseNitroGiftAsync(Id, nitroType);
Expand Down
2 changes: 0 additions & 2 deletions Anarchy/REST/Channel/Channel/CreationProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ public class ChannelCreationProperties
[JsonProperty("name")]
public string Name { get; set; }


[JsonProperty("type")]
public ChannelType Type { get; set; }


public override string ToString()
{
return Type.ToString();
Expand Down
Loading

0 comments on commit c6d398e

Please sign in to comment.