Skip to content

Commit 40bf7da

Browse files
committed
* fix some violations of ReSharper inspections
* 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
1 parent 3124903 commit 40bf7da

12 files changed

+26
-27
lines changed

.github/workflows/c#.yml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737

3838
- uses: muno92/resharper_inspectcode@v1
3939
with:
40+
minimumReportSeverity: info
4041
solutionPath: c#/tbm.sln
4142
cachesHome: ${{ github.workspace }}/.resharper
4243

c#/.editorconfig

+1-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggest
118118
# https://youtrack.jetbrains.com/issue/RSRP-463998
119119
resharper_arrange_constructor_or_destructor_body_highlighting = none
120120
resharper_arrange_method_or_operator_body_highlighting = none
121-
resharper_arrange_object_creation_when_type_not_evident_highlighting = suggestion
122121
resharper_arrange_redundant_parentheses_highlighting = hint
123122
resharper_arrange_this_qualifier_highlighting = hint
124123
resharper_arrange_type_member_modifiers_highlighting = hint
@@ -137,12 +136,12 @@ resharper_enforce_lock_statement_braces_highlighting = warning
137136
resharper_enforce_using_statement_braces_highlighting = warning
138137
resharper_enforce_while_statement_braces_highlighting = warning
139138
resharper_loop_can_be_partly_converted_to_query_highlighting = warning
140-
resharper_redundant_base_qualifier_highlighting = warning
141139
resharper_remove_redundant_braces_highlighting = warning
142140
resharper_suggest_var_or_type_built_in_types_highlighting = hint
143141
resharper_suggest_var_or_type_elsewhere_highlighting = hint
144142
resharper_suggest_var_or_type_simple_types_highlighting = hint
145143
resharper_entity_framework_model_validation_unlimited_string_length_highlighting = none
144+
resharper_move_local_function_after_jump_statement_highlighting = none
146145

147146
###############################
148147
# .NET Coding Conventions #

c#/crawler/src/Db/CrawlerDbContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public CrawlerDbContext() : this(fid: 0) { }
2121
public DbSet<ReplyPost> Replies => Set<ReplyPost>();
2222
public DbSet<ReplySignature> ReplySignatures => Set<ReplySignature>();
2323
public DbSet<ReplyContent> ReplyContents => Set<ReplyContent>();
24-
public DbSet<SubReplyPost> SubReplies => Set<SubReplyPost>();
2524
public DbSet<SubReplyContent> SubReplyContents => Set<SubReplyContent>();
2625
public DbSet<Forum> Forums => Set<Forum>();
2726

@@ -36,6 +35,7 @@ public void TimestampingEntities() =>
3635
var updatedAtProp = e.Property(ie => ie.UpdatedAt);
3736
var lastSeenAtProp = e.Entity is IPost ? e.Property(ie => ((IPost)ie).LastSeenAt) : null;
3837

38+
// ReSharper disable once SwitchStatementMissingSomeEnumCasesNoDefault
3939
switch (originalEntityState)
4040
{ // mutates Entry.CurrentValue will always update Entry.IsModified
4141
// and the value of corresponding field in entity class instance

c#/crawler/src/Db/Post/IPostWithAuthorExpGrade.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ReSharper disable UnusedMemberInSuper.Global
12
namespace tbm.Crawler.Db.Post;
23

34
public interface IPostWithAuthorExpGrade

c#/crawler/src/ExtensionMethods.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static IEnumerable<Exception> GetInnerExceptions(this Exception ex)
5555
} while (inner != null);
5656
}
5757

58-
public static void SetIfNotNull<T1, T2>(this IDictionary<T1, T2> dict, T1 key, T2? value)
58+
public static void SetIfNotNull<T1, T2>(this IDictionary<T1, T2> dict, T1 key, T2? value) where T2 : class
5959
{
6060
if (value != null) dict[key] = value;
6161
}

c#/crawler/src/SonicPusher.cs

+7-10
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public float PushPost(Fid fid, string type, PostId id, RepeatedField<Content>? c
3636
.Trim()
3737

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

4242
try
@@ -72,16 +72,13 @@ public void PushPostWithCancellationToken<T>(
7272
_ = PushPost(fid, postType, postIdSelector(p), postContentSelector(p));
7373
}
7474
}
75-
catch (OperationCanceledException e)
75+
catch (OperationCanceledException e) when (e.CancellationToken == stoppingToken)
7676
{
77-
if (e.CancellationToken == stoppingToken)
78-
{
79-
string GetBase64EncodedPostContent(T p) =>
80-
Convert.ToBase64String(Helper.WrapPostContent(postContentSelector(p))
81-
?.ToByteArray() ?? ReadOnlySpan<byte>.Empty);
82-
File.AppendAllLines(ResumeSuspendPostContentsPushingWorker.GetFilePath(postType),
83-
posts.Select(p => $"{fid},{postIdSelector(p)},{GetBase64EncodedPostContent(p)}"));
84-
}
77+
string GetBase64EncodedPostContent(T p) =>
78+
Convert.ToBase64String(Helper.WrapPostContent(postContentSelector(p))
79+
?.ToByteArray() ?? ReadOnlySpan<byte>.Empty);
80+
File.AppendAllLines(ResumeSuspendPostContentsPushingWorker.GetFilePath(postType),
81+
posts.Select(p => $"{fid},{postIdSelector(p)},{GetBase64EncodedPostContent(p)}"));
8582
throw;
8683
}
8784
finally

c#/crawler/src/Tieba/ClientRequester.cs

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ private async Task<HttpResponseMessage> Post(
155155
var ret = responseTaskFactory(http);
156156
_ = ret.ContinueWith(task =>
157157
{
158+
// ReSharper disable once MergeIntoPattern
158159
if (task.IsCompletedSuccessfully && task.Result.IsSuccessStatusCode) requesterTcs.Increase();
159160
else requesterTcs.Decrease();
160161
}, stoppingToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);

c#/crawler/src/Tieba/Crawl/Crawler/ReplyCrawler.cs

+7-8
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,20 @@ public override IList<Reply> GetValidPosts(ReplyResponse response, CrawlRequestF
1919
var ret = EnsureNonEmptyPostList(response,
2020
"Reply list is empty, posts might already deleted from tieba.");
2121
var fidInResponse = response.Data.Forum.Id;
22-
if (fidInResponse != fid)
23-
{ // fid will be the protoBuf default value 0 when reply list is empty, so we EnsureNonEmptyPostList() by first
24-
var message = $"Parent forum id within thread response: {fidInResponse} is not match with the param value of"
25-
+ $" crawler ctor: {fid}, this thread might be multi forum or \"livepost\" thread.";
26-
throw new TiebaException(shouldRetry: false, message);
27-
}
28-
return ret;
22+
if (fidInResponse == fid) return ret;
23+
24+
// fid will be the protoBuf default value 0 when reply list is empty, so we EnsureNonEmptyPostList() by first
25+
var message = $"Parent forum id within thread response: {fidInResponse} is not match with the param value of"
26+
+ $" crawler ctor: {fid}, this thread might be multi forum or \"livepost\" thread.";
27+
throw new TiebaException(shouldRetry: false, message);
2928
}
3029

3130
public override TbClient.Page GetResponsePage(ReplyResponse response) => response.Data.Page;
3231
protected override RepeatedField<Reply> GetResponsePostList(ReplyResponse response) => response.Data.PostList;
3332
protected override int GetResponseErrorCode(ReplyResponse response) => response.Error.Errorno;
3433
protected override IEnumerable<Request> GetRequestsForPage(Page page, CancellationToken stoppingToken = default) =>
3534
[
36-
new Request(Requester.RequestProtoBuf("c/f/pb/page?cmd=302001", "12.26.1.0",
35+
new(Requester.RequestProtoBuf("c/f/pb/page?cmd=302001", "12.26.1.0",
3736
new ReplyRequest {Data = new()
3837
{ // reverse order will be {"last", "1"}, {"r", "1"}
3938
Kz = (long)tid,

c#/crawler/src/Tieba/Crawl/Crawler/SubReplyCrawler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override IList<SubReply> GetValidPosts(SubReplyResponse response, CrawlRe
3333
protected override int GetResponseErrorCode(SubReplyResponse response) => response.Error.Errorno;
3434
protected override IEnumerable<Request> GetRequestsForPage(Page page, CancellationToken stoppingToken = default) =>
3535
[
36-
new Request(Requester.RequestProtoBuf("c/f/pb/floor?cmd=302002", "12.26.1.0",
36+
new(Requester.RequestProtoBuf("c/f/pb/floor?cmd=302002", "12.26.1.0",
3737
new SubReplyRequest {Data = new()
3838
{
3939
Kz = (long)tid,

c#/crawler/src/Tieba/Crawl/Crawler/ThreadArchiveCrawler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ protected override IEnumerable<Request> GetRequestsForPage(Page page, Cancellati
1212
() => new ThreadResponse(), stoppingToken);
1313
return
1414
[ // passing CrawlRequestFlag.ThreadClientVersion602 in the second one in order to invokes ThreadParser.ShouldSkipParse()
15-
new Request(response),
16-
new Request(response, CrawlRequestFlag.ThreadClientVersion602)
15+
new(response),
16+
new(response, CrawlRequestFlag.ThreadClientVersion602)
1717
];
1818
}
1919
}

c#/crawler/src/Tieba/Crawl/Crawler/ThreadCrawler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ protected override IEnumerable<Request> GetRequestsForPage(Page page, Cancellati
3737
};
3838
return
3939
[
40-
new Request(Requester.RequestProtoBuf(EndPointUrl, "12.26.1.0",
40+
new(Requester.RequestProtoBuf(EndPointUrl, "12.26.1.0",
4141
new ThreadRequest {Data = data},
4242
(req, common) => req.Data.Common = common,
4343
() => new ThreadResponse(), stoppingToken)),
44-
new Request(Requester.RequestProtoBuf(LegacyEndPointUrl, "6.0.2",
44+
new(Requester.RequestProtoBuf(LegacyEndPointUrl, "6.0.2",
4545
new ThreadRequest {Data = data602},
4646
(req, common) => req.Data.Common = common,
4747
() => new ThreadResponse(), stoppingToken), CrawlRequestFlag.ThreadClientVersion602)

c#/imagePipeline/src/Consumer/MetadataConsumer.cs

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ private Func<ImageWithBytes, ImageMetadata> GetImageMetaData
9393
IEnumerable<ulong> commonXxHash3ToIgnore,
9494
TImageSharpProfile? profile,
9595
Func<TImageSharpProfile, byte[]?> rawBytesSelector)
96+
where TImageSharpProfile : class
9697
where TEmbeddedMetadata : class, ImageMetadata.IEmbedded, new()
9798
{
9899
if (profile == null) return null;

0 commit comments

Comments
 (0)