From 2028d24befd7ec74bcc2e16fd6229654ea5961be Mon Sep 17 00:00:00 2001 From: n0099 Date: Tue, 26 Mar 2024 20:21:31 +0800 Subject: [PATCH] * 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 --- .github/workflows/c#.yml | 4 ++-- c#/GlobalSuppressions.cs | 10 ++++++++++ c#/crawler/src/Db/CrawlerDbContext.cs | 8 ++++---- c#/crawler/src/Db/Revision/RevisionWithSplitting.cs | 2 +- c#/crawler/src/Helper.cs | 2 ++ c#/crawler/src/Tieba/ClientRequester.cs | 4 ++++ c#/crawler/src/Tieba/Crawl/Facade/BaseCrawlFacade.cs | 3 ++- .../Worker/ResumeSuspendPostContentsPushingWorker.cs | 3 ++- c#/imagePipeline/src/Db/ImageMetadata.cs | 1 + c#/imagePipeline/src/Db/ImagePipelineDbContext.cs | 3 +-- 10 files changed, 29 insertions(+), 11 deletions(-) diff --git a/.github/workflows/c#.yml b/.github/workflows/c#.yml index 8332141f..855a51f4 100644 --- a/.github/workflows/c#.yml +++ b/.github/workflows/c#.yml @@ -32,8 +32,8 @@ jobs: path: | ${{ github.workspace }}/.resharper ~/.dotnet/tools - key: ${{ runner.os }}-resharper-${{ hashFiles('c#/**/*') }} - restore-keys: ${{ runner.os }}-nuget- + key: ${{ runner.os }}-resharper + restore-keys: ${{ runner.os }}-resharper- - uses: muno92/resharper_inspectcode@v1 with: diff --git a/c#/GlobalSuppressions.cs b/c#/GlobalSuppressions.cs index ce490629..5f4d8c51 100644 --- a/c#/GlobalSuppressions.cs +++ b/c#/GlobalSuppressions.cs @@ -33,6 +33,16 @@ [assembly: SuppressMessage("Maintainability", "AV1537:If-else-if construct should end with an unconditional else clause")] [assembly: SuppressMessage("Maintainability", "AV1554:Method contains optional parameter in type hierarchy")] [assembly: SuppressMessage("Maintainability", "AV1564:Parameter in public or internal member is of type bool or bool?")] +[assembly: SuppressMessage("Class Design", "AV1010:Member hides inherited member")] +[assembly: SuppressMessage("Maintainability", "AV1562:Do not declare a parameter as ref or out")] +[assembly: SuppressMessage("Maintainability", "AV1532:Loop statement contains nested loop")] +[assembly: SuppressMessage("Design", "CC0091:Use static method", Justification = "https://github.com/code-cracker/code-cracker/issues/1087")] +[assembly: SuppressMessage("Usage", "MA0015:Specify the parameter name in ArgumentException")] +[assembly: SuppressMessage("Class Design", "AV1008:Class should not be static")] +[assembly: SuppressMessage("Framework", "AV2220:Simple query should be replaced by extension method call")] +[assembly: SuppressMessage("Style", "CC0001:You should use 'var' whenever possible.")] +[assembly: SuppressMessage("Style", "CC0037:Remove commented code.")] +[assembly: SuppressMessage("Documentation", "AV2305:Missing XML comment for internally visible type, member or parameter")] [assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:Prefix local calls with this")] [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented")] diff --git a/c#/crawler/src/Db/CrawlerDbContext.cs b/c#/crawler/src/Db/CrawlerDbContext.cs index 973bdffe..fa8c7afb 100644 --- a/c#/crawler/src/Db/CrawlerDbContext.cs +++ b/c#/crawler/src/Db/CrawlerDbContext.cs @@ -74,22 +74,22 @@ protected override void OnModelCreating(ModelBuilder b) b.Entity().ToTable($"tbmc_f{Fid}_subReply"); b.Entity().ToTable($"tbmc_f{Fid}_subReply_content"); - var thread = new RevisionWithSplitting.ModelBuilderHelper(b, "tbmcr_thread"); + var thread = new RevisionWithSplitting.ModelBuilderExtension(b, "tbmcr_thread"); thread.HasKey(e => new {e.Tid, e.TakenAt}); thread.SplittingHasKeyAndName("viewCount", e => new {e.Tid, e.TakenAt}); - var reply = new RevisionWithSplitting.ModelBuilderHelper(b, "tbmcr_reply"); + var reply = new RevisionWithSplitting.ModelBuilderExtension(b, "tbmcr_reply"); reply.HasKey(e => new {e.Pid, e.TakenAt}); reply.SplittingHasKeyAndName("agreeCount", e => new {e.Pid, e.TakenAt}); reply.SplittingHasKeyAndName("subReplyCount", e => new {e.Pid, e.TakenAt}); reply.SplittingHasKeyAndName("floor", e => new {e.Pid, e.TakenAt}); - var subReply = new RevisionWithSplitting.ModelBuilderHelper(b, "tbmcr_subReply"); + var subReply = new RevisionWithSplitting.ModelBuilderExtension(b, "tbmcr_subReply"); subReply.HasKey(e => new {e.Spid, e.TakenAt}); subReply.SplittingHasKeyAndName("agreeCount", e => new {e.Spid, e.TakenAt}); subReply.SplittingHasKeyAndName("disagreeCount", e => new {e.Spid, e.TakenAt}); - var user = new RevisionWithSplitting.ModelBuilderHelper(b, "tbmcr_user"); + var user = new RevisionWithSplitting.ModelBuilderExtension(b, "tbmcr_user"); user.HasKey(e => new {e.Uid, e.TakenAt}); user.SplittingHasKeyAndName("ipGeolocation", e => new {e.Uid, e.TakenAt}); user.SplittingHasKeyAndName("portraitUpdatedAt", e => new {e.Uid, e.TakenAt}); diff --git a/c#/crawler/src/Db/Revision/RevisionWithSplitting.cs b/c#/crawler/src/Db/Revision/RevisionWithSplitting.cs index 62b6d5c8..9a3899df 100644 --- a/c#/crawler/src/Db/Revision/RevisionWithSplitting.cs +++ b/c#/crawler/src/Db/Revision/RevisionWithSplitting.cs @@ -26,7 +26,7 @@ protected void SetSplitEntityValue SplitEntities[typeof(TSplitEntity)] = entityFactory(); } - public class ModelBuilderHelper(ModelBuilder builder, string baseTableName) + public class ModelBuilderExtension(ModelBuilder builder, string baseTableName) { public void HasKey(Expression> keySelector) where TRevision : class, TBaseRevision => diff --git a/c#/crawler/src/Helper.cs b/c#/crawler/src/Helper.cs index c4297461..0c4bad65 100644 --- a/c#/crawler/src/Helper.cs +++ b/c#/crawler/src/Helper.cs @@ -3,7 +3,9 @@ namespace tbm.Crawler; +#pragma warning disable AV1708 // Type name contains term that should be avoided public abstract partial class Helper +#pragma warning restore AV1708 // Type name contains term that should be avoided { public static byte[]? SerializedProtoBufOrNullIfEmpty(IMessage? protoBuf) => protoBuf == null || protoBuf.CalculateSize() == 0 ? null : protoBuf.ToByteArray(); diff --git a/c#/crawler/src/Tieba/ClientRequester.cs b/c#/crawler/src/Tieba/ClientRequester.cs index 57be4e57..f0e4edf1 100644 --- a/c#/crawler/src/Tieba/ClientRequester.cs +++ b/c#/crawler/src/Tieba/ClientRequester.cs @@ -153,10 +153,14 @@ private async Task Post( await requesterTcs.Wait(stoppingToken); if (_config.GetValue("LogTrace", false)) logTraceAction(); var ret = responseTaskFactory(http); +#pragma warning disable AV2235 // Call to Task.ContinueWith should be replaced with an await expression _ = ret.ContinueWith(task => +#pragma warning restore AV2235 // Call to Task.ContinueWith should be replaced with an await expression { // ReSharper disable once MergeIntoPattern +#pragma warning disable SS034 // Use await to get the result of an asynchronous operation if (task.IsCompletedSuccessfully && task.Result.IsSuccessStatusCode) requesterTcs.Increase(); +#pragma warning restore SS034 // Use await to get the result of an asynchronous operation else requesterTcs.Decrease(); }, stoppingToken, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); return await ret; diff --git a/c#/crawler/src/Tieba/Crawl/Facade/BaseCrawlFacade.cs b/c#/crawler/src/Tieba/Crawl/Facade/BaseCrawlFacade.cs index ac85c3e9..8536df1f 100644 --- a/c#/crawler/src/Tieba/Crawl/Facade/BaseCrawlFacade.cs +++ b/c#/crawler/src/Tieba/Crawl/Facade/BaseCrawlFacade.cs @@ -1,7 +1,8 @@ namespace tbm.Crawler.Tieba.Crawl.Facade; -[SuppressMessage("Major Code Smell", "S3881:\"IDisposable\" should be implemented correctly")] +#pragma warning disable S3881 // "IDisposable" should be implemented correctly public abstract class BaseCrawlFacade( +#pragma warning restore S3881 // "IDisposable" should be implemented correctly BaseCrawler crawler, BaseParser parser, Func, BaseSaver> saverFactory, diff --git a/c#/crawler/src/Worker/ResumeSuspendPostContentsPushingWorker.cs b/c#/crawler/src/Worker/ResumeSuspendPostContentsPushingWorker.cs index ec4cc987..6227141b 100644 --- a/c#/crawler/src/Worker/ResumeSuspendPostContentsPushingWorker.cs +++ b/c#/crawler/src/Worker/ResumeSuspendPostContentsPushingWorker.cs @@ -8,15 +8,16 @@ public class ResumeSuspendPostContentsPushingWorker( public static string GetFilePath(string postType) => Path.Combine(AppContext.BaseDirectory, $"suspendPostContentsPushIntoSonic.{postType}.csv"); - [SuppressMessage("Reliability", "CA2021:Do not call Enumerable.Cast or Enumerable.OfType with incompatible types", Justification = "https://github.com/dotnet/roslyn-analyzers/issues/7031")] protected override Task DoWork(CancellationToken stoppingToken) { foreach (var postType in new[] {"replies", "subReplies"}) { var path = GetFilePath(postType); if (!File.Exists(path)) continue; +#pragma warning disable CA2021 // Do not call Enumerable.Cast or Enumerable.OfType with incompatible types var postTuples = File.ReadLines(path).Select(ParseLine) .OfType<(Fid Fid, PostId Id, string Content)>().ToList(); +#pragma warning restore CA2021 // https://github.com/dotnet/roslyn-analyzers/issues/7031 postTuples.GroupBy(t => t.Fid).ForEach(g => pusher.PushPostWithCancellationToken(g.ToList(), g.Key, postType, t => t.Id, t => Helper.ParseThenUnwrapPostContent(Convert.FromBase64String(t.Content)), diff --git a/c#/imagePipeline/src/Db/ImageMetadata.cs b/c#/imagePipeline/src/Db/ImageMetadata.cs index 4349faee..da9b4134 100644 --- a/c#/imagePipeline/src/Db/ImageMetadata.cs +++ b/c#/imagePipeline/src/Db/ImageMetadata.cs @@ -48,6 +48,7 @@ public class ByteSize : IImageMetadata public class Exif : IEmbedded { + [SuppressMessage("ApiDesign", "SS039:An enum should specify a default value")] public enum ExifOrientation { // https://magnushoff.com/articles/jpeg-orientation/ Horizontal = 1, diff --git a/c#/imagePipeline/src/Db/ImagePipelineDbContext.cs b/c#/imagePipeline/src/Db/ImagePipelineDbContext.cs index 92177c5d..e6c7abbb 100644 --- a/c#/imagePipeline/src/Db/ImagePipelineDbContext.cs +++ b/c#/imagePipeline/src/Db/ImagePipelineDbContext.cs @@ -22,7 +22,7 @@ public ImagePipelineDbContext() : this(fid: 0, script: "") { } protected override void OnConfiguringMysql(MySqlDbContextOptionsBuilder builder) => builder.UseNetTopologySuite(); -#pragma warning disable IDE0058 // Expression value is never used + [SuppressMessage("Style", "IDE0058:Expression value is never used")] protected override void OnModelCreating(ModelBuilder b) { base.OnModelCreating(b); @@ -56,7 +56,6 @@ void SplitImageMetadata SplitImageMetadata(e => e.GifMetadata, "gif"); SplitImageMetadata(e => e.BmpMetadata, "bmp"); } -#pragma warning restore IDE0058 // Expression value is never used public class ModelCacheKeyFactory : IModelCacheKeyFactory { // https://stackoverflow.com/questions/51864015/entity-framework-map-model-class-to-table-at-run-time/51899590#51899590