Skip to content

Commit 2028d24

Browse files
committed
* rename nested class ModelBuilderHelper to ModelBuilderExtension to fix AV1708 @ RevisionWithSplitting.cs
* suppress other violations of Roslyn analyzer rules * replace some `$pragma warning (disable|restore)` with `[SuppressMessage]` attribute and vice versa for better limiting about its scope @ c# * always cache regardless of other file changes, this will prevent updating ReSharper tool as long as still using cache @ .github/workflows/c#.yml
1 parent 5100379 commit 2028d24

10 files changed

+29
-11
lines changed

.github/workflows/c#.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ jobs:
3232
path: |
3333
${{ github.workspace }}/.resharper
3434
~/.dotnet/tools
35-
key: ${{ runner.os }}-resharper-${{ hashFiles('c#/**/*') }}
36-
restore-keys: ${{ runner.os }}-nuget-
35+
key: ${{ runner.os }}-resharper
36+
restore-keys: ${{ runner.os }}-resharper-
3737

3838
- uses: muno92/resharper_inspectcode@v1
3939
with:

c#/GlobalSuppressions.cs

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
[assembly: SuppressMessage("Maintainability", "AV1537:If-else-if construct should end with an unconditional else clause")]
3434
[assembly: SuppressMessage("Maintainability", "AV1554:Method contains optional parameter in type hierarchy")]
3535
[assembly: SuppressMessage("Maintainability", "AV1564:Parameter in public or internal member is of type bool or bool?")]
36+
[assembly: SuppressMessage("Class Design", "AV1010:Member hides inherited member")]
37+
[assembly: SuppressMessage("Maintainability", "AV1562:Do not declare a parameter as ref or out")]
38+
[assembly: SuppressMessage("Maintainability", "AV1532:Loop statement contains nested loop")]
39+
[assembly: SuppressMessage("Design", "CC0091:Use static method", Justification = "https://github.com/code-cracker/code-cracker/issues/1087")]
40+
[assembly: SuppressMessage("Usage", "MA0015:Specify the parameter name in ArgumentException")]
41+
[assembly: SuppressMessage("Class Design", "AV1008:Class should not be static")]
42+
[assembly: SuppressMessage("Framework", "AV2220:Simple query should be replaced by extension method call")]
43+
[assembly: SuppressMessage("Style", "CC0001:You should use 'var' whenever possible.")]
44+
[assembly: SuppressMessage("Style", "CC0037:Remove commented code.")]
45+
[assembly: SuppressMessage("Documentation", "AV2305:Missing XML comment for internally visible type, member or parameter")]
3646

3747
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this")]
3848
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented")]

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,22 @@ protected override void OnModelCreating(ModelBuilder b)
7474
b.Entity<SubReplyPost>().ToTable($"tbmc_f{Fid}_subReply");
7575
b.Entity<SubReplyContent>().ToTable($"tbmc_f{Fid}_subReply_content");
7676

77-
var thread = new RevisionWithSplitting<BaseThreadRevision>.ModelBuilderHelper(b, "tbmcr_thread");
77+
var thread = new RevisionWithSplitting<BaseThreadRevision>.ModelBuilderExtension(b, "tbmcr_thread");
7878
thread.HasKey<ThreadRevision>(e => new {e.Tid, e.TakenAt});
7979
thread.SplittingHasKeyAndName<SplitViewCount>("viewCount", e => new {e.Tid, e.TakenAt});
8080

81-
var reply = new RevisionWithSplitting<BaseReplyRevision>.ModelBuilderHelper(b, "tbmcr_reply");
81+
var reply = new RevisionWithSplitting<BaseReplyRevision>.ModelBuilderExtension(b, "tbmcr_reply");
8282
reply.HasKey<ReplyRevision>(e => new {e.Pid, e.TakenAt});
8383
reply.SplittingHasKeyAndName<ReplyRevision.SplitAgreeCount>("agreeCount", e => new {e.Pid, e.TakenAt});
8484
reply.SplittingHasKeyAndName<SplitSubReplyCount>("subReplyCount", e => new {e.Pid, e.TakenAt});
8585
reply.SplittingHasKeyAndName<SplitFloor>("floor", e => new {e.Pid, e.TakenAt});
8686

87-
var subReply = new RevisionWithSplitting<BaseSubReplyRevision>.ModelBuilderHelper(b, "tbmcr_subReply");
87+
var subReply = new RevisionWithSplitting<BaseSubReplyRevision>.ModelBuilderExtension(b, "tbmcr_subReply");
8888
subReply.HasKey<SubReplyRevision>(e => new {e.Spid, e.TakenAt});
8989
subReply.SplittingHasKeyAndName<SubReplyRevision.SplitAgreeCount>("agreeCount", e => new {e.Spid, e.TakenAt});
9090
subReply.SplittingHasKeyAndName<SplitDisagreeCount>("disagreeCount", e => new {e.Spid, e.TakenAt});
9191

92-
var user = new RevisionWithSplitting<BaseUserRevision>.ModelBuilderHelper(b, "tbmcr_user");
92+
var user = new RevisionWithSplitting<BaseUserRevision>.ModelBuilderExtension(b, "tbmcr_user");
9393
user.HasKey<UserRevision>(e => new {e.Uid, e.TakenAt});
9494
user.SplittingHasKeyAndName<SplitIpGeolocation>("ipGeolocation", e => new {e.Uid, e.TakenAt});
9595
user.SplittingHasKeyAndName<SplitPortraitUpdatedAt>("portraitUpdatedAt", e => new {e.Uid, e.TakenAt});

c#/crawler/src/Db/Revision/RevisionWithSplitting.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected void SetSplitEntityValue<TSplitEntity, TValue>
2626
SplitEntities[typeof(TSplitEntity)] = entityFactory();
2727
}
2828

29-
public class ModelBuilderHelper(ModelBuilder builder, string baseTableName)
29+
public class ModelBuilderExtension(ModelBuilder builder, string baseTableName)
3030
{
3131
public void HasKey<TRevision>(Expression<Func<TRevision, object?>> keySelector)
3232
where TRevision : class, TBaseRevision =>

c#/crawler/src/Helper.cs

+2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
namespace tbm.Crawler;
55

6+
#pragma warning disable AV1708 // Type name contains term that should be avoided
67
public abstract partial class Helper
8+
#pragma warning restore AV1708 // Type name contains term that should be avoided
79
{
810
public static byte[]? SerializedProtoBufOrNullIfEmpty(IMessage? protoBuf) =>
911
protoBuf == null || protoBuf.CalculateSize() == 0 ? null : protoBuf.ToByteArray();

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

+4
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,14 @@ private async Task<HttpResponseMessage> Post(
153153
await requesterTcs.Wait(stoppingToken);
154154
if (_config.GetValue("LogTrace", false)) logTraceAction();
155155
var ret = responseTaskFactory(http);
156+
#pragma warning disable AV2235 // Call to Task.ContinueWith should be replaced with an await expression
156157
_ = ret.ContinueWith(task =>
158+
#pragma warning restore AV2235 // Call to Task.ContinueWith should be replaced with an await expression
157159
{
158160
// ReSharper disable once MergeIntoPattern
161+
#pragma warning disable SS034 // Use await to get the result of an asynchronous operation
159162
if (task.IsCompletedSuccessfully && task.Result.IsSuccessStatusCode) requesterTcs.Increase();
163+
#pragma warning restore SS034 // Use await to get the result of an asynchronous operation
160164
else requesterTcs.Decrease();
161165
}, stoppingToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
162166
return await ret;

c#/crawler/src/Tieba/Crawl/Facade/BaseCrawlFacade.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
namespace tbm.Crawler.Tieba.Crawl.Facade;
22

3-
[SuppressMessage("Major Code Smell", "S3881:\"IDisposable\" should be implemented correctly")]
3+
#pragma warning disable S3881 // "IDisposable" should be implemented correctly
44
public abstract class BaseCrawlFacade<TPost, TBaseRevision, TResponse, TPostProtoBuf>(
5+
#pragma warning restore S3881 // "IDisposable" should be implemented correctly
56
BaseCrawler<TResponse, TPostProtoBuf> crawler,
67
BaseParser<TPost, TPostProtoBuf> parser,
78
Func<ConcurrentDictionary<PostId, TPost>, BaseSaver<TPost, TBaseRevision>> saverFactory,

c#/crawler/src/Worker/ResumeSuspendPostContentsPushingWorker.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ public class ResumeSuspendPostContentsPushingWorker(
88
public static string GetFilePath(string postType) =>
99
Path.Combine(AppContext.BaseDirectory, $"suspendPostContentsPushIntoSonic.{postType}.csv");
1010

11-
[SuppressMessage("Reliability", "CA2021:Do not call Enumerable.Cast<T> or Enumerable.OfType<T> with incompatible types", Justification = "https://github.com/dotnet/roslyn-analyzers/issues/7031")]
1211
protected override Task DoWork(CancellationToken stoppingToken)
1312
{
1413
foreach (var postType in new[] {"replies", "subReplies"})
1514
{
1615
var path = GetFilePath(postType);
1716
if (!File.Exists(path)) continue;
17+
#pragma warning disable CA2021 // Do not call Enumerable.Cast<T> or Enumerable.OfType<T> with incompatible types
1818
var postTuples = File.ReadLines(path).Select(ParseLine)
1919
.OfType<(Fid Fid, PostId Id, string Content)>().ToList();
20+
#pragma warning restore CA2021 // https://github.com/dotnet/roslyn-analyzers/issues/7031
2021
postTuples.GroupBy(t => t.Fid).ForEach(g =>
2122
pusher.PushPostWithCancellationToken(g.ToList(), g.Key, postType, t => t.Id,
2223
t => Helper.ParseThenUnwrapPostContent(Convert.FromBase64String(t.Content)),

c#/imagePipeline/src/Db/ImageMetadata.cs

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class ByteSize : IImageMetadata
4848

4949
public class Exif : IEmbedded
5050
{
51+
[SuppressMessage("ApiDesign", "SS039:An enum should specify a default value")]
5152
public enum ExifOrientation
5253
{ // https://magnushoff.com/articles/jpeg-orientation/
5354
Horizontal = 1,

c#/imagePipeline/src/Db/ImagePipelineDbContext.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public ImagePipelineDbContext() : this(fid: 0, script: "") { }
2222

2323
protected override void OnConfiguringMysql(MySqlDbContextOptionsBuilder builder) => builder.UseNetTopologySuite();
2424

25-
#pragma warning disable IDE0058 // Expression value is never used
25+
[SuppressMessage("Style", "IDE0058:Expression value is never used")]
2626
protected override void OnModelCreating(ModelBuilder b)
2727
{
2828
base.OnModelCreating(b);
@@ -56,7 +56,6 @@ void SplitImageMetadata<TRelatedEntity>
5656
SplitImageMetadata(e => e.GifMetadata, "gif");
5757
SplitImageMetadata(e => e.BmpMetadata, "bmp");
5858
}
59-
#pragma warning restore IDE0058 // Expression value is never used
6059

6160
public class ModelCacheKeyFactory : IModelCacheKeyFactory
6261
{ // https://stackoverflow.com/questions/51864015/entity-framework-map-model-class-to-table-at-run-time/51899590#51899590

0 commit comments

Comments
 (0)