Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed IDE warnings #8

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions Bot/Coc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,76 @@

namespace Hyperstellar;

internal class Coc

Check notice on line 6 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[ClassNeverInstantiated.Global] Class 'Coc' is never instantiated" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(6,88)

Check warning on line 6 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[CA1852] Type 'Coc' can be sealed because it has no subtypes in its containing assembly and is not externally visible" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(6,88)
{
private class ClanUtil

Check warning on line 8 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / build

Type 'ClanUtil' can be sealed because it has no subtypes in its containing assembly and is not externally visible (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852)

Check warning on line 8 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[CA1852] Type 'ClanUtil' can be sealed because it has no subtypes in its containing assembly and is not externally visible" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(8,112)
{
internal readonly Clan Clan;
internal readonly Dictionary<string, ClanMember> Members = [];
internal readonly Dictionary<string, ClanMember> ExistingMembers = [];
internal readonly Dictionary<string, ClanMember> JoiningMembers = [];
internal readonly Dictionary<string, ClanMember> LeavingMembers;
internal readonly Clan _clan;

Check warning on line 10 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[NotAccessedField.Local] Field '_clan' is assigned but its value is never used" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(10,158)
internal readonly Dictionary<string, ClanMember> _members = [];
internal readonly Dictionary<string, ClanMember> _existingMembers = [];
internal readonly Dictionary<string, ClanMember> _joiningMembers = [];

Check notice on line 13 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[MemberCanBePrivate.Local] Field '_joiningMembers' can be made private" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(13,325)

Check warning on line 13 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[CollectionNeverQueried.Local] Content of collection '_joiningMembers' is only updated but never used" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(13,374)
internal readonly Dictionary<string, ClanMember> _leavingMembers;

Check notice on line 14 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[MemberCanBePrivate.Local] Field '_leavingMembers' can be made private" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(14,404)

internal ClanUtil(Clan clan)
{
LeavingMembers = s_prevClan.Members;
_leavingMembers = s_prevClan._members;
foreach (ClanMember member in clan.MemberList!)
{
Members[member.Tag] = member;
_members[member.Tag] = member;
if (s_prevClan.HasMember(member))
{
ExistingMembers[member.Tag] = member;
LeavingMembers.Remove(member.Tag);
_existingMembers[member.Tag] = member;
_ = _leavingMembers.Remove(member.Tag);
}
else
{
JoiningMembers[member.Tag] = member;
_joiningMembers[member.Tag] = member;
}
}
Clan = clan;
_clan = clan;
}

internal ClanUtil(Clan clan, bool init)

Check warning on line 35 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[UnusedParameter.Local] Parameter 'init' is never used" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(35,1103)
{
LeavingMembers = [];
_leavingMembers = [];
foreach (ClanMember member in clan.MemberList!)
{
Members[member.Tag] = member;
_members[member.Tag] = member;
}
Clan = clan;
_clan = clan;
}

internal bool HasMember(ClanMember member)
{
return Members.ContainsKey(member.Tag);
}
internal bool HasMember(ClanMember member) => _members.ContainsKey(member.Tag);

Check notice on line 45 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[MemberCanBePrivate.Local] Method 'HasMember' can be made private" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(45,1333)

Check notice on line 45 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[SuggestBaseTypeForParameter] Parameter can be of type 'ClashOfClans.Models.Identity'" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(45,1357)
}

internal readonly struct DonationTuple(int donated, int received)
{
internal readonly int Donated = donated;
internal readonly int Received = received;
internal readonly int _donated = donated;
internal readonly int _received = received;
}

private const string ClanId = "#2QU2UCJJC";
internal static readonly ClashOfClansClient s_client = new(Secrets.Coc);

Check notice on line 55 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[MemberCanBePrivate.Global] Field 's_client' can be made private" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(55,1657)

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
private static ClanUtil s_prevClan;
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

private static async Task<Clan> GetClanAsync()
{
return await s_client.Clans.GetClanAsync(ClanId);
}
private static async Task<Clan> GetClanAsync() => await s_client.Clans.GetClanAsync(ClanId);

private static async Task PollAsync()
{
var clan = await GetClanAsync();
if (clan == null) return;
if (clan.MemberList == null) return;
Clan clan = await GetClanAsync();
if (clan == null)

Check warning on line 66 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract] Expression is always false according to nullable reference types' annotations" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(66,2254)
{
return;
}

if (clan.MemberList == null)
{
return;
}

ClanUtil clanUtil = new(clan);
await CheckDonations(clanUtil);
s_prevClan = clanUtil;
Expand All @@ -79,13 +81,13 @@
private static async Task CheckDonations(ClanUtil clan)
{
Dictionary<string, DonationTuple> donationsDelta = [];
foreach (string tag in clan.ExistingMembers.Keys)
foreach (string tag in clan._existingMembers.Keys)
{
ClanMember current = clan.Members[tag];
ClanMember previous = s_prevClan.Members[tag];
ClanMember current = clan._members[tag];
ClanMember previous = s_prevClan._members[tag];
if (current.Donations > previous.Donations || current.DonationsReceived > previous.DonationsReceived)
{
donationsDelta[current.Name] = new(current.Donations - previous.Donations, current.DonationsReceived - previous.DonationsReceived);

Check notice on line 90 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[ArrangeObjectCreationWhenTypeNotEvident] Missing type specification" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(90,2990)
}
}
if (donationsDelta.Count > 0)
Expand All @@ -94,10 +96,7 @@
}
}

internal static async Task InitAsync()
{
s_prevClan = new(await GetClanAsync(), true);
}
internal static async Task InitAsync() => s_prevClan = new(await GetClanAsync(), true);

Check notice on line 99 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[ArrangeObjectCreationWhenTypeNotEvident] Missing type specification" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(99,3304)

internal static async Task BotReadyAsync()
{
Expand All @@ -106,4 +105,4 @@
await PollAsync();
await Task.Delay(5000);
}
}

Check warning on line 108 in Bot/Coc.cs

View workflow job for this annotation

GitHub Actions / inspect

"[FunctionNeverReturns] Function never returns" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Coc.cs(108,3503)
Expand Down
4 changes: 2 additions & 2 deletions Bot/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace Hyperstellar;

internal class Discord

Check warning on line 7 in Bot/Discord.cs

View workflow job for this annotation

GitHub Actions / build

Type 'Discord' can be sealed because it has no subtypes in its containing assembly and is not externally visible (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852)

Check notice on line 7 in Bot/Discord.cs

View workflow job for this annotation

GitHub Actions / inspect

"[ClassNeverInstantiated.Global] Class 'Discord' is never instantiated" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Discord.cs(7,112)

Check warning on line 7 in Bot/Discord.cs

View workflow job for this annotation

GitHub Actions / inspect

"[CA1852] Type 'Discord' can be sealed because it has no subtypes in its containing assembly and is not externally visible" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Discord.cs(7,112)
{
#if DEBUG
private const ulong BotLogId = 666431254312517633;
#else
const ulong BotLogId = 1099026457268863017;

Check warning on line 12 in Bot/Discord.cs

View workflow job for this annotation

GitHub Actions / build

Accessibility modifiers required (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0040)
#endif
private static readonly DiscordSocketClient s_bot = new();

Expand All @@ -26,7 +26,7 @@
private static Task Ready()
{
s_botLog = (SocketTextChannel)s_bot.GetChannel(BotLogId);
Task.Run(BotReadyAsync);

Check warning on line 29 in Bot/Discord.cs

View workflow job for this annotation

GitHub Actions / build

Expression value is never used (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0058)

Check warning on line 29 in Bot/Discord.cs

View workflow job for this annotation

GitHub Actions / inspect

"[IDE0058] Expression value is never used" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Discord.cs(29,889)
return Task.CompletedTask;
}

Expand All @@ -42,9 +42,9 @@
{
string msg = "[DNT] ";
List<string> items = new(donationsDelta.Count / 2);
foreach (string name in donationsDelta.Keys)

Check notice on line 45 in Bot/Discord.cs

View workflow job for this annotation

GitHub Actions / inspect

"[ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator] Loop can be converted into LINQ-expression but another 'GetEnumerator' method will be used" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Discord.cs(45,1374)
{
int donated = donationsDelta[name].Donated;
int donated = donationsDelta[name]._donated;
if (donated > 0)
{
items.Add($"{name}: {donated}");
Expand All @@ -55,12 +55,12 @@
items.Clear();
foreach (string name in donationsDelta.Keys)
{
int received = donationsDelta[name].Received;
int received = donationsDelta[name]._received;
if (received > 0)
{
items.Add($"{name}: {received}");
}
}
msg += string.Join(", ", items);
await s_botLog.SendMessageAsync(msg);

Check warning on line 65 in Bot/Discord.cs

View workflow job for this annotation

GitHub Actions / build

Expression value is never used (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0058)

Check warning on line 65 in Bot/Discord.cs

View workflow job for this annotation

GitHub Actions / inspect

"[IDE0058] Expression value is never used" on /home/runner/work/Hyperstellar/Hyperstellar/Bot/Discord.cs(65,1979)
}
Expand Down
Loading