From ea34da2f73b6bb504cfa591b3987acad5b250e8b Mon Sep 17 00:00:00 2001 From: pajlada Date: Mon, 22 Apr 2024 16:44:24 +0200 Subject: [PATCH] Add .editorconfig & run `dotnet format` (#16) The only contentious addition I made was adding `object_collection_array_initializers` to `csharp_new_line_before_open_brace`. With it added, one line changed. Without it, one line changed. --- .editorconfig | 12 ++++++++++++ 7TVEmoteProvider.cs | 12 ++++++------ BTTVEmoteProvider.cs | 5 +++-- MessageHeightTwitch.cs | 12 ++++++------ MessageHeightTwitchStatic.cs | 5 +++-- 5 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1b11e4d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*.cs] +indent_size = 4 +indent_style = tab +tab_width = 4 + +csharp_new_line_before_open_brace = accessors, anonymous_methods, anonymous_types, events, indexers, local_functions, methods, object_collection_array_initializers, properties, types +csharp_new_line_before_else = false +csharp_new_line_before_catch = false +csharp_new_line_before_members_in_object_initializers = true +csharp_preserve_single_line_statements = true diff --git a/7TVEmoteProvider.cs b/7TVEmoteProvider.cs index 0d74d80..5a70074 100644 --- a/7TVEmoteProvider.cs +++ b/7TVEmoteProvider.cs @@ -23,13 +23,13 @@ internal class SevenTVEmoticonFile public int width { get; set; } public int height { get; set; } } - + public List files { get; set; } } - + public SevenTVEmoticonHost host { get; set; } } - + public string name { get; set; } public int flags { get; set; } public SevenTVEmoticonData data { get; set; } @@ -39,17 +39,17 @@ private class SevenTVGlobalEmotes { public List emotes { get; set; } } - + private class SevenTVUserEmotes { internal class SevenTVEmoteSet { public List emotes { get; set; } } - + public SevenTVEmoteSet emote_set { get; set; } } - + public bool TryGetEmote(string Name, out SizeF Size) => EmoteCache.TryGetValue(Name, out Size); public async Task Initialize(string ChannelID, CancellationToken Token) diff --git a/BTTVEmoteProvider.cs b/BTTVEmoteProvider.cs index b4e2099..31d2c48 100644 --- a/BTTVEmoteProvider.cs +++ b/BTTVEmoteProvider.cs @@ -54,7 +54,7 @@ public async Task Initialize(string ChannelId, CancellationToken Token) var rawJson = await Client.GetAsync("https://api.betterttv.net/3/cached/emotes/global", Token); rawJson.EnsureSuccessStatusCode(); - + var globalEmotes = await JsonSerializer.DeserializeAsync>(await rawJson.Content.ReadAsStreamAsync()); void addToList(string Name, Stream EmoteStream) @@ -102,7 +102,8 @@ void fetchAllForList(IEnumerable Emotes) .Replace("module.exports = ", "") .Replace(";", "") .Replace("'", "\""); - var emojiBlacklist = JsonSerializer.Deserialize>(rawContents, new JsonSerializerOptions() { + var emojiBlacklist = JsonSerializer.Deserialize>(rawContents, new JsonSerializerOptions() + { ReadCommentHandling = JsonCommentHandling.Skip }); diff --git a/MessageHeightTwitch.cs b/MessageHeightTwitch.cs index cf042ea..3856048 100644 --- a/MessageHeightTwitch.cs +++ b/MessageHeightTwitch.cs @@ -9,8 +9,8 @@ namespace MessageHeightTwitch { - public class MessageHeightTwitch - { + public class MessageHeightTwitch + { public struct CharacterProperty { public float Width; @@ -56,7 +56,7 @@ public static void FillCharMap(string CharMapPath) } CharacterProperties = charProperties.ToArray(); - + Debug.Assert(broken); Debug.Assert(CharacterProperties['A'].Width == 8); Debug.Assert(CharacterProperties['@'].Width == 12.171875f); @@ -318,7 +318,7 @@ public float CalculateMessageHeightEx( var split = Regex.Split(Input, @"(?<=[ -])"); int curChar = 0; - for (int x = 0;x < split.Length;/* Increment is at the end of the loop */) { + for (int x = 0; x < split.Length;/* Increment is at the end of the loop */) { // Currently processing emote name string curEmoteName = null; // Currently processing emote provider @@ -389,7 +389,7 @@ bool tryGetEmote() // No dice, try to: curEmoteName = split[x].Substring(curChar); emojiMatch = EmojiRegex.Match(curEmoteName); - + // ...limit current lookup to first possible emoji if (emojiMatch.Success) curEmoteName = curEmoteName.Substring(0, emojiMatch.Index); @@ -552,7 +552,7 @@ bool tryGetEmote() if (split[x].Substring(curChar) != " ") prevEmote = null; - for (int oldCurChar = curChar;curChar < split[x].Length;curChar++) { + for (int oldCurChar = curChar; curChar < split[x].Length; curChar++) { if (emojiMatch.Success && emojiMatch.Index == curChar - oldCurChar) { if (!FFZIsEmojiSupported(split[x].Substring(curChar, emojiMatch.Length)) && !BTTVIsEmojiSupported(split[x].Substring(curChar, emojiMatch.Length))) { diff --git a/MessageHeightTwitchStatic.cs b/MessageHeightTwitchStatic.cs index 5d8278f..1b6cf85 100644 --- a/MessageHeightTwitchStatic.cs +++ b/MessageHeightTwitchStatic.cs @@ -4,7 +4,8 @@ class MessageHeightTwitchStatic { - public struct TwitchEmote { + public struct TwitchEmote + { public string Name; public string Url; } @@ -65,7 +66,7 @@ public static float CalculateMessageHeight(string Channel, string Input, string try { var dict = new Dictionary(); if (TwitchEmotes != null) { - for (int x = 0;x < TwitchEmotesLen * Marshal.SizeOf();x += Marshal.SizeOf()) { + for (int x = 0; x < TwitchEmotesLen * Marshal.SizeOf(); x += Marshal.SizeOf()) { var te = Marshal.PtrToStructure(new IntPtr(TwitchEmotes.ToInt64() + x)); dict.Add(te.Name, te.Url); }