Skip to content

Commit

Permalink
* fix some violations of ReSharper inspections
Browse files Browse the repository at this point in the history
* remove two overrides over inspection which is enabled by default and silent `resharper_move_local_function_after_jump_statement_highlighting` @ .editorconfig
@ c#
* lower the input `minimumReportSeverity` of `muno92/resharper_inspectcode` @ .github/workflows/c#.yml
  • Loading branch information
n0099 committed Mar 24, 2024
1 parent 3124903 commit 40bf7da
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 27 deletions.
1 change: 1 addition & 0 deletions .github/workflows/c#.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:

- uses: muno92/resharper_inspectcode@v1
with:
minimumReportSeverity: info
solutionPath: c#/tbm.sln
cachesHome: ${{ github.workspace }}/.resharper

Expand Down
3 changes: 1 addition & 2 deletions c#/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggest
# https://youtrack.jetbrains.com/issue/RSRP-463998
resharper_arrange_constructor_or_destructor_body_highlighting = none
resharper_arrange_method_or_operator_body_highlighting = none
resharper_arrange_object_creation_when_type_not_evident_highlighting = suggestion
resharper_arrange_redundant_parentheses_highlighting = hint
resharper_arrange_this_qualifier_highlighting = hint
resharper_arrange_type_member_modifiers_highlighting = hint
Expand All @@ -137,12 +136,12 @@ resharper_enforce_lock_statement_braces_highlighting = warning
resharper_enforce_using_statement_braces_highlighting = warning
resharper_enforce_while_statement_braces_highlighting = warning
resharper_loop_can_be_partly_converted_to_query_highlighting = warning
resharper_redundant_base_qualifier_highlighting = warning
resharper_remove_redundant_braces_highlighting = warning
resharper_suggest_var_or_type_built_in_types_highlighting = hint
resharper_suggest_var_or_type_elsewhere_highlighting = hint
resharper_suggest_var_or_type_simple_types_highlighting = hint
resharper_entity_framework_model_validation_unlimited_string_length_highlighting = none
resharper_move_local_function_after_jump_statement_highlighting = none

###############################
# .NET Coding Conventions #
Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/Db/CrawlerDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public CrawlerDbContext() : this(fid: 0) { }
public DbSet<ReplyPost> Replies => Set<ReplyPost>();
public DbSet<ReplySignature> ReplySignatures => Set<ReplySignature>();
public DbSet<ReplyContent> ReplyContents => Set<ReplyContent>();
public DbSet<SubReplyPost> SubReplies => Set<SubReplyPost>();
public DbSet<SubReplyContent> SubReplyContents => Set<SubReplyContent>();
public DbSet<Forum> Forums => Set<Forum>();

Expand All @@ -36,6 +35,7 @@ public void TimestampingEntities() =>
var updatedAtProp = e.Property(ie => ie.UpdatedAt);
var lastSeenAtProp = e.Entity is IPost ? e.Property(ie => ((IPost)ie).LastSeenAt) : null;
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
switch (originalEntityState)
{ // mutates Entry.CurrentValue will always update Entry.IsModified
// and the value of corresponding field in entity class instance
Expand Down
1 change: 1 addition & 0 deletions c#/crawler/src/Db/Post/IPostWithAuthorExpGrade.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ReSharper disable UnusedMemberInSuper.Global
namespace tbm.Crawler.Db.Post;

public interface IPostWithAuthorExpGrade
Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static IEnumerable<Exception> GetInnerExceptions(this Exception ex)
} while (inner != null);
}

public static void SetIfNotNull<T1, T2>(this IDictionary<T1, T2> dict, T1 key, T2? value)
public static void SetIfNotNull<T1, T2>(this IDictionary<T1, T2> dict, T1 key, T2? value) where T2 : class
{
if (value != null) dict[key] = value;
}
Expand Down
17 changes: 7 additions & 10 deletions c#/crawler/src/SonicPusher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public float PushPost(Fid fid, string type, PostId id, RepeatedField<Content>? c
.Trim()

// https://github.com/spikensbror-dotnet/nsonic/pull/10
.Replace("\\", "\\\\").Replace("\n", "\\n").Replace("\"", "\\\"");
.Replace("\\", @"\\").Replace("\n", "\\n").Replace("\"", "\\\"");
if (contentTexts == "") return GetElapsedMs();

try
Expand Down Expand Up @@ -72,16 +72,13 @@ public void PushPostWithCancellationToken<T>(
_ = PushPost(fid, postType, postIdSelector(p), postContentSelector(p));
}
}
catch (OperationCanceledException e)
catch (OperationCanceledException e) when (e.CancellationToken == stoppingToken)
{
if (e.CancellationToken == stoppingToken)
{
string GetBase64EncodedPostContent(T p) =>
Convert.ToBase64String(Helper.WrapPostContent(postContentSelector(p))
?.ToByteArray() ?? ReadOnlySpan<byte>.Empty);
File.AppendAllLines(ResumeSuspendPostContentsPushingWorker.GetFilePath(postType),
posts.Select(p => $"{fid},{postIdSelector(p)},{GetBase64EncodedPostContent(p)}"));
}
string GetBase64EncodedPostContent(T p) =>
Convert.ToBase64String(Helper.WrapPostContent(postContentSelector(p))
?.ToByteArray() ?? ReadOnlySpan<byte>.Empty);
File.AppendAllLines(ResumeSuspendPostContentsPushingWorker.GetFilePath(postType),
posts.Select(p => $"{fid},{postIdSelector(p)},{GetBase64EncodedPostContent(p)}"));
throw;
}
finally
Expand Down
1 change: 1 addition & 0 deletions c#/crawler/src/Tieba/ClientRequester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private async Task<HttpResponseMessage> Post(
var ret = responseTaskFactory(http);
_ = ret.ContinueWith(task =>
{
// ReSharper disable once MergeIntoPattern
if (task.IsCompletedSuccessfully && task.Result.IsSuccessStatusCode) requesterTcs.Increase();
else requesterTcs.Decrease();
}, stoppingToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
Expand Down
15 changes: 7 additions & 8 deletions c#/crawler/src/Tieba/Crawl/Crawler/ReplyCrawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@ public override IList<Reply> GetValidPosts(ReplyResponse response, CrawlRequestF
var ret = EnsureNonEmptyPostList(response,
"Reply list is empty, posts might already deleted from tieba.");
var fidInResponse = response.Data.Forum.Id;
if (fidInResponse != fid)
{ // fid will be the protoBuf default value 0 when reply list is empty, so we EnsureNonEmptyPostList() by first
var message = $"Parent forum id within thread response: {fidInResponse} is not match with the param value of"
+ $" crawler ctor: {fid}, this thread might be multi forum or \"livepost\" thread.";
throw new TiebaException(shouldRetry: false, message);
}
return ret;
if (fidInResponse == fid) return ret;

// fid will be the protoBuf default value 0 when reply list is empty, so we EnsureNonEmptyPostList() by first
var message = $"Parent forum id within thread response: {fidInResponse} is not match with the param value of"
+ $" crawler ctor: {fid}, this thread might be multi forum or \"livepost\" thread.";
throw new TiebaException(shouldRetry: false, message);
}

public override TbClient.Page GetResponsePage(ReplyResponse response) => response.Data.Page;
protected override RepeatedField<Reply> GetResponsePostList(ReplyResponse response) => response.Data.PostList;
protected override int GetResponseErrorCode(ReplyResponse response) => response.Error.Errorno;
protected override IEnumerable<Request> GetRequestsForPage(Page page, CancellationToken stoppingToken = default) =>
[
new Request(Requester.RequestProtoBuf("c/f/pb/page?cmd=302001", "12.26.1.0",
new(Requester.RequestProtoBuf("c/f/pb/page?cmd=302001", "12.26.1.0",
new ReplyRequest {Data = new()
{ // reverse order will be {"last", "1"}, {"r", "1"}
Kz = (long)tid,
Expand Down
2 changes: 1 addition & 1 deletion c#/crawler/src/Tieba/Crawl/Crawler/SubReplyCrawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override IList<SubReply> GetValidPosts(SubReplyResponse response, CrawlRe
protected override int GetResponseErrorCode(SubReplyResponse response) => response.Error.Errorno;
protected override IEnumerable<Request> GetRequestsForPage(Page page, CancellationToken stoppingToken = default) =>
[
new Request(Requester.RequestProtoBuf("c/f/pb/floor?cmd=302002", "12.26.1.0",
new(Requester.RequestProtoBuf("c/f/pb/floor?cmd=302002", "12.26.1.0",
new SubReplyRequest {Data = new()
{
Kz = (long)tid,
Expand Down
4 changes: 2 additions & 2 deletions c#/crawler/src/Tieba/Crawl/Crawler/ThreadArchiveCrawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ protected override IEnumerable<Request> GetRequestsForPage(Page page, Cancellati
() => new ThreadResponse(), stoppingToken);
return
[ // passing CrawlRequestFlag.ThreadClientVersion602 in the second one in order to invokes ThreadParser.ShouldSkipParse()
new Request(response),
new Request(response, CrawlRequestFlag.ThreadClientVersion602)
new(response),
new(response, CrawlRequestFlag.ThreadClientVersion602)
];
}
}
4 changes: 2 additions & 2 deletions c#/crawler/src/Tieba/Crawl/Crawler/ThreadCrawler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ protected override IEnumerable<Request> GetRequestsForPage(Page page, Cancellati
};
return
[
new Request(Requester.RequestProtoBuf(EndPointUrl, "12.26.1.0",
new(Requester.RequestProtoBuf(EndPointUrl, "12.26.1.0",
new ThreadRequest {Data = data},
(req, common) => req.Data.Common = common,
() => new ThreadResponse(), stoppingToken)),
new Request(Requester.RequestProtoBuf(LegacyEndPointUrl, "6.0.2",
new(Requester.RequestProtoBuf(LegacyEndPointUrl, "6.0.2",
new ThreadRequest {Data = data602},
(req, common) => req.Data.Common = common,
() => new ThreadResponse(), stoppingToken), CrawlRequestFlag.ThreadClientVersion602)
Expand Down
1 change: 1 addition & 0 deletions c#/imagePipeline/src/Consumer/MetadataConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private Func<ImageWithBytes, ImageMetadata> GetImageMetaData
IEnumerable<ulong> commonXxHash3ToIgnore,
TImageSharpProfile? profile,
Func<TImageSharpProfile, byte[]?> rawBytesSelector)
where TImageSharpProfile : class
where TEmbeddedMetadata : class, ImageMetadata.IEmbedded, new()
{
if (profile == null) return null;
Expand Down

0 comments on commit 40bf7da

Please sign in to comment.