Skip to content

Commit

Permalink
misc cleanups from resharper inspections
Browse files Browse the repository at this point in the history
  • Loading branch information
adelikat committed Jan 14, 2024
1 parent c57c9ff commit 7c932bb
Show file tree
Hide file tree
Showing 37 changed files with 102 additions and 123 deletions.
4 changes: 2 additions & 2 deletions TASVideos.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public static class SiteGlobalConstants
The posts after this message will continue to apply to the submission.
";

public const string NewSubmissionPost = @"This topic is for the purpose of discussing ";
public const string PollQuestion = @"Vote: Did you like watching this movie? (Vote after watching!)";
public const string NewSubmissionPost = "This topic is for the purpose of discussing ";
public const string PollQuestion = "Vote: Did you like watching this movie? (Vote after watching!)";
public const string PollOptionYes = "Yes";
public const string PollOptionNo = "No";
public const string PollOptionsMeh = "Meh";
Expand Down
2 changes: 1 addition & 1 deletion TASVideos.Common/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private static string SplitCamelCaseInternal(this string? str)
: "";
}

private static readonly Regex SpaceRegex = new(@" +");
private static readonly Regex SpaceRegex = new(" +");
public static string RemoveAllSpaces(this string? str)
{
return SpaceRegex.Replace(str ?? "", "");
Expand Down
3 changes: 0 additions & 3 deletions TASVideos.Core/Dtos/RatingDto.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,19 @@ public async Task Post(IPostable post)

if (post.Type == PostType.Administrative)
{
if (post.Group == PostGroups.UserManagement)
{
channel = _settings.PrivateUserChannelId;
}
else
{
channel = _settings.PrivateChannelId;
}
channel = post.Group == PostGroups.UserManagement
? _settings.PrivateUserChannelId
: _settings.PrivateChannelId;
}
else
{
if (post.Group == PostGroups.Game)
{
channel = _settings.PublicGameChannelId;
}
else if (post.Group == PostGroups.Publication
|| post.Group == PostGroups.Submission
|| post.Group == PostGroups.UserFiles)
else if (post.Group is PostGroups.Publication
or PostGroups.Submission
or PostGroups.UserFiles)
{
channel = _settings.PublicTasChannelId;
}
Expand Down
3 changes: 1 addition & 2 deletions TASVideos.Data/Entity/Submission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ public static class SubmissionExtensions
{
public static bool CanPublish(this Submission submission)
{
return submission.SystemId > 0
&& submission.SystemFrameRateId > 0
return submission is { SystemId: > 0, SystemFrameRateId: > 0 }
&& submission.GameId > 0
&& submission.GameVersionId > 0
&& submission.IntendedClassId > 0
Expand Down
2 changes: 1 addition & 1 deletion TASVideos.Data/Entity/UserFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class UserFile
public virtual Game.Game? Game { get; set; }

public int? SystemId { get; set; }
public virtual Game.GameSystem? System { get; set; }
public virtual GameSystem? System { get; set; }

public bool Hidden { get; set; }

Expand Down
4 changes: 1 addition & 3 deletions TASVideos.Data/Helpers/SubmissionHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Microsoft.AspNetCore.Mvc.Rendering;

namespace TASVideos.Data.Helpers;
namespace TASVideos.Data.Helpers;

public static class SubmissionHelper
{
Expand Down
3 changes: 1 addition & 2 deletions TASVideos.ForumEngine/BbParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ private void ParseLoop()
if (_allowBb
&& ChildrenExpected()
&& (m = Url.Match(_input, _index)).Success
&& !_stack.Any(element => element.Name == "url")
)
&& _stack.All(element => element.Name != "url"))
{
FlushText();
Push(new Element { Name = "url" });
Expand Down
3 changes: 1 addition & 2 deletions TASVideos.Parsers/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ public static bool Bit(this byte b, int index)
var frames = 0;
var header = new List<string>();

string? line;
while ((line = await reader.ReadLineAsync()) is not null)
while (await reader.ReadLineAsync() is { } line)
{
if (line.StartsWith('|'))
{
Expand Down
1 change: 0 additions & 1 deletion TASVideos.Parsers/Parsers/Bk2.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Globalization;
using System.IO;

namespace TASVideos.MovieParsers.Parsers;

Expand Down
7 changes: 2 additions & 5 deletions TASVideos.Parsers/Parsers/Ltm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Globalization;
using System.Reflection;
using System.Text;
using SharpCompress.Readers;

Expand Down Expand Up @@ -50,8 +49,7 @@ public async Task<IParseResult> Parse(Stream file, long length)
switch (reader.Entry.Key)
{
case "config.ini":
string? s;
while ((s = await textReader.ReadLineAsync()) != null)
while (await textReader.ReadLineAsync() is { } s)
{
if (s.StartsWith(FrameCountHeader))
{
Expand Down Expand Up @@ -95,9 +93,8 @@ public async Task<IParseResult> Parse(Stream file, long length)

break;
case "annotations.txt":
string? line;
var sb = new StringBuilder();
while ((line = await textReader.ReadLineAsync()) != null)
while (await textReader.ReadLineAsync() is { } line)
{
if (line.ToLower().StartsWith("platform:"))
{
Expand Down
20 changes: 8 additions & 12 deletions TASVideos.Parsers/Parsers/Omr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,23 @@ public async Task<IParseResult> Parse(Stream file, long length)

result.Frames = (int)Math.Round(seconds * (result.Region == RegionType.Pal ? 50.1589758045661 : 59.9227510135505));

var version = "";

version = ((IEnumerable)replay.XPathEvaluate("//snapshots/item"))
.Cast<XElement>()
.Attributes()
.First(x => x.Name == "version")
.Value;
var version = ((IEnumerable)replay.XPathEvaluate("//snapshots/item"))
.Cast<XElement>()
.Attributes()
.First(x => x.Name == "version")
.Value;

var system = "";
string system;

if(Convert.ToInt16(version) >= 4)
{
var confversion = "";

confversion = ((IEnumerable)replay.XPathEvaluate("//snapshots/item/config"))
var confVersion = ((IEnumerable)replay.XPathEvaluate("//snapshots/item/config"))
.Cast<XElement>()
.Attributes()
.First(x => x.Name == "version")
.Value;

if(Convert.ToInt16(confversion) >= 6)
if(Convert.ToInt16(confVersion) >= 6)
{
system = ((IEnumerable)replay.XPathEvaluate("//snapshots/item/config/config/msxconfig/info"))
.Cast<XElement>()
Expand Down
5 changes: 5 additions & 0 deletions TASVideos.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<s:Boolean x:Key="/Default/CodeEditing/TypingAssist/FormatBlockOnRBrace/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeEditing/TypingAssist/FormatStatementOnSemicolon/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Browsers/Browsers/@EntryValue">C60+,E12+,FF41+,IE11+,O13+,S8+</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=B386F775_002D4453_002D4ADB_002D906F_002DF081FE8459EF_002Fd_003Awwwroot_002Fd_003Ajs_002Ff_003Adiff_005Fmatch_005Fpatch_002Ejs/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=B386F775_002D4453_002D4ADB_002D906F_002DF081FE8459EF_002Fd_003Awwwroot_002Fd_003Ajs_002Ff_003Adiff_005Fview_002Ejs/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/GeneratedFilesAndFolders/=B386F775_002D4453_002D4ADB_002D906F_002DF081FE8459EF_002Fd_003Awwwroot_002Fd_003Acss_002Ff_003Adiffview_002Ecss/@EntryIndexedValue">B386F775-4453-4ADB-906F-F081FE8459EF/d:wwwroot/d:css/f:diffview.css</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/GeneratedFilesAndFolders/=B386F775_002D4453_002D4ADB_002D906F_002DF081FE8459EF_002Fd_003Awwwroot_002Fd_003Acss_002Ff_003Aprism_002Ecss/@EntryIndexedValue">B386F775-4453-4ADB-906F-F081FE8459EF/d:wwwroot/d:css/f:prism.css</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/GeneratedFilesAndFolders/=B386F775_002D4453_002D4ADB_002D906F_002DF081FE8459EF_002Fd_003Awwwroot_002Fd_003Ajs_002Ff_003Adifflib_002Ejs/@EntryIndexedValue">B386F775-4453-4ADB-906F-F081FE8459EF/d:wwwroot/d:js/f:difflib.js</s:String>
Expand All @@ -12,6 +14,8 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeObjectCreationWhenTypeNotEvident/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeThisQualifier/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CoercedEqualsUsing/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CoercedEqualsUsingWithNullUndefined/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=Html_002EPathError/@EntryIndexedValue">HINT</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MissingHasOwnPropertyInForeach/@EntryIndexedValue">HINT</s:String>
Expand Down Expand Up @@ -158,6 +162,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Debouncer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dendy/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=deprecator/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Determinator/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=difflib/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=diffview/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=diskinfo/@EntryIndexedValue">True</s:Boolean>
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Extensions/EntityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public static IQueryable<PublicationDisplayModel> ToViewModel(this IQueryable<Pu
Rating = new PublicationRateModel
{
Rating = p.PublicationRatings.Where(pr => pr.UserId == userId).Select(pr => pr.Value.ToString()).FirstOrDefault(),
Unrated = !p.PublicationRatings.Any(pr => pr.UserId == userId)
Unrated = p.PublicationRatings.All(pr => pr.UserId != userId)
},
});

Expand Down
12 changes: 5 additions & 7 deletions TASVideos/Pages/Account/Register.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,11 @@
@*For manual implementation of Google's ReCaptcha scripts, will require embedding site's public key.*@
<script src="https://www.google.com/recaptcha/api.js"></script>
<script>
{
// Autofill timezone if not set
if (!document.querySelector("#SelectedTimeZone option:checked").value) {
const timezoneOffset = 0 - new Date().getTimezoneOffset();
let timezone = document.querySelector(`[data-offset="${timezoneOffset}"]`);
timezone.setAttribute('selected', 'selected');
}
// Autofill timezone if not set
if (!document.querySelector("#SelectedTimeZone option:checked").value) {
const timezoneOffset = 0 - new Date().getTimezoneOffset();
let timezone = document.querySelector(`[data-offset="${timezoneOffset}"]`);
timezone.setAttribute('selected', 'selected');
}
</script>
}
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
if (displayClass) {
activitySubforum.classList.add(displayClass);
activitySubforum.classList.remove('d-none');
activitySubforum.parentElement.setAttribute('href', '/Forum/Posts/' + firstPostId);
activitySubforum.parentElement.setAttribute('href', `/Forum/Posts/${firstPostId}`);
}
}
Expand Down
10 changes: 5 additions & 5 deletions TASVideos/Pages/Forum/Subforum/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
{
<timezone-convert asp-for="@topic.LastPost.CreateTimestamp" /> <br />
<profile-link username="@topic.LastPost.PosterName"></profile-link>
<a href="/Forum/Posts/@topic.LastPost.Id" class="fa fa-arrow-circle-right" />
<a href="/Forum/Posts/@topic.LastPost.Id" class="fa fa-arrow-circle-right"></a>
}
</td>
</tr>
Expand Down Expand Up @@ -123,20 +123,20 @@
if (displayClass) {
activityTopic.classList.add(displayClass);
activityTopic.classList.remove('d-none');
activityTopic.parentElement.setAttribute('href', '/Forum/Posts/' + firstPostId);
activityTopic.parentElement.setAttribute('href', `/Forum/Posts/${firstPostId}`);
}
}
}
function markSubforumPostsRead(){
let visitedPosts = localStorage.getItem('VisitedPosts');
visitedPosts = JSON.parse(visitedPosts) ?? {};
let activityTopics = document.getElementsByClassName('activity-topic');
const activityTopics = document.getElementsByClassName('activity-topic');
for (let activityTopic of activityTopics) {
let activityPostsCreated = activityTopic.dataset.activityPostsCreated ? JSON.parse(activityTopic.dataset.activityPostsCreated) : {};
const activityPostsCreated = activityTopic.dataset.activityPostsCreated ? JSON.parse(activityTopic.dataset.activityPostsCreated) : {};
for (let postId in activityPostsCreated) {
visitedPosts[postId] = currentTime;
}
let activityPostsEdited = activityTopic.dataset.activityPostsEdited ? JSON.parse(activityTopic.dataset.activityPostsEdited) : {};
const activityPostsEdited = activityTopic.dataset.activityPostsEdited ? JSON.parse(activityTopic.dataset.activityPostsEdited) : {};
for (let postId in activityPostsEdited) {
visitedPosts[postId] = currentTime;
}
Expand Down
1 change: 0 additions & 1 deletion TASVideos/Pages/Forum/Topics/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@page "{id}"
@using TASVideos.Data.Helpers
@model IndexModel
@{
ViewData.SetTitle($"{Model.Topic.Title} - Topic {Model.Topic.Id}");
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/Topics/_PollCreate.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<fieldset>
<label asp-for="Question"></label>
<input condition="!restricted" type="text" asp-for="Question" class="form-control" />
<input condition="restricted" disabled placeholder="@Model!.Question" type="text" class="form-control" />
<input condition="restricted" disabled placeholder="@Model.Question" type="text" class="form-control" />
<span asp-validation-for="Question" class="text-danger"></span>
</fieldset>
<fieldset>
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Forum/_Category.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<card class="mb-2">
<cardheader>
<a permission="EditCategories" asp-page="Edit" asp-route-id="@Model!.Id" class="btn btn-primary btn-sm border border-warning float-end"><i class="fa fa-pencil"></i> Edit</a>
<a permission="EditCategories" asp-page="Edit" asp-route-id="@Model.Id" class="btn btn-primary btn-sm border border-warning float-end"><i class="fa fa-pencil"></i> Edit</a>
<h4>@Model.Title</h4>
@if (!string.IsNullOrWhiteSpace(Model.Description))
{
Expand Down
29 changes: 15 additions & 14 deletions TASVideos/Pages/Games/Versions/Edit.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -120,62 +120,63 @@
dropArea.classList.remove('border-secondary');
}
function calculateHashes(file) {
let sha1 = CryptoJS.algo.SHA1.create();
let md5 = CryptoJS.algo.MD5.create();
let fileSize = file.size;
let chunkSize = 16 * 1024 * 1024;
const sha1 = CryptoJS.algo.SHA1.create();
const md5 = CryptoJS.algo.MD5.create();
const fileSize = file.size;
const chunkSize = 16 * 1024 * 1024;
let offset = 0;
if (fileSize > chunkSize) {
hashProgress.style.width = '0%';
hashProgress.parentElement.classList.remove('d-none');
}
let reader = new FileReader();
const reader = new FileReader();
reader.onload = function () {
offset += reader.result.length;
sha1.update(CryptoJS.enc.Latin1.parse(reader.result));
md5.update(CryptoJS.enc.Latin1.parse(reader.result));
hashProgress.style.width = `${Math.ceil((offset / fileSize) * 100)}%`;
if (offset >= fileSize) {
let sha1hash = sha1.finalize();
let md5hash = md5.finalize();
sha1Input.value = sha1hash.toString(CryptoJS.enc.Hex);
md5Input.value = md5hash.toString(CryptoJS.enc.Hex);
const sha1Hash = sha1.finalize();
const md5Hash = md5.finalize();
sha1Input.value = sha1Hash.toString(CryptoJS.enc.Hex);
md5Input.value = md5Hash.toString(CryptoJS.enc.Hex);
setTimeout(() => { hashProgress.parentElement.classList.add('d-none'); }, 600);
return;
}
readNext();
};
function readNext() {
let fileSlice = file.slice(offset, offset + chunkSize);
const fileSlice = file.slice(offset, offset + chunkSize);
reader.readAsBinaryString(fileSlice);
}
readNext();
}
hashInput.addEventListener('change', (e) => {
calculateHashes(e.currentTarget.files[0]);
});
dropArea.addEventListener('click', (e) => {
dropArea.addEventListener('click', () => {
hashInput.click();
});
dropArea.addEventListener('dragover', (e) => {
e.preventDefault();
});
let dropCount = 0;
dropArea.addEventListener('dragenter', (e) => {
dropArea.addEventListener('dragenter', () => {
if (dropCount == 0) {
dropEnterStyle();
}
dropCount++;
});
dropArea.addEventListener('dragleave', (e) => {
dropArea.addEventListener('dragleave', () => {
dropCount--;
if (dropCount == 0) {
dropLeaveStyle();
}
})
});
dropArea.addEventListener('drop', (e) => {
e.preventDefault();
dropLeaveStyle();
Expand Down
2 changes: 1 addition & 1 deletion TASVideos/Pages/Publications/Filter.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@
|| gameGroups.selectedIndex >= 0
|| authors.selectedIndex >= 0
|| systemCodes.selectedIndex >= 0
|| tags.selectedIndex >= 0
|| tags.selectedIndex >= 0;
}
</script>
2 changes: 1 addition & 1 deletion TASVideos/Pages/Roles/_Role.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<label class="form-control-label">No users currently have this role.</label>
</div>
<div condition="Model.Users.Count > 100">
<i>@Model!.Users.Count Users (too many to display)</i>
<i>@Model.Users.Count Users (too many to display)</i>
</div>
<div condition="Model.Users.Any() && Model.Users.Count <= 100">
@foreach (var user in Model.Users)
Expand Down
Loading

0 comments on commit 7c932bb

Please sign in to comment.