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

♻️ Lot of analyser fixes #399

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

♻️ Lot of analyser fixes #399

wants to merge 1 commit into from

Conversation

ostorc
Copy link
Contributor

@ostorc ostorc commented Sep 19, 2022

Quite a lot of fixes from the analyzer. I have only used the most relevant ones. There was also one nullable warning (in Poll.cs).

Comment on lines 129 to +130
input = Regex.Replace(input ?? "", @"\p{C}+", string.Empty);
return input.Trim().Length == 0 ? defaultValue : input.Substring(0, Math.Min(input.Length, 30));
return input.Trim().Length == 0 ? defaultValue : input[..Math.Min(input.Length, 30)];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really cool. Feels like python :D

@@ -17,7 +17,7 @@ protected ActionResult Page(string message, int code)
{
Response.StatusCode = code;

bool success = code >= 200 && code < 300;
bool success = code is >= 200 and < 300;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wtf :D

Copy link
Contributor

@stepech stepech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perosnaly have no issues with changes, apart from that Mention removal method which is already hard to read, idk if it's a good idea to listen to IDE there. Otherwise very nice 👍

Comment on lines 32 to +34
var text = new StringBuilder("I picked: ");
var winNumber = random.Next(answers.Length);
var winner = answers[winNumber];
int winNumber = random.Next(answers.Length);
string winner = answers[winNumber];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You marked this change as inconsistent in PR #317 (here)


var response = new DiscordInteractionResponseBuilder()
.WithTitle($"New Warning for {ctx.TargetMember.DisplayName}")
.WithCustomId(modalId)
.AddComponents(new TextInputComponent("Reason:", reasonId, required: true));
await ctx.CreateResponseAsync(InteractionResponseType.Modal, response);

var numberOfWarnings = await _warningService.GetNumberOfWarnings(ctx.TargetUser.Id);
int numberOfWarnings = await _warningService.GetNumberOfWarnings(ctx.TargetUser.Id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same goes here link

}
catch (NotFoundException)
{}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this change increases readability. There is also duplicite code now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github changed it... This review was for the changes in the whole file StringExtensions.cs

return null;

return GetDto(reminder);
return reminder == null ? null : GetDto(reminder);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return reminder == null ? null : GetDto(reminder);
return reminder is null ? null : GetDto(reminder);

Comment on lines +12 to +16
int encLen = (input.Length + 1) * 3;
var enc = encLen <= 1024 ? stackalloc byte[encLen] : new byte[encLen];
Span<byte> bytes = stackalloc byte[256 / 8];

var len = Encoding.UTF8.GetBytes(input, enc);
int len = Encoding.UTF8.GetBytes(input, enc);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing diferent declaration types 😄

return null;

return GetDto(warning);
return warning == null ? null : GetDto(warning);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return warning == null ? null : GetDto(warning);
return warning is null ? null : GetDto(warning);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants